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::table_type MathMacroTable::macro_table;
23 bool MathMacroTable::built = false;
26 void MathMacroTable::dump()
28 cerr << "\n------------------------------------------\n";
29 table_type::const_iterator it;
30 for (it = macro_table.begin(); it != macro_table.end(); ++it)
31 cerr << it->first << ": " << it->second->GetData() << endl;
32 cerr << "------------------------------------------\n";
37 MathMacroTable::provideTemplate(string const & name, int na)
42 if (macro_table.find(name) == macro_table.end())
43 macro_table.insert(make_pair(name, new MathMacroTemplate(name, na)));
45 return *(macro_table.find(name)->second);
50 MathMacroTable::provideTemplate(string const & name)
55 return *macro_table[name];
59 bool MathMacroTable::hasTemplate(string const & name)
64 return macro_table.find(name) != macro_table.end();
68 MathMacro * MathMacroTable::cloneTemplate(string const & name)
70 return new MathMacro(provideTemplate(name));
74 void MathMacroTable::builtinMacros()
78 lyxerr[Debug::MATHED] << "Building macros" << endl;
80 // This macro doesn't have arguments
82 MathMacroTemplate & m = provideTemplate("notin", 0);
83 MathedIter iter(&m.GetData());
84 iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
88 // These two are only while we are still with LyX 2.x
90 MathMacroTemplate & m = provideTemplate("emptyset", 0);
91 MathedIter iter(&m.GetData());
92 iter.insertInset(new MathAccentInset('0', LM_TC_RM, LM_not),
97 MathMacroTemplate & m = provideTemplate("perp", 0);
98 MathedIter iter(&m.GetData());
99 iter.insert(LM_bot, LM_TC_BOP);
102 // binom has two arguments
104 MathMacroTemplate & m = provideTemplate("binom", 2);
105 MathedIter iter(&m.GetData());
107 MathParInset * inset = new MathDelimInset('(', ')');
108 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
111 MathedIter iter2(&array2);
112 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
113 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
114 frac->setData(array2);
117 MathedIter iter3(&array3);
118 iter3.insertInset(new MathMacroArgument(1), LM_TC_INSET);
121 MathedIter iter4(&array4);
122 iter4.insertInset(new MathMacroArgument(2), LM_TC_INSET);
124 frac->SetData(array3, array4);
129 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
132 MathedIter iter(&array);
133 iter.insert(LM_bot, LM_TC_BOP);
137 // binom has two arguments
139 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
143 MathedIter iter(&array);
144 MathParInset * inset = new MathDelimInset('(', ')');
145 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
146 array = MathedArray();
147 MathedIter iter2(&array);
148 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
149 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
150 inset->setData(array);
151 array = MathedArray();
153 MathedIter iter3(&array);
154 iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
155 MathedIter iter4(&array2);
156 iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
157 frac->SetData(array, array2);