3 #include "math_parser.h"
6 #include "support/filetools.h" // LibFileSearch
7 #include "support/lyxfunctional.h"
24 latexkeys_a wordlist_array[] =
26 {"!", LM_TK_SPACE, 0},
27 {"#", LM_TK_SPECIAL, '#'},
28 {"$", LM_TK_SPECIAL, '$'},
29 {"%", LM_TK_SPECIAL, '%'},
30 {"&", LM_TK_SPECIAL, '&'},
31 {"(", LM_TK_BEGIN, LM_OT_SIMPLE},
32 {")", LM_TK_END, LM_OT_SIMPLE},
33 {",", LM_TK_SPACE, 1},
34 {".", LM_TK_SPECIAL, '.'},
35 {":", LM_TK_SPACE, 2},
36 {";", LM_TK_SPACE, 3},
37 {"Pr", LM_TK_FUNCLIM, 0},
38 {"[", LM_TK_BEGIN, LM_OT_EQUATION},
39 {"\\", LM_TK_NEWLINE, static_cast<unsigned>(-1)}, // -1 needed in mathed_parse_lines!
40 {"]", LM_TK_END, LM_OT_EQUATION},
41 {"_", LM_TK_SPECIAL, '_'},
42 {"acute", LM_TK_DECORATION, LM_acute},
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 {"backslash", LM_TK_SPECIAL, '\\'},
49 {"bar", LM_TK_DECORATION, LM_bar},
50 {"begin", LM_TK_BEGIN, 0},
51 {"binom", LM_TK_BINOM, 0},
52 {"bmod", LM_TK_FUNC, 0},
53 {"breve", LM_TK_DECORATION, LM_breve},
54 {"cal", LM_TK_OLDFONT, LM_TC_CAL},
55 {"cdots", LM_TK_DOTS, LM_cdots},
56 {"check", LM_TK_DECORATION, LM_check},
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, LM_ddot},
64 {"ddots", LM_TK_DOTS, LM_ddots},
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, LM_dot},
70 {"end", LM_TK_END, 0},
71 {"exp", LM_TK_FUNC, 0},
72 {"frac", LM_TK_FRAC, 0},
73 {"gcd", LM_TK_FUNCLIM, 0},
74 {"grave", LM_TK_DECORATION, LM_grave},
75 {"hat", LM_TK_DECORATION, LM_hat},
76 {"hom", LM_TK_FUNC, 0},
77 {"inf", LM_TK_FUNCLIM, 0},
78 {"ker", LM_TK_FUNC, 0},
79 {"kern", LM_TK_KERN, 0},
80 {"label", LM_TK_LABEL, 0},
81 {"ldots", LM_TK_DOTS, LM_ldots},
82 {"left", LM_TK_LEFT, 0},
83 {"lg", LM_TK_FUNC, 0},
84 {"lim", LM_TK_FUNCLIM, 0},
85 {"liminf", LM_TK_FUNCLIM, 0},
86 {"limits", LM_TK_LIMIT, 1 },
87 {"limsup", LM_TK_FUNCLIM, 0},
88 {"ln", LM_TK_FUNC, 0},
89 {"log", LM_TK_FUNC, 0},
90 {"mathbb", LM_TK_FONT, LM_TC_BB},
91 {"mathbf", LM_TK_FONT, LM_TC_BF},
92 {"mathcal", LM_TK_FONT, LM_TC_CAL},
93 {"mathit", LM_TK_FONT, LM_TC_IT},
94 {"mathnormal", LM_TK_FONT, LM_TC_VAR},
95 {"mathrm", LM_TK_FONT, LM_TC_RM},
96 {"mathsf", LM_TK_FONT, LM_TC_SF},
97 {"mathtt", LM_TK_FONT, LM_TC_TT},
98 {"max", LM_TK_FUNCLIM, 0},
99 {"min", LM_TK_FUNCLIM, 0},
100 {"newcommand", LM_TK_NEWCOMMAND, 0 },
101 {"nolimits", LM_TK_LIMIT, static_cast<unsigned>(-1)},
102 {"nonumber", LM_TK_NONUM, 0},
103 {"not", LM_TK_NOT, LM_not},
104 {"over", LM_TK_OVER, 0},
105 {"overbrace", LM_TK_DECORATION, LM_overbrace},
106 {"overleftarrow", LM_TK_DECORATION, LM_overleftarrow},
107 {"overline", LM_TK_DECORATION, LM_overline},
108 {"overrightarrow", LM_TK_DECORATION, LM_overightarrow},
109 {"protect", LM_TK_PROTECT, 0},
110 {"qquad", LM_TK_SPACE, 5},
111 {"quad", LM_TK_SPACE, 4},
112 {"right", LM_TK_RIGHT, 0},
113 {"root", LM_TK_ROOT, 0},
114 //{"scriptscriptstyle", LM_TK_STY, LM_ST_SCRIPTSCRIPT},
115 //{"scriptstyle", LM_TK_STY, LM_ST_SCRIPT},
116 {"sec", LM_TK_FUNC, 0},
117 {"sin", LM_TK_FUNC, 0},
118 {"sinh", LM_TK_FUNC, 0},
119 {"sqrt", LM_TK_SQRT, 0},
120 {"stackrel", LM_TK_STACK, 0},
121 {"sup", LM_TK_FUNCLIM, 0},
122 {"tan", LM_TK_FUNC, 0},
123 {"tanh", LM_TK_FUNC, 0},
124 {"textrm", LM_TK_FONT, LM_TC_TEXTRM},
125 //{"textstyle", LM_TK_STY, LM_ST_TEXT},
126 {"tilde", LM_TK_DECORATION, LM_tilde},
127 {"underbrace", LM_TK_DECORATION, LM_underbrace},
128 {"underline", LM_TK_DECORATION, LM_underline},
129 {"vdots", LM_TK_DOTS, LM_vdots},
130 {"vec", LM_TK_DECORATION, LM_vec},
131 {"widehat", LM_TK_DECORATION, LM_widehat},
132 {"widetilde", LM_TK_DECORATION, LM_widetilde},
133 {"{", LM_TK_SPECIAL, '{'},
134 {"|", LM_TK_UNDEF, '|'},
135 {"}", LM_TK_SPECIAL, '}'},
139 std::map<string, latexkeys> wordlist;
143 MathTokenEnum tokenEnum(const string & font)
160 MathSymbolTypes symbolType(const string & type)
162 if (type == "mathrel")
164 if (type == "mathbin")
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 = symbolType(lex.getString());
188 wordlist[tmp.name] = tmp;
195 unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
196 for (latexkeys_a * p = wordlist_array; p != wordlist_array + n; ++p) {
199 tmp.token = p->token;
202 tmp.latex_font_id = 0;
203 wordlist[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";
215 latexkeys const * in_word_set(string const & str)
217 static bool initialized = false;
224 std::map<string, latexkeys>::iterator it = wordlist.find(str);
225 return (it != wordlist.end()) ? &(it->second) : 0;