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