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 "math_metricsinfo.h"
36 #include "math_support.h"
38 #include "support/filetools.h" // LibFileSearch
39 #include "frontends/font_loader.h"
48 typedef std::map<string, latexkeys> WordList;
62 key_type wordlist_array[] =
72 {"Vmatrix", "matrix", ""},
73 {"acute", "decoration", ""},
74 {"bar", "decoration", ""},
75 {"begin", "begin", ""},
76 {"bf", "oldfont", ""},
77 {"bmatrix", "matrix", ""},
78 {"acute", "decoration", ""},
79 {"breve", "decoration", ""},
80 {"cal", "oldfont", ""},
81 {"cdots", "dots", ""},
82 {"check", "decoration", ""},
83 {"ddot", "decoration", ""},
84 {"dddot", "decoration", ""},
85 {"ddots", "dots", ""},
86 {"displaystyle", "style", ""},
87 {"dot", "decoration", ""},
88 {"dotsb", "dots", ""},
89 {"dotsc", "dots", ""},
90 {"dotsi", "dots", ""},
91 {"dotsm", "dots", ""},
92 {"dotso", "dots", ""},
96 {"grave", "decoration", ""},
97 {"hat", "decoration", ""},
98 {"it", "oldfont", ""},
99 {"label", "label", ""},
100 {"ldots", "dots", ""},
101 {"left", "left", ""},
102 {"limits", "limit", ""},
103 {"lyxbox", "box", ""},
104 {"lyxnegspace", "space", ""},
105 {"lyxposspace", "space", ""},
106 {"mathbb", "font", ""},
107 {"mathbf", "font", ""},
108 {"mathcal", "font", ""},
109 {"mathfrak", "font", ""},
110 {"mathit", "font", ""},
111 {"mathnormal", "font", ""},
112 {"mathring", "decoration", ""},
113 {"mathrm", "font", ""},
114 {"mathsf", "font", ""},
115 {"mathtt", "font", ""},
116 {"matrix", "matrix", ""},
118 {"newcommand", "newcommand", ""},
119 {"nolimits", "limit", ""},
120 {"nonumber", "nonum", ""},
121 {"overbrace", "decoration", ""},
122 {"overleftarrow", "decoration", ""},
123 {"overline", "decoration", ""},
124 {"overrightarrow", "decoration", ""},
125 {"overleftrightarrow", "decoration", ""},
126 {"pmatrix", "matrix", ""},
127 {"protect", "protect", ""},
128 {"qquad", "space", ""},
129 {"quad", "space", ""},
130 {"right", "right", ""},
131 {"rm", "oldfont", ""},
132 {"scriptscriptstyle", "style", ""},
133 {"scriptstyle", "style", ""},
134 {"textbf", "font", "mathtext"},
135 {"textit", "font", "mathtext"},
136 {"textmd", "font", "mathtext"},
137 {"textrm", "font", "mathtext"},
138 {"textsl", "font", "mathtext"},
139 {"textup", "font", "mathtext"},
140 {"textstyle", "style", ""},
141 {"tilde", "decoration", ""},
142 {"tt", "oldfont", ""},
143 {"underbar", "decoration", ""},
144 {"underbrace", "decoration", ""},
145 {"underleftarrow", "decoration", ""},
146 {"underline", "decoration", ""},
147 {"underrightarrow", "decoration", ""},
148 {"underleftrightarrow", "decoration", ""},
149 {"underset", "underset", ""},
150 {"vdots", "dots", ""},
151 {"vec", "decoration", ""},
152 {"vmatrix", "matrix", ""},
153 {"widehat", "decoration", ""},
154 {"widetilde", "decoration", ""}
158 bool math_font_available(string & name)
161 augmentFont(f, name);
163 // Do we have the font proper?
164 if (fontloader.available(f))
168 if (name == "eufrak") {
169 name = "lyxfakefrak";
173 lyxerr[Debug::MATHED] << "font " << name << " not available and I can't fake it\n";
178 void readSymbols(string const & filename)
180 std::ifstream fs(filename.c_str());
187 istringstream is(line);
197 // tmp.inset _is_ the fontname here.
198 // create fallbacks if necessary
199 if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra=="special") {
200 lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n";
202 } else if (math_font_available(tmp.inset)) {
203 lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n";
204 tmp.draw += char(charid);
205 } else if (fallbackid) {
206 if (tmp.inset == "cmex")
207 tmp.inset = "lyxsymbol";
209 tmp.inset = "lyxboldsymbol";
210 lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n";
211 tmp.draw += char(fallbackid);
213 lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n";
215 tmp.inset = "lyxtex";
218 if (theWordList.find(tmp.name) != theWordList.end())
219 lyxerr[Debug::MATHED] << "readSymbols: inset " << tmp.name
220 << " already exists.\n";
222 theWordList[tmp.name] = tmp;
223 lyxerr[Debug::MATHED] << "read symbol '" << tmp.name
224 << " inset: " << tmp.inset
225 << " draw: " << int(tmp.draw[0])
226 << " extra: " << tmp.extra
234 unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
235 for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
238 tmp.inset = p->inset;
240 theWordList[p->name] = tmp;
243 lyxerr[Debug::MATHED] << "reading symbols file\n";
244 string const file = LibFileSearch(string(), "symbols");
246 lyxerr << "Could not find symbols file\n";
255 latexkeys const * in_word_set(string const & str)
257 static bool initialized = false;
264 WordList::iterator it = theWordList.find(str);
265 //lyxerr << "looking up '" << str << "' found: "
266 // << (it != theWordList.end()) << "\n";
267 return (it != theWordList.end()) ? &(it->second) : 0;
271 MathAtom createMathInset(string const & s)
273 lyxerr[Debug::MATHED] << "creating inset with name: '" << s << "'\n";
274 if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
275 return MathAtom(new MathMacroArgument(s[1] - '0'));
277 if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
278 && s[2] >= '1' && s[2] <= '9')
279 return MathAtom(new MathMacroArgument(s[2] - '0'));
281 return MathAtom(new MathKernInset);
283 return MathAtom(new MathXYMatrixInset);
284 if (s == "xrightarrow" || s == "xleftarrow")
285 return MathAtom(new MathXArrowInset(s));
286 if (s == "split" || s == "gathered" || s == "aligned")
287 return MathAtom(new MathSplitInset(s));
289 return MathAtom(new MathCasesInset);
291 return MathAtom(new MathSubstackInset);
292 if (s == "subarray" || s == "array")
293 return MathAtom(new MathArrayInset(s, 1, 1));
295 return MathAtom(new MathSqrtInset);
297 return MathAtom(new MathRootInset);
299 return MathAtom(new MathStackrelInset);
300 if (s == "binom" || s == "choose")
301 return MathAtom(new MathBinomInset);
302 if (s == "over" || s == "frac")
303 return MathAtom(new MathFracInset);
305 return MathAtom(new MathFracInset(true));
307 return MathAtom(new MathNotInset);
309 return MathAtom(new MathLefteqnInset);
311 return MathAtom(new RefInset);
314 latexkeys const * l = in_word_set(s);
316 string const & inset = l->inset;
317 lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n";
318 if (inset == "underset")
319 return MathAtom(new MathUndersetInset);
320 if (inset == "decoration")
321 return MathAtom(new MathDecorationInset(l->name));
322 //if (inset == "space")
323 // return MathAtom(new MathSpaceInset(l->id));
325 return MathAtom(new MathDotsInset(l->name));
327 return MathAtom(new MathBoxInset(l->name));
329 return MathAtom(new MathFboxInset);
330 if (inset == "style")
331 return MathAtom(new MathSizeInset(l));
333 return MathAtom(new MathFontInset(l->name));
334 if (inset == "oldfont")
335 return MathAtom(new MathFontInset(l->name));
336 if (inset == "matrix")
337 return MathAtom(new MathAMSArrayInset(s));
338 return MathAtom(new MathSymbolInset(l));
341 if (MathMacroTable::has(s))
342 return MathAtom(new MathMacro(s));
344 //lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << "'\n";
345 return MathAtom(new MathUnknownInset(s));