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 Abstract base class for all math objects. A math insets is for use of the
45 math editor only, it isn't a general LyX inset. It's used to represent all
48 Math insets do not know their parents, a cursor position or things
49 like that. They are dumb objects that are contained in other math insets
50 (InsetMathNests, in fact) thus forming a tree. The root of this tree is
51 always a InsetMathHull, which provides an interface to the Outer World by
52 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
61 class InsetMathAMSArray;
65 class InsetMathFracBase;
70 class InsetMathMatrix;
72 class InsetMathScript;
73 class InsetMathString;
75 class InsetMathSpecialChar;
76 class InsetMathSymbol;
77 class InsetMathSubstack;
78 class InsetMathUnknown;
86 class MathematicaStream;
91 class InsetMathMacroTemplate;
95 class TextMetricsInfo;
98 /// Type of unique identifiers for math insets (used in TexRow)
99 typedef void const * uid_type;
102 class InsetMath : public Inset {
105 explicit InsetMath(Buffer * buf = 0) : Inset(buf) {}
106 /// identification as math inset
107 InsetMath * asInsetMath() { return this; }
108 /// identification as math inset
109 InsetMath const * asInsetMath() const { return this; }
110 /// this is overridden in math text insets (i.e. mbox)
111 bool inMathed() const { return true; }
113 virtual docstring name() const;
115 /// this is overridden by specific insets
116 virtual mode_type currentMode() const { return MATH_MODE; }
118 // The possible marker types for math insets
119 enum marker_type { NO_MARKER, MARKER2, MARKER, BOX_MARKER };
120 /// this is overridden by insets with specific edit marker type
121 virtual marker_type marker(BufferView const *) const;
123 /// the ascent of the inset above the baseline
124 /// compute the size of the object for text based drawing
125 virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
126 /// draw the object as text
127 virtual void drawT(TextPainter &, int x, int y) const;
129 /// return cell given its number
130 virtual MathData & cell(idx_type);
131 /// return cell given its number
132 virtual MathData const & cell(idx_type) const;
134 /// identifies certain types of insets
135 virtual InsetMathAMSArray * asAMSArrayInset() { return nullptr; }
136 virtual InsetMathAMSArray const * asAMSArrayInset() const { return nullptr; }
137 virtual InsetMathArray * asArrayInset() { return nullptr; }
138 virtual InsetMathArray const * asArrayInset() const { return nullptr; }
139 virtual InsetMathBrace * asBraceInset() { return nullptr; }
140 virtual InsetMathBrace const * asBraceInset() const { return nullptr; }
141 virtual InsetMathChar const * asCharInset() const { return nullptr; }
142 virtual InsetMathDelim * asDelimInset() { return nullptr; }
143 virtual InsetMathDelim const * asDelimInset() const { return nullptr; }
144 virtual InsetMathFracBase * asFracBaseInset() { return nullptr; }
145 virtual InsetMathFracBase const * asFracBaseInset() const { return nullptr; }
146 virtual InsetMathFrac * asFracInset() { return nullptr; }
147 virtual InsetMathFrac const * asFracInset() const { return nullptr; }
148 virtual InsetMathFont * asFontInset() { return nullptr; }
149 virtual InsetMathFont const * asFontInset() const { return nullptr; }
150 virtual InsetMathGrid * asGridInset() { return nullptr; }
151 virtual InsetMathGrid const * asGridInset() const { return nullptr; }
152 virtual InsetMathHull * asHullInset() { return nullptr; }
153 virtual InsetMathHull const * asHullInset() const { return nullptr; }
154 virtual InsetMathMacro * asMacro() { return nullptr; }
155 virtual InsetMathMacro const * asMacro() const { return nullptr; }
156 virtual InsetMathMacroTemplate * asMacroTemplate() { return nullptr; }
157 virtual InsetMathMacroTemplate const * asMacroTemplate() const { return nullptr; }
158 virtual InsetMathMatrix const * asMatrixInset() const { return nullptr; }
159 virtual InsetMathNest * asNestInset() { return nullptr; }
160 virtual InsetMathNest const * asNestInset() const { return nullptr; }
161 virtual InsetMathScript * asScriptInset() { return nullptr; }
162 virtual InsetMathScript const * asScriptInset() const { return nullptr; }
163 virtual InsetMathSpace * asSpaceInset() { return nullptr; }
164 virtual InsetMathSpace const * asSpaceInset() const { return nullptr; }
165 virtual InsetMathString * asStringInset() { return nullptr; }
166 virtual InsetMathString const * asStringInset() const { return nullptr; }
167 virtual InsetMathSubstack * asSubstackInset() { return nullptr; }
168 virtual InsetMathSubstack const * asSubstackInset() const { return nullptr; }
169 virtual InsetMathSymbol const * asSymbolInset() const { return nullptr; }
170 virtual InsetMathUnknown * asUnknownInset() { return nullptr; }
171 virtual InsetMathUnknown const * asUnknownInset() const { return nullptr; }
172 virtual InsetMathRef * asRefInset() { return nullptr; }
173 virtual InsetMathSpecialChar const * asSpecialCharInset() const { return nullptr; }
175 /// The class of the math object (used primarily for spacing)
176 virtual MathClass mathClass() const;
177 /// Add this inset to a math row. Return true if contents got added
178 virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
179 /// Hook that is run before metrics computation starts
180 virtual void beforeMetrics() const {}
181 /// Hook that is run after metrics computation
182 virtual void afterMetrics() const {}
183 /// Hook that is run before actual drawing
184 virtual void beforeDraw(PainterInfo const &) const {}
185 /// Hook that is run after drawing
186 virtual void afterDraw(PainterInfo const &) const {}
188 /// identifies things that can get scripts
189 virtual bool isScriptable() const { return false; }
190 /// will this get written as a single block in {..}
191 virtual bool extraBraces() const { return false; }
193 /// return the content as char if the inset is able to do so
194 virtual char_type getChar() const { return 0; }
195 /// identifies things that can get \limits or \nolimits
196 virtual bool takesLimits() const { return false; }
198 /// replace things by other things
199 virtual void replace(ReplaceData &) {}
200 /// do we contain a given subsequence?
201 virtual bool contains(MathData const &) const { return false; }
202 /// access to the lock (only nest array have one)
203 virtual bool lock() const { return false; }
204 /// access to the lock (only nest array have one)
205 virtual void lock(bool) {}
207 // Indicate that we do not want to hide the normal version of
208 // write(). This is to shut off a clang warning.
210 /// write LaTeX and LyX code
211 virtual void write(WriteStream & os) const;
212 /// write normalized content
213 virtual void normalize(NormalStream &) const;
214 /// write content as something readable by Maple
215 virtual void maple(MapleStream &) const;
216 /// write content as something readable by Maxima
217 virtual void maxima(MaximaStream &) const;
218 /// write content as something readable by Mathematica
219 virtual void mathematica(MathematicaStream &) const;
220 /// write content as MathML
221 virtual void mathmlize(MathStream &) const;
222 /// write content as HTML, best we can.
223 /// the idea for this, and some of the details, come from
224 /// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
225 /// we try to mimic how eLyXer outputs some math.
226 virtual void htmlize(HtmlStream &) const;
227 /// write content as something readable by Octave
228 virtual void octave(OctaveStream &) const;
230 /// plain text output in ucs4 encoding
231 int plaintext(odocstringstream &, OutputParams const &, size_t) const;
233 /// dump content to stderr for debugging
234 virtual void dump() const;
237 virtual bool numberedType() const { return false; }
239 virtual HullType getType() const;
241 virtual void mutate(HullType /*newtype*/) {}
243 /// math stuff usually isn't allowed in text mode
244 virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
246 /// Italic correction as described in InsetMathScript.h
247 virtual int kerning(BufferView const *) const { return 0; }
249 bool isInToc() const { return true; }
251 InsetCode lyxCode() const { return MATH_CODE; }
253 uid_type id() const { return this; }
257 std::ostream & operator<<(std::ostream &, MathAtom const &);
259 odocstream & operator<<(odocstream &, MathAtom const &);