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 InsetMathUnknown;
85 class MathematicaStream;
90 class InsetMathMacroTemplate;
94 class TextMetricsInfo;
97 /// Type of unique identifiers for math insets (used in TexRow)
98 typedef void const * uid_type;
101 class InsetMath : public Inset {
104 InsetMath(Buffer * buf = 0) : Inset(buf) {}
105 /// identification as math inset
106 InsetMath * asInsetMath() { return this; }
107 /// identification as math inset
108 InsetMath const * asInsetMath() const { return this; }
109 /// this is overridden in math text insets (i.e. mbox)
110 bool inMathed() const { return true; }
112 virtual docstring name() const;
114 /// this is overridden by specific insets
115 virtual mode_type currentMode() const { return MATH_MODE; }
117 // The possible marker types for math insets
118 enum marker_type { NO_MARKER, MARKER2, MARKER, BOX_MARKER };
119 /// this is overridden by insets with specific edit marker type
120 virtual marker_type marker(BufferView const *) const;
122 /// the ascent of the inset above the baseline
123 /// compute the size of the object for text based drawing
124 virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
125 /// draw the object as text
126 virtual void drawT(TextPainter &, int x, int y) const;
128 /// return cell given its number
129 virtual MathData & cell(idx_type);
130 /// return cell given its number
131 virtual MathData const & cell(idx_type) const;
133 /// identifies certain types of insets
134 virtual InsetMathAMSArray * asAMSArrayInset() { return 0; }
135 virtual InsetMathAMSArray const * asAMSArrayInset() const { return 0; }
136 virtual InsetMathArray * asArrayInset() { return 0; }
137 virtual InsetMathArray const * asArrayInset() const { return 0; }
138 virtual InsetMathBrace * asBraceInset() { return 0; }
139 virtual InsetMathBrace const * asBraceInset() const { return 0; }
140 virtual InsetMathChar const * asCharInset() const { return 0; }
141 virtual InsetMathDelim * asDelimInset() { return 0; }
142 virtual InsetMathDelim const * asDelimInset() const { return 0; }
143 virtual InsetMathFracBase * asFracBaseInset() { return 0; }
144 virtual InsetMathFracBase const * asFracBaseInset() const { return 0; }
145 virtual InsetMathFrac * asFracInset() { return 0; }
146 virtual InsetMathFrac const * asFracInset() const { return 0; }
147 virtual InsetMathFont * asFontInset() { return 0; }
148 virtual InsetMathFont const * asFontInset() const { return 0; }
149 virtual InsetMathGrid * asGridInset() { return 0; }
150 virtual InsetMathGrid const * asGridInset() const { return 0; }
151 virtual InsetMathHull * asHullInset() { return 0; }
152 virtual InsetMathHull const * asHullInset() const { return 0; }
153 virtual InsetMathMacro * asMacro() { return 0; }
154 virtual InsetMathMacro const * asMacro() const { return 0; }
155 virtual InsetMathMacroTemplate * asMacroTemplate() { return 0; }
156 virtual InsetMathMacroTemplate const * asMacroTemplate() const { return 0; }
157 virtual InsetMathMatrix const * asMatrixInset() const { return 0; }
158 virtual InsetMathNest * asNestInset() { return 0; }
159 virtual InsetMathNest const * asNestInset() const { return 0; }
160 virtual InsetMathScript * asScriptInset() { return 0; }
161 virtual InsetMathScript const * asScriptInset() const { return 0; }
162 virtual InsetMathSpace * asSpaceInset() { return 0; }
163 virtual InsetMathSpace const * asSpaceInset() const { return 0; }
164 virtual InsetMathString * asStringInset() { return 0; }
165 virtual InsetMathString const * asStringInset() const { return 0; }
166 virtual InsetMathSymbol const * asSymbolInset() const { return 0; }
167 virtual InsetMathUnknown * asUnknownInset() { return 0; }
168 virtual InsetMathUnknown const * asUnknownInset() const { return 0; }
169 virtual InsetMathRef * asRefInset() { return 0; }
170 virtual InsetMathSpecialChar const * asSpecialCharInset() const { return 0; }
172 /// The class of the math object (used primarily for spacing)
173 virtual MathClass mathClass() const;
174 /// Add this inset to a math row. Return true if contents got added
175 virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
176 /// Hook that is run before metrics computation starts
177 virtual void beforeMetrics() const {}
178 /// Hook that is run after metrics computation
179 virtual void afterMetrics() const {}
180 /// Hook that is run before actual drawing
181 virtual void beforeDraw(PainterInfo const &) const {}
182 /// Hook that is run after drawing
183 virtual void afterDraw(PainterInfo const &) const {}
185 /// identifies things that can get scripts
186 virtual bool isScriptable() const { return false; }
187 /// will this get written as a single block in {..}
188 virtual bool extraBraces() const { return false; }
190 /// return the content as char if the inset is able to do so
191 virtual char_type getChar() const { return 0; }
192 /// identifies things that can get \limits or \nolimits
193 virtual bool takesLimits() const { return false; }
195 /// replace things by other things
196 virtual void replace(ReplaceData &) {}
197 /// do we contain a given subsequence?
198 virtual bool contains(MathData const &) const { return false; }
199 /// access to the lock (only nest array have one)
200 virtual bool lock() const { return false; }
201 /// access to the lock (only nest array have one)
202 virtual void lock(bool) {}
204 // Indicate that we do not want to hide the normal version of
205 // write(). This is to shut off a clang warning.
207 /// write LaTeX and LyX code
208 virtual void write(WriteStream & os) const;
209 /// write normalized content
210 virtual void normalize(NormalStream &) const;
211 /// write content as something readable by Maple
212 virtual void maple(MapleStream &) const;
213 /// write content as something readable by Maxima
214 virtual void maxima(MaximaStream &) const;
215 /// write content as something readable by Mathematica
216 virtual void mathematica(MathematicaStream &) const;
217 /// write content as MathML
218 virtual void mathmlize(MathStream &) const;
219 /// write content as HTML, best we can.
220 /// the idea for this, and some of the details, come from
221 /// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
222 /// we try to mimic how eLyXer outputs some math.
223 virtual void htmlize(HtmlStream &) const;
224 /// write content as something readable by Octave
225 virtual void octave(OctaveStream &) const;
227 /// plain text output in ucs4 encoding
228 int plaintext(odocstringstream &, OutputParams const &, size_t) const;
230 /// dump content to stderr for debugging
231 virtual void dump() const;
234 virtual bool numberedType() const { return false; }
236 virtual HullType getType() const;
238 virtual void mutate(HullType /*newtype*/) {}
240 /// math stuff usually isn't allowed in text mode
241 virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
243 /// Italic correction as described in InsetMathScript.h
244 virtual int kerning(BufferView const *) const { return 0; }
246 bool isInToc() const { return true; }
248 InsetCode lyxCode() const { return MATH_CODE; }
250 uid_type id() const { return this; }
254 std::ostream & operator<<(std::ostream &, MathAtom const &);
256 odocstream & operator<<(odocstream &, MathAtom const &);