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 {"dddot", LM_TK_DECORATION, 0},
68 {"ddots", LM_TK_DOTS, 0},
69 {"deg", LM_TK_FUNC, 0},
70 {"det", LM_TK_FUNCLIM, 0},
71 {"dim", LM_TK_FUNC, 0},
72 {"displaystyle", LM_TK_STY, LM_ST_DISPLAY},
73 {"dot", LM_TK_DECORATION, 0},
74 {"end", LM_TK_END, 0},
75 {"exp", LM_TK_FUNC, 0},
76 {"frac", LM_TK_FRAC, 0},
77 {"frak", LM_TK_FONT, LM_TC_EUFRAK},
78 {"gcd", LM_TK_FUNCLIM, 0},
79 {"grave", LM_TK_DECORATION, 0},
80 {"hat", LM_TK_DECORATION, 0},
81 {"hom", LM_TK_FUNC, 0},
82 {"inf", LM_TK_FUNCLIM, 0},
83 {"it", LM_TK_OLDFONT, LM_TC_IT},
84 {"ker", LM_TK_FUNC, 0},
85 {"kern", LM_TK_KERN, 0},
86 {"label", LM_TK_LABEL, 0},
87 {"lefteqn", LM_TK_LEFTEQN, 1},
88 {"ldots", LM_TK_DOTS, 0},
89 {"left", LM_TK_LEFT, 0},
90 {"lg", LM_TK_FUNC, 0},
91 {"lim", LM_TK_FUNCLIM, 0},
92 {"liminf", LM_TK_FUNCLIM, 0},
93 {"limits", LM_TK_LIMIT, 1 },
94 {"limsup", LM_TK_FUNCLIM, 0},
95 {"ln", LM_TK_FUNC, 0},
96 {"log", LM_TK_FUNC, 0},
97 {"lyxbox", LM_TK_BOX, 0},
98 {"mathbb", LM_TK_FONT, LM_TC_BB},
99 {"mathbf", LM_TK_FONT, LM_TC_BF},
100 {"mathcal", LM_TK_FONT, LM_TC_CAL},
101 {"mathfrak", LM_TK_FONT, LM_TC_EUFRAK},
102 {"mathit", LM_TK_FONT, LM_TC_IT},
103 {"mathnormal", LM_TK_FONT, LM_TC_VAR},
104 {"mathrm", LM_TK_FONT, LM_TC_RM},
105 {"mathsf", LM_TK_FONT, LM_TC_SF},
106 {"mathtt", LM_TK_FONT, LM_TC_TT},
107 {"max", LM_TK_FUNCLIM, 0},
108 //{"mbox", LM_TK_BOX, 0},
109 {"min", LM_TK_FUNCLIM, 0},
110 {"newcommand", LM_TK_NEWCOMMAND, 0 },
111 {"nolimits", LM_TK_LIMIT, static_cast<unsigned>(-1)},
112 {"nonumber", LM_TK_NONUM, 0},
113 {"not", LM_TK_NOT, 0},
114 {"over", LM_TK_OVER, 0},
115 {"overbrace", LM_TK_DECORATION, 0},
116 {"overleftarrow", LM_TK_DECORATION, 0},
117 {"overline", LM_TK_DECORATION, 0},
118 {"overrightarrow", LM_TK_DECORATION, 0},
119 {"protect", LM_TK_PROTECT, 0},
120 {"qquad", LM_TK_SPACE, 5},
121 {"quad", LM_TK_SPACE, 4},
122 {"right", LM_TK_RIGHT, 0},
123 {"rm", LM_TK_OLDFONT, LM_TC_RM},
124 {"root", LM_TK_ROOT, 0},
125 {"scriptscriptstyle", LM_TK_STY, LM_ST_SCRIPTSCRIPT},
126 {"scriptstyle", LM_TK_STY, LM_ST_SCRIPT},
127 {"sec", LM_TK_FUNC, 0},
128 {"sin", LM_TK_FUNC, 0},
129 {"sinh", LM_TK_FUNC, 0},
130 {"sqrt", LM_TK_SQRT, 0},
131 {"stackrel", LM_TK_STACK, 0},
132 {"sup", LM_TK_FUNCLIM, 0},
133 {"tan", LM_TK_FUNC, 0},
134 {"tanh", LM_TK_FUNC, 0},
135 {"textrm", LM_TK_FONT, LM_TC_TEXTRM},
136 {"textstyle", LM_TK_STY, LM_ST_TEXT},
137 {"tilde", LM_TK_DECORATION, 0},
138 {"tt", LM_TK_OLDFONT, LM_TC_TT},
139 {"underbar", LM_TK_DECORATION, 0},
140 {"underbrace", LM_TK_DECORATION, 0},
141 {"underleftarrow", LM_TK_DECORATION, 0},
142 {"underline", LM_TK_DECORATION, 0},
143 {"underrightarrow", LM_TK_DECORATION, 0},
144 {"underset", LM_TK_UNDERSET, 0},
145 {"vdots", LM_TK_DOTS, 0},
146 {"vec", LM_TK_DECORATION, 0},
147 {"widehat", LM_TK_DECORATION, 0},
148 {"widetilde", LM_TK_DECORATION, 0},
149 {"{", LM_TK_SPECIAL, '{'},
150 {"}", LM_TK_SPECIAL, '}'}
155 MathTokenEnum tokenEnum(const string & font)
173 void readSymbols(string const & filename)
176 lex.setFile(filename);
177 while (lex.isOK() && lex.next()) {
179 tmp.name = lex.getString();
181 tmp.token = tokenEnum(lex.getString());
183 tmp.latex_font_id = lex.getInteger();
185 tmp.id = lex.getInteger();
187 tmp.type = lex.getString();
189 tmp.xmlname = lex.getString();
190 if (theWordList.find(tmp.name) != theWordList.end())
191 lyxerr << "readSymbols: token " << tmp.name
192 << " already exists.\n";
194 theWordList[tmp.name] = tmp;
200 unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
201 for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
204 tmp.token = p->token;
206 tmp.latex_font_id = 0;
207 theWordList[p->name] = tmp;
210 lyxerr[Debug::MATHED] << "reading symbols file\n";
211 string const file = LibFileSearch(string(), "symbols");
213 lyxerr << "Could not find symbols file\n";
222 latexkeys const * in_word_set(string const & str)
224 static bool initialized = false;
231 std::map<string, latexkeys>::iterator it = theWordList.find(str);
232 return (it != theWordList.end()) ? &(it->second) : 0;