3 #include "math_parser.h"
4 #include "math_metricsinfo.h"
7 #include "support/filetools.h" // LibFileSearch
16 typedef map<string, latexkeys> WordList;
30 key_type wordlist_array[] =
32 {"!", LM_TK_SPACE, 0},
33 {"#", LM_TK_SPECIAL, '#'},
34 {"$", LM_TK_SPECIAL, '$'},
35 {"%", LM_TK_SPECIAL, '%'},
36 {"&", LM_TK_SPECIAL, '&'},
37 {"(", LM_TK_BEGIN, LM_OT_SIMPLE},
38 {")", LM_TK_END, LM_OT_SIMPLE},
39 {",", LM_TK_SPACE, 1},
40 {".", LM_TK_SPECIAL, '.'},
41 {":", LM_TK_SPACE, 2},
42 {";", LM_TK_SPACE, 3},
43 {"Pr", LM_TK_FUNCLIM, 0},
44 {"[", LM_TK_BEGIN, LM_OT_EQUATION},
45 {"]", LM_TK_END, LM_OT_EQUATION},
46 {"_", LM_TK_SPECIAL, '_'},
47 {"acute", LM_TK_DECORATION, 0},
48 {"arccos", LM_TK_FUNC, 0},
49 {"arcsin", LM_TK_FUNC, 0},
50 {"arctan", LM_TK_FUNC, 0},
51 {"arg", LM_TK_FUNC, 0},
52 {"atop", LM_TK_ATOP, 0},
53 {"bar", LM_TK_DECORATION, 0},
54 {"begin", LM_TK_BEGIN, 0},
55 {"bf", LM_TK_OLDFONT, LM_TC_BF},
56 {"binom", LM_TK_BINOM, 0},
57 {"bmod", LM_TK_FUNC, 0},
58 {"breve", LM_TK_DECORATION, 0},
59 {"cal", LM_TK_OLDFONT, LM_TC_CAL},
60 {"cdots", LM_TK_DOTS, 0},
61 {"check", LM_TK_DECORATION, 0},
62 {"choose", LM_TK_CHOOSE, 0},
63 {"cos", LM_TK_FUNC, 0},
64 {"cosh", LM_TK_FUNC, 0},
65 {"cot", LM_TK_FUNC, 0},
66 {"coth", LM_TK_FUNC, 0},
67 {"csc", LM_TK_FUNC, 0},
68 {"ddot", LM_TK_DECORATION, 0},
69 {"dddot", LM_TK_DECORATION, 0},
70 {"ddots", LM_TK_DOTS, 0},
71 {"deg", LM_TK_FUNC, 0},
72 {"det", LM_TK_FUNCLIM, 0},
73 {"dim", LM_TK_FUNC, 0},
74 {"displaystyle", LM_TK_STY, LM_ST_DISPLAY},
75 {"dot", LM_TK_DECORATION, 0},
76 {"end", LM_TK_END, 0},
77 {"exp", LM_TK_FUNC, 0},
78 {"frac", LM_TK_FRAC, 0},
79 {"frak", LM_TK_FONT, LM_TC_EUFRAK},
80 {"gcd", LM_TK_FUNCLIM, 0},
81 {"grave", LM_TK_DECORATION, 0},
82 {"hat", LM_TK_DECORATION, 0},
83 {"hom", LM_TK_FUNC, 0},
84 {"inf", LM_TK_FUNCLIM, 0},
85 {"it", LM_TK_OLDFONT, LM_TC_IT},
86 {"ker", LM_TK_FUNC, 0},
87 {"label", LM_TK_LABEL, 0},
88 {"lefteqn", LM_TK_LEFTEQN, 1},
89 {"ldots", LM_TK_DOTS, 0},
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 {"lyxbox", LM_TK_BOX, 0},
99 {"lyxnegspace", LM_TK_SPACE, 6},
100 {"mathbb", LM_TK_FONT, LM_TC_BB},
101 {"mathbf", LM_TK_FONT, LM_TC_BF},
102 {"mathcal", LM_TK_FONT, LM_TC_CAL},
103 {"mathfrak", LM_TK_FONT, LM_TC_EUFRAK},
104 {"mathit", LM_TK_FONT, LM_TC_IT},
105 {"mathnormal", LM_TK_FONT, LM_TC_VAR},
106 {"mathring", LM_TK_DECORATION, 0},
107 {"mathrm", LM_TK_FONT, LM_TC_RM},
108 {"mathsf", LM_TK_FONT, LM_TC_SF},
109 {"mathtt", LM_TK_FONT, LM_TC_TT},
110 {"max", LM_TK_FUNCLIM, 0},
111 //{"mbox", LM_TK_BOX, 0},
112 {"min", LM_TK_FUNCLIM, 0},
113 {"newcommand", LM_TK_NEWCOMMAND, 0 },
114 {"nolimits", LM_TK_LIMIT, static_cast<unsigned>(-1)},
115 {"nonumber", LM_TK_NONUM, 0},
116 {"not", LM_TK_NOT, 0},
117 {"over", LM_TK_OVER, 0},
118 {"overbrace", LM_TK_DECORATION, 0},
119 {"overleftarrow", LM_TK_DECORATION, 0},
120 {"overline", LM_TK_DECORATION, 0},
121 {"overrightarrow", LM_TK_DECORATION, 0},
122 {"overleftrightarrow", LM_TK_DECORATION, 0},
123 {"protect", LM_TK_PROTECT, 0},
124 {"qquad", LM_TK_SPACE, 5},
125 {"quad", LM_TK_SPACE, 4},
126 {"right", LM_TK_RIGHT, 0},
127 {"rm", LM_TK_OLDFONT, LM_TC_RM},
128 {"root", LM_TK_ROOT, 0},
129 {"scriptscriptstyle", LM_TK_STY, LM_ST_SCRIPTSCRIPT},
130 {"scriptstyle", LM_TK_STY, LM_ST_SCRIPT},
131 {"sec", LM_TK_FUNC, 0},
132 {"sin", LM_TK_FUNC, 0},
133 {"sinh", LM_TK_FUNC, 0},
134 {"sqrt", LM_TK_SQRT, 0},
135 {"stackrel", LM_TK_STACK, 0},
136 {"sup", LM_TK_FUNCLIM, 0},
137 {"tan", LM_TK_FUNC, 0},
138 {"tanh", LM_TK_FUNC, 0},
139 {"textrm", LM_TK_FONT, LM_TC_TEXTRM},
140 {"textstyle", LM_TK_STY, LM_ST_TEXT},
141 {"tilde", LM_TK_DECORATION, 0},
142 {"tt", LM_TK_OLDFONT, LM_TC_TT},
143 {"underbar", LM_TK_DECORATION, 0},
144 {"underbrace", LM_TK_DECORATION, 0},
145 {"underleftarrow", LM_TK_DECORATION, 0},
146 {"underline", LM_TK_DECORATION, 0},
147 {"underrightarrow", LM_TK_DECORATION, 0},
148 {"underleftrightarrow", LM_TK_DECORATION, 0},
149 {"underset", LM_TK_UNDERSET, 0},
150 {"vdots", LM_TK_DOTS, 0},
151 {"vec", LM_TK_DECORATION, 0},
152 {"widehat", LM_TK_DECORATION, 0},
153 {"widetilde", LM_TK_DECORATION, 0},
154 {"{", LM_TK_SPECIAL, '{'},
155 {"}", LM_TK_SPECIAL, '}'}
160 MathTokenEnum tokenEnum(const string & font)
178 void readSymbols(string const & filename)
181 lex.setFile(filename);
182 while (lex.isOK() && lex.next()) {
184 tmp.name = lex.getString();
186 tmp.token = tokenEnum(lex.getString());
188 tmp.latex_font_id = lex.getInteger();
190 tmp.id = lex.getInteger();
192 tmp.type = lex.getString();
194 tmp.xmlname = lex.getString();
195 if (theWordList.find(tmp.name) != theWordList.end())
196 lyxerr << "readSymbols: token " << tmp.name
197 << " already exists.\n";
199 theWordList[tmp.name] = tmp;
206 unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
207 for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
210 tmp.token = p->token;
212 tmp.latex_font_id = 0;
213 theWordList[p->name] = tmp;
216 lyxerr[Debug::MATHED] << "reading symbols file\n";
217 string const file = LibFileSearch(string(), "symbols");
219 lyxerr << "Could not find symbols file\n";
228 latexkeys const * in_word_set(string const & str)
230 static bool initialized = false;
237 WordList::iterator it = theWordList.find(str);
238 return (it != theWordList.end()) ? &(it->second) : 0;