7 #include "math_macrotable.h"
8 #include "math_macro.h"
9 #include "math_macrotemplate.h"
10 #include "math_iter.h"
12 #include "math_accentinset.h"
13 #include "math_deliminset.h"
14 #include "math_fracinset.h"
15 #include "math_parinset.h"
17 #include "support/LAssert.h"
21 MathMacroTable MathMacroTable::mathMTable;
23 bool MathMacroTable::built = false;
26 MathMacro * MathMacroTable::createMacro(string const & name) const
28 boost::shared_ptr<MathMacroTemplate> mt = getTemplate(name);
29 return (mt.get()) ? new MathMacro(mt) : 0;
33 boost::shared_ptr<MathMacroTemplate> const
34 MathMacroTable::getTemplate(string const & name) const
36 table_type::const_iterator cit = macro_table.find(name);
37 if (cit != macro_table.end()) return (*cit).second;
38 return boost::shared_ptr<MathMacroTemplate>();
43 MathMacroTable::addTemplate(boost::shared_ptr<MathMacroTemplate> const & m)
46 macro_table[m->GetName()] = m;
50 void MathMacroTable::builtinMacros()
54 lyxerr[Debug::MATHED] << "Building macros" << endl;
56 // This macro doesn't have arguments
58 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("notin", 0));
61 MathedIter iter(&array);
62 iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
67 // These two are only while we are still with LyX 2.x
69 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("emptyset", 0));
72 MathedIter iter(&array);
73 iter.insertInset(new MathAccentInset('O', LM_TC_RM, LM_not),
79 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
82 MathedIter iter(&array);
83 iter.insert(LM_bot, LM_TC_BOP);
87 // binom has two arguments
89 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
93 MathedIter iter(&array);
94 MathParInset * inset = new MathDelimInset('(', ')');
95 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
96 array = MathedArray();
97 MathedIter iter2(&array);
98 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
99 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
100 inset->setData(array);
101 array = MathedArray();
103 MathedIter iter3(&array);
104 iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
105 MathedIter iter4(&array2);
106 iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
107 frac->SetData(array, array2);