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[] =
70 {"Vmatrix", "matrix", ""},
71 {"acute", "decoration", ""},
72 {"bar", "decoration", ""},
73 {"begin", "begin", ""},
74 {"bf", "oldfont", ""},
75 {"bmatrix", "matrix", ""},
76 {"acute", "decoration", ""},
77 {"breve", "decoration", ""},
78 {"cal", "oldfont", ""},
79 {"cdots", "dots", ""},
80 {"check", "decoration", ""},
81 {"ddot", "decoration", ""},
82 {"dddot", "decoration", ""},
83 {"ddots", "dots", ""},
84 {"displaystyle", "style", ""},
85 {"dot", "decoration", ""},
86 {"dotsb", "dots", ""},
87 {"dotsc", "dots", ""},
88 {"dotsi", "dots", ""},
89 {"dotsm", "dots", ""},
90 {"dotso", "dots", ""},
94 {"grave", "decoration", ""},
95 {"hat", "decoration", ""},
96 {"it", "oldfont", ""},
97 {"label", "label", ""},
98 {"ldots", "dots", ""},
100 {"limits", "limit", ""},
101 {"lyxbox", "box", ""},
102 {"lyxnegspace", "space", ""},
103 {"lyxposspace", "space", ""},
104 {"mathbb", "font", ""},
105 {"mathbf", "font", ""},
106 {"mathcal", "font", ""},
107 {"mathfrak", "font", ""},
108 {"mathit", "font", ""},
109 {"mathnormal", "font", ""},
110 {"mathring", "decoration", ""},
111 {"mathrm", "font", ""},
112 {"mathsf", "font", ""},
113 {"mathtt", "font", ""},
114 {"matrix", "matrix", ""},
116 {"newcommand", "newcommand", ""},
117 {"nolimits", "limit", ""},
118 {"nonumber", "nonum", ""},
119 {"overbrace", "decoration", ""},
120 {"overleftarrow", "decoration", ""},
121 {"overline", "decoration", ""},
122 {"overrightarrow", "decoration", ""},
123 {"overleftrightarrow", "decoration", ""},
124 {"pmatrix", "matrix", ""},
125 {"protect", "protect", ""},
126 {"qquad", "space", ""},
127 {"quad", "space", ""},
128 {"right", "right", ""},
129 {"rm", "oldfont", ""},
130 {"scriptscriptstyle", "style", ""},
131 {"scriptstyle", "style", ""},
132 {"textbf", "font", "mathtext"},
133 {"textit", "font", "mathtext"},
134 {"textmd", "font", "mathtext"},
135 {"textrm", "font", "mathtext"},
136 {"textsl", "font", "mathtext"},
137 {"textup", "font", "mathtext"},
138 {"textstyle", "style", ""},
139 {"tilde", "decoration", ""},
140 {"tt", "oldfont", ""},
141 {"underbar", "decoration", ""},
142 {"underbrace", "decoration", ""},
143 {"underleftarrow", "decoration", ""},
144 {"underline", "decoration", ""},
145 {"underrightarrow", "decoration", ""},
146 {"underleftrightarrow", "decoration", ""},
147 {"underset", "underset", ""},
148 {"vdots", "dots", ""},
149 {"vec", "decoration", ""},
150 {"vmatrix", "matrix", ""},
151 {"widehat", "decoration", ""},
152 {"widetilde", "decoration", ""}
156 bool math_font_available(string & name)
159 augmentFont(f, name);
161 // Do we have the font proper?
162 if (fontloader.available(f))
166 if (name == "eufrak") {
167 name = "lyxfakefrak";
171 lyxerr[Debug::MATHED] << "font " << name << " not available and I can't fake it\n";
176 void readSymbols(string const & filename)
178 lyxerr[Debug::MATHED] << "read symbols from " << filename << "\n";
179 std::ifstream fs(filename.c_str());
186 istringstream is(line);
196 // tmp.inset _is_ the fontname here.
197 // create fallbacks if necessary
198 if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra=="special") {
199 lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n";
201 } else if (math_font_available(tmp.inset)) {
202 lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n";
203 tmp.draw += char(charid);
204 } else if (fallbackid) {
205 if (tmp.inset == "cmex")
206 tmp.inset = "lyxsymbol";
208 tmp.inset = "lyxboldsymbol";
209 lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n";
210 tmp.draw += char(fallbackid);
212 lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n";
214 tmp.inset = "lyxtex";
217 if (theWordList.find(tmp.name) != theWordList.end())
218 lyxerr[Debug::MATHED] << "readSymbols: inset " << tmp.name
219 << " already exists.\n";
221 theWordList[tmp.name] = tmp;
222 lyxerr[Debug::MATHED] << "read symbol '" << tmp.name
223 << " inset: " << tmp.inset
224 << " draw: " << int(tmp.draw[0])
225 << " extra: " << tmp.extra
233 unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
234 for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
237 tmp.inset = p->inset;
239 theWordList[p->name] = tmp;
242 lyxerr[Debug::MATHED] << "reading symbols file\n";
243 string const file = LibFileSearch(string(), "symbols");
245 lyxerr << "Could not find symbols file\n";
254 latexkeys const * in_word_set(string const & str)
256 static bool initialized = false;
263 WordList::iterator it = theWordList.find(str);
264 //lyxerr << "looking up '" << str << "' found: "
265 // << (it != theWordList.end()) << "\n";
266 return (it != theWordList.end()) ? &(it->second) : 0;
270 MathAtom createMathInset(string const & s)
272 lyxerr[Debug::MATHED] << "creating inset with name: '" << s << "'\n";
273 if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
274 return MathAtom(new MathMacroArgument(s[1] - '0'));
276 if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
277 && s[2] >= '1' && s[2] <= '9')
278 return MathAtom(new MathMacroArgument(s[2] - '0'));
280 return MathAtom(new MathKernInset);
282 return MathAtom(new MathXYMatrixInset);
283 if (s == "xrightarrow" || s == "xleftarrow")
284 return MathAtom(new MathXArrowInset(s));
285 if (s == "split" || s == "gathered" || s == "aligned")
286 return MathAtom(new MathSplitInset(s));
288 return MathAtom(new MathCasesInset);
290 return MathAtom(new MathSubstackInset);
291 if (s == "subarray" || s == "array")
292 return MathAtom(new MathArrayInset(s, 1, 1));
294 return MathAtom(new MathSqrtInset);
296 return MathAtom(new MathRootInset);
298 return MathAtom(new MathStackrelInset);
299 if (s == "binom" || s == "choose")
300 return MathAtom(new MathBinomInset);
301 if (s == "over" || s == "frac")
302 return MathAtom(new MathFracInset);
304 return MathAtom(new MathFracInset(true));
306 return MathAtom(new MathNotInset);
308 return MathAtom(new MathLefteqnInset);
310 return MathAtom(new RefInset);
313 latexkeys const * l = in_word_set(s);
315 string const & inset = l->inset;
316 lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n";
317 if (inset == "underset")
318 return MathAtom(new MathUndersetInset);
319 if (inset == "decoration")
320 return MathAtom(new MathDecorationInset(l->name));
321 if (inset == "space")
322 return MathAtom(new MathSpaceInset(l->name));
324 return MathAtom(new MathDotsInset(l->name));
326 return MathAtom(new MathBoxInset(l->name));
328 return MathAtom(new MathFboxInset);
329 if (inset == "style")
330 return MathAtom(new MathSizeInset(l));
332 return MathAtom(new MathFontInset(l->name));
333 if (inset == "oldfont")
334 return MathAtom(new MathFontInset(l->name));
335 if (inset == "matrix")
336 return MathAtom(new MathAMSArrayInset(s));
337 return MathAtom(new MathSymbolInset(l));
340 if (MathMacroTable::has(s))
341 return MathAtom(new MathMacro(s));
343 //lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << "'\n";
344 return MathAtom(new MathUnknownInset(s));