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_fracinset.h"
14 #include "math_kerninset.h"
15 #include "math_lefteqninset.h"
16 #include "math_macro.h"
17 #include "math_macrotable.h"
18 #include "math_macroarg.h"
19 #include "math_notinset.h"
20 #include "math_parboxinset.h"
21 #include "math_rootinset.h"
22 #include "math_sizeinset.h"
23 #include "math_spaceinset.h"
24 #include "math_splitinset.h"
25 #include "math_sqrtinset.h"
26 #include "math_stackrelinset.h"
27 #include "math_substackinset.h"
28 #include "math_symbolinset.h"
29 #include "math_undersetinset.h"
30 #include "math_unknowninset.h"
31 #include "math_xarrowinset.h"
32 #include "math_xymatrixinset.h"
33 #include "math_xyarrowinset.h"
35 //#include "insets/insetref.h"
36 #include "ref_inset.h"
38 #include "math_metricsinfo.h"
40 #include "math_support.h"
42 #include "support/filetools.h" // LibFileSearch
43 #include "frontends/font_loader.h"
52 typedef std::map<string, latexkeys> WordList;
56 bool math_font_available(string & name)
61 // Do we have the font proper?
62 if (fontloader.available(f))
66 if (name == "eufrak") {
71 lyxerr[Debug::MATHED] << "font " << name << " not available and I can't fake it\n";
78 string const filename = LibFileSearch(string(), "symbols");
79 lyxerr[Debug::MATHED] << "read symbols from " << filename << "\n";
80 if (filename.empty()) {
81 lyxerr << "Could not find symbols file\n";
85 std::ifstream fs(filename.c_str());
92 if (line.size() > 1 && line[0] == '#')
94 istringstream is(line);
95 is >> tmp.name >> tmp.inset;
96 if (isFontName(tmp.inset))
97 is >> charid >> fallbackid >> tmp.extra >> tmp.xmlname;
101 lyxerr[Debug::MATHED] << "skipping line '" << line << "'\n";
102 lyxerr[Debug::MATHED]
103 << tmp.name << ' ' << tmp.inset << ' ' << tmp.extra << "\n";
107 if (isFontName(tmp.inset)) {
108 // tmp.inset _is_ the fontname here.
109 // create fallbacks if necessary
110 if (tmp.extra=="func" || tmp.extra=="funclim" || tmp.extra=="special") {
111 lyxerr[Debug::MATHED] << "symbol abuse for " << tmp.name << "\n";
113 } else if (math_font_available(tmp.inset)) {
114 lyxerr[Debug::MATHED] << "symbol available for " << tmp.name << "\n";
115 tmp.draw += char(charid);
116 } else if (fallbackid) {
117 if (tmp.inset == "cmex")
118 tmp.inset = "lyxsymbol";
120 tmp.inset = "lyxboldsymbol";
121 lyxerr[Debug::MATHED] << "symbol fallback for " << tmp.name << "\n";
122 tmp.draw += char(fallbackid);
124 lyxerr[Debug::MATHED] << "faking " << tmp.name << "\n";
126 tmp.inset = "lyxtex";
129 // it's a proper inset
130 lyxerr[Debug::MATHED] << "inset " << tmp.inset << " used for "
134 if (theWordList.find(tmp.name) != theWordList.end())
135 lyxerr[Debug::MATHED] << "readSymbols: inset " << tmp.name
136 << " already exists.\n";
138 theWordList[tmp.name] = tmp;
139 lyxerr[Debug::MATHED] << "read symbol '" << tmp.name
140 << " inset: " << tmp.inset
141 << " draw: " << int(tmp.draw[0])
142 << " extra: " << tmp.extra
151 latexkeys const * in_word_set(string const & str)
153 static bool initialized = false;
160 WordList::iterator it = theWordList.find(str);
161 //lyxerr << "looking up '" << str << "' found: "
162 // << (it != theWordList.end()) << "\n";
163 return (it != theWordList.end()) ? &(it->second) : 0;
167 MathAtom createMathInset(string const & s)
169 lyxerr[Debug::MATHED] << "creating inset with name: '" << s << "'\n";
170 if (s.size() == 2 && s[0] == '#' && s[1] >= '1' && s[1] <= '9')
171 return MathAtom(new MathMacroArgument(s[1] - '0'));
173 if (s.size() == 3 && s[0] == '\\' && s[1] == '#'
174 && s[2] >= '1' && s[2] <= '9')
175 return MathAtom(new MathMacroArgument(s[2] - '0'));
177 return MathAtom(new MathKernInset);
179 return MathAtom(new MathXYMatrixInset);
180 if (s == "xrightarrow" || s == "xleftarrow")
181 return MathAtom(new MathXArrowInset(s));
182 if (s == "split" || s == "gathered" || s == "aligned")
183 return MathAtom(new MathSplitInset(s));
185 return MathAtom(new MathCasesInset);
187 return MathAtom(new MathSubstackInset);
188 if (s == "subarray" || s == "array")
189 return MathAtom(new MathArrayInset(s, 1, 1));
191 return MathAtom(new MathSqrtInset);
193 return MathAtom(new MathRootInset);
195 return MathAtom(new MathStackrelInset);
196 if (s == "binom" || s == "choose")
197 return MathAtom(new MathBinomInset(s == "choose"));
198 if (s == "over" || s == "frac")
199 return MathAtom(new MathFracInset);
201 return MathAtom(new MathFracInset(true));
203 return MathAtom(new MathNotInset);
205 return MathAtom(new MathLefteqnInset);
207 latexkeys const * l = in_word_set(s);
209 string const & inset = l->inset;
210 lyxerr[Debug::MATHED] << " found inset: '" << inset << "'\n";
212 return MathAtom(new RefInset(l->name));
213 if (inset == "underset")
214 return MathAtom(new MathUndersetInset);
215 if (inset == "decoration")
216 return MathAtom(new MathDecorationInset(l->name));
217 if (inset == "space")
218 return MathAtom(new MathSpaceInset(l->name));
220 return MathAtom(new MathDotsInset(l->name));
222 return MathAtom(new MathBoxInset(l->name));
223 if (inset == "parbox")
224 return MathAtom(new MathParboxInset);
226 return MathAtom(new MathFboxInset);
227 if (inset == "style")
228 return MathAtom(new MathSizeInset(l));
230 return MathAtom(new MathFontInset(l->name));
231 if (inset == "oldfont")
232 return MathAtom(new MathFontInset(l->name));
233 if (inset == "matrix")
234 return MathAtom(new MathAMSArrayInset(s));
235 return MathAtom(new MathSymbolInset(l));
238 if (MathMacroTable::has(s))
239 return MathAtom(new MathMacro(s));
241 //lyxerr[Debug::MATHED] << "creating inset 2 with name: '" << s << "'\n";
242 return MathAtom(new MathUnknownInset(s));