9 #include "math_macrotable.h"
10 #include "math_macro.h"
11 #include "math_macrotemplate.h"
12 #include "math_parser.h"
14 #include "math_decorationinset.h"
15 #include "math_deliminset.h"
16 #include "math_fracinset.h"
17 #include "math_inset.h"
19 #include "support/LAssert.h"
23 MathMacroTable::table_type MathMacroTable::macro_table;
26 void MathMacroTable::dump()
28 lyxerr << "\n------------------------------------------\n";
29 table_type::const_iterator it;
30 for (it = macro_table.begin(); it != macro_table.end(); ++it)
31 lyxerr << it->first << " [" << it->second->nargs() << "] : "
32 << it->second << endl;
33 lyxerr << "------------------------------------------" << endl;;
37 void MathMacroTable::updateTemplate(MathMacroTemplate * par)
39 table_type::iterator pos = macro_table.find(par->name());
41 if (pos == macro_table.end())
42 lyxerr << "MathMacroTable::updateTemplate: no template with name '"
43 << par->name() << "' available." << endl;
49 void MathMacroTable::insertTemplate(MathMacroTemplate * p)
51 macro_table[p->name()] = p;
55 MathMacroTemplate & MathMacroTable::provideTemplate(string const & name)
59 table_type::iterator pos = macro_table.find(name);
61 if (pos == macro_table.end()) {
62 lyxerr << "MathMacroTable::provideTemplate: no template with name '"
63 << name << "' available." << endl;
70 bool MathMacroTable::hasTemplate(string const & name)
73 return macro_table.find(name) != macro_table.end();
77 MathMacro * MathMacroTable::cloneTemplate(string const & name)
79 return new MathMacro(provideTemplate(name));
83 void MathMacroTable::builtinMacros()
85 static bool built = false;
92 lyxerr[Debug::MATHED] << "Building macros" << endl;
94 // This macro doesn't have arguments
96 MathMacroTemplate * t = new MathMacroTemplate("notin", 0);
97 MathDecorationInset * p = new MathDecorationInset("not", LM_not);
98 p->cell(0).push_back(LM_in, LM_TC_BOPS);
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 MathDecorationInset * p = new MathDecorationInset("not", LM_not);
117 p->cell(0).push_back('O', LM_TC_VAR);
123 MathMacroTemplate * t = new MathMacroTemplate("to", 0);
124 t->push_back(LM_rightarrow, LM_TC_SYMB);
129 MathMacroTemplate * t = new MathMacroTemplate("perp", 0);
130 t->push_back(LM_bot, LM_TC_BOP);
135 MathMacroTemplate & m = createTemplate("lint", 4);
136 istringstream is("\\int_{#1}^{#2}#3 d#4\0");
137 mathed_parser_file(is, 0);
138 MathMatrixInset * p = &m;
139 mathed_parse(m.array, p, 0);
144 MathMacroTemplate * t = new MathMacroTemplate("binomii", 2);
145 istringstream is("\\left(\\frac{#1}{#2}\\right)\0");
146 mathed_parser_file(is, 0);
147 mathed_parse(t->array, t, 0);
152 // binom has two arguments
154 MathFracInset * frac = new MathFracInset("atop");
155 frac->cell(0).push_back(new MathMacroArgument(1));
156 frac->cell(1).push_back(new MathMacroArgument(2));
158 MathInset * inset = new MathDelimInset('(', ')');
159 inset->push_back(frac);
161 MathMacroTemplate * t = new MathMacroTemplate("binom", 2);
169 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
170 frac->cell(0)->push_back(new MathMacroArgument(1));
171 frac->cell(1)->push_back(new MathMacroArgument(2));
173 MathMacroTemplate * t = new MathMacroTemplate("choose", 2);