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_fontoldinset.h"
14 #include "math_fracinset.h"
15 #include "math_kerninset.h"
16 #include "math_lefteqninset.h"
17 #include "math_macro.h"
18 #include "math_macrotable.h"
19 #include "math_macrotemplate.h"
20 #include "math_macroarg.h"
21 #include "math_parboxinset.h"
22 #include "math_rootinset.h"
23 #include "math_sizeinset.h"
24 #include "math_spaceinset.h"
25 #include "math_splitinset.h"
26 #include "math_sqrtinset.h"
27 #include "math_stackrelinset.h"
28 #include "math_substackinset.h"
29 #include "math_symbolinset.h"
30 #include "math_undersetinset.h"
31 #include "math_unknowninset.h"
32 #include "math_xarrowinset.h"
33 #include "math_xymatrixinset.h"
34 #include "math_xyarrowinset.h"
36 //#include "insets/insetref.h"
37 #include "ref_inset.h"
39 #include "math_metricsinfo.h"
41 #include "math_support.h"
43 #include "support/filetools.h" // LibFileSearch
44 #include "frontends/lyx_gui.h"
53 typedef std::map<string, latexkeys> WordList;
57 bool math_font_available(string & name)
62 // Do we have the font proper?
63 if (lyx_gui::font_available(f))
67 if (name == "eufrak") {
72 lyxerr[Debug::MATHED] << "font " << name << " not available and I can't fake it\n";
79 string const filename = LibFileSearch(string(), "symbols");
80 lyxerr[Debug::MATHED] << "read symbols from " << filename << "\n";
81 if (filename.empty()) {
82 lyxerr << "Could not find symbols file\n";
86 std::ifstream fs(filename.c_str());
88 while (getline(fs, line)) {
92 if (line.size() > 0 && line[0] == '#')
95 // special case of pre-defined macros
96 if (line.size() > 8 && line.substr(0, 5) == "\\def\\") {
97 lyxerr << "defining: '" << line << "'\n";
98 istringstream is(line);
99 MathMacroTable::create(MathAtom(new MathMacroTemplate(is)));
103 istringstream is(line);
104 is >> tmp.name >> tmp.inset;
105 if (isFontName(tmp.inset))
106 is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname;
110 lyxerr[Debug::MATHED] << "skipping line '" << line << "'\n";
111 lyxerr[Debug::MATHED]
112 << tmp.name << ' ' << tmp.inset << ' ' << tmp.extra << "\n";
116 if (isFontName(tmp.inset)) {
117 // tmp.inset _is_ the fontname here.
118 // create fallbacks if necessary
119 if (tmp.extra=="func" || tmp.extra=="funclim" || tmp.extra=="special") {
120 lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n";
122 } else if (math_font_available(tmp.inset)) {
123 lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n";
124 tmp.draw += char(charid);
125 } else if (fallbackid) {
126 if (tmp.inset == "cmex")
127 tmp.inset = "lyxsymbol";
129 tmp.inset = "lyxboldsymbol";
130 lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n";
131 tmp.draw += char(fallbackid);
133 lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n";
135 tmp.inset = "lyxtex";
138 // it's a proper inset
139 lyxerr[Debug::MATHED] << "inset " << tmp.inset << " used for "
143 if (theWordList.find(tmp.name) != theWordList.end())
144 lyxerr[Debug::MATHED] << "readSymbols: inset " << tmp.name
145 << " already exists.\n";
147 theWordList[tmp.name] = tmp;
148 lyxerr[Debug::MATHED] << "read symbol '" << tmp.name
149 << " inset: " << tmp.inset
150 << " draw: " << int(tmp.draw[0])
151 << " extra: " << tmp.extra
162 static bool initialized = false;
170 latexkeys const * in_word_set(string const & str)
172 WordList::iterator it = theWordList.find(str);
173 //lyxerr << "looking up '" << str << "' found: "
174 // << (it != theWordList.end()) << "\n";
175 return (it != theWordList.end()) ? &(it->second) : 0;
179 MathAtom createMathInset(string const & s)
181 lyxerr[Debug::MATHED] << "creating inset with name: '" << s << "'\n";
182 if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
183 return MathAtom(new MathMacroArgument(s[1] - '0'));
185 if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
186 && s[2] >= '1' && s[2] <= '9')
187 return MathAtom(new MathMacroArgument(s[2] - '0'));
189 return MathAtom(new MathKernInset);
191 return MathAtom(new MathXYMatrixInset);
192 if (s == "xrightarrow" || s == "xleftarrow")
193 return MathAtom(new MathXArrowInset(s));
194 if (s == "split" || s == "gathered" || s == "aligned")
195 return MathAtom(new MathSplitInset(s));
197 return MathAtom(new MathCasesInset);
199 return MathAtom(new MathSubstackInset);
200 if (s == "subarray" || s == "array")
201 return MathAtom(new MathArrayInset(s, 1, 1));
203 return MathAtom(new MathSqrtInset);
205 return MathAtom(new MathRootInset);
207 return MathAtom(new MathStackrelInset);
208 if (s == "binom" || s == "choose")
209 return MathAtom(new MathBinomInset(s == "choose"));
210 if (s == "over" || s == "frac")
211 return MathAtom(new MathFracInset);
213 return MathAtom(new MathFracInset(true));
215 return MathAtom(new MathLefteqnInset);
217 latexkeys const * l = in_word_set(s);
219 string const & inset = l->inset;
220 lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n";
222 return MathAtom(new RefInset(l->name));
223 if (inset == "underset")
224 return MathAtom(new MathUndersetInset);
225 if (inset == "decoration")
226 return MathAtom(new MathDecorationInset(l));
227 if (inset == "space")
228 return MathAtom(new MathSpaceInset(l->name));
230 return MathAtom(new MathDotsInset(l));
232 return MathAtom(new MathBoxInset(l->name));
233 if (inset == "parbox")
234 return MathAtom(new MathParboxInset);
236 return MathAtom(new MathFboxInset);
237 if (inset == "style")
238 return MathAtom(new MathSizeInset(l));
240 return MathAtom(new MathFontInset(l));
241 if (inset == "oldfont")
242 return MathAtom(new MathFontOldInset(l));
243 if (inset == "matrix")
244 return MathAtom(new MathAMSArrayInset(s));
245 return MathAtom(new MathSymbolInset(l));
248 if (MathMacroTable::has(s))
249 return MathAtom(new MathMacro(s));
251 //lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << "'\n";
252 return MathAtom(new MathUnknownInset(s));