9 #include "math_macrotable.h"
10 #include "math_macro.h"
11 #include "math_macrotemplate.h"
12 #include "math_parser.h"
13 #include "math_deliminset.h"
14 #include "math_fracinset.h"
19 MathArray mathed_parse_cell(string const &);
22 MathMacroTable::table_type MathMacroTable::macro_table;
25 void MathMacroTable::dump()
27 lyxerr << "\n------------------------------------------\n";
28 table_type::const_iterator it;
29 for (it = macro_table.begin(); it != macro_table.end(); ++it)
30 lyxerr << it->first << " [" << it->second->nargs() << "] : "
31 << it->second << endl;
32 lyxerr << "------------------------------------------" << endl;;
36 void MathMacroTable::updateTemplate(MathMacroTemplate * par)
38 table_type::iterator pos = macro_table.find(par->name());
40 if (pos == macro_table.end())
41 lyxerr << "MathMacroTable::updateTemplate: no template with name '"
42 << par->name() << "' available." << endl;
48 void MathMacroTable::insertTemplate(MathMacroTemplate * p)
50 macro_table[p->name()] = p;
54 MathMacroTemplate & MathMacroTable::provideTemplate(string const & name)
58 table_type::iterator pos = macro_table.find(name);
60 if (pos == macro_table.end()) {
61 lyxerr << "MathMacroTable::provideTemplate: no template with name '"
62 << name << "' available." << endl;
69 void MathMacroTable::createTemplate
70 (string const & name, int na, string const & text)
72 MathMacroTemplate * t = new MathMacroTemplate(name, na);
73 t->cell(0) = mathed_parse_cell(text);
78 bool MathMacroTable::hasTemplate(string const & name)
81 return macro_table.find(name) != macro_table.end();
85 MathMacro * MathMacroTable::cloneTemplate(string const & name)
87 return new MathMacro(provideTemplate(name));
91 void MathMacroTable::builtinMacros()
93 static bool built = false;
99 //lyxerr[Debug::MATHED] << "Building macros" << endl;
101 createTemplate("emptyset", 0, "\\not0");
102 createTemplate("ge", 0, "\\geq");
103 createTemplate("gets", 0, "\\leftarrow");
104 createTemplate("land", 0, "\\wedge");
105 createTemplate("le", 0, "\\leq");
106 createTemplate("lor", 0, "\\vee");
107 createTemplate("notin", 0, "\\not\\in");
108 createTemplate("perp", 0, "\\bot");
109 createTemplate("to", 0, "\\rightarrow");
110 //createTemplate("lint", 4, "\\int_{#1}^{#2}#3 d#4");
111 //createTemplate("silentmult", 0, "\\cdot");
112 //createTemplate("binomi", 2, "\\left(\\frac{#1}{#2}\\right)");
114 // binom has two arguments
116 MathFracInset * frac = new MathFracInset("atop");
117 frac->cell(0).push_back(new MathMacroArgument(1));
118 frac->cell(1).push_back(new MathMacroArgument(2));
120 MathInset * inset = new MathDelimInset('(', ')');
121 inset->push_back(frac);
123 MathMacroTemplate * t = new MathMacroTemplate("binom", 2);
131 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
132 frac->cell(0)->push_back(new MathMacroArgument(1));
133 frac->cell(1)->push_back(new MathMacroArgument(2));
135 MathMacroTemplate * t = new MathMacroTemplate("choose", 2);