7 #include "math_parser.h"
8 #include "math_arrayinset.h"
9 #include "math_amsarrayinset.h"
10 #include "math_binominset.h"
11 #include "math_boxinset.h"
12 #include "math_casesinset.h"
13 #include "math_decorationinset.h"
14 #include "math_dotsinset.h"
15 #include "math_ertinset.h"
16 #include "math_fboxinset.h"
17 #include "math_frameboxinset.h"
18 #include "math_fontinset.h"
19 #include "math_fontoldinset.h"
20 #include "math_fracinset.h"
21 #include "math_kerninset.h"
22 #include "math_inferinset.h"
23 #include "math_lefteqninset.h"
24 #include "math_macro.h"
25 #include "math_macrotable.h"
26 #include "math_macrotemplate.h"
27 #include "math_macroarg.h"
28 #include "math_parboxinset.h"
29 #include "math_rootinset.h"
30 #include "math_sizeinset.h"
31 #include "math_spaceinset.h"
32 #include "math_splitinset.h"
33 #include "math_sqrtinset.h"
34 #include "math_stackrelinset.h"
35 #include "math_substackinset.h"
36 #include "math_symbolinset.h"
37 #include "math_undersetinset.h"
38 #include "math_unknowninset.h"
39 #include "math_xarrowinset.h"
40 #include "math_xymatrixinset.h"
41 #include "math_xyarrowinset.h"
43 //#include "insets/insetref.h"
44 #include "ref_inset.h"
46 #include "math_metricsinfo.h"
48 #include "math_support.h"
50 #include "support/filetools.h" // LibFileSearch
51 #include "frontends/lyx_gui.h"
63 typedef std::map<string, latexkeys> WordList;
67 bool math_font_available(string & name)
72 // Do we have the font proper?
73 if (lyx_gui::font_available(f))
77 if (name == "eufrak") {
83 << "font " << name << " not available and I can't fake it"
91 string const filename = LibFileSearch(string(), "symbols");
92 lyxerr[Debug::MATHED] << "read symbols from " << filename << endl;
93 if (filename.empty()) {
94 lyxerr << "Could not find symbols file" << endl;
98 std::ifstream fs(filename.c_str());
101 while (std::getline(fs, line)) {
104 if (line.size() > 0 && line[0] == '#')
107 // special case of iffont/else/endif
108 if (line.size() >= 7 && line.substr(0, 6) == "iffont") {
109 istringstream is(line);
113 skip = !math_font_available(tmp);
115 } else if (line.size() >= 4 && line.substr(0, 4) == "else") {
117 } else if (line.size() >= 5 && line.substr(0, 5) == "endif") {
123 // special case of pre-defined macros
124 if (line.size() > 8 && line.substr(0, 5) == "\\def\\") {
125 //lyxerr << "defining: '" << line << "'\n";
126 istringstream is(line);
127 MathMacroTable::create(MathAtom(new MathMacroTemplate(is)));
131 istringstream is(line);
133 is >> tmp.name >> tmp.inset;
134 if (isFontName(tmp.inset))
135 is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname;
139 lyxerr[Debug::MATHED] << "skipping line '" << line << "'" << endl;
140 lyxerr[Debug::MATHED]
141 << tmp.name << ' ' << tmp.inset << ' ' << tmp.extra << endl;
145 if (isFontName(tmp.inset)) {
146 // tmp.inset _is_ the fontname here.
147 // create fallbacks if necessary
148 if (tmp.extra=="func" || tmp.extra=="funclim" || tmp.extra=="special") {
149 lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << endl;
151 } else if (math_font_available(tmp.inset)) {
152 lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << endl;
153 tmp.draw += char(charid);
154 } else if (fallbackid) {
155 if (tmp.inset == "cmex")
156 tmp.inset = "lyxsymbol";
158 tmp.inset = "lyxboldsymbol";
159 lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << endl;
160 tmp.draw += char(fallbackid);
162 lyxerr[Debug::MATHED] << "faking " << tmp.name << endl;
164 tmp.inset = "lyxtex";
167 // it's a proper inset
168 lyxerr[Debug::MATHED] << "inset " << tmp.inset << " used for "
172 if (theWordList.find(tmp.name) != theWordList.end())
173 lyxerr[Debug::MATHED] << "readSymbols: inset " << tmp.name
174 << " already exists." << endl;
176 theWordList[tmp.name] = tmp;
177 lyxerr[Debug::MATHED] << "read symbol '" << tmp.name
178 << " inset: " << tmp.inset
179 << " draw: " << int(tmp.draw[0])
180 << " extra: " << tmp.extra
184 string tmp2 = "cmsy";
185 has_math_fonts = math_font_available(tmp) && math_font_available(tmp2);
194 static bool initialized = false;
202 latexkeys const * in_word_set(string const & str)
204 WordList::iterator it = theWordList.find(str);
205 //lyxerr << "looking up '" << str << "' found: "
206 // << (it != theWordList.end()) << "\n";
207 return (it != theWordList.end()) ? &(it->second) : 0;
211 MathAtom createMathInset(string const & s)
213 lyxerr[Debug::MATHED] << "creating inset with name: '" << s << "'" << endl;
214 latexkeys const * l = in_word_set(s);
216 string const & inset = l->inset;
217 lyxerr[Debug::MATHED] << " found inset: '" << inset << "'" << endl;
219 return MathAtom(new RefInset(l->name));
220 if (inset == "underset")
221 return MathAtom(new MathUndersetInset);
222 if (inset == "decoration")
223 return MathAtom(new MathDecorationInset(l));
224 if (inset == "space")
225 return MathAtom(new MathSpaceInset(l->name));
227 return MathAtom(new MathDotsInset(l));
229 return MathAtom(new MathBoxInset(l->name));
230 if (inset == "parbox")
231 return MathAtom(new MathParboxInset);
233 return MathAtom(new MathFboxInset(l));
234 if (inset == "style")
235 return MathAtom(new MathSizeInset(l));
237 return MathAtom(new MathFontInset(l));
238 if (inset == "oldfont")
239 return MathAtom(new MathFontOldInset(l));
240 if (inset == "matrix")
241 return MathAtom(new MathAMSArrayInset(s));
242 return MathAtom(new MathSymbolInset(l));
245 if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
246 return MathAtom(new MathMacroArgument(s[1] - '0'));
247 if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
248 && s[2] >= '1' && s[2] <= '9')
249 return MathAtom(new MathMacroArgument(s[2] - '0'));
251 return MathAtom(new MathFrameboxInset);
253 return MathAtom(new MathKernInset);
255 return MathAtom(new MathXYMatrixInset);
256 if (s == "xrightarrow" || s == "xleftarrow")
257 return MathAtom(new MathXArrowInset(s));
258 if (s == "split" || s == "gathered" || s == "aligned")
259 return MathAtom(new MathSplitInset(s));
261 return MathAtom(new MathCasesInset);
263 return MathAtom(new MathSubstackInset);
264 if (s == "subarray" || s == "array")
265 return MathAtom(new MathArrayInset(s, 1, 1));
267 return MathAtom(new MathSqrtInset);
269 return MathAtom(new MathRootInset);
271 return MathAtom(new MathStackrelInset);
272 if (s == "binom" || s == "choose")
273 return MathAtom(new MathBinomInset(s == "choose"));
274 if (s == "over" || s == "frac")
275 return MathAtom(new MathFracInset);
277 // return MathAtom(new MathInferInset);
279 return MathAtom(new MathFracInset(true));
281 return MathAtom(new MathLefteqnInset);
283 return MathAtom(new MathErtInset);
285 if (MathMacroTable::has(s))
286 return MathAtom(new MathMacro(s));
288 //lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << "'" << endl;
289 return MathAtom(new MathUnknownInset(s));