]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.C
support for TeX's \choose
[lyx.git] / src / mathed / math_macrotable.C
1 #include <config.h>
2
3 #include <iostream>
4
5 #ifdef __GNUG__
6 #pragma implementation
7 #endif
8
9 #include "math_macrotable.h"
10 #include "math_macro.h"
11 #include "math_macrotemplate.h"
12 #include "math_parser.h"
13 #include "math_fracinset.h"
14 #include "debug.h"
15
16
17 MathArray mathed_parse_cell(string const &);
18
19
20 MathMacroTable::table_type MathMacroTable::macro_table;
21
22
23 void MathMacroTable::dump()
24 {
25         lyxerr << "\n------------------------------------------\n";
26         table_type::const_iterator it;
27         for (it = macro_table.begin(); it != macro_table.end(); ++it)
28                 lyxerr << it->first << " [" << it->second.nargs() << "] : "
29                         << it->second << "\n";
30         lyxerr << "------------------------------------------\n";
31 }
32
33
34 void MathMacroTable::insertTemplate(MathMacroTemplate const & p)
35 {
36         if (macro_table.find(p.name()) != macro_table.end()) 
37                 lyxerr << "macro '" << p.name() << "' not new\n";
38         macro_table[p.name()] = p;
39 }
40
41
42 MathMacroTemplate & MathMacroTable::provideTemplate(string const & name)
43 {
44         builtinMacros();
45         
46         table_type::iterator pos = macro_table.find(name);
47
48         if (pos == macro_table.end()) {
49                 lyxerr << "MathMacroTable::provideTemplate: no template with name '"
50                        << name << "' available.\n";
51         }
52                 
53         return pos->second;
54 }
55
56
57 void MathMacroTable::createTemplate
58         (string const & name, int na, string const & text)
59 {
60         MathMacroTemplate t(name, na);
61         t.cell(0) = mathed_parse_cell(text);
62         insertTemplate(t);
63 }
64
65
66 bool MathMacroTable::hasTemplate(string const & name)
67 {
68         builtinMacros();
69         return macro_table.find(name) != macro_table.end();
70 }
71
72
73 MathMacro * MathMacroTable::cloneTemplate(string const & name)
74 {
75         return new MathMacro(provideTemplate(name));
76 }
77
78
79 void MathMacroTable::builtinMacros()
80 {
81         static bool built = false;
82         
83         if (built)
84                 return; 
85
86         built = true;
87         //lyxerr[Debug::MATHED] << "Building macros\n";
88    
89         createTemplate("emptyset",     0, "\\not0");
90         createTemplate("ge",           0, "\\geq");
91         createTemplate("gets",         0, "\\leftarrow");
92         createTemplate("land",         0, "\\wedge");
93         createTemplate("le",           0, "\\leq");
94         createTemplate("lor",          0, "\\vee");
95         createTemplate("notin",        0, "\\not\\in");
96         createTemplate("perp",         0, "\\bot");
97         createTemplate("to",           0, "\\rightarrow");
98         //createTemplate("lint",       4, "\\int_#1^#2#3 d#4");
99         //createTemplate("silentmult", 0, "\\cdot");
100         //createTemplate("binom",        2, "\\left(\\frac#1#2\\right)");
101 }