]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.C
some *cough* support for \ll and \gg and potentially more...
[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 "math_cheatinset.h"
15 #include "math_charinset.h"
16 #include "debug.h"
17
18
19 MathArray mathed_parse_cell(string const &);
20
21
22 MathMacroTable::table_type MathMacroTable::macro_table;
23
24
25 void MathMacroTable::dump()
26 {
27         lyxerr << "\n------------------------------------------\n";
28         table_type::const_iterator it;
29         for (it = macro_table.begin(); it != macro_table.end(); ++it)
30                 lyxerr << it->first << " [" << it->second.nargs() << "] : "
31                         << it->second << "\n";
32         lyxerr << "------------------------------------------\n";
33 }
34
35
36 void MathMacroTable::insertTemplate(MathMacroTemplate const & p)
37 {
38         if (macro_table.find(p.name()) != macro_table.end()) 
39                 lyxerr << "macro '" << p.name() << "' not new\n";
40         macro_table[p.name()] = p;
41 }
42
43
44 MathMacroTemplate & MathMacroTable::provideTemplate(string const & name)
45 {
46         builtinMacros();
47         
48         table_type::iterator pos = macro_table.find(name);
49
50         if (pos == macro_table.end()) {
51                 lyxerr << "MathMacroTable::provideTemplate: no template with name '"
52                        << name << "' available.\n";
53         }
54                 
55         return pos->second;
56 }
57
58
59 void MathMacroTable::createTemplate
60         (string const & name, int na, string const & text)
61 {
62         MathMacroTemplate t(name, na);
63         t.cell(0) = mathed_parse_cell(text);
64         insertTemplate(t);
65 }
66
67
68 bool MathMacroTable::hasTemplate(string const & name)
69 {
70         builtinMacros();
71         return macro_table.find(name) != macro_table.end();
72 }
73
74
75 MathMacro * MathMacroTable::cloneTemplate(string const & name)
76 {
77         return new MathMacro(provideTemplate(name));
78 }
79
80
81 void MathMacroTable::builtinMacros()
82 {
83         static bool built = false;
84         
85         if (built)
86                 return; 
87
88         built = true;
89         //lyxerr[Debug::MATHED] << "Building macros\n";
90    
91         createTemplate("emptyset",     0, "\\not0");
92         createTemplate("ne",           0, "\\not=");
93         createTemplate("ge",           0, "\\geq");
94         createTemplate("gets",         0, "\\leftarrow");
95         createTemplate("land",         0, "\\wedge");
96         createTemplate("le",           0, "\\leq");
97         createTemplate("lor",          0, "\\vee");
98         createTemplate("notin",        0, "\\not\\in");
99         createTemplate("perp",         0, "\\bot");
100         createTemplate("owns",         0, "\\ni");
101         createTemplate("to",           0, "\\rightarrow");
102         //createTemplate("lint",       4, "\\int_#1^#2#3 d#4");
103         //createTemplate("silentmult", 0, "\\cdot");
104         //createTemplate("binom",        2, "\\left(\\frac#1#2\\right)");
105         
106         MathMacroTemplate ll("ll", 0);
107         ll.cell(0).push_back(new MathCharInset('<', LM_TC_CONST));
108         ll.cell(0).push_back(new MathCheatInset(-0.9));
109         ll.cell(0).push_back(new MathCharInset('<', LM_TC_CONST));
110         insertTemplate(ll);
111
112         MathMacroTemplate gg("gg", 0);
113         gg.cell(0).push_back(new MathCharInset('>', LM_TC_CONST));
114         gg.cell(0).push_back(new MathCheatInset(-0.9));
115         gg.cell(0).push_back(new MathCharInset('>', LM_TC_CONST));
116         insertTemplate(gg);
117 }