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 MathArray mathed_parse_cell(string const &);
26 MathMacroTable::table_type MathMacroTable::macro_table;
29 void MathMacroTable::dump()
31 lyxerr << "\n------------------------------------------\n";
32 table_type::const_iterator it;
33 for (it = macro_table.begin(); it != macro_table.end(); ++it)
34 lyxerr << it->first << " [" << it->second->nargs() << "] : "
35 << it->second << endl;
36 lyxerr << "------------------------------------------" << endl;;
40 void MathMacroTable::updateTemplate(MathMacroTemplate * par)
42 table_type::iterator pos = macro_table.find(par->name());
44 if (pos == macro_table.end())
45 lyxerr << "MathMacroTable::updateTemplate: no template with name '"
46 << par->name() << "' available." << endl;
52 void MathMacroTable::insertTemplate(MathMacroTemplate * p)
54 macro_table[p->name()] = p;
58 MathMacroTemplate & MathMacroTable::provideTemplate(string const & name)
62 table_type::iterator pos = macro_table.find(name);
64 if (pos == macro_table.end()) {
65 lyxerr << "MathMacroTable::provideTemplate: no template with name '"
66 << name << "' available." << endl;
73 void MathMacroTable::createTemplate
74 (string const & name, int na, string const & text)
76 MathMacroTemplate * t = new MathMacroTemplate(name, na);
77 t->cell(0) = mathed_parse_cell(text);
82 bool MathMacroTable::hasTemplate(string const & name)
85 return macro_table.find(name) != macro_table.end();
89 MathMacro * MathMacroTable::cloneTemplate(string const & name)
91 return new MathMacro(provideTemplate(name));
95 void MathMacroTable::builtinMacros()
97 static bool built = false;
104 lyxerr[Debug::MATHED] << "Building macros" << endl;
107 // This macro doesn't have arguments
109 MathMacroTemplate * t = new MathMacroTemplate("notin", 0);
110 MathDecorationInset * p = new MathDecorationInset("not");
111 p->cell(0).push_back(LM_in, LM_TC_SYMB);
117 createTemplate("silentmult", 0, "\\cdot");
118 createTemplate("emptyset", 0, "\\not0");
119 createTemplate("notin", 0, "\\not\\in");
125 MathMacroTemplate * t = new MathMacroTemplate("emptyset", 0);
126 MathDecorationInset * p = new MathDecorationInset("not", LM_not);
127 p->cell(0).push_back('O', LM_TC_VAR);
135 MathMacroTemplate * t = new MathMacroTemplate("land", 0);
136 t->push_back(LM_wedge, LM_TC_SYMB);
141 MathMacroTemplate * t = new MathMacroTemplate("lor", 0);
142 t->push_back(LM_vee, LM_TC_SYMB);
147 MathMacroTemplate * t = new MathMacroTemplate("to", 0);
148 t->push_back(LM_rightarrow, LM_TC_SYMB);
153 MathMacroTemplate * t = new MathMacroTemplate("perp", 0);
154 t->push_back(LM_bot, LM_TC_BOP);
160 MathMacroTemplate & m = createTemplate("lint", 4);
161 istringstream is("\\int_{#1}^{#2}#3 d#4\0");
162 mathed_parser_file(is, 0);
163 MathMatrixInset * p = &m;
164 mathed_parse(m.array, p, 0);
169 MathMacroTemplate * t = new MathMacroTemplate("binomii", 2);
170 istringstream is("\\left(\\frac{#1}{#2}\\right)\0");
171 mathed_parser_file(is, 0);
172 mathed_parse(t->array, t, 0);
177 // binom has two arguments
179 MathFracInset * frac = new MathFracInset("atop");
180 frac->cell(0).push_back(new MathMacroArgument(1));
181 frac->cell(1).push_back(new MathMacroArgument(2));
183 MathInset * inset = new MathDelimInset('(', ')');
184 inset->push_back(frac);
186 MathMacroTemplate * t = new MathMacroTemplate("binom", 2);
194 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
195 frac->cell(0)->push_back(new MathMacroArgument(1));
196 frac->cell(1)->push_back(new MathMacroArgument(2));
198 MathMacroTemplate * t = new MathMacroTemplate("choose", 2);