9 #include "math_macrotable.h"
10 #include "math_macro.h"
11 #include "math_macrotemplate.h"
13 #include "math_accentinset.h"
14 #include "math_deliminset.h"
15 #include "math_fracinset.h"
16 #include "math_parinset.h"
18 #include "support/LAssert.h"
23 MathMacroTable::table_type MathMacroTable::macro_table;
25 bool MathMacroTable::built = false;
28 void MathMacroTable::dump()
32 cerr << "\n------------------------------------------\n";
33 table_type::const_iterator it;
34 for (it = macro_table.begin(); it != macro_table.end(); ++it)
35 cerr << it->first << ": " << it->second->GetData() << endl;
36 cerr << "------------------------------------------\n";
41 MathMacroTable::provideTemplate(string const & name, int na)
46 if (macro_table.find(name) == macro_table.end())
47 macro_table.insert(make_pair(name, new MathMacroTemplate(name, na)));
49 return *(macro_table.find(name)->second);
54 MathMacroTable::provideTemplate(string const & name)
59 return *macro_table[name];
63 bool MathMacroTable::hasTemplate(string const & name)
68 return macro_table.find(name) != macro_table.end();
72 MathMacro * MathMacroTable::cloneTemplate(string const & name)
74 return new MathMacro(provideTemplate(name));
78 void MathMacroTable::builtinMacros()
82 lyxerr[Debug::MATHED] << "Building macros" << endl;
84 // This macro doesn't have arguments
86 MathMacroTemplate & m = provideTemplate("notin", 0);
87 m.push_back(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not), LM_TC_INSET);
90 // This macro doesn't have arguments
92 MathMacroTemplate & m = provideTemplate("silentmult", 0);
93 istringstream is("\\cdot\0");
94 mathed_parser_file(is, 0);
95 MathParInset * p = &m;
96 mathed_parse(m.array, p, 0);
100 MathMacroTemplate & m = provideTemplate("emptyset", 0);
101 m.push_back(new MathAccentInset('0', LM_TC_RM, LM_not), LM_TC_INSET);
105 MathMacroTemplate & m = provideTemplate("perp", 0);
106 m.GetData().push_back(LM_bot, LM_TC_BOP);
110 MathMacroTemplate & m = provideTemplate("lint", 4);
111 istringstream is("\\int_{#1}^{#2}#3 d#4\0");
112 mathed_parser_file(is, 0);
113 MathParInset * p = &m;
114 mathed_parse(m.array, p, 0);
117 // binom has two arguments
119 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
120 frac->push_back(new MathMacroArgument(1), LM_TC_INSET);
121 frac->denom()->push_back(new MathMacroArgument(2), LM_TC_INSET);
123 MathParInset * inset = new MathDelimInset('(', ')');
124 inset->push_back(frac, LM_TC_ACTIVE_INSET);
126 MathMacroTemplate & m = provideTemplate("binom", 2);
127 m.push_back(inset, LM_TC_ACTIVE_INSET);