3 #include "math_parser.h"
4 #include "math_arrayinset.h"
5 #include "math_amsarrayinset.h"
6 #include "math_binominset.h"
7 #include "math_boxinset.h"
8 #include "math_casesinset.h"
9 #include "math_decorationinset.h"
10 #include "math_dotsinset.h"
11 #include "math_fboxinset.h"
12 #include "math_fontinset.h"
13 #include "math_fracinset.h"
14 #include "math_kerninset.h"
15 #include "math_lefteqninset.h"
16 #include "math_macro.h"
17 #include "math_macrotable.h"
18 #include "math_macroarg.h"
19 #include "math_notinset.h"
20 #include "math_rootinset.h"
21 #include "math_sizeinset.h"
22 #include "math_spaceinset.h"
23 #include "math_splitinset.h"
24 #include "math_sqrtinset.h"
25 #include "math_stackrelinset.h"
26 #include "math_substackinset.h"
27 #include "math_symbolinset.h"
28 #include "math_undersetinset.h"
29 #include "math_unknowninset.h"
30 #include "math_xarrowinset.h"
31 #include "math_xymatrixinset.h"
32 #include "math_xyarrowinset.h"
34 #include "ref_inset.h"
36 #include "math_metricsinfo.h"
38 #include "math_support.h"
40 #include "support/filetools.h" // LibFileSearch
41 #include "frontends/font_loader.h"
50 typedef std::map<string, latexkeys> WordList;
64 key_type wordlist_array[] =
74 {"Vmatrix", "matrix", ""},
75 {"acute", "decoration", ""},
76 {"bar", "decoration", ""},
77 {"begin", "begin", ""},
78 {"bf", "oldfont", ""},
79 {"bmatrix", "matrix", ""},
80 {"acute", "decoration", ""},
81 {"breve", "decoration", ""},
82 {"cal", "oldfont", ""},
83 {"cdots", "dots", ""},
84 {"check", "decoration", ""},
85 {"ddot", "decoration", ""},
86 {"dddot", "decoration", ""},
87 {"ddots", "dots", ""},
88 {"displaystyle", "style", ""},
89 {"dot", "decoration", ""},
90 {"dotsb", "dots", ""},
91 {"dotsc", "dots", ""},
92 {"dotsi", "dots", ""},
93 {"dotsm", "dots", ""},
94 {"dotso", "dots", ""},
98 {"grave", "decoration", ""},
99 {"hat", "decoration", ""},
100 {"it", "oldfont", ""},
101 {"label", "label", ""},
102 {"ldots", "dots", ""},
103 {"left", "left", ""},
104 {"limits", "limit", ""},
105 {"lyxbox", "box", ""},
106 {"lyxnegspace", "space", ""},
107 {"lyxposspace", "space", ""},
108 {"mathbb", "font", ""},
109 {"mathbf", "font", ""},
110 {"mathcal", "font", ""},
111 {"mathfrak", "font", ""},
112 {"mathit", "font", ""},
113 {"mathnormal", "font", ""},
114 {"mathring", "decoration", ""},
115 {"mathrm", "font", ""},
116 {"mathsf", "font", ""},
117 {"mathtt", "font", ""},
118 {"matrix", "matrix", ""},
120 {"newcommand", "newcommand", ""},
121 {"nolimits", "limit", ""},
122 {"nonumber", "nonum", ""},
123 {"overbrace", "decoration", ""},
124 {"overleftarrow", "decoration", ""},
125 {"overline", "decoration", ""},
126 {"overrightarrow", "decoration", ""},
127 {"overleftrightarrow", "decoration", ""},
128 {"pmatrix", "matrix", ""},
129 {"protect", "protect", ""},
130 {"qquad", "space", ""},
131 {"quad", "space", ""},
132 {"right", "right", ""},
133 {"rm", "oldfont", ""},
134 {"scriptscriptstyle", "style", ""},
135 {"scriptstyle", "style", ""},
136 {"textbf", "font", "mathtext"},
137 {"textit", "font", "mathtext"},
138 {"textmd", "font", "mathtext"},
139 {"textrm", "font", "mathtext"},
140 {"textsl", "font", "mathtext"},
141 {"textup", "font", "mathtext"},
142 {"textstyle", "style", ""},
143 {"tilde", "decoration", ""},
144 {"tt", "oldfont", ""},
145 {"underbar", "decoration", ""},
146 {"underbrace", "decoration", ""},
147 {"underleftarrow", "decoration", ""},
148 {"underline", "decoration", ""},
149 {"underrightarrow", "decoration", ""},
150 {"underleftrightarrow", "decoration", ""},
151 {"underset", "underset", ""},
152 {"vdots", "dots", ""},
153 {"vec", "decoration", ""},
154 {"vmatrix", "matrix", ""},
155 {"widehat", "decoration", ""},
156 {"widetilde", "decoration", ""}
160 bool math_font_available(string & name)
163 augmentFont(f, name);
165 // Do we have the font proper?
166 if (fontloader.available(f))
170 if (name == "eufrak") {
171 name = "lyxfakefrak";
175 lyxerr[Debug::MATHED] << "font " << name << " not available and I can't fake it\n";
180 void readSymbols(string const & filename)
182 std::ifstream fs(filename.c_str());
189 istringstream is(line);
199 // tmp.inset _is_ the fontname here.
200 // create fallbacks if necessary
201 if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra=="special") {
202 lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n";
204 } else if (math_font_available(tmp.inset)) {
205 lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n";
206 tmp.draw += char(charid);
207 } else if (fallbackid) {
208 if (tmp.inset == "cmex")
209 tmp.inset = "lyxsymbol";
211 tmp.inset = "lyxboldsymbol";
212 lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n";
213 tmp.draw += char(fallbackid);
215 lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n";
217 tmp.inset = "lyxtex";
220 if (theWordList.find(tmp.name) != theWordList.end())
221 lyxerr[Debug::MATHED] << "readSymbols: inset " << tmp.name
222 << " already exists.\n";
224 theWordList[tmp.name] = tmp;
225 lyxerr[Debug::MATHED] << "read symbol '" << tmp.name
226 << " inset: " << tmp.inset
227 << " draw: " << int(tmp.draw[0])
228 << " extra: " << tmp.extra
236 unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
237 for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
240 tmp.inset = p->inset;
242 theWordList[p->name] = tmp;
245 lyxerr[Debug::MATHED] << "reading symbols file\n";
246 string const file = LibFileSearch(string(), "symbols");
248 lyxerr << "Could not find symbols file\n";
257 latexkeys const * in_word_set(string const & str)
259 static bool initialized = false;
266 WordList::iterator it = theWordList.find(str);
267 //lyxerr << "looking up '" << str << "' found: "
268 // << (it != theWordList.end()) << "\n";
269 return (it != theWordList.end()) ? &(it->second) : 0;
273 MathAtom createMathInset(string const & s)
275 lyxerr[Debug::MATHED] << "creating inset with name: '" << s << "'\n";
276 if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
277 return MathAtom(new MathMacroArgument(s[1] - '0'));
279 if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
280 && s[2] >= '1' && s[2] <= '9')
281 return MathAtom(new MathMacroArgument(s[2] - '0'));
283 return MathAtom(new MathKernInset);
285 return MathAtom(new MathXYMatrixInset);
286 if (s == "xrightarrow" || s == "xleftarrow")
287 return MathAtom(new MathXArrowInset(s));
288 if (s == "split" || s == "gathered" || s == "aligned")
289 return MathAtom(new MathSplitInset(s));
291 return MathAtom(new MathCasesInset);
293 return MathAtom(new MathSubstackInset);
294 if (s == "subarray" || s == "array")
295 return MathAtom(new MathArrayInset(s, 1, 1));
297 return MathAtom(new MathSqrtInset);
299 return MathAtom(new MathRootInset);
301 return MathAtom(new MathStackrelInset);
302 if (s == "binom" || s == "choose")
303 return MathAtom(new MathBinomInset);
304 if (s == "over" || s == "frac")
305 return MathAtom(new MathFracInset);
307 return MathAtom(new MathFracInset(true));
309 return MathAtom(new MathNotInset);
311 return MathAtom(new MathLefteqnInset);
313 return MathAtom(new RefInset);
316 latexkeys const * l = in_word_set(s);
318 string const & inset = l->inset;
319 lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n";
320 if (inset == "underset")
321 return MathAtom(new MathUndersetInset);
322 if (inset == "decoration")
323 return MathAtom(new MathDecorationInset(l->name));
324 //if (inset == "space")
325 // return MathAtom(new MathSpaceInset(l->id));
327 return MathAtom(new MathDotsInset(l->name));
329 return MathAtom(new MathBoxInset(l->name));
331 return MathAtom(new MathFboxInset);
332 if (inset == "style")
333 return MathAtom(new MathSizeInset(l));
335 return MathAtom(new MathFontInset(l->name));
336 if (inset == "oldfont")
337 return MathAtom(new MathFontInset(l->name));
338 if (inset == "matrix")
339 return MathAtom(new MathAMSArrayInset(s));
340 return MathAtom(new MathSymbolInset(l));
343 if (MathMacroTable::has(s))
344 return MathAtom(new MathMacro(s));
346 //lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << "'\n";
347 return MathAtom(new MathUnknownInset(s));