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.
18 #include "insets/Inset.h"
41 HullType hullType(docstring const & name);
42 docstring hullName(HullType type);
46 Abstract base class for all math objects. A math insets is for use of the
47 math editor only, it isn't a general LyX inset. It's used to represent all
50 Math insets do not know their parents, a cursor position or things
51 like that. They are dumb objects that are contained in other math insets
52 (InsetMathNests, in fact) thus forming a tree. The root of this tree is
53 always a InsetMathHull, which provides an interface to the Outer World by
54 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
60 class InsetMathAMSArray;
64 class InsetMathFracBase;
69 class InsetMathMatrix;
71 class InsetMathScript;
72 class InsetMathString;
74 class InsetMathSpecialChar;
75 class InsetMathSymbol;
76 class InsetMathUnknown;
85 class MathematicaStream;
90 class MathMacroTemplate;
95 class TextMetricsInfo;
99 class InsetMath : public Inset {
102 InsetMath(Buffer * buf = 0) : Inset(buf) {}
103 /// identification as math inset
104 InsetMath * asInsetMath() { return this; }
105 /// identification as math inset
106 InsetMath const * asInsetMath() const { return this; }
107 /// this is overridden in math text insets (i.e. mbox)
108 bool inMathed() const { return true; }
110 virtual docstring name() const;
112 /// this is overridden by specific insets
113 virtual mode_type currentMode() const { return MATH_MODE; }
115 /// the ascent of the inset above the baseline
116 /// compute the size of the object for text based drawing
117 virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
118 /// draw the object as text
119 virtual void drawT(TextPainter &, int x, int y) const;
121 /// return cell given its number
122 virtual MathData & cell(idx_type);
123 /// return cell given its number
124 virtual MathData const & cell(idx_type) const;
126 /// identifies certain types of insets
127 virtual InsetMathAMSArray * asAMSArrayInset() { return 0; }
128 virtual InsetMathAMSArray const * asAMSArrayInset() const { return 0; }
129 virtual InsetMathArray * asArrayInset() { return 0; }
130 virtual InsetMathArray const * asArrayInset() const { return 0; }
131 virtual InsetMathBrace * asBraceInset() { return 0; }
132 virtual InsetMathBrace const * asBraceInset() const { return 0; }
133 virtual InsetMathChar const * asCharInset() const { return 0; }
134 virtual InsetMathDelim * asDelimInset() { return 0; }
135 virtual InsetMathDelim const * asDelimInset() const { return 0; }
136 virtual InsetMathFracBase * asFracBaseInset() { return 0; }
137 virtual InsetMathFracBase const * asFracBaseInset() const { return 0; }
138 virtual InsetMathFrac * asFracInset() { return 0; }
139 virtual InsetMathFrac const * asFracInset() const { return 0; }
140 virtual InsetMathFont * asFontInset() { return 0; }
141 virtual InsetMathFont const * asFontInset() const { return 0; }
142 virtual InsetMathGrid * asGridInset() { return 0; }
143 virtual InsetMathGrid const * asGridInset() const { return 0; }
144 virtual InsetMathHull * asHullInset() { return 0; }
145 virtual InsetMathHull const * asHullInset() const { return 0; }
146 virtual MathMacro * asMacro() { return 0; }
147 virtual MathMacro const * asMacro() const { return 0; }
148 virtual MathMacroTemplate * asMacroTemplate() { return 0; }
149 virtual MathMacroTemplate const * asMacroTemplate() const { return 0; }
150 virtual InsetMathMatrix const * asMatrixInset() const { return 0; }
151 virtual InsetMathNest * asNestInset() { return 0; }
152 virtual InsetMathNest const * asNestInset() const { return 0; }
153 virtual InsetMathScript * asScriptInset() { return 0; }
154 virtual InsetMathScript const * asScriptInset() const { return 0; }
155 virtual InsetMathSpace * asSpaceInset() { return 0; }
156 virtual InsetMathSpace const * asSpaceInset() const { return 0; }
157 virtual InsetMathString * asStringInset() { return 0; }
158 virtual InsetMathString const * asStringInset() const { return 0; }
159 virtual InsetMathSymbol const * asSymbolInset() const { return 0; }
160 virtual InsetMathUnknown * asUnknownInset() { return 0; }
161 virtual InsetMathUnknown const * asUnknownInset() const { return 0; }
162 virtual InsetMathRef * asRefInset() { return 0; }
163 virtual InsetMathSpecialChar const * asSpecialCharInset() const { return 0; }
165 /// identifies things that can get scripts
166 virtual bool isScriptable() const { return false; }
167 /// is the a relational operator (used for splitting equations)
168 virtual bool isRelOp() const { return false; }
169 /// will this get written as a single block in {..}
170 virtual bool extraBraces() const { return false; }
172 /// return the content as char if the inset is able to do so
173 virtual char_type getChar() const { return 0; }
174 /// identifies things that can get \limits or \nolimits
175 virtual bool takesLimits() const { return false; }
177 /// replace things by other things
178 virtual void replace(ReplaceData &) {}
179 /// do we contain a given subsequence?
180 virtual bool contains(MathData const &) const { return false; }
181 /// access to the lock (only nest array have one)
182 virtual bool lock() const { return false; }
183 /// access to the lock (only nest array have one)
184 virtual void lock(bool) {}
186 // Indicate that we do not want to hide the normal version of
187 // write(). This is to shut off a clang warning.
189 /// write LaTeX and LyX code
190 virtual void write(WriteStream & os) const;
191 /// write normalized content
192 virtual void normalize(NormalStream &) const;
193 /// write content as something readable by Maple
194 virtual void maple(MapleStream &) const;
195 /// write content as something readable by Maxima
196 virtual void maxima(MaximaStream &) const;
197 /// write content as something readable by Mathematica
198 virtual void mathematica(MathematicaStream &) const;
199 /// write content as MathML
200 virtual void mathmlize(MathStream &) const;
201 /// write content as HTML, best we can.
202 /// the idea for this, and some of the details, come from
203 /// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
204 /// we try to mimic how eLyXer outputs some math.
205 virtual void htmlize(HtmlStream &) const;
206 /// write content as something readable by Octave
207 virtual void octave(OctaveStream &) const;
209 /// plain text output in ucs4 encoding
210 int plaintext(odocstringstream &, OutputParams const &, size_t) const;
212 /// dump content to stderr for debugging
213 virtual void dump() const;
216 virtual bool numberedType() const { return false; }
218 virtual HullType getType() const;
220 virtual void mutate(HullType /*newtype*/) {}
222 /// math stuff usually isn't allowed in text mode
223 virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
225 /// superscript kerning
226 virtual int kerning(BufferView const *) const { return 0; }
228 bool isInToc() const { return true; }
230 InsetCode lyxCode() const { return MATH_CODE; }
232 uid_type id() const { return this; }
236 std::ostream & operator<<(std::ostream &, MathAtom const &);
238 odocstream & operator<<(odocstream &, MathAtom const &);