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("land", 0);
124 t->push_back(LM_wedge, LM_TC_SYMB);
129 MathMacroTemplate * t = new MathMacroTemplate("lor", 0);
130 t->push_back(LM_vee, LM_TC_SYMB);
135 MathMacroTemplate * t = new MathMacroTemplate("to", 0);
136 t->push_back(LM_rightarrow, LM_TC_SYMB);
141 MathMacroTemplate * t = new MathMacroTemplate("perp", 0);
142 t->push_back(LM_bot, LM_TC_BOP);
148 MathMacroTemplate & m = createTemplate("lint", 4);
149 istringstream is("\\int_{#1}^{#2}#3 d#4\0");
150 mathed_parser_file(is, 0);
151 MathMatrixInset * p = &m;
152 mathed_parse(m.array, p, 0);
157 MathMacroTemplate * t = new MathMacroTemplate("binomii", 2);
158 istringstream is("\\left(\\frac{#1}{#2}\\right)\0");
159 mathed_parser_file(is, 0);
160 mathed_parse(t->array, t, 0);
165 // binom has two arguments
167 MathFracInset * frac = new MathFracInset("atop");
168 frac->cell(0).push_back(new MathMacroArgument(1));
169 frac->cell(1).push_back(new MathMacroArgument(2));
171 MathInset * inset = new MathDelimInset('(', ')');
172 inset->push_back(frac);
174 MathMacroTemplate * t = new MathMacroTemplate("binom", 2);
182 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
183 frac->cell(0)->push_back(new MathMacroArgument(1));
184 frac->cell(1)->push_back(new MathMacroArgument(2));
186 MathMacroTemplate * t = new MathMacroTemplate("choose", 2);