3 #include "math_macrotable.h"
4 #include "math_macro.h"
5 #include "math_macrotemplate.h"
8 #include "math_accentinset.h"
9 #include "math_deliminset.h"
10 #include "math_fracinset.h"
11 #include "math_parinset.h"
16 MathMacroTable MathMacroTable::mathMTable;
18 bool MathMacroTable::built = false;
21 MathMacro * MathMacroTable::getMacro(string const & name) const
23 MathMacroTemplate * mt = getTemplate(name);
24 return (mt) ? new MathMacro(mt): 0;
28 // The search is currently linear but will be binary or hash, later.
29 MathMacroTemplate * MathMacroTable::getTemplate(string const & name) const
31 for (size_type i = 0; i < macro_table.size(); ++i) {
32 if (name == macro_table[i]->GetName())
33 return macro_table[i];
39 void MathMacroTable::addTemplate(MathMacroTemplate * m)
41 macro_table.push_back(m);
45 // All this stuff aparently leaks because it's created here and is not
46 // deleted never, but it have to live all the LyX sesion. OK, would not
47 // so hard to do it in the MacroTable destructor, but this doesn't harm
48 // seriously, so don't bother me with purify results here. ;-)
50 void MathMacroTable::builtinMacros()
53 MathParInset * inset;// *arg;
58 lyxerr[Debug::MATHED] << "Building macros" << endl;
60 // This macro doesn't have arguments
61 MathMacroTemplate * m = new MathMacroTemplate("notin"); // this leaks
63 MathedArray * array = new MathedArray; // this leaks
65 iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
66 LM_TC_INSET); // this leaks
69 // These two are only while we are still with LyX 2.x
70 m = new MathMacroTemplate("emptyset"); // this leaks
72 array = new MathedArray; // this leaks
74 iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not),
75 LM_TC_INSET); // this leaks
78 m = new MathMacroTemplate("perp"); // this leaks
80 array = new MathedArray; // this leaks
82 iter.insert(LM_bot, LM_TC_BOP);
85 // binom has two arguments
86 m = new MathMacroTemplate("binom", 2);
88 array = new MathedArray;
91 inset = new MathDelimInset('(', ')');
92 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
93 array = new MathedArray;
95 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
96 iter.insertInset(frac, LM_TC_ACTIVE_INSET);
97 inset->setData(array);
98 array = new MathedArray;
99 array2 = new MathedArray;
101 iter.insertInset(m->getMacroPar(0), LM_TC_INSET);
102 iter.SetData(array2);
103 iter.insertInset(m->getMacroPar(1), LM_TC_INSET);
104 frac->SetData(array, array2);
107 // Cases has 1 argument
108 m = new MathMacroTemplate("cases", 1, MMF_Env); // this leaks
110 array = new MathedArray; // this leaks
112 arg = new MathMatrixInset(2, 1); // this leaks
115 arg->SetAlign('c', "ll");
116 iter.Insert(arg, LM_TC_ACTIVE_INSET);
117 inset = new MathDelimInset('{', '.'); // this leaks
118 inset->SetData(array);
119 array = new MathedArray; // this leaks
121 iter.Insert(inset, LM_TC_ACTIVE_INSET);
125 // the environment substack has 1 argument
126 m = new MathMacroTemplate("substack", 1, MMF_Env); // this leaks
128 arg = new MathMatrixInset(1, 1); // this leaks
130 arg->SetType(LM_OT_MACRO);
131 array = new MathedArray; // this leaks
133 iter.Insert(arg, LM_TC_ACTIVE_INSET);