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 // This macro doesn't have arguments
93 MathMacroTemplate & m = provideTemplate("silentmult", 0);
94 istringstream is("\\cdot\0");
95 mathed_parser_file(is, 0);
96 MathParInset * p = &m;
97 mathed_parse(m.array, p, 0);
100 // These two are only while we are still with LyX 2.x
102 MathMacroTemplate & m = provideTemplate("emptyset", 0);
103 MathedIter iter(&m.GetData());
104 iter.insertInset(new MathAccentInset('0', LM_TC_RM, LM_not),
109 MathMacroTemplate & m = provideTemplate("perp", 0);
110 MathedIter iter(&m.GetData());
111 iter.insert(LM_bot, LM_TC_BOP);
115 MathMacroTemplate & m = provideTemplate("lint", 4);
116 istringstream is("\\int_{#1}^{#2}#3 d#4\0");
117 mathed_parser_file(is, 0);
118 MathParInset * p = &m;
119 mathed_parse(m.array, p, 0);
123 MathMacroTemplate & m = provideTemplate("binom", 2);
124 istringstream is("\\choose{#1}{#2}");
125 mathed_parser_file(is, 0);
126 MathParInset * p = &m;
127 mathed_parse(m.array, p, 0);
130 // binom has two arguments
132 MathMacroTemplate & m = provideTemplate("binom1", 2);
133 MathedIter iter(&m.GetData());
135 MathParInset * inset = new MathDelimInset('(', ')');
136 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
139 MathedIter iter2(&array2);
140 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
141 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
142 frac->setData(array2);
145 MathedIter iter3(&array3);
146 iter3.insertInset(new MathMacroArgument(1), LM_TC_INSET);
149 MathedIter iter4(&array4);
150 iter4.insertInset(new MathMacroArgument(2), LM_TC_INSET);
152 frac->SetData(array3, array4);
157 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
160 MathedIter iter(&array);
161 iter.insert(LM_bot, LM_TC_BOP);
165 // binom has two arguments
167 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
171 MathedIter iter(&array);
172 MathParInset * inset = new MathDelimInset('(', ')');
173 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
174 array = MathedArray();
175 MathedIter iter2(&array);
176 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
177 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
178 inset->setData(array);
179 array = MathedArray();
181 MathedIter iter3(&array);
182 iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
183 MathedIter iter4(&array2);
184 iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
185 frac->SetData(array, array2);