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"
64 typedef std::map<string, latexkeys> WordList;
68 bool math_font_available(string & name)
73 // Do we have the font proper?
74 if (lyx_gui::font_available(f))
78 if (name == "eufrak") {
84 << "font " << name << " not available and I can't fake it"
92 string const filename = LibFileSearch(string(), "symbols");
93 lyxerr[Debug::MATHED] << "read symbols from " << filename << endl;
94 if (filename.empty()) {
95 lyxerr << "Could not find symbols file" << endl;
99 std::ifstream fs(filename.c_str());
102 while (getline(fs, line)) {
105 if (!line.empty() && line[0] == '#')
108 // special case of iffont/else/endif
109 if (line.size() >= 7 && line.substr(0, 6) == "iffont") {
110 istringstream is(STRCONV(line));
114 skip = !math_font_available(tmp);
116 } else if (line.size() >= 4 && line.substr(0, 4) == "else") {
118 } else if (line.size() >= 5 && line.substr(0, 5) == "endif") {
124 // special case of pre-defined macros
125 if (line.size() > 8 && line.substr(0, 5) == "\\def\\") {
126 //lyxerr << "defining: '" << line << '\'' << endl;
127 istringstream is(STRCONV(line));
128 MathMacroTable::create(MathAtom(new MathMacroTemplate(is)));
132 istringstream is(STRCONV(line));
134 is >> tmp.name >> tmp.inset;
135 if (isFontName(tmp.inset))
136 is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname;
140 lyxerr[Debug::MATHED] << "skipping line '" << line << '\'' << endl;
141 lyxerr[Debug::MATHED]
142 << tmp.name << ' ' << tmp.inset << ' ' << tmp.extra << endl;
146 if (isFontName(tmp.inset)) {
147 // tmp.inset _is_ the fontname here.
148 // create fallbacks if necessary
149 if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra == "special") {
150 lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << endl;
152 } else if (math_font_available(tmp.inset)) {
153 lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << endl;
154 tmp.draw += char(charid);
155 } else if (fallbackid) {
156 if (tmp.inset == "cmex")
157 tmp.inset = "lyxsymbol";
159 tmp.inset = "lyxboldsymbol";
160 lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << endl;
161 tmp.draw += char(fallbackid);
163 lyxerr[Debug::MATHED] << "faking " << tmp.name << endl;
165 tmp.inset = "lyxtex";
168 // it's a proper inset
169 lyxerr[Debug::MATHED] << "inset " << tmp.inset
170 << " used for " << tmp.name
174 if (theWordList.find(tmp.name) != theWordList.end())
175 lyxerr[Debug::MATHED]
176 << "readSymbols: inset " << tmp.name
177 << " already exists." << endl;
179 theWordList[tmp.name] = tmp;
181 lyxerr[Debug::MATHED]
182 << "read symbol '" << tmp.name
183 << " inset: " << tmp.inset
184 << " draw: " << int(tmp.draw.empty() ? 0 : tmp.draw[0])
185 << " extra: " << tmp.extra
189 string tmp2 = "cmsy";
190 has_math_fonts = math_font_available(tmp) && math_font_available(tmp2);
199 static bool initialized = false;
207 latexkeys const * in_word_set(string const & str)
209 WordList::iterator it = theWordList.find(str);
210 //lyxerr << "looking up '" << str << "' found: "
211 // << (it != theWordList.end()) << endl;
212 return (it != theWordList.end()) ? &(it->second) : 0;
216 MathAtom createMathInset(string const & s)
218 lyxerr[Debug::MATHED] << "creating inset with name: '"
219 << s << '\'' << endl;;
220 latexkeys const * l = in_word_set(s);
222 string const & inset = l->inset;
223 lyxerr[Debug::MATHED] << " found inset: '" <<
224 inset << '\'' << endl;
226 return MathAtom(new RefInset(l->name));
227 if (inset == "underset")
228 return MathAtom(new MathUndersetInset);
229 if (inset == "decoration")
230 return MathAtom(new MathDecorationInset(l));
231 if (inset == "space")
232 return MathAtom(new MathSpaceInset(l->name));
234 return MathAtom(new MathDotsInset(l));
236 return MathAtom(new MathBoxInset(l->name));
237 if (inset == "parbox")
238 return MathAtom(new MathParboxInset);
240 return MathAtom(new MathFboxInset(l));
241 if (inset == "style")
242 return MathAtom(new MathSizeInset(l));
244 return MathAtom(new MathFontInset(l));
245 if (inset == "oldfont")
246 return MathAtom(new MathFontOldInset(l));
247 if (inset == "matrix")
248 return MathAtom(new MathAMSArrayInset(s));
249 return MathAtom(new MathSymbolInset(l));
252 if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
253 return MathAtom(new MathMacroArgument(s[1] - '0'));
254 if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
255 && s[2] >= '1' && s[2] <= '9')
256 return MathAtom(new MathMacroArgument(s[2] - '0'));
258 return MathAtom(new MathFrameboxInset);
260 return MathAtom(new MathKernInset);
262 return MathAtom(new MathXYMatrixInset);
263 if (s == "xrightarrow" || s == "xleftarrow")
264 return MathAtom(new MathXArrowInset(s));
265 if (s == "split" || s == "gathered" || s == "aligned")
266 return MathAtom(new MathSplitInset(s));
268 return MathAtom(new MathCasesInset);
270 return MathAtom(new MathSubstackInset);
271 if (s == "subarray" || s == "array")
272 return MathAtom(new MathArrayInset(s, 1, 1));
274 return MathAtom(new MathSqrtInset);
276 return MathAtom(new MathRootInset);
278 return MathAtom(new MathStackrelInset);
279 if (s == "binom" || s == "choose")
280 return MathAtom(new MathBinomInset(s == "choose"));
281 if (s == "over" || s == "frac")
282 return MathAtom(new MathFracInset);
284 // return MathAtom(new MathInferInset);
286 return MathAtom(new MathFracInset(true));
288 return MathAtom(new MathLefteqnInset);
290 return MathAtom(new MathErtInset);
292 if (MathMacroTable::has(s))
293 return MathAtom(new MathMacro(s));
295 //lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << '\'' << endl;
296 return MathAtom(new MathUnknownInset(s));