9 #include "math_macrotable.h"
10 #include "math_macro.h"
11 #include "math_macrotemplate.h"
12 #include "math_iter.h"
14 #include "math_accentinset.h"
15 #include "math_deliminset.h"
16 #include "math_fracinset.h"
17 #include "math_parinset.h"
19 #include "support/LAssert.h"
24 MathMacroTable::table_type MathMacroTable::macro_table;
26 bool MathMacroTable::built = false;
29 void MathMacroTable::dump()
33 cerr << "\n------------------------------------------\n";
34 table_type::const_iterator it;
35 for (it = macro_table.begin(); it != macro_table.end(); ++it)
36 cerr << it->first << ": " << it->second->GetData() << endl;
37 cerr << "------------------------------------------\n";
42 MathMacroTable::provideTemplate(string const & name, int na)
47 if (macro_table.find(name) == macro_table.end())
48 macro_table.insert(make_pair(name, new MathMacroTemplate(name, na)));
50 return *(macro_table.find(name)->second);
55 MathMacroTable::provideTemplate(string const & name)
60 return *macro_table[name];
64 bool MathMacroTable::hasTemplate(string const & name)
69 return macro_table.find(name) != macro_table.end();
73 MathMacro * MathMacroTable::cloneTemplate(string const & name)
75 return new MathMacro(provideTemplate(name));
79 void MathMacroTable::builtinMacros()
83 lyxerr[Debug::MATHED] << "Building macros" << endl;
85 // This macro doesn't have arguments
87 MathMacroTemplate & m = provideTemplate("notin", 0);
88 MathedIter iter(&m.GetData());
89 iter.insertInset(new MathAccentInset(LM_in, LM_TC_BOPS, LM_not),
93 // This macro doesn't have arguments
95 MathMacroTemplate & m = provideTemplate("silentmult", 0);
96 istringstream is("\\cdot\0");
97 mathed_parser_file(is, 0);
98 MathParInset * p = &m;
99 mathed_parse(m.array, p, 0);
102 // These two are only while we are still with LyX 2.x
104 MathMacroTemplate & m = provideTemplate("emptyset", 0);
105 MathedIter iter(&m.GetData());
106 iter.insertInset(new MathAccentInset('0', LM_TC_RM, LM_not),
111 MathMacroTemplate & m = provideTemplate("perp", 0);
112 MathedIter iter(&m.GetData());
113 iter.insert(LM_bot, LM_TC_BOP);
117 MathMacroTemplate & m = provideTemplate("lint", 4);
118 istringstream is("\\int_{#1}^{#2}#3 d#4\0");
119 mathed_parser_file(is, 0);
120 MathParInset * p = &m;
121 mathed_parse(m.array, p, 0);
125 MathMacroTemplate & m = provideTemplate("binom", 2);
126 istringstream is("\\choose{#1}{#2}");
127 mathed_parser_file(is, 0);
128 MathParInset * p = &m;
129 mathed_parse(m.array, p, 0);
132 // binom has two arguments
134 MathMacroTemplate & m = provideTemplate("binom1", 2);
135 MathedIter iter(&m.GetData());
137 MathParInset * inset = new MathDelimInset('(', ')');
138 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
141 MathedIter iter2(&array2);
142 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
143 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
144 frac->setData(array2);
147 MathedIter iter3(&array3);
148 iter3.insertInset(new MathMacroArgument(1), LM_TC_INSET);
151 MathedIter iter4(&array4);
152 iter4.insertInset(new MathMacroArgument(2), LM_TC_INSET);
154 frac->SetData(array3, array4);
159 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("perp", 0));
162 MathedIter iter(&array);
163 iter.insert(LM_bot, LM_TC_BOP);
167 // binom has two arguments
169 boost::shared_ptr<MathMacroTemplate> m(new MathMacroTemplate("binom", 2));
173 MathedIter iter(&array);
174 MathParInset * inset = new MathDelimInset('(', ')');
175 iter.insertInset(inset, LM_TC_ACTIVE_INSET);
176 array = MathedArray();
177 MathedIter iter2(&array);
178 MathFracInset * frac = new MathFracInset(LM_OT_ATOP);
179 iter2.insertInset(frac, LM_TC_ACTIVE_INSET);
180 inset->setData(array);
181 array = MathedArray();
183 MathedIter iter3(&array);
184 iter3.insertInset(m->getMacroPar(0), LM_TC_INSET);
185 MathedIter iter4(&array2);
186 iter4.insertInset(m->getMacroPar(1), LM_TC_INSET);
187 frac->SetData(array, array2);