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