]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.C
oh well
[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)
51 {
52         macro_table[name] = MathAtom(new MathMacroTemplate(name, na));
53 }
54
55
56 void MathMacroTable::create
57         (string const & name, int na, MathArray const & ar1, MathArray const & ar2)
58 {
59         MathAtom t(new MathMacroTemplate(name, na));
60         t->cell(0) = ar1;
61         t->cell(1) = ar2;
62         macro_table[name] = t;
63 }
64
65
66 void MathMacroTable::define(string const & display)
67 {
68         string name;
69         mathed_parse_macro(name, display);
70 }
71
72
73 bool MathMacroTable::has(string const & name)
74 {
75         builtinMacros();
76         return macro_table.find(name) != macro_table.end();
77 }
78
79
80 void MathMacroTable::builtinMacros()
81 {
82         static bool built = false;
83
84         if (built)
85                 return;
86
87         built = true;
88         //lyxerr[Debug::MATHED] << "Building macros\n";
89         //define("\\def\\emptyset{\\not0}");
90         define("\\def\\notin{\\not\\in}");
91         define("\\def\\slash{/}");
92         //define("\\def\\mathcircumflex{\\^}");
93
94         // fontmath.ltx
95
96         define("\\def\\lnot{\\neg}");
97         define("\\def\\land{\\wedge}");
98         define("\\def\\lor{\\vee}");
99         define("\\def\\ne{\\neq}");
100         define("\\def\\le{\\leq}");
101         define("\\def\\ge{\\geq}");
102         define("\\def\\owns{\\ni}");
103         define("\\def\\gets{\\leftarrow}");
104         define("\\def\\to{\\rightarrow}");
105         define("\\def\\|{\\Vert}");
106
107         define("\\def\\longleftrightarrow{\\leftarrow\\kern-8mu\\rightarrow}");
108         define("\\def\\Longleftrightarrow{\\Leftarrow\\kern-8mu\\Rightarrow}");
109         define("\\def\\doteq{\\stackrel{\\cdot}{\\=}}");
110
111         if (math_font_available(LM_TC_CMSY)) {
112                 define("\\def\\longrightarrow{\\lyxbar\\kern-6mu\\rightarrow}");
113                 define("\\def\\longleftarrow{\\leftarrow\\kern-6mu\\lyxbar}");
114                 define("\\def\\mapsto{\\mapstochar\\kern-4mu\\rightarrow}");
115                 define("\\def\\longmapsto{\\mapstochar\\kern-3mu\\lyxbar\\kern-6mu\\rightarrow}");
116         }
117
118         if (math_font_available(LM_TC_CMR) && math_font_available(LM_TC_CMSY)) {
119                 define("\\def\\Longrightarrow{\\lyxeq\\kern-5mu\\Rightarrow}");
120                 define("\\def\\Longleftarrow{\\Leftarrow\\kern-5mu\\lyxeq}");
121                 define("\\def\\models{\\vert\\kern-3mu\\lyxeq}");
122         }
123
124         if (math_font_available(LM_TC_CMM)) {
125                 define("\\def\\hookrightarrow{\\lhook\\kern-8mu\\rightarrow}");
126                 define("\\def\\hookleftarrow{\\leftarrow\\kern-8mu\\rhook}");
127                 define("\\def\\bowtie{\\triangleright\\kern-2mu\\triangleleft}");
128         }
129
130         if (math_font_available(LM_TC_MSA)) {
131                 //amsfonts.sty
132
133                 define("\\def\\dashrightarrow{\\lyxdabar\\lyxdabar\\lyxright}");
134                 define("\\def\\dashleftarrow{\\lyxleft\\lyxdabar\\lyxdabar}");
135                 define("\\def\\dasharrow{\\dashrightarrow}");
136                 define("\\def\\Box{\\square}");
137                 define("\\def\\Diamond{\\lozenge}");
138                 define("\\def\\leadsto{\\rightsquigarrow}");
139
140                 // amssymb.sty
141
142                 define("\\def\\restriction{\\upharpoonright}");
143                 define("\\def\\Doteq{\\doteqdot}");
144                 define("\\def\\doublecup{\\Cup}");
145                 define("\\def\\doublecap{\\Cap}");
146                 define("\\def\\llless{\\lll}");
147                 define("\\def\\gggtr{\\ggg}");
148         }
149
150         if (math_font_available(LM_TC_MSB)) {
151                 define("\\def\\Join{\\ltimes\\kern-12mu\\rtimes}");
152         }
153
154         //
155         define("\\def\\mathcircumflex{\\mbox{\\^{}}}\n"   "{\\hat{}}");
156
157         //define("\def\lint",       4, "\\int_#1^#2#3 d#4}");
158         //define("\\def\\silentmult{\\cdot}");
159         //define("\def\binom",        2, "\\left(\\frac#1#2\\right)}");
160 }