3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS.
14 #include "InsetMath.h"
17 #include "MathStream.h"
19 #include "MetricsInfo.h"
21 #include "support/debug.h"
22 #include "support/docstream.h"
23 #include "support/gettext.h"
24 #include "support/lassert.h"
25 #include "support/lstrings.h"
26 #include "support/textutils.h"
33 HullType hullType(docstring const & name)
35 if (name == "none") return hullNone;
36 if (name == "simple") return hullSimple;
37 if (name == "equation") return hullEquation;
38 if (name == "eqnarray") return hullEqnArray;
39 if (name == "align") return hullAlign;
40 if (name == "alignat") return hullAlignAt;
41 if (name == "xalignat") return hullXAlignAt;
42 if (name == "xxalignat") return hullXXAlignAt;
43 if (name == "multline") return hullMultline;
44 if (name == "gather") return hullGather;
45 if (name == "flalign") return hullFlAlign;
46 if (name == "regexp") return hullRegexp;
47 lyxerr << "unknown hull type '" << to_utf8(name) << "'" << endl;
52 docstring hullName(HullType type)
55 case hullNone: return from_ascii("none");
56 case hullSimple: return from_ascii("simple");
57 case hullEquation: return from_ascii("equation");
58 case hullEqnArray: return from_ascii("eqnarray");
59 case hullAlign: return from_ascii("align");
60 case hullAlignAt: return from_ascii("alignat");
61 case hullXAlignAt: return from_ascii("xalignat");
62 case hullXXAlignAt: return from_ascii("xxalignat");
63 case hullMultline: return from_ascii("multline");
64 case hullGather: return from_ascii("gather");
65 case hullFlAlign: return from_ascii("flalign");
66 case hullRegexp: return from_ascii("regexp");
68 lyxerr << "unknown hull type" << endl;
71 return from_ascii("none");
75 docstring InsetMath::name() const
77 return from_utf8("Unknown");
81 MathData & InsetMath::cell(idx_type)
83 static MathData dummyCell(&buffer());
84 LYXERR0("I don't have any cell");
89 MathData const & InsetMath::cell(idx_type) const
91 static MathData dummyCell;
92 LYXERR0("I don't have any cell");
97 marker_type InsetMath::marker(BufferView const *) const
99 return nargs() > 0 ? marker_type::MARKER : marker_type::NO_MARKER;
103 bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
105 MathRow::Element e(mi, MathRow::INSET, mathClass());
107 e.marker = mi.base.macro_nesting ? marker_type::NO_MARKER : marker(mi.base.bv);
113 /// write LaTeX and LyX code
114 void InsetMath::writeLimits(TeXMathStream & os) const
116 if (limits() == LIMITS) {
118 os.pendingSpace(true);
119 } else if (limits() == NO_LIMITS) {
121 os.pendingSpace(true);
126 void InsetMath::dump() const
128 lyxerr << "---------------------------------------------" << endl;
130 otexrowstream ots(os);
131 TeXMathStream wi(ots, false, true, TeXMathStream::wsDefault);
133 lyxerr << to_utf8(os.str());
134 lyxerr << "\n---------------------------------------------" << endl;
138 void InsetMath::metricsT(TextMetricsInfo const &, Dimension &) const
140 LYXERR0("InsetMath::metricsT(Text) called directly!");
144 void InsetMath::drawT(TextPainter &, int, int) const
146 LYXERR0("InsetMath::drawT(Text) called directly!");
150 void InsetMath::write(TeXMathStream & os) const
152 MathEnsurer ensurer(os);
153 docstring const s = name();
155 // We need an extra ' ' unless this is a single-char-non-ASCII name
156 // or anything non-ASCII follows
157 if (s.size() != 1 || isAlphaASCII(s[0]))
158 os.pendingSpace(true);
162 int InsetMath::plaintext(odocstringstream &,
163 OutputParams const &, size_t) const
165 // all math plain text output shall take place in InsetMathHull
171 void InsetMath::normalize(NormalStream & os) const
173 os << '[' << name() << "] ";
177 void InsetMath::octave(OctaveStream & os) const
179 NormalStream ns(os.os());
184 void InsetMath::maple(MapleStream & os) const
186 NormalStream ns(os.os());
191 void InsetMath::maxima(MaximaStream & os) const
193 MapleStream ns(os.os());
198 void InsetMath::mathematica(MathematicaStream & os) const
200 NormalStream ns(os.os());
205 void InsetMath::mathmlize(MathMLStream & ms) const
207 ms << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
208 ms << MTagInline("mi");
209 NormalStream ns(ms.os());
211 ms << ETagInline("mi");
215 void InsetMath::htmlize(HtmlStream & os) const
217 os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
218 os << MTag("span", "style='color: red;'");
219 NormalStream ns(os.os());
225 HullType InsetMath::getType() const
231 ostream & operator<<(ostream & os, MathAtom const & at)
233 odocstringstream oss;
234 otexrowstream ots(oss);
235 TeXMathStream wi(ots, false, false, TeXMathStream::wsDefault);
237 return os << to_utf8(oss.str());
241 odocstream & operator<<(odocstream & os, MathAtom const & at)
243 otexrowstream ots(os);
244 TeXMathStream wi(ots, false, false, TeXMathStream::wsDefault);