4 #include "math_parser.h"
5 #include "math_arrayinset.h"
6 #include "math_amsarrayinset.h"
7 #include "math_binominset.h"
8 #include "math_boxinset.h"
9 #include "math_casesinset.h"
10 #include "math_decorationinset.h"
11 #include "math_dotsinset.h"
12 #include "math_ertinset.h"
13 #include "math_fboxinset.h"
14 #include "math_frameboxinset.h"
15 #include "math_fontinset.h"
16 #include "math_fontoldinset.h"
17 #include "math_fracinset.h"
18 #include "math_kerninset.h"
19 #include "math_inferinset.h"
20 #include "math_lefteqninset.h"
21 #include "math_macro.h"
22 #include "math_macrotable.h"
23 #include "math_macrotemplate.h"
24 #include "math_macroarg.h"
25 #include "math_parboxinset.h"
26 #include "math_rootinset.h"
27 #include "math_sizeinset.h"
28 #include "math_spaceinset.h"
29 #include "math_splitinset.h"
30 #include "math_sqrtinset.h"
31 #include "math_stackrelinset.h"
32 #include "math_substackinset.h"
33 #include "math_symbolinset.h"
34 #include "math_tabularinset.h"
35 #include "math_undersetinset.h"
36 #include "math_unknowninset.h"
37 #include "math_xarrowinset.h"
38 #include "math_xymatrixinset.h"
39 #include "math_xyarrowinset.h"
41 //#include "insets/insetref.h"
42 #include "ref_inset.h"
44 #include "math_metricsinfo.h"
46 #include "math_support.h"
48 #include "support/filetools.h" // LibFileSearch
49 #include "frontends/lyx_gui.h"
62 typedef std::map<string, latexkeys> WordList;
66 bool math_font_available(string & name)
71 // Do we have the font proper?
72 if (lyx_gui::font_available(f))
76 if (name == "eufrak") {
82 << "font " << name << " not available and I can't fake it"
90 string const filename = LibFileSearch(string(), "symbols");
91 lyxerr[Debug::MATHED] << "read symbols from " << filename << endl;
92 if (filename.empty()) {
93 lyxerr << "Could not find symbols file" << endl;
97 std::ifstream fs(filename.c_str());
100 while (getline(fs, line)) {
103 if (!line.empty() && line[0] == '#')
106 // special case of iffont/else/endif
107 if (line.size() >= 7 && line.substr(0, 6) == "iffont") {
108 istringstream is(STRCONV(line));
112 skip = !math_font_available(tmp);
114 } else if (line.size() >= 4 && line.substr(0, 4) == "else") {
116 } else if (line.size() >= 5 && line.substr(0, 5) == "endif") {
122 // special case of pre-defined macros
123 if (line.size() > 8 && line.substr(0, 5) == "\\def\\") {
124 //lyxerr << "defining: '" << line << '\'' << endl;
125 istringstream is(STRCONV(line));
126 MathMacroTable::create(MathAtom(new MathMacroTemplate(is)));
130 istringstream is(STRCONV(line));
132 is >> tmp.name >> tmp.inset;
133 if (isFontName(tmp.inset))
134 is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname;
138 lyxerr[Debug::MATHED] << "skipping line '" << line << '\'' << endl;
139 lyxerr[Debug::MATHED]
140 << tmp.name << ' ' << tmp.inset << ' ' << tmp.extra << endl;
144 if (isFontName(tmp.inset)) {
145 // tmp.inset _is_ the fontname here.
146 // create fallbacks if necessary
148 // symbol font is not available sometimes
149 string symbol_font = "lyxsymbol";
151 if (tmp.extra == "func" || tmp.extra == "funclim" || tmp.extra == "special") {
152 lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << endl;
154 } else if (math_font_available(tmp.inset)) {
155 lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << endl;
156 tmp.draw += char(charid);
157 } else if (fallbackid && math_font_available(symbol_font)) {
158 if (tmp.inset == "cmex")
159 tmp.inset = "lyxsymbol";
161 tmp.inset = "lyxboldsymbol";
162 lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << endl;
163 tmp.draw += char(fallbackid);
165 lyxerr[Debug::MATHED] << "faking " << tmp.name << endl;
167 tmp.inset = "lyxtex";
170 // it's a proper inset
171 lyxerr[Debug::MATHED] << "inset " << tmp.inset
172 << " used for " << tmp.name
176 if (theWordList.find(tmp.name) != theWordList.end())
177 lyxerr[Debug::MATHED]
178 << "readSymbols: inset " << tmp.name
179 << " already exists." << endl;
181 theWordList[tmp.name] = tmp;
183 lyxerr[Debug::MATHED]
184 << "read symbol '" << tmp.name
185 << " inset: " << tmp.inset
186 << " draw: " << int(tmp.draw.empty() ? 0 : tmp.draw[0])
187 << " extra: " << tmp.extra
191 string tmp2 = "cmsy";
192 has_math_fonts = math_font_available(tmp) && math_font_available(tmp2);
201 static bool initialized = false;
209 latexkeys const * in_word_set(string const & str)
211 WordList::iterator it = theWordList.find(str);
212 //lyxerr << "looking up '" << str << "' found: "
213 // << (it != theWordList.end()) << endl;
214 return (it != theWordList.end()) ? &(it->second) : 0;
218 MathAtom createMathInset(string const & s)
220 lyxerr[Debug::MATHED] << "creating inset with name: '"
221 << s << '\'' << endl;;
222 latexkeys const * l = in_word_set(s);
224 string const & inset = l->inset;
225 lyxerr[Debug::MATHED] << " found inset: '" <<
226 inset << '\'' << endl;
228 return MathAtom(new RefInset(l->name));
229 if (inset == "underset")
230 return MathAtom(new MathUndersetInset);
231 if (inset == "decoration")
232 return MathAtom(new MathDecorationInset(l));
233 if (inset == "space")
234 return MathAtom(new MathSpaceInset(l->name));
236 return MathAtom(new MathDotsInset(l));
238 return MathAtom(new MathBoxInset(l->name));
239 if (inset == "parbox")
240 return MathAtom(new MathParboxInset);
242 return MathAtom(new MathFboxInset(l));
243 if (inset == "style")
244 return MathAtom(new MathSizeInset(l));
246 return MathAtom(new MathFontInset(l));
247 if (inset == "oldfont")
248 return MathAtom(new MathFontOldInset(l));
249 if (inset == "matrix")
250 return MathAtom(new MathAMSArrayInset(s));
251 return MathAtom(new MathSymbolInset(l));
254 if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
255 return MathAtom(new MathMacroArgument(s[1] - '0'));
256 if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
257 && s[2] >= '1' && s[2] <= '9')
258 return MathAtom(new MathMacroArgument(s[2] - '0'));
260 return MathAtom(new MathFrameboxInset);
262 return MathAtom(new MathKernInset);
264 return MathAtom(new MathXYMatrixInset);
265 if (s == "xrightarrow" || s == "xleftarrow")
266 return MathAtom(new MathXArrowInset(s));
267 if (s == "split" || s == "gathered" || s == "aligned")
268 return MathAtom(new MathSplitInset(s));
270 return MathAtom(new MathCasesInset);
272 return MathAtom(new MathSubstackInset);
273 if (s == "subarray" || s == "array")
274 return MathAtom(new MathArrayInset(s, 1, 1));
276 return MathAtom(new MathSqrtInset);
278 return MathAtom(new MathRootInset);
280 return MathAtom(new MathTabularInset(s, 1, 1));
282 return MathAtom(new MathStackrelInset);
283 if (s == "binom" || s == "choose")
284 return MathAtom(new MathBinomInset(s == "choose"));
285 if (s == "over" || s == "frac")
286 return MathAtom(new MathFracInset);
288 // return MathAtom(new MathInferInset);
290 return MathAtom(new MathFracInset(true));
292 return MathAtom(new MathLefteqnInset);
294 return MathAtom(new MathErtInset);
296 if (MathMacroTable::has(s))
297 return MathAtom(new MathMacro(s));
299 //lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << '\'' << endl;
300 return MathAtom(new MathUnknownInset(s));