9 #include "math_macrotable.h"
10 #include "math_macro.h"
11 #include "math_macrotemplate.h"
12 #include "math_parser.h"
14 #include "math_accentinset.h"
15 #include "math_deliminset.h"
16 #include "math_fracinset.h"
17 #include "math_inset.h"
19 #include "support/LAssert.h"
25 MathMacroTable::table_type MathMacroTable::macro_table;
28 void MathMacroTable::dump()
30 cerr << "\n------------------------------------------\n";
31 table_type::const_iterator it;
32 for (it = macro_table.begin(); it != macro_table.end(); ++it)
33 cerr << it->first << " [" << it->second->nargs() << "] : "
34 << it->second << endl;
35 cerr << "------------------------------------------\n";
39 void MathMacroTable::updateTemplate(MathMacroTemplate * par)
41 table_type::iterator pos = macro_table.find(par->name());
43 if (pos == macro_table.end())
44 lyxerr << "MathMacroTable::updateTemplate: no template with name '"
45 << par->name() << "' available.\n";
51 void MathMacroTable::insertTemplate(MathMacroTemplate * p)
53 macro_table[p->name()] = p;
57 MathMacroTemplate & MathMacroTable::provideTemplate(string const & name)
61 table_type::iterator pos = macro_table.find(name);
63 if (pos == macro_table.end()) {
64 lyxerr << "MathMacroTable::provideTemplate: no template with name '"
65 << name << "' available.\n";
72 bool MathMacroTable::hasTemplate(string const & name)
75 return macro_table.find(name) != macro_table.end();
79 MathMacro * MathMacroTable::cloneTemplate(string const & name)
81 return new MathMacro(provideTemplate(name));
85 void MathMacroTable::builtinMacros()
87 static bool built = false;
94 lyxerr[Debug::MATHED] << "Building macros\n";
96 // This macro doesn't have arguments
98 MathMacroTemplate * t = new MathMacroTemplate("notin", 0);
99 t->push_back(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not));
104 // This macro doesn't have arguments
106 MathMacroTemplate & m = createTemplate("silentmult", 0);
107 istringstream is("\\cdot\0");
108 mathed_parser_file(is, 0);
109 MathMatrixInset * p = &m;
110 mathed_parse(m.array, p, 0);
115 MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0);
116 t->push_back(new MathAccentInset('0', LM_TC_RM, LM_not));
121 MathMacroTemplate * t = new MathMacroTemplate("to", 0);
122 t->push_back(LM_rightarrow, LM_TC_SYMB);
127 MathMacroTemplate * t = new MathMacroTemplate("perp", 0);
128 t->push_back(LM_bot, LM_TC_BOP);
133 MathMacroTemplate & m = createTemplate("lint", 4);
134 istringstream is("\\int_{#1}^{#2}#3 d#4\0");
135 mathed_parser_file(is, 0);
136 MathMatrixInset * p = &m;
137 mathed_parse(m.array, p, 0);
142 MathMacroTemplate * t = new MathMacroTemplate("binomii", 2);
143 istringstream is("\\left(\\frac{#1}{#2}\\right)\0");
144 mathed_parser_file(is, 0);
145 mathed_parse(t->array, t, 0);
150 // binom has two arguments
152 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
153 frac->cell(0).push_back(new MathMacroArgument(1));
154 frac->cell(1).push_back(new MathMacroArgument(2));
156 MathInset * inset = new MathDelimInset('(', ')');
157 inset->push_back(frac);
159 MathMacroTemplate * t = new MathMacroTemplate("binom", 2);
167 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
168 frac->cell(0)->push_back(new MathMacroArgument(1));
169 frac->cell(1)->push_back(new MathMacroArgument(2));
171 MathMacroTemplate * t = new MathMacroTemplate("choose", 2);