3 #include "math_parser.h"
6 #include "support/filetools.h" // LibFileSearch
7 #include "support/lyxfunctional.h"
14 bool operator<(const latexkeys & a, const latexkeys & b)
16 return string(a.name) < string(b.name);
21 // This lists needs to remain sorted all the time!
32 latexkeys_a wordlist_array[] =
34 {"!", LM_TK_SPACE, 0},
35 {"#", LM_TK_SPECIAL, '#'},
36 {"$", LM_TK_SPECIAL, '$'},
37 {"%", LM_TK_SPECIAL, '%'},
38 {"&", LM_TK_SPECIAL, '&'},
39 {"(", LM_TK_BEGIN, LM_OT_SIMPLE},
40 {")", LM_TK_END, LM_OT_SIMPLE},
41 {",", LM_TK_SPACE, 1},
42 {".", LM_TK_SPECIAL, '.'},
43 {":", LM_TK_SPACE, 2},
44 {";", LM_TK_SPACE, 3},
45 {"Pr", LM_TK_FUNCLIM, 0},
46 {"[", LM_TK_BEGIN, LM_OT_EQUATION},
47 {"\\", LM_TK_NEWLINE, static_cast<unsigned>(-1)}, // -1 needed in mathed_parse_lines!
48 {"]", LM_TK_END, LM_OT_EQUATION},
49 {"_", LM_TK_SPECIAL, '_'},
50 {"acute", LM_TK_DECORATION, LM_acute},
51 {"arccos", LM_TK_FUNC, 0},
52 {"arcsin", LM_TK_FUNC, 0},
53 {"arctan", LM_TK_FUNC, 0},
54 {"arg", LM_TK_FUNC, 0},
55 {"atop", LM_TK_ATOP, 0},
56 {"backslash", LM_TK_SPECIAL, '\\'},
57 {"bar", LM_TK_DECORATION, LM_bar},
58 {"begin", LM_TK_BEGIN, 0},
59 {"binom", LM_TK_BINOM, 0},
60 {"bmod", LM_TK_FUNC, 0},
61 {"breve", LM_TK_DECORATION, LM_breve},
62 {"cal", LM_TK_OLDFONT, LM_TC_CAL},
63 {"cdots", LM_TK_DOTS, LM_cdots},
64 {"check", LM_TK_DECORATION, LM_check},
65 {"choose", LM_TK_CHOOSE, 0},
66 {"cos", LM_TK_FUNC, 0},
67 {"cosh", LM_TK_FUNC, 0},
68 {"cot", LM_TK_FUNC, 0},
69 {"coth", LM_TK_FUNC, 0},
70 {"csc", LM_TK_FUNC, 0},
71 {"ddot", LM_TK_DECORATION, LM_ddot},
72 {"ddots", LM_TK_DOTS, LM_ddots},
73 {"deg", LM_TK_FUNC, 0},
74 {"det", LM_TK_FUNCLIM, 0},
75 {"dim", LM_TK_FUNC, 0},
76 //{"displaystyle", LM_TK_STY, LM_ST_DISPLAY},
77 {"dot", LM_TK_DECORATION, LM_dot},
78 {"end", LM_TK_END, 0},
79 {"exp", LM_TK_FUNC, 0},
80 {"frac", LM_TK_FRAC, 0},
81 {"gcd", LM_TK_FUNCLIM, 0},
82 {"grave", LM_TK_DECORATION, LM_grave},
83 {"hat", LM_TK_DECORATION, LM_hat},
84 {"hom", LM_TK_FUNC, 0},
85 {"inf", LM_TK_FUNCLIM, 0},
86 {"ker", LM_TK_FUNC, 0},
87 {"kern", LM_TK_KERN, 0},
88 {"label", LM_TK_LABEL, 0},
89 {"ldots", LM_TK_DOTS, LM_ldots},
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 {"mathbb", LM_TK_FONT, LM_TC_BB},
99 {"mathbf", LM_TK_FONT, LM_TC_BF},
100 {"mathcal", LM_TK_FONT, LM_TC_CAL},
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 {"min", LM_TK_FUNCLIM, 0},
108 {"newcommand", LM_TK_NEWCOMMAND, 0 },
109 {"nolimits", LM_TK_LIMIT, static_cast<unsigned>(-1)},
110 {"nonumber", LM_TK_NONUM, 0},
111 {"not", LM_TK_NOT, LM_not},
112 {"over", LM_TK_OVER, 0},
113 {"overbrace", LM_TK_DECORATION, LM_overbrace},
114 {"overleftarrow", LM_TK_DECORATION, LM_overleftarrow},
115 {"overline", LM_TK_DECORATION, LM_overline},
116 {"overrightarrow", LM_TK_DECORATION, LM_overightarrow},
117 {"protect", LM_TK_PROTECT, 0},
118 {"qquad", LM_TK_SPACE, 5},
119 {"quad", LM_TK_SPACE, 4},
120 {"right", LM_TK_RIGHT, 0},
121 {"root", LM_TK_ROOT, 0},
122 //{"scriptscriptstyle", LM_TK_STY, LM_ST_SCRIPTSCRIPT},
123 //{"scriptstyle", LM_TK_STY, LM_ST_SCRIPT},
124 {"sec", LM_TK_FUNC, 0},
125 {"sin", LM_TK_FUNC, 0},
126 {"sinh", LM_TK_FUNC, 0},
127 {"sqrt", LM_TK_SQRT, 0},
128 {"stackrel", LM_TK_STACK, 0},
129 {"sup", LM_TK_FUNCLIM, 0},
130 {"tan", LM_TK_FUNC, 0},
131 {"tanh", LM_TK_FUNC, 0},
132 {"textrm", LM_TK_FONT, LM_TC_TEXTRM},
133 //{"textstyle", LM_TK_STY, LM_ST_TEXT},
134 {"tilde", LM_TK_DECORATION, LM_tilde},
135 {"underbrace", LM_TK_DECORATION, LM_underbrace},
136 {"underline", LM_TK_DECORATION, LM_underline},
137 {"vdots", LM_TK_DOTS, LM_vdots},
138 {"vec", LM_TK_DECORATION, LM_vec},
139 {"widehat", LM_TK_DECORATION, LM_widehat},
140 {"widetilde", LM_TK_DECORATION, LM_widetilde},
141 {"{", LM_TK_SPECIAL, '{'},
142 {"|", LM_TK_UNDEF, '|'},
143 {"}", LM_TK_SPECIAL, '}'},
144 {"", LM_TK_SPECIAL, 0}
148 std::vector<latexkeys> wordlist;
150 bool initialized = false;
155 void ReadSymbols(string const & filename)
158 lex.setFile(filename);
165 tmp.name = lex.getString();
170 font = lex.getString();
172 tmp.latex_font_id = lex.getInteger();
174 tmp.id = lex.getInteger();
176 type = lex.getString();
179 tmp.token = LM_TK_CMR;
180 else if (font == "cmsy")
181 tmp.token = LM_TK_CMSY;
182 else if (font == "cmm")
183 tmp.token = LM_TK_CMM;
184 else if (font == "cmex")
185 tmp.token = LM_TK_CMEX;
186 else if (font == "msa")
187 tmp.token = LM_TK_MSA;
188 else if (font == "msb")
189 tmp.token = LM_TK_MSB;
191 tmp.token = LM_TK_SYM;
193 if (type == "mathrel")
194 tmp.type = LMB_RELATION;
195 else if (type == "mathbin")
196 tmp.type = LMB_OPERATOR;
200 wordlist.push_back(tmp);
207 for (latexkeys_a * p = wordlist_array; !string(p->name).empty(); ++p) {
210 tmp.token = p->token;
213 tmp.latex_font_id = 0;
214 wordlist.push_back(tmp);
217 lyxerr[Debug::MATHED] << "Reading symbols file\n";
218 string const file = LibFileSearch(string(), "symbols");
220 lyxerr << "Could not find symbols file" << endl;
224 std::sort(wordlist.begin(), wordlist.end());
228 latexkeys const * in_word_set(string const & str)
235 std::vector<latexkeys>::iterator it =
236 std::find_if(wordlist.begin(), wordlist.end(),
237 lyx::compare_memfun(&latexkeys::Name, str));
238 return (it != wordlist.end()) ? &(*it) : 0;