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