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"
22 MathMacroTable::table_type MathMacroTable::macro_table;
24 bool MathMacroTable::built = false;
27 void MathMacroTable::dump()
31 cerr << "\n------------------------------------------\n";
32 table_type::const_iterator it;
33 for (it = macro_table.begin(); it != macro_table.end(); ++it)
34 cerr << it->first << ": " << it->second->GetData() << endl;
35 cerr << "------------------------------------------\n";
40 MathMacroTable::provideTemplate(string const & name, int na)
45 if (macro_table.find(name) == macro_table.end())
46 macro_table.insert(make_pair(name, new MathMacroTemplate(name, na)));
48 return *(macro_table.find(name)->second);
53 MathMacroTable::provideTemplate(string const & name)
58 return *macro_table[name];
62 bool MathMacroTable::hasTemplate(string const & name)
67 return macro_table.find(name) != macro_table.end();
71 MathMacro * MathMacroTable::cloneTemplate(string const & name)
73 return new MathMacro(provideTemplate(name));
77 void MathMacroTable::builtinMacros()
81 lyxerr[Debug::MATHED] << "Building macros" << endl;
83 // This macro doesn't have arguments
85 MathMacroTemplate & m = provideTemplate("notin", 0);
86 MathedIter iter(&m.GetData());
87 iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
91 // These two are only while we are still with LyX 2.x
93 MathMacroTemplate & m = provideTemplate("emptyset", 0);
94 MathedIter iter(&m.GetData());
95 iter.insertInset(new MathAccentInset('0', LM_TC_RM, LM_not),
100 MathMacroTemplate & m = provideTemplate("perp", 0);
101 MathedIter iter(&m.GetData());
102 iter.insert(LM_bot, LM_TC_BOP);
105 // binom has two arguments
107 MathMacroTemplate & m = provideTemplate("binom", 2);
108 MathedIter iter(&m.GetData());
110 MathParInset * inset = new MathDelimInset('(', ')');
111 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
114 MathedIter iter2(&array2);
115 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
116 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
117 frac->setData(array2);
120 MathedIter iter3(&array3);
121 iter3.insertInset(new MathMacroArgument(1), LM_TC_INSET);
124 MathedIter iter4(&array4);
125 iter4.insertInset(new MathMacroArgument(2), LM_TC_INSET);
127 frac->SetData(array3, array4);
132 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
135 MathedIter iter(&array);
136 iter.insert(LM_bot, LM_TC_BOP);
140 // binom has two arguments
142 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
146 MathedIter iter(&array);
147 MathParInset * inset = new MathDelimInset('(', ')');
148 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
149 array = MathedArray();
150 MathedIter iter2(&array);
151 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
152 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
153 inset->setData(array);
154 array = MathedArray();
156 MathedIter iter3(&array);
157 iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
158 MathedIter iter4(&array2);
159 iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
160 frac->SetData(array, array2);