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 MathMacroTemplate;
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 /// this is overridden by insets with specific edit marker type
118 virtual marker_type marker() const;
120 /// the ascent of the inset above the baseline
121 /// compute the size of the object for text based drawing
122 virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
123 /// draw the object as text
124 virtual void drawT(TextPainter &, int x, int y) const;
126 /// return cell given its number
127 virtual MathData & cell(idx_type);
128 /// return cell given its number
129 virtual MathData const & cell(idx_type) const;
131 /// identifies certain types of insets
132 virtual InsetMathAMSArray * asAMSArrayInset() { return 0; }
133 virtual InsetMathAMSArray const * asAMSArrayInset() const { return 0; }
134 virtual InsetMathArray * asArrayInset() { return 0; }
135 virtual InsetMathArray const * asArrayInset() const { return 0; }
136 virtual InsetMathBrace * asBraceInset() { return 0; }
137 virtual InsetMathBrace const * asBraceInset() const { return 0; }
138 virtual InsetMathChar const * asCharInset() const { return 0; }
139 virtual InsetMathDelim * asDelimInset() { return 0; }
140 virtual InsetMathDelim const * asDelimInset() const { return 0; }
141 virtual InsetMathFracBase * asFracBaseInset() { return 0; }
142 virtual InsetMathFracBase const * asFracBaseInset() const { return 0; }
143 virtual InsetMathFrac * asFracInset() { return 0; }
144 virtual InsetMathFrac const * asFracInset() const { return 0; }
145 virtual InsetMathFont * asFontInset() { return 0; }
146 virtual InsetMathFont const * asFontInset() const { return 0; }
147 virtual InsetMathGrid * asGridInset() { return 0; }
148 virtual InsetMathGrid const * asGridInset() const { return 0; }
149 virtual InsetMathHull * asHullInset() { return 0; }
150 virtual InsetMathHull const * asHullInset() const { return 0; }
151 virtual MathMacro * asMacro() { return 0; }
152 virtual MathMacro const * asMacro() const { return 0; }
153 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
154 virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
155 virtual InsetMathMatrix const * asMatrixInset() const { return 0; }
156 virtual InsetMathNest * asNestInset() { return 0; }
157 virtual InsetMathNest const * asNestInset() const { return 0; }
158 virtual InsetMathScript * asScriptInset() { return 0; }
159 virtual InsetMathScript const * asScriptInset() const { return 0; }
160 virtual InsetMathSpace * asSpaceInset() { return 0; }
161 virtual InsetMathSpace const * asSpaceInset() const { return 0; }
162 virtual InsetMathString * asStringInset() { return 0; }
163 virtual InsetMathString const * asStringInset() const { return 0; }
164 virtual InsetMathSymbol const * asSymbolInset() const { return 0; }
165 virtual InsetMathUnknown * asUnknownInset() { return 0; }
166 virtual InsetMathUnknown const * asUnknownInset() const { return 0; }
167 virtual InsetMathRef * asRefInset() { return 0; }
168 virtual InsetMathSpecialChar const * asSpecialCharInset() const { return 0; }
170 /// The class of the math object (used primarily for spacing)
171 virtual MathClass mathClass() const;
172 /// Add this inset to a math row. Return true if contents got added
173 virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
175 /// identifies things that can get scripts
176 virtual bool isScriptable() const { return false; }
177 /// will this get written as a single block in {..}
178 virtual bool extraBraces() const { return false; }
180 /// return the content as char if the inset is able to do so
181 virtual char_type getChar() const { return 0; }
182 /// identifies things that can get \limits or \nolimits
183 virtual bool takesLimits() const { return false; }
185 /// replace things by other things
186 virtual void replace(ReplaceData &) {}
187 /// do we contain a given subsequence?
188 virtual bool contains(MathData const &) const { return false; }
189 /// access to the lock (only nest array have one)
190 virtual bool lock() const { return false; }
191 /// access to the lock (only nest array have one)
192 virtual void lock(bool) {}
194 // Indicate that we do not want to hide the normal version of
195 // write(). This is to shut off a clang warning.
197 /// write LaTeX and LyX code
198 virtual void write(WriteStream & os) const;
199 /// write normalized content
200 virtual void normalize(NormalStream &) const;
201 /// write content as something readable by Maple
202 virtual void maple(MapleStream &) const;
203 /// write content as something readable by Maxima
204 virtual void maxima(MaximaStream &) const;
205 /// write content as something readable by Mathematica
206 virtual void mathematica(MathematicaStream &) const;
207 /// write content as MathML
208 virtual void mathmlize(MathStream &) const;
209 /// write content as HTML, best we can.
210 /// the idea for this, and some of the details, come from
211 /// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
212 /// we try to mimic how eLyXer outputs some math.
213 virtual void htmlize(HtmlStream &) const;
214 /// write content as something readable by Octave
215 virtual void octave(OctaveStream &) const;
217 /// plain text output in ucs4 encoding
218 int plaintext(odocstringstream &, OutputParams const &, size_t) const;
220 /// dump content to stderr for debugging
221 virtual void dump() const;
224 virtual bool numberedType() const { return false; }
226 virtual HullType getType() const;
228 virtual void mutate(HullType /*newtype*/) {}
230 /// math stuff usually isn't allowed in text mode
231 virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
233 /// superscript kerning
234 virtual int kerning(BufferView const *) const { return 0; }
236 bool isInToc() const { return true; }
238 InsetCode lyxCode() const { return MATH_CODE; }
240 uid_type id() const { return this; }
244 std::ostream & operator<<(std::ostream &, MathAtom const &);
246 odocstream & operator<<(odocstream &, MathAtom const &);