]> git.lyx.org Git - lyx.git/blob - src/mathed/math_macrotable.C
fix typo that put too many include paths for most people
[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 & def)
67 {
68         string name;
69         mathed_parse_macro(name, def);
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
93         // fontmath.ltx
94
95         define("\\def\\lnot{\\neg}");
96         define("\\def\\land{\\wedge}");
97         define("\\def\\lor{\\vee}");
98         define("\\def\\ne{\\neq}");
99         define("\\def\\le{\\leq}");
100         define("\\def\\ge{\\geq}");
101         define("\\def\\owns{\\ni}");
102         define("\\def\\gets{\\leftarrow}");
103         define("\\def\\to{\\rightarrow}");
104         define("\\def\\|{\\Vert}");
105
106         define("\\def\\longleftrightarrow{\\leftarrow\\kern-8mu\\rightarrow}");
107         define("\\def\\Longleftrightarrow{\\Leftarrow\\kern-8mu\\Rightarrow}");
108         define("\\def\\doteq{\\stackrel{\\cdot}{\\=}}");
109
110         if (math_font_available(LM_TC_CMSY)) {
111                 define("\\def\\longrightarrow{\\lyxbar\\kern-6mu\\rightarrow}");
112                 define("\\def\\longleftarrow{\\leftarrow\\kern-6mu\\lyxbar}");
113                 define("\\def\\mapsto{\\mapstochar\\kern-4mu\\rightarrow}");
114                 define("\\def\\longmapsto{\\mapstochar\\kern-3mu\\lyxbar\\kern-6mu\\rightarrow}");
115         }
116
117         if (math_font_available(LM_TC_CMR) && math_font_available(LM_TC_CMSY)) {
118                 define("\\def\\Longrightarrow{\\lyxeq\\kern-5mu\\Rightarrow}");
119                 define("\\def\\Longleftarrow{\\Leftarrow\\kern-5mu\\lyxeq}");
120                 define("\\def\\models{\\vert\\kern-3mu\\lyxeq}");
121         }
122
123         if (math_font_available(LM_TC_CMM)) {
124                 define("\\def\\hookrightarrow{\\lhook\\kern-8mu\\rightarrow}");
125                 define("\\def\\hookleftarrow{\\leftarrow\\kern-8mu\\rhook}");
126                 define("\\def\\bowtie{\\triangleright\\kern-2mu\\triangleleft}");
127         }
128
129         if (math_font_available(LM_TC_MSA)) {
130                 //amsfonts.sty
131
132                 define("\\def\\dashrightarrow{\\lyxdabar\\lyxdabar\\lyxright}");
133                 define("\\def\\dashleftarrow{\\lyxleft\\lyxdabar\\lyxdabar}");
134                 define("\\def\\dasharrow{\\dashrightarrow}");
135                 define("\\def\\Box{\\square}");
136                 define("\\def\\Diamond{\\lozenge}");
137                 define("\\def\\leadsto{\\rightsquigarrow}");
138
139                 // amssymb.sty
140
141                 define("\\def\\restriction{\\upharpoonright}");
142                 define("\\def\\Doteq{\\doteqdot}");
143                 define("\\def\\doublecup{\\Cup}");
144                 define("\\def\\doublecap{\\Cap}");
145                 define("\\def\\llless{\\lll}");
146                 define("\\def\\gggtr{\\ggg}");
147         }
148
149         if (math_font_available(LM_TC_MSB)) {
150                 define("\\def\\Join{\\ltimes\\kern-12mu\\rtimes}");
151         }
152
153         //define("\def\lint",       4, "\\int_#1^#2#3 d#4}");
154         //define("\\def\\silentmult{\\cdot}");
155         //define("\def\binom",        2, "\\left(\\frac#1#2\\right)}");
156 }