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 "insets/insetref.h"
35 #include "ref_inset.h"
37 #include "math_metricsinfo.h"
39 #include "math_support.h"
41 #include "support/filetools.h" // LibFileSearch
42 #include "frontends/font_loader.h"
51 typedef std::map<string, latexkeys> WordList;
65 key_type wordlist_array[] =
71 {"Vmatrix", "matrix", ""},
72 {"acute", "decoration", ""},
73 {"bar", "decoration", ""},
74 {"begin", "begin", ""},
75 {"bf", "oldfont", ""},
76 {"bmatrix", "matrix", ""},
77 {"acute", "decoration", ""},
78 {"breve", "decoration", ""},
79 {"cal", "oldfont", ""},
80 {"cdots", "dots", ""},
81 {"check", "decoration", ""},
82 {"ddot", "decoration", ""},
83 {"dddot", "decoration", ""},
84 {"ddots", "dots", ""},
85 {"displaystyle", "style", ""},
86 {"dot", "decoration", ""},
87 {"dotsb", "dots", ""},
88 {"dotsc", "dots", ""},
89 {"dotsi", "dots", ""},
90 {"dotsm", "dots", ""},
91 {"dotso", "dots", ""},
95 {"grave", "decoration", ""},
96 {"hat", "decoration", ""},
97 {"it", "oldfont", ""},
98 {"label", "label", ""},
99 {"ldots", "dots", ""},
100 {"left", "left", ""},
101 {"limits", "limit", ""},
102 {"lyxbox", "box", ""},
103 {"lyxnegspace", "space", ""},
104 {"lyxposspace", "space", ""},
105 {"mathbb", "font", ""},
106 {"mathbf", "font", ""},
107 {"mathcal", "font", ""},
108 {"mathfrak", "font", ""},
109 {"mathit", "font", ""},
110 {"mathnormal", "font", ""},
111 {"mathring", "decoration", ""},
112 {"mathrm", "font", ""},
113 {"mathsf", "font", ""},
114 {"mathtt", "font", ""},
115 {"matrix", "matrix", ""},
117 {"newcommand", "newcommand", ""},
118 {"nolimits", "limit", ""},
119 {"nonumber", "nonum", ""},
120 {"overbrace", "decoration", ""},
121 {"overleftarrow", "decoration", ""},
122 {"overline", "decoration", ""},
123 {"overrightarrow", "decoration", ""},
124 {"overleftrightarrow", "decoration", ""},
125 {"pageref", "ref", ""},
126 {"pmatrix", "matrix", ""},
127 {"prettyref", "ref", ""},
128 {"protect", "protect", ""},
129 {"qquad", "space", ""},
130 {"quad", "space", ""},
132 {"right", "right", ""},
133 {"rm", "oldfont", ""},
134 {"scriptscriptstyle", "style", ""},
135 {"scriptstyle", "style", ""},
136 {"text", "font", "mathtext"},
137 {"textbf", "font", "mathtext"},
138 {"textit", "font", "mathtext"},
139 {"textmd", "font", "mathtext"},
140 {"textrm", "font", "mathtext"},
141 {"textsl", "font", "mathtext"},
142 {"textup", "font", "mathtext"},
143 {"textstyle", "style", ""},
144 {"tilde", "decoration", ""},
145 {"tt", "oldfont", ""},
146 {"underbar", "decoration", ""},
147 {"underbrace", "decoration", ""},
148 {"underleftarrow", "decoration", ""},
149 {"underline", "decoration", ""},
150 {"underrightarrow", "decoration", ""},
151 {"underleftrightarrow", "decoration", ""},
152 {"underset", "underset", ""},
153 {"vdots", "dots", ""},
154 {"vec", "decoration", ""},
155 {"vmatrix", "matrix", ""},
156 {"vpageref", "ref", ""},
158 {"widehat", "decoration", ""},
159 {"widetilde", "decoration", ""}
163 bool math_font_available(string & name)
166 augmentFont(f, name);
168 // Do we have the font proper?
169 if (fontloader.available(f))
173 if (name == "eufrak") {
174 name = "lyxfakefrak";
178 lyxerr[Debug::MATHED] << "font " << name << " not available and I can't fake it\n";
183 void readSymbols(string const & filename)
185 lyxerr[Debug::MATHED] << "read symbols from " << filename << "\n";
186 std::ifstream fs(filename.c_str());
193 istringstream is(line);
203 // tmp.inset _is_ the fontname here.
204 // create fallbacks if necessary
205 if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra=="special") {
206 lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n";
208 } else if (math_font_available(tmp.inset)) {
209 lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n";
210 tmp.draw += char(charid);
211 } else if (fallbackid) {
212 if (tmp.inset == "cmex")
213 tmp.inset = "lyxsymbol";
215 tmp.inset = "lyxboldsymbol";
216 lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n";
217 tmp.draw += char(fallbackid);
219 lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n";
221 tmp.inset = "lyxtex";
224 if (theWordList.find(tmp.name) != theWordList.end())
225 lyxerr[Debug::MATHED] << "readSymbols: inset " << tmp.name
226 << " already exists.\n";
228 theWordList[tmp.name] = tmp;
229 lyxerr[Debug::MATHED] << "read symbol '" << tmp.name
230 << " inset: " << tmp.inset
231 << " draw: " << int(tmp.draw[0])
232 << " extra: " << tmp.extra
240 unsigned const n = sizeof(wordlist_array) / sizeof(wordlist_array[0]);
241 for (key_type * p = wordlist_array; p != wordlist_array + n; ++p) {
244 tmp.inset = p->inset;
246 theWordList[p->name] = tmp;
249 lyxerr[Debug::MATHED] << "reading symbols file\n";
250 string const file = LibFileSearch(string(), "symbols");
252 lyxerr << "Could not find symbols file\n";
261 latexkeys const * in_word_set(string const & str)
263 static bool initialized = false;
270 WordList::iterator it = theWordList.find(str);
271 //lyxerr << "looking up '" << str << "' found: "
272 // << (it != theWordList.end()) << "\n";
273 return (it != theWordList.end()) ? &(it->second) : 0;
277 MathAtom createMathInset(string const & s)
279 lyxerr[Debug::MATHED] << "creating inset with name: '" << s << "'\n";
280 if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
281 return MathAtom(new MathMacroArgument(s[1] - '0'));
283 if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
284 && s[2] >= '1' && s[2] <= '9')
285 return MathAtom(new MathMacroArgument(s[2] - '0'));
287 return MathAtom(new MathKernInset);
289 return MathAtom(new MathXYMatrixInset);
290 if (s == "xrightarrow" || s == "xleftarrow")
291 return MathAtom(new MathXArrowInset(s));
292 if (s == "split" || s == "gathered" || s == "aligned")
293 return MathAtom(new MathSplitInset(s));
295 return MathAtom(new MathCasesInset);
297 return MathAtom(new MathSubstackInset);
298 if (s == "subarray" || s == "array")
299 return MathAtom(new MathArrayInset(s, 1, 1));
301 return MathAtom(new MathSqrtInset);
303 return MathAtom(new MathRootInset);
305 return MathAtom(new MathStackrelInset);
306 if (s == "binom" || s == "choose")
307 return MathAtom(new MathBinomInset(s == "choose"));
308 if (s == "over" || s == "frac")
309 return MathAtom(new MathFracInset);
311 return MathAtom(new MathFracInset(true));
313 return MathAtom(new MathNotInset);
315 return MathAtom(new MathLefteqnInset);
317 latexkeys const * l = in_word_set(s);
319 string const & inset = l->inset;
320 lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n";
322 return MathAtom(new RefInset(l->name));
323 if (inset == "underset")
324 return MathAtom(new MathUndersetInset);
325 if (inset == "decoration")
326 return MathAtom(new MathDecorationInset(l->name));
327 if (inset == "space")
328 return MathAtom(new MathSpaceInset(l->name));
330 return MathAtom(new MathDotsInset(l->name));
332 return MathAtom(new MathBoxInset(l->name));
334 return MathAtom(new MathFboxInset);
335 if (inset == "style")
336 return MathAtom(new MathSizeInset(l));
338 return MathAtom(new MathFontInset(l->name));
339 if (inset == "oldfont")
340 return MathAtom(new MathFontInset(l->name));
341 if (inset == "matrix")
342 return MathAtom(new MathAMSArrayInset(s));
343 return MathAtom(new MathSymbolInset(l));
346 if (MathMacroTable::has(s))
347 return MathAtom(new MathMacro(s));
349 //lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << "'\n";
350 return MathAtom(new MathUnknownInset(s));