]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.C
Use references instead of pointers where possible
[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 "debug.h"
14 #include "support.h" // math_font_available
15
16 MathArray mathed_parse_cell(string const &);
17
18
19 MathMacroTable::table_type MathMacroTable::macro_table;
20
21
22 void MathMacroTable::dump()
23 {
24         lyxerr << "\n------------------------------------------\n";
25         table_type::const_iterator it;
26         for (it = macro_table.begin(); it != macro_table.end(); ++it)
27                 lyxerr << it->first
28                         << " [" << it->second->asMacroTemplate()->nargs() << "] : "
29                         << it->second->cell(0) << "\n";
30         lyxerr << "------------------------------------------\n";
31 }
32
33
34 MathAtom & MathMacroTable::provide(string const & name)
35 {
36         builtinMacros();
37         
38         table_type::iterator pos = macro_table.find(name);
39
40         if (pos == macro_table.end()) {
41                 lyxerr << "MathMacroTable::provideTemplate: no template with name '"
42                        << name << "' available.\n";
43         }
44                 
45         return pos->second;
46 }
47
48
49 void MathMacroTable::create(string const & name, int na, string const & text)
50 {
51         MathAtom t(new MathMacroTemplate(name, na));
52         t->cell(0) = mathed_parse_cell(text);
53         macro_table[name] = t;
54 }
55
56
57 void MathMacroTable::create(string const & name, int na, MathArray const & ar)
58 {
59         MathAtom t(new MathMacroTemplate(name, na));
60         t->cell(0) = ar;
61         macro_table[name] = t;
62 }
63
64
65
66 bool MathMacroTable::has(string const & name)
67 {
68         builtinMacros();
69         return macro_table.find(name) != macro_table.end();
70 }
71
72
73 void MathMacroTable::builtinMacros()
74 {
75         static bool built = false;
76         
77         if (built)
78                 return; 
79
80         built = true;
81         //lyxerr[Debug::MATHED] << "Building macros\n";
82    
83         //create("emptyset",     0, "\\not0");
84         create("notin",        0, "\\not\\in");
85         create("slash",        0, "/");
86
87         // fontmath.ltx
88
89         create("lnot",         0, "\\neg");
90         create("land",         0, "\\wedge");
91         create("lor",          0, "\\vee");
92         create("ne",           0, "\\neq");
93         create("le",           0, "\\leq");
94         create("ge",           0, "\\geq");
95         create("owns",         0, "\\ni");
96         create("gets",         0, "\\leftarrow");
97         create("to",           0, "\\rightarrow");
98         create("|",            0, "\\parallel");
99
100         create("longleftrightarrow", 0, "\\leftarrow\\kern-6mu\\rightarrow");
101         create("Longleftrightarrow", 0, "\\Leftarrow\\kern-6mu\\Rightarrow");
102         create("doteq", 0, "\\stackrel{\\cdot}{=}");
103
104         //create("models",         0, "|\\kern-9mu=");
105
106         if (math_font_available(LM_TC_CMSY)) {
107                 create("longrightarrow", 0, "\\lyxbar\\kern-5mu\\rightarrow");
108                 create("longleftarrow",  0, "\\leftarrow\\kern-5mu\\lyxbar");
109                 create("mapsto",  0, "\\mapstochar\\rightarrow");
110                 create("longmapsto",  0, "\\mapstochar\\lyxbar\\kern-5mu\\rightarrow");
111         }
112
113         if (math_font_available(LM_TC_CMR)) {
114                 create("Longrightarrow", 0, "\\lyxeq\\kern-3mu\\Rightarrow");
115                 create("Longleftarrow",  0, "\\Leftarrow\\kern-9mu\\lyxeq");
116         }
117
118         if (math_font_available(LM_TC_CMM)) {
119                 create("hookrightarrow", 0, "\\lhook\\kern-5mu\\rightarrow");
120                 create("hookleftarrow",  0, "\\leftarrow\\kern-5mu\\rhook");
121                 create("bowtie",         0, "\\triangleright\\kern-3mu\\triangleleft");
122         }
123
124         if (math_font_available(LM_TC_MSA)) {
125                 //amsfonts.sty
126
127                 create("dashrightarrow", 0, "\\lyxdabar\\lyxdabar\\lyxright");
128                 create("dashleftarrow", 0, "\\lyxleft\\lyxdabar\\lyxdabar");
129                 create("dasharrow",    0, "\\dashrightarrow");
130                 create("Box",          0, "\\square");
131                 create("Diamond",      0, "\\lozenge");
132                 create("leadsto",      0, "\\rightsquigarrow");
133
134                 // amssymb.sty
135
136                 create("restriction",  0, "\\upharpoonright");
137                 create("Doteq",        0, "\\doteqdot");
138                 create("doublecup",    0, "\\Cup");
139                 create("doublecap",    0, "\\Cap");
140                 create("llless",       0, "\\lll");
141                 create("gggtr",        0, "\\ggg");
142         }
143
144         //create("lint",       4, "\\int_#1^#2#3 d#4");
145         //create("silentmult", 0, "\\cdot");
146         //create("binom",        2, "\\left(\\frac#1#2\\right)");
147 }