3 #include "math_parser.h"
4 #include "math_metricsinfo.h"
7 #include "support/filetools.h" // LibFileSearch
16 typedef map<string, latexkeys> WordList;
30 key_type wordlist_array[] =
32 {"!", LM_TK_SPACE, 0},
33 {"#", LM_TK_SPECIAL, '#'},
34 {"$", LM_TK_SPECIAL, '$'},
35 {"%", LM_TK_SPECIAL, '%'},
36 {"&", LM_TK_SPECIAL, '&'},
37 {"(", LM_TK_BEGIN, LM_OT_SIMPLE},
38 {")", LM_TK_END, LM_OT_SIMPLE},
39 {",", LM_TK_SPACE, 1},
40 {".", LM_TK_SPECIAL, '.'},
41 {":", LM_TK_SPACE, 2},
42 {";", LM_TK_SPACE, 3},
43 {"Pr", LM_TK_FUNCLIM, 0},
44 {"[", LM_TK_BEGIN, LM_OT_EQUATION},
45 {"]", LM_TK_END, LM_OT_EQUATION},
46 {"_", LM_TK_SPECIAL, '_'},
47 {"acute", LM_TK_DECORATION, 0},
48 {"arccos", LM_TK_FUNC, 0},
49 {"arcsin", LM_TK_FUNC, 0},
50 {"arctan", LM_TK_FUNC, 0},
51 {"arg", LM_TK_FUNC, 0},
52 {"atop", LM_TK_ATOP, 0},
53 {"bar", LM_TK_DECORATION, 0},
54 {"begin", LM_TK_BEGIN, 0},
55 {"bf", LM_TK_OLDFONT, LM_TC_BF},
56 {"binom", LM_TK_BINOM, 0},
57 {"bmod", LM_TK_FUNC, 0},
58 {"breve", LM_TK_DECORATION, 0},
59 {"cal", LM_TK_OLDFONT, LM_TC_CAL},
60 {"cdots", LM_TK_DOTS, 0},
61 {"check", LM_TK_DECORATION, 0},
62 {"choose", LM_TK_CHOOSE, 0},
63 {"cos", LM_TK_FUNC, 0},
64 {"cosh", LM_TK_FUNC, 0},
65 {"cot", LM_TK_FUNC, 0},
66 {"coth", LM_TK_FUNC, 0},
67 {"csc", LM_TK_FUNC, 0},
68 {"ddot", LM_TK_DECORATION, 0},
69 {"dddot", LM_TK_DECORATION, 0},
70 {"ddots", LM_TK_DOTS, 0},
71 {"deg", LM_TK_FUNC, 0},
72 {"det", LM_TK_FUNCLIM, 0},
73 {"dim", LM_TK_FUNC, 0},
74 {"displaystyle", LM_TK_STY, LM_ST_DISPLAY},
75 {"dot", LM_TK_DECORATION, 0},
76 {"end", LM_TK_END, 0},
77 {"exp", LM_TK_FUNC, 0},
78 {"frac", LM_TK_FRAC, 0},
79 {"frak", LM_TK_FONT, LM_TC_EUFRAK},
80 {"gcd", LM_TK_FUNCLIM, 0},
81 {"grave", LM_TK_DECORATION, 0},
82 {"hat", LM_TK_DECORATION, 0},
83 {"hom", LM_TK_FUNC, 0},
84 {"inf", LM_TK_FUNCLIM, 0},
85 {"it", LM_TK_OLDFONT, LM_TC_IT},
86 {"ker", LM_TK_FUNC, 0},
87 {"label", LM_TK_LABEL, 0},
88 {"lefteqn", LM_TK_LEFTEQN, 1},
89 {"ldots", LM_TK_DOTS, 0},
90 {"left", LM_TK_LEFT, 0},
91 {"lg", LM_TK_FUNC, 0},
92 {"lim", LM_TK_FUNCLIM, 0},
93 {"liminf", LM_TK_FUNCLIM, 0},
94 {"limits", LM_TK_LIMIT, 1 },
95 {"limsup", LM_TK_FUNCLIM, 0},
96 {"ln", LM_TK_FUNC, 0},
97 {"log", LM_TK_FUNC, 0},
98 {"lyxbox", LM_TK_BOX, 0},
99 {"lyxnegspace", LM_TK_SPACE, 6},
100 {"mathbb", LM_TK_FONT, LM_TC_BB},
101 {"mathbf", LM_TK_FONT, LM_TC_BF},
102 {"mathcal", LM_TK_FONT, LM_TC_CAL},
103 {"mathfrak", LM_TK_FONT, LM_TC_EUFRAK},
104 {"mathit", LM_TK_FONT, LM_TC_IT},
105 {"mathnormal", LM_TK_FONT, LM_TC_VAR},
106 {"mathrm", LM_TK_FONT, LM_TC_RM},
107 {"mathsf", LM_TK_FONT, LM_TC_SF},
108 {"mathtt", LM_TK_FONT, LM_TC_TT},
109 {"max", LM_TK_FUNCLIM, 0},
110 //{"mbox", LM_TK_BOX, 0},
111 {"min", LM_TK_FUNCLIM, 0},
112 {"newcommand", LM_TK_NEWCOMMAND, 0 },
113 {"nolimits", LM_TK_LIMIT, static_cast<unsigned>(-1)},
114 {"nonumber", LM_TK_NONUM, 0},
115 {"not", LM_TK_NOT, 0},
116 {"over", LM_TK_OVER, 0},
117 {"overbrace", LM_TK_DECORATION, 0},
118 {"overleftarrow", LM_TK_DECORATION, 0},
119 {"overline", LM_TK_DECORATION, 0},
120 {"overrightarrow", LM_TK_DECORATION, 0},
121 {"overleftrightarrow", LM_TK_DECORATION, 0},
122 {"protect", LM_TK_PROTECT, 0},
123 {"qquad", LM_TK_SPACE, 5},
124 {"quad", LM_TK_SPACE, 4},
125 {"right", LM_TK_RIGHT, 0},
126 {"rm", LM_TK_OLDFONT, LM_TC_RM},
127 {"root", LM_TK_ROOT, 0},
128 {"scriptscriptstyle", LM_TK_STY, LM_ST_SCRIPTSCRIPT},
129 {"scriptstyle", LM_TK_STY, LM_ST_SCRIPT},
130 {"sec", LM_TK_FUNC, 0},
131 {"sin", LM_TK_FUNC, 0},
132 {"sinh", LM_TK_FUNC, 0},
133 {"sqrt", LM_TK_SQRT, 0},
134 {"stackrel", LM_TK_STACK, 0},
135 {"sup", LM_TK_FUNCLIM, 0},
136 {"tan", LM_TK_FUNC, 0},
137 {"tanh", LM_TK_FUNC, 0},
138 {"textrm", LM_TK_FONT, LM_TC_TEXTRM},
139 {"textstyle", LM_TK_STY, LM_ST_TEXT},
140 {"tilde", LM_TK_DECORATION, 0},
141 {"tt", LM_TK_OLDFONT, LM_TC_TT},
142 {"underbar", LM_TK_DECORATION, 0},
143 {"underbrace", LM_TK_DECORATION, 0},
144 {"underleftarrow", LM_TK_DECORATION, 0},
145 {"underline", LM_TK_DECORATION, 0},
146 {"underrightarrow", LM_TK_DECORATION, 0},
147 {"underleftrightarrow", LM_TK_DECORATION, 0},
148 {"underset", LM_TK_UNDERSET, 0},
149 {"vdots", LM_TK_DOTS, 0},
150 {"vec", LM_TK_DECORATION, 0},
151 {"widehat", LM_TK_DECORATION, 0},
152 {"widetilde", LM_TK_DECORATION, 0},
153 {"{", LM_TK_SPECIAL, '{'},
154 {"}", LM_TK_SPECIAL, '}'}
159 MathTokenEnum tokenEnum(const string & font)
177 void readSymbols(string const & filename)
180 lex.setFile(filename);
181 while (lex.isOK() && lex.next()) {
183 tmp.name = lex.getString();
185 tmp.token = tokenEnum(lex.getString());
187 tmp.latex_font_id = lex.getInteger();
189 tmp.id = lex.getInteger();
191 tmp.type = lex.getString();
193 tmp.xmlname = lex.getString();
194 if (theWordList.find(tmp.name) != theWordList.end())
195 lyxerr << "readSymbols: token " << tmp.name
196 << " already exists.\n";
198 theWordList[tmp.name] = tmp;
205 unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
206 for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
209 tmp.token = p->token;
211 tmp.latex_font_id = 0;
212 theWordList[p->name] = tmp;
215 lyxerr[Debug::MATHED] << "reading symbols file\n";
216 string const file = LibFileSearch(string(), "symbols");
218 lyxerr << "Could not find symbols file\n";
227 latexkeys const * in_word_set(string const & str)
229 static bool initialized = false;
236 WordList::iterator it = theWordList.find(str);
237 return (it != theWordList.end()) ? &(it->second) : 0;