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_NEWLINE, static_cast<unsigned>(-1)}, // -1 needed in mathed_parse_lines!
41 {"]", LM_TK_END, LM_OT_EQUATION},
42 {"_", LM_TK_SPECIAL, '_'},
43 {"acute", LM_TK_DECORATION, 0},
44 {"arccos", LM_TK_FUNC, 0},
45 {"arcsin", LM_TK_FUNC, 0},
46 {"arctan", LM_TK_FUNC, 0},
47 {"arg", LM_TK_FUNC, 0},
48 {"atop", LM_TK_ATOP, 0},
49 {"bar", LM_TK_DECORATION, 0},
50 {"begin", LM_TK_BEGIN, 0},
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 {"gcd", LM_TK_FUNCLIM, 0},
74 {"grave", LM_TK_DECORATION, 0},
75 {"hat", LM_TK_DECORATION, 0},
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 {"lefteqn", LM_TK_LEFTEQN, 1},
82 {"ldots", LM_TK_DOTS, 0},
83 {"left", LM_TK_LEFT, 0},
84 {"lg", LM_TK_FUNC, 0},
85 {"lim", LM_TK_FUNCLIM, 0},
86 {"liminf", LM_TK_FUNCLIM, 0},
87 {"limits", LM_TK_LIMIT, 1 },
88 {"limsup", LM_TK_FUNCLIM, 0},
89 {"ln", LM_TK_FUNC, 0},
90 {"log", LM_TK_FUNC, 0},
91 {"mathbb", LM_TK_FONT, LM_TC_BB},
92 {"mathbf", LM_TK_FONT, LM_TC_BF},
93 {"mathcal", LM_TK_FONT, LM_TC_CAL},
94 {"mathit", LM_TK_FONT, LM_TC_IT},
95 {"mathnormal", LM_TK_FONT, LM_TC_VAR},
96 {"mathrm", LM_TK_FONT, LM_TC_RM},
97 {"mathsf", LM_TK_FONT, LM_TC_SF},
98 {"mathtt", LM_TK_FONT, LM_TC_TT},
99 {"max", LM_TK_FUNCLIM, 0},
100 //{"mbox", LM_TK_BOX, 0},
101 {"min", LM_TK_FUNCLIM, 0},
102 {"newcommand", LM_TK_NEWCOMMAND, 0 },
103 {"nolimits", LM_TK_LIMIT, static_cast<unsigned>(-1)},
104 {"nonumber", LM_TK_NONUM, 0},
105 {"not", LM_TK_NOT, 0},
106 {"over", LM_TK_OVER, 0},
107 {"overbrace", LM_TK_DECORATION, 0},
108 {"overleftarrow", LM_TK_DECORATION, 0},
109 {"overline", LM_TK_DECORATION, 0},
110 {"overrightarrow", LM_TK_DECORATION, 0},
111 {"protect", LM_TK_PROTECT, 0},
112 {"qquad", LM_TK_SPACE, 5},
113 {"quad", LM_TK_SPACE, 4},
114 {"right", LM_TK_RIGHT, 0},
115 {"root", LM_TK_ROOT, 0},
116 //{"scriptscriptstyle", LM_TK_STY, LM_ST_SCRIPTSCRIPT},
117 //{"scriptstyle", LM_TK_STY, LM_ST_SCRIPT},
118 {"sec", LM_TK_FUNC, 0},
119 {"sin", LM_TK_FUNC, 0},
120 {"sinh", LM_TK_FUNC, 0},
121 {"sqrt", LM_TK_SQRT, 0},
122 {"stackrel", LM_TK_STACK, 0},
123 {"sup", LM_TK_FUNCLIM, 0},
124 {"tan", LM_TK_FUNC, 0},
125 {"tanh", LM_TK_FUNC, 0},
126 {"textrm", LM_TK_FONT, LM_TC_TEXTRM},
127 //{"textstyle", LM_TK_STY, LM_ST_TEXT},
128 {"tilde", LM_TK_DECORATION, 0},
129 {"underbrace", LM_TK_DECORATION, 0},
130 {"underline", LM_TK_DECORATION, 0},
131 {"vdots", LM_TK_DOTS, 0},
132 {"vec", LM_TK_DECORATION, 0},
133 {"widehat", LM_TK_DECORATION, 0},
134 {"widetilde", LM_TK_DECORATION, 0},
135 {"{", LM_TK_SPECIAL, '{'},
136 {"}", LM_TK_SPECIAL, '}'}
141 MathTokenEnum tokenEnum(const string & font)
159 MathSymbolTypes symbolType(const string & type)
161 if (type == "mathrel")
163 if (type == "mathbin")
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 = symbolType(lex.getString());
184 if (theWordList.find(tmp.name) != theWordList.end())
185 lyxerr << "readSymbols: token " << tmp.name
186 << " already exists.\n";
188 theWordList[tmp.name] = tmp;
194 unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
195 for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
198 tmp.token = p->token;
201 tmp.latex_font_id = 0;
202 theWordList[p->name] = tmp;
205 lyxerr[Debug::MATHED] << "reading symbols file\n";
206 string const file = LibFileSearch(string(), "symbols");
208 lyxerr << "Could not find symbols file\n";
217 latexkeys const * in_word_set(string const & str)
219 static bool initialized = false;
226 std::map<string, latexkeys>::iterator it = theWordList.find(str);
227 return (it != theWordList.end()) ? &(it->second) : 0;