4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
7 * \author Alejandro Aguilar Sierra
10 * Full author contact details are available in file CREDITS.
16 #include "MathClass.h"
18 #include "insets/Inset.h"
39 HullType hullType(docstring const & name);
40 docstring hullName(HullType type);
44 // what is obtained with \c \\nolimits
48 // what is obtained with \c \\limits
55 Abstract base class for all math objects. A math insets is for use of the
56 math editor only, it isn't a general LyX inset. It's used to represent all
59 Math insets do not know their parents, a cursor position or things
60 like that. They are dumb objects that are contained in other math insets
61 (InsetMathNests, in fact) thus forming a tree. The root of this tree is
62 always a InsetMathHull, which provides an interface to the Outer World by
63 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
71 class InsetMathAMSArray;
76 class InsetMathFracBase;
81 class InsetMathMatrix;
83 class InsetMathScript;
84 class InsetMathString;
86 class InsetMathSpecialChar;
87 class InsetMathSymbol;
88 class InsetMathSubstack;
89 class InsetMathUnknown;
97 class MathematicaStream;
102 class InsetMathMacroTemplate;
103 class InsetMathMacro;
106 class TextMetricsInfo;
110 class InsetMath : public Inset {
113 explicit InsetMath(Buffer * buf = 0) : Inset(buf) {}
114 /// identification as math inset
115 InsetMath * asInsetMath() override { return this; }
116 /// identification as math inset
117 InsetMath const * asInsetMath() const override { return this; }
118 /// this is overridden in math text insets (i.e. mbox)
119 bool inMathed() const override { return true; }
121 virtual docstring name() const;
123 /// this is overridden by specific insets
124 mode_type currentMode() const override { return MATH_MODE; }
126 // The possible marker types for math insets
127 enum marker_type { NO_MARKER, MARKER2, MARKER, BOX_MARKER };
128 /// this is overridden by insets with specific edit marker type
129 virtual marker_type marker(BufferView const *) const;
131 /// the ascent of the inset above the baseline
132 /// compute the size of the object for text based drawing
133 virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
134 /// draw the object as text
135 virtual void drawT(TextPainter &, int x, int y) const;
137 /// return cell given its number
138 virtual MathData & cell(idx_type);
139 /// return cell given its number
140 virtual MathData const & cell(idx_type) const;
142 /// identifies certain types of insets
143 virtual InsetMathAMSArray * asAMSArrayInset() { return nullptr; }
144 virtual InsetMathAMSArray const * asAMSArrayInset() const { return nullptr; }
145 virtual InsetMathArray * asArrayInset() { return nullptr; }
146 virtual InsetMathArray const * asArrayInset() const { return nullptr; }
147 virtual InsetMathBrace * asBraceInset() { return nullptr; }
148 virtual InsetMathBrace const * asBraceInset() const { return nullptr; }
149 virtual InsetMathChar const * asCharInset() const { return nullptr; }
150 virtual InsetMathClass const * asClassInset() const { return nullptr; }
151 virtual InsetMathDelim * asDelimInset() { return nullptr; }
152 virtual InsetMathDelim const * asDelimInset() const { return nullptr; }
153 virtual InsetMathFracBase * asFracBaseInset() { return nullptr; }
154 virtual InsetMathFracBase const * asFracBaseInset() const { return nullptr; }
155 virtual InsetMathFrac * asFracInset() { return nullptr; }
156 virtual InsetMathFrac const * asFracInset() const { return nullptr; }
157 virtual InsetMathFont * asFontInset() { return nullptr; }
158 virtual InsetMathFont const * asFontInset() const { return nullptr; }
159 virtual InsetMathGrid * asGridInset() { return nullptr; }
160 virtual InsetMathGrid const * asGridInset() const { return nullptr; }
161 virtual InsetMathHull * asHullInset() { return nullptr; }
162 virtual InsetMathHull const * asHullInset() const { return nullptr; }
163 virtual InsetMathMacro * asMacro() { return nullptr; }
164 virtual InsetMathMacro const * asMacro() const { return nullptr; }
165 virtual InsetMathMacroTemplate * asMacroTemplate() { return nullptr; }
166 virtual InsetMathMacroTemplate const * asMacroTemplate() const { return nullptr; }
167 virtual InsetMathMatrix const * asMatrixInset() const { return nullptr; }
168 virtual InsetMathNest * asNestInset() { return nullptr; }
169 virtual InsetMathNest const * asNestInset() const { return nullptr; }
170 virtual InsetMathScript * asScriptInset() { return nullptr; }
171 virtual InsetMathScript const * asScriptInset() const { return nullptr; }
172 virtual InsetMathSpace * asSpaceInset() { return nullptr; }
173 virtual InsetMathSpace const * asSpaceInset() const { return nullptr; }
174 virtual InsetMathString * asStringInset() { return nullptr; }
175 virtual InsetMathString const * asStringInset() const { return nullptr; }
176 virtual InsetMathSubstack * asSubstackInset() { return nullptr; }
177 virtual InsetMathSubstack const * asSubstackInset() const { return nullptr; }
178 virtual InsetMathSymbol const * asSymbolInset() const { return nullptr; }
179 virtual InsetMathUnknown * asUnknownInset() { return nullptr; }
180 virtual InsetMathUnknown const * asUnknownInset() const { return nullptr; }
181 virtual InsetMathRef * asRefInset() { return nullptr; }
182 virtual InsetMathSpecialChar const * asSpecialCharInset() const { return nullptr; }
184 /// The class of the math object (used primarily for spacing)
185 virtual MathClass mathClass() const { return MC_ORD; }
186 /// Add this inset to a math row. Return true if contents got added
187 virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
188 /// Hook that is run before metrics computation starts
189 virtual void beforeMetrics() const {}
190 /// Hook that is run after metrics computation
191 virtual void afterMetrics() const {}
192 /// Hook that is run before actual drawing
193 virtual void beforeDraw(PainterInfo const &) const {}
194 /// Hook that is run after drawing
195 virtual void afterDraw(PainterInfo const &) const {}
197 /// will this get written as a single block in {..}
198 virtual bool extraBraces() const { return false; }
200 /// return the content as char if the inset is able to do so
201 virtual char_type getChar() const { return 0; }
203 /// Whether the inset allows \(no)limits
204 bool allowsLimitsChange() const { return mathClass() == MC_OP; }
205 /// The default limits value
206 virtual Limits defaultLimits() const { return NO_LIMITS; }
207 /// whether the inset has limit-like sub/superscript
208 virtual Limits limits() const { return AUTO_LIMITS; }
209 /// sets types of sub/superscripts
210 virtual void limits(Limits) {}
211 /// write limits status for LaTeX and LyX code
212 void writeLimits(WriteStream & os) const;
214 /// replace things by other things
215 virtual void replace(ReplaceData &) {}
216 /// do we contain a given subsequence?
217 virtual bool contains(MathData const &) const { return false; }
218 /// access to the lock (only nest array have one)
219 virtual bool lock() const { return false; }
220 /// access to the lock (only nest array have one)
221 virtual void lock(bool) {}
223 // Indicate that we do not want to hide the normal version of
224 // write(). This is to shut off a clang warning.
226 /// write LaTeX and LyX code
227 virtual void write(WriteStream & os) const;
228 /// write normalized content
229 virtual void normalize(NormalStream &) const;
230 /// write content as something readable by Maple
231 virtual void maple(MapleStream &) const;
232 /// write content as something readable by Maxima
233 virtual void maxima(MaximaStream &) const;
234 /// write content as something readable by Mathematica
235 virtual void mathematica(MathematicaStream &) const;
236 /// write content as MathML
237 virtual void mathmlize(MathStream &) const;
238 /// write content as HTML, best we can.
239 /// the idea for this, and some of the details, come from
240 /// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
241 /// we try to mimic how eLyXer outputs some math.
242 virtual void htmlize(HtmlStream &) const;
243 /// write content as something readable by Octave
244 virtual void octave(OctaveStream &) const;
246 /// plain text output in ucs4 encoding
247 int plaintext(odocstringstream &, OutputParams const &, size_t) const override;
249 /// dump content to stderr for debugging
250 void dump() const override;
253 virtual bool numberedType() const { return false; }
255 virtual HullType getType() const;
257 virtual void mutate(HullType /*newtype*/) {}
259 /// math stuff usually isn't allowed in text mode
260 bool allowedIn(mode_type mode) const override { return mode == MATH_MODE; }
262 /// Italic correction as described in InsetMathScript.h
263 virtual int kerning(BufferView const *) const { return 0; }
265 bool isInToc() const override { return true; }
267 InsetCode lyxCode() const override { return MATH_CODE; }
269 uid_type id() const { return this; }
273 std::ostream & operator<<(std::ostream &, MathAtom const &);
275 odocstream & operator<<(odocstream &, MathAtom const &);