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"
15 MathMacroTable MathMacroTable::mathMTable;
17 bool MathMacroTable::built = false;
20 MathMacro * MathMacroTable::getMacro(string const & name) const
22 MathMacroTemplate * mt = getTemplate(name);
23 return (mt) ? new MathMacro(mt): 0;
27 // The search is currently linear but will be binary or hash, later.
28 MathMacroTemplate * MathMacroTable::getTemplate(string const & name) const
30 for (size_type i = 0; i < macro_table.size(); ++i) {
31 if (name == macro_table[i]->GetName())
32 return macro_table[i];
38 void MathMacroTable::addTemplate(MathMacroTemplate * m)
40 macro_table.push_back(m);
44 // All this stuff aparently leaks because it's created here and is not
45 // deleted never, but it have to live all the LyX sesion. OK, would not
46 // so hard to do it in the MacroTable destructor, but this doesn't harm
47 // seriously, so don't bother me with purify results here. ;-)
49 void MathMacroTable::builtinMacros()
52 MathParInset * inset;// *arg;
57 lyxerr[Debug::MATHED] << "Building macros" << endl;
59 // This macro doesn't have arguments
60 MathMacroTemplate * m = new MathMacroTemplate("notin"); // this leaks
62 MathedArray * array = new MathedArray; // this leaks
64 iter.Insert(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not)); // this leaks
67 // These two are only while we are still with LyX 2.x
68 m = new MathMacroTemplate("emptyset"); // this leaks
70 array = new MathedArray; // this leaks
72 iter.Insert(new MathAccentInset('O', LM_TC_RM, LM_not)); // this leaks
75 m = new MathMacroTemplate("perp"); // this leaks
77 array = new MathedArray; // this leaks
79 iter.Insert(LM_bot, LM_TC_BOP);
82 // binom has two arguments
83 m = new MathMacroTemplate("binom", 2);
85 array = new MathedArray;
88 inset = new MathDelimInset('(', ')');
89 iter.Insert(inset, LM_TC_ACTIVE_INSET);
90 array = new MathedArray;
92 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
93 iter.Insert(frac, LM_TC_ACTIVE_INSET);
94 inset->SetData(array);
95 array = new MathedArray;
96 array2 = new MathedArray;
98 iter.Insert(m->getMacroPar(0));
100 iter.Insert(m->getMacroPar(1));
101 frac->SetData(array, array2);
104 // Cases has 1 argument
105 m = new MathMacroTemplate("cases", 1, MMF_Env); // this leaks
107 array = new MathedArray; // this leaks
109 arg = new MathMatrixInset(2, 1); // this leaks
112 arg->SetAlign('c', "ll");
113 iter.Insert(arg, LM_TC_ACTIVE_INSET);
114 inset = new MathDelimInset('{', '.'); // this leaks
115 inset->SetData(array);
116 array = new MathedArray; // this leaks
118 iter.Insert(inset, LM_TC_ACTIVE_INSET);
122 // the environment substack has 1 argument
123 m = new MathMacroTemplate("substack", 1, MMF_Env); // this leaks
125 arg = new MathMatrixInset(1, 1); // this leaks
127 arg->SetType(LM_OT_MACRO);
128 array = new MathedArray; // this leaks
130 iter.Insert(arg, LM_TC_ACTIVE_INSET);