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
53 /// The possible marker types for math insets
54 enum class marker_type : int {
64 Abstract base class for all math objects. A math insets is for use of the
65 math editor only, it isn't a general LyX inset. It's used to represent all
68 Math insets do not know their parents, a cursor position or things
69 like that. They are dumb objects that are contained in other math insets
70 (InsetMathNests, in fact) thus forming a tree. The root of this tree is
71 always a InsetMathHull, which provides an interface to the Outer World by
72 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
80 class InsetMathAMSArray;
85 class InsetMathFracBase;
90 class InsetMathMatrix;
92 class InsetMathScript;
93 class InsetMathString;
95 class InsetMathSpecialChar;
96 class InsetMathSymbol;
97 class InsetMathSubstack;
98 class InsetMathUnknown;
106 class MathematicaStream;
111 class InsetMathMacroTemplate;
112 class InsetMathMacro;
115 class TextMetricsInfo;
119 class InsetMath : public Inset {
122 explicit InsetMath(Buffer * buf = 0) : Inset(buf) {}
123 /// identification as math inset
124 InsetMath * asInsetMath() override { return this; }
125 /// identification as math inset
126 InsetMath const * asInsetMath() const override { return this; }
127 /// this is overridden in math text insets (i.e. mbox)
128 bool inMathed() const override { return true; }
130 virtual docstring name() const;
132 /// this is overridden by specific insets
133 mode_type currentMode() const override { return MATH_MODE; }
135 /// this is overridden by insets with specific edit marker type
136 virtual marker_type marker(BufferView const *) const;
138 /// the ascent of the inset above the baseline
139 /// compute the size of the object for text based drawing
140 virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
141 /// draw the object as text
142 virtual void drawT(TextPainter &, int x, int y) const;
144 /// return cell given its number
145 virtual MathData & cell(idx_type);
146 /// return cell given its number
147 virtual MathData const & cell(idx_type) const;
149 /// identifies certain types of insets
150 virtual InsetMathAMSArray * asAMSArrayInset() { return nullptr; }
151 virtual InsetMathAMSArray const * asAMSArrayInset() const { return nullptr; }
152 virtual InsetMathArray * asArrayInset() { return nullptr; }
153 virtual InsetMathArray const * asArrayInset() const { return nullptr; }
154 virtual InsetMathBrace * asBraceInset() { return nullptr; }
155 virtual InsetMathBrace const * asBraceInset() const { return nullptr; }
156 virtual InsetMathChar const * asCharInset() const { return nullptr; }
157 virtual InsetMathClass const * asClassInset() const { return nullptr; }
158 virtual InsetMathDelim * asDelimInset() { return nullptr; }
159 virtual InsetMathDelim const * asDelimInset() const { return nullptr; }
160 virtual InsetMathFracBase * asFracBaseInset() { return nullptr; }
161 virtual InsetMathFracBase const * asFracBaseInset() const { return nullptr; }
162 virtual InsetMathFrac * asFracInset() { return nullptr; }
163 virtual InsetMathFrac const * asFracInset() const { return nullptr; }
164 virtual InsetMathFont * asFontInset() { return nullptr; }
165 virtual InsetMathFont const * asFontInset() const { return nullptr; }
166 virtual InsetMathGrid * asGridInset() { return nullptr; }
167 virtual InsetMathGrid const * asGridInset() const { return nullptr; }
168 virtual InsetMathHull * asHullInset() { return nullptr; }
169 virtual InsetMathHull const * asHullInset() const { return nullptr; }
170 virtual InsetMathMacro * asMacro() { return nullptr; }
171 virtual InsetMathMacro const * asMacro() const { return nullptr; }
172 virtual InsetMathMacroTemplate * asMacroTemplate() { return nullptr; }
173 virtual InsetMathMacroTemplate const * asMacroTemplate() const { return nullptr; }
174 virtual InsetMathMatrix const * asMatrixInset() const { return nullptr; }
175 virtual InsetMathNest * asNestInset() { return nullptr; }
176 virtual InsetMathNest const * asNestInset() const { return nullptr; }
177 virtual InsetMathScript * asScriptInset() { return nullptr; }
178 virtual InsetMathScript const * asScriptInset() const { return nullptr; }
179 virtual InsetMathSpace * asSpaceInset() { return nullptr; }
180 virtual InsetMathSpace const * asSpaceInset() const { return nullptr; }
181 virtual InsetMathString * asStringInset() { return nullptr; }
182 virtual InsetMathString const * asStringInset() const { return nullptr; }
183 virtual InsetMathSubstack * asSubstackInset() { return nullptr; }
184 virtual InsetMathSubstack const * asSubstackInset() const { return nullptr; }
185 virtual InsetMathSymbol const * asSymbolInset() const { return nullptr; }
186 virtual InsetMathUnknown * asUnknownInset() { return nullptr; }
187 virtual InsetMathUnknown const * asUnknownInset() const { return nullptr; }
188 virtual InsetMathRef * asRefInset() { return nullptr; }
189 virtual InsetMathSpecialChar const * asSpecialCharInset() const { return nullptr; }
191 /// The class of the math object (used primarily for spacing)
192 virtual MathClass mathClass() const { return MC_ORD; }
193 /// Add this inset to a math row. Return true if contents got added
194 virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
195 /// Hook that is run before metrics computation starts
196 virtual void beforeMetrics() const {}
197 /// Hook that is run after metrics computation
198 virtual void afterMetrics() const {}
199 /// Hook that is run before actual drawing
200 virtual void beforeDraw(PainterInfo const &) const {}
201 /// Hook that is run after drawing
202 virtual void afterDraw(PainterInfo const &) const {}
204 /// will this get written as a single block in {..}
205 virtual bool extraBraces() const { return false; }
207 /// return the content as char if the inset is able to do so
208 virtual char_type getChar() const { return 0; }
210 /// Whether the inset allows \(no)limits
211 bool allowsLimitsChange() const { return mathClass() == MC_OP; }
212 /// The default limits value depending on whether display mode is on
213 virtual Limits defaultLimits(bool /* display */) const { return NO_LIMITS; }
214 /// whether the inset has limit-like sub/superscript
215 virtual Limits limits() const { return AUTO_LIMITS; }
216 /// sets types of sub/superscripts
217 virtual void limits(Limits) {}
218 /// write limits status for LaTeX and LyX code
219 void writeLimits(TeXMathStream & os) const;
221 /// replace things by other things
222 virtual void replace(ReplaceData &) {}
223 /// do we contain a given subsequence?
224 virtual bool contains(MathData const &) const { return false; }
225 /// access to the lock (only nest array have one)
226 virtual bool lock() const { return false; }
227 /// access to the lock (only nest array have one)
228 virtual void lock(bool) {}
230 // Indicate that we do not want to hide the normal version of
231 // write(). This is to shut off a clang warning.
233 /// write LaTeX and LyX code
234 virtual void write(TeXMathStream & os) const;
235 /// write normalized content
236 virtual void normalize(NormalStream &) const;
237 /// write content as something readable by Maple
238 virtual void maple(MapleStream &) const;
239 /// write content as something readable by Maxima
240 virtual void maxima(MaximaStream &) const;
241 /// write content as something readable by Mathematica
242 virtual void mathematica(MathematicaStream &) const;
243 /// write content as MathML
244 virtual void mathmlize(MathMLStream &) const;
245 /// write content as HTML, best we can.
246 /// the idea for this, and some of the details, come from
247 /// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
248 /// we try to mimic how eLyXer outputs some math.
249 virtual void htmlize(HtmlStream &) const;
250 /// write content as something readable by Octave
251 virtual void octave(OctaveStream &) const;
253 /// plain text output in ucs4 encoding
254 int plaintext(odocstringstream &, OutputParams const &, size_t) const override;
256 /// dump content to stderr for debugging
257 void dump() const override;
260 virtual bool numberedType() const { return false; }
262 virtual HullType getType() const;
264 virtual void mutate(HullType /*newtype*/) {}
266 /// math stuff usually isn't allowed in text mode
267 bool allowedIn(mode_type mode) const override { return mode == MATH_MODE; }
269 /// Italic correction as described in InsetMathScript.h
270 virtual int kerning(BufferView const *) const { return 0; }
272 bool isInToc() const override { return true; }
274 InsetCode lyxCode() const override { return MATH_CODE; }
276 uid_type id() const { return this; }
280 std::ostream & operator<<(std::ostream &, MathAtom const &);
282 odocstream & operator<<(odocstream &, MathAtom const &);