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 docstring InsetMath::name() const
35 return from_utf8("Unknown");
39 MathData & InsetMath::cell(idx_type)
41 static MathData dummyCell(&buffer());
42 LYXERR0("I don't have any cell");
47 MathData const & InsetMath::cell(idx_type) const
49 static MathData dummyCell;
50 LYXERR0("I don't have any cell");
55 InsetMath::marker_type InsetMath::marker(BufferView const *) const
57 return nargs() > 0 ? MARKER : NO_MARKER;
61 bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
63 MathRow::Element e(mi, MathRow::INSET, mathClass());
65 e.marker = mi.base.macro_nesting ? NO_MARKER : marker(mi.base.bv);
71 /// write LaTeX and LyX code
72 void InsetMath::writeLimits(WriteStream & os) const
74 if (limits() == LIMITS) {
76 os.pendingSpace(true);
77 } else if (limits() == NO_LIMITS) {
79 os.pendingSpace(true);
84 void InsetMath::dump() const
86 lyxerr << "---------------------------------------------" << endl;
88 otexrowstream ots(os);
89 WriteStream wi(ots, false, true, WriteStream::wsDefault);
91 lyxerr << to_utf8(os.str());
92 lyxerr << "\n---------------------------------------------" << endl;
96 void InsetMath::metricsT(TextMetricsInfo const &, Dimension &) const
98 LYXERR0("InsetMath::metricsT(Text) called directly!");
102 void InsetMath::drawT(TextPainter &, int, int) const
104 LYXERR0("InsetMath::drawT(Text) called directly!");
108 void InsetMath::write(WriteStream & os) const
110 MathEnsurer ensurer(os);
111 docstring const s = name();
113 // We need an extra ' ' unless this is a single-char-non-ASCII name
114 // or anything non-ASCII follows
115 if (s.size() != 1 || isAlphaASCII(s[0]))
116 os.pendingSpace(true);
120 int InsetMath::plaintext(odocstringstream &,
121 OutputParams const &, size_t) const
123 // all math plain text output shall take place in InsetMathHull
129 void InsetMath::normalize(NormalStream & os) const
131 os << '[' << name() << "] ";
135 void InsetMath::octave(OctaveStream & os) const
137 NormalStream ns(os.os());
142 void InsetMath::maple(MapleStream & os) const
144 NormalStream ns(os.os());
149 void InsetMath::maxima(MaximaStream & os) const
151 MapleStream ns(os.os());
156 void InsetMath::mathematica(MathematicaStream & os) const
158 NormalStream ns(os.os());
163 void InsetMath::mathmlize(MathStream & ms) const
165 ms << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
167 NormalStream ns(ms.os());
173 void InsetMath::htmlize(HtmlStream & os) const
175 os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
176 os << MTag("span", "style='color: red;'");
177 NormalStream ns(os.os());
183 HullType InsetMath::getType() const
189 ostream & operator<<(ostream & os, MathAtom const & at)
191 odocstringstream oss;
192 otexrowstream ots(oss);
193 WriteStream wi(ots, false, false, WriteStream::wsDefault);
195 return os << to_utf8(oss.str());
199 odocstream & operator<<(odocstream & os, MathAtom const & at)
201 otexrowstream ots(os);
202 WriteStream wi(ots, false, false, WriteStream::wsDefault);