8 #include "math_parser.h"
9 #include "math_arrayinset.h"
10 #include "math_amsarrayinset.h"
11 #include "math_binominset.h"
12 #include "math_boxinset.h"
13 #include "math_casesinset.h"
14 #include "math_decorationinset.h"
15 #include "math_dotsinset.h"
16 #include "math_ertinset.h"
17 #include "math_fboxinset.h"
18 #include "math_frameboxinset.h"
19 #include "math_fontinset.h"
20 #include "math_fontoldinset.h"
21 #include "math_fracinset.h"
22 #include "math_kerninset.h"
23 #include "math_inferinset.h"
24 #include "math_lefteqninset.h"
25 #include "math_macro.h"
26 #include "math_macrotable.h"
27 #include "math_macrotemplate.h"
28 #include "math_macroarg.h"
29 #include "math_parboxinset.h"
30 #include "math_rootinset.h"
31 #include "math_sizeinset.h"
32 #include "math_spaceinset.h"
33 #include "math_splitinset.h"
34 #include "math_sqrtinset.h"
35 #include "math_stackrelinset.h"
36 #include "math_substackinset.h"
37 #include "math_symbolinset.h"
38 #include "math_undersetinset.h"
39 #include "math_unknowninset.h"
40 #include "math_xarrowinset.h"
41 #include "math_xymatrixinset.h"
42 #include "math_xyarrowinset.h"
44 //#include "insets/insetref.h"
45 #include "ref_inset.h"
47 #include "math_metricsinfo.h"
49 #include "math_support.h"
51 #include "support/filetools.h" // LibFileSearch
52 #include "frontends/lyx_gui.h"
61 typedef std::map<string, latexkeys> WordList;
65 bool math_font_available(string & name)
70 // Do we have the font proper?
71 if (lyx_gui::font_available(f))
75 if (name == "eufrak") {
81 << "font " << name << " not available and I can't fake it\n";
88 string const filename = LibFileSearch(string(), "symbols");
89 lyxerr[Debug::MATHED] << "read symbols from " << filename << "\n";
90 if (filename.empty()) {
91 lyxerr << "Could not find symbols file\n";
95 std::ifstream fs(filename.c_str());
98 while (std::getline(fs, line)) {
101 if (line.size() > 0 && line[0] == '#')
104 // special case of \iffont / \fi
105 if (line.size() >= 7 && line.substr(0, 6) == "iffont") {
106 istringstream is(line);
110 skip = !math_font_available(tmp);
112 } else if (line.size() >= 3 && line.substr(0, 3) == "end") {
118 // special case of pre-defined macros
119 if (line.size() > 8 && line.substr(0, 5) == "\\def\\") {
120 //lyxerr << "defining: '" << line << "'\n";
121 istringstream is(line);
122 MathMacroTable::create(MathAtom(new MathMacroTemplate(is)));
126 istringstream is(line);
128 is >> tmp.name >> tmp.inset;
129 if (isFontName(tmp.inset))
130 is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname;
134 lyxerr[Debug::MATHED] << "skipping line '" << line << "'\n";
135 lyxerr[Debug::MATHED]
136 << tmp.name << ' ' << tmp.inset << ' ' << tmp.extra << "\n";
140 if (isFontName(tmp.inset)) {
141 // tmp.inset _is_ the fontname here.
142 // create fallbacks if necessary
143 if (tmp.extra=="func" || tmp.extra=="funclim" || tmp.extra=="special") {
144 lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n";
146 } else if (math_font_available(tmp.inset)) {
147 lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n";
148 tmp.draw += char(charid);
149 } else if (fallbackid) {
150 if (tmp.inset == "cmex")
151 tmp.inset = "lyxsymbol";
153 tmp.inset = "lyxboldsymbol";
154 lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n";
155 tmp.draw += char(fallbackid);
157 lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n";
159 tmp.inset = "lyxtex";
162 // it's a proper inset
163 lyxerr[Debug::MATHED] << "inset " << tmp.inset << " used for "
167 if (theWordList.find(tmp.name) != theWordList.end())
168 lyxerr[Debug::MATHED] << "readSymbols: inset " << tmp.name
169 << " already exists.\n";
171 theWordList[tmp.name] = tmp;
172 lyxerr[Debug::MATHED] << "read symbol '" << tmp.name
173 << " inset: " << tmp.inset
174 << " draw: " << int(tmp.draw[0])
175 << " extra: " << tmp.extra
186 static bool initialized = false;
194 latexkeys const * in_word_set(string const & str)
196 WordList::iterator it = theWordList.find(str);
197 //lyxerr << "looking up '" << str << "' found: "
198 // << (it != theWordList.end()) << "\n";
199 return (it != theWordList.end()) ? &(it->second) : 0;
203 MathAtom createMathInset(string const & s)
205 lyxerr[Debug::MATHED] << "creating inset with name: '" << s << "'\n";
206 latexkeys const * l = in_word_set(s);
208 string const & inset = l->inset;
209 lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n";
211 return MathAtom(new RefInset(l->name));
212 if (inset == "underset")
213 return MathAtom(new MathUndersetInset);
214 if (inset == "decoration")
215 return MathAtom(new MathDecorationInset(l));
216 if (inset == "space")
217 return MathAtom(new MathSpaceInset(l->name));
219 return MathAtom(new MathDotsInset(l));
221 return MathAtom(new MathBoxInset(l->name));
222 if (inset == "parbox")
223 return MathAtom(new MathParboxInset);
225 return MathAtom(new MathFboxInset(l));
226 if (inset == "style")
227 return MathAtom(new MathSizeInset(l));
229 return MathAtom(new MathFontInset(l));
230 if (inset == "oldfont")
231 return MathAtom(new MathFontOldInset(l));
232 if (inset == "matrix")
233 return MathAtom(new MathAMSArrayInset(s));
234 return MathAtom(new MathSymbolInset(l));
237 if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
238 return MathAtom(new MathMacroArgument(s[1] - '0'));
239 if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
240 && s[2] >= '1' && s[2] <= '9')
241 return MathAtom(new MathMacroArgument(s[2] - '0'));
243 return MathAtom(new MathFrameboxInset);
245 return MathAtom(new MathKernInset);
247 return MathAtom(new MathXYMatrixInset);
248 if (s == "xrightarrow" || s == "xleftarrow")
249 return MathAtom(new MathXArrowInset(s));
250 if (s == "split" || s == "gathered" || s == "aligned")
251 return MathAtom(new MathSplitInset(s));
253 return MathAtom(new MathCasesInset);
255 return MathAtom(new MathSubstackInset);
256 if (s == "subarray" || s == "array")
257 return MathAtom(new MathArrayInset(s, 1, 1));
259 return MathAtom(new MathSqrtInset);
261 return MathAtom(new MathRootInset);
263 return MathAtom(new MathStackrelInset);
264 if (s == "binom" || s == "choose")
265 return MathAtom(new MathBinomInset(s == "choose"));
266 if (s == "over" || s == "frac")
267 return MathAtom(new MathFracInset);
269 // return MathAtom(new MathInferInset);
271 return MathAtom(new MathFracInset(true));
273 return MathAtom(new MathLefteqnInset);
275 return MathAtom(new MathErtInset);
277 if (MathMacroTable::has(s))
278 return MathAtom(new MathMacro(s));
280 //lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << "'\n";
281 return MathAtom(new MathUnknownInset(s));