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"
18 MathArray mathed_parse_cell(string const &);
21 MathMacroTable::table_type MathMacroTable::macro_table;
24 void MathMacroTable::dump()
26 lyxerr << "\n------------------------------------------\n";
27 table_type::const_iterator it;
28 for (it = macro_table.begin(); it != macro_table.end(); ++it)
29 lyxerr << it->first << " [" << it->second->nargs() << "] : "
30 << it->second << "\n";
31 lyxerr << "------------------------------------------\n";
35 void MathMacroTable::insertTemplate(MathMacroTemplate * p)
37 macro_table[p->name()] = p;
41 MathMacroTemplate & MathMacroTable::provideTemplate(string const & name)
45 table_type::iterator pos = macro_table.find(name);
47 if (pos == macro_table.end()) {
48 lyxerr << "MathMacroTable::provideTemplate: no template with name '"
49 << name << "' available.\n";
56 void MathMacroTable::createTemplate
57 (string const & name, int na, string const & text)
59 MathMacroTemplate * t = new MathMacroTemplate(name, na);
60 t->cell(0) = mathed_parse_cell(text);
63 #warning who frees this?
68 bool MathMacroTable::hasTemplate(string const & name)
71 return macro_table.find(name) != macro_table.end();
75 MathMacro * MathMacroTable::cloneTemplate(string const & name)
77 return new MathMacro(provideTemplate(name));
81 void MathMacroTable::builtinMacros()
83 static bool built = false;
89 //lyxerr[Debug::MATHED] << "Building macros\n";
91 createTemplate("emptyset", 0, "\\not0");
92 createTemplate("ge", 0, "\\geq");
93 createTemplate("gets", 0, "\\leftarrow");
94 createTemplate("land", 0, "\\wedge");
95 createTemplate("le", 0, "\\leq");
96 createTemplate("lor", 0, "\\vee");
97 createTemplate("notin", 0, "\\not\\in");
98 createTemplate("perp", 0, "\\bot");
99 createTemplate("to", 0, "\\rightarrow");
100 //createTemplate("lint", 4, "\\int_{#1}^{#2}#3 d#4");
101 //createTemplate("silentmult", 0, "\\cdot");
102 //createTemplate("binomi", 2, "\\left(\\frac{#1}{#2}\\right)");
104 // binom has two arguments
106 MathFracInset * frac = new MathFracInset("atop");
107 frac->cell(0).push_back(new MathMacroArgument(1));
108 frac->cell(1).push_back(new MathMacroArgument(2));
110 MathInset * inset = new MathDelimInset('(', ')');
111 inset->push_back(frac);
113 MathMacroTemplate * t = new MathMacroTemplate("binom", 2);
121 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
122 frac->cell(0)->push_back(new MathMacroArgument(1));
123 frac->cell(1)->push_back(new MathMacroArgument(2));
125 MathMacroTemplate * t = new MathMacroTemplate("choose", 2);