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