]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.h
Revert "XHTML: remove DOCTYPE, as the document is then understood as HTML4/XHTML1...
[lyx.git] / src / mathed / InsetMath.h
1 // -*- C++ -*-
2 /**
3  * \file InsetMath.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Alejandro Aguilar Sierra
8  * \author André Pönitz
9  *
10  * Full author contact details are available in file CREDITS.
11  */
12
13 #ifndef MATH_INSET_H
14 #define MATH_INSET_H
15
16 #include "MathClass.h"
17
18 #include "insets/Inset.h"
19
20
21 namespace lyx {
22
23 enum HullType {
24         hullNone,
25         hullSimple,
26         hullEquation,
27         hullEqnArray,
28         hullAlign,
29         hullAlignAt,
30         hullXAlignAt,
31         hullXXAlignAt,
32         hullFlAlign,
33         hullMultline,
34         hullGather,
35         hullRegexp,
36         hullUnknown
37 };
38
39 HullType hullType(docstring const & name);
40 docstring hullName(HullType type);
41
42
43 enum Limits {
44         // what is obtained with \c \\nolimits
45         NO_LIMITS = -1,
46         // the default
47         AUTO_LIMITS = 0,
48         // what is obtained with \c \\limits
49         LIMITS = 1
50 };
51
52
53 /**
54
55 Abstract base class for all math objects.  A math insets is for use of the
56 math editor only, it isn't a general LyX inset. It's used to represent all
57 the math objects.
58
59 Math insets do not know their parents, a cursor position or things
60 like that. They are dumb objects that are contained in other math insets
61 (InsetMathNests, in fact) thus forming a tree. The root of this tree is
62 always a InsetMathHull, which provides an interface to the Outer World by
63 inclusion in the "real LyX insets" FormulaInset and FormulaMacroInset.
64
65 */
66
67 class Cursor;
68 class OutputParams;
69 class MetricsInfo;
70
71 class InsetMathArray;
72 class InsetMathAMSArray;
73 class InsetMathBrace;
74 class InsetMathChar;
75 class InsetMathClass;
76 class InsetMathDelim;
77 class InsetMathFracBase;
78 class InsetMathFrac;
79 class InsetMathFont;
80 class InsetMathGrid;
81 class InsetMathHull;
82 class InsetMathMatrix;
83 class InsetMathNest;
84 class InsetMathScript;
85 class InsetMathString;
86 class InsetMathSpace;
87 class InsetMathSpecialChar;
88 class InsetMathSymbol;
89 class InsetMathSubstack;
90 class InsetMathUnknown;
91 class InsetMathRef;
92
93 class HtmlStream;
94 class NormalStream;
95 class OctaveStream;
96 class MapleStream;
97 class MaximaStream;
98 class MathematicaStream;
99 class MathStream;
100 class WriteStream;
101
102 class MathData;
103 class InsetMathMacroTemplate;
104 class InsetMathMacro;
105 class MathRow;
106 class TextPainter;
107 class TextMetricsInfo;
108 class ReplaceData;
109
110 /// Type of unique identifiers for math insets (used in TexRow)
111 typedef void const * uid_type;
112
113
114 class InsetMath : public Inset {
115 public:
116         ///
117         explicit InsetMath(Buffer * buf = 0) : Inset(buf) {}
118         /// identification as math inset
119         InsetMath * asInsetMath() { return this; }
120         /// identification as math inset
121         InsetMath const * asInsetMath() const { return this; }
122         /// this is overridden in math text insets (i.e. mbox)
123         bool inMathed() const { return true; }
124         ///
125         virtual docstring name() const;
126
127         /// this is overridden by specific insets
128         virtual mode_type currentMode() const { return MATH_MODE; }
129
130         // The possible marker types for math insets
131         enum marker_type { NO_MARKER, MARKER2, MARKER, BOX_MARKER };
132         /// this is overridden by insets with specific edit marker type
133         virtual marker_type marker(BufferView const *) const;
134
135         /// the ascent of the inset above the baseline
136         /// compute the size of the object for text based drawing
137         virtual void metricsT(TextMetricsInfo const & mi, Dimension & dim) const;
138         /// draw the object as text
139         virtual void drawT(TextPainter &, int x, int y) const;
140
141         /// return cell given its number
142         virtual MathData & cell(idx_type);
143         /// return cell given its number
144         virtual MathData const & cell(idx_type) const;
145
146         /// identifies certain types of insets
147         virtual InsetMathAMSArray       * asAMSArrayInset()       { return nullptr; }
148         virtual InsetMathAMSArray const * asAMSArrayInset() const { return nullptr; }
149         virtual InsetMathArray          * asArrayInset()          { return nullptr; }
150         virtual InsetMathArray const    * asArrayInset() const    { return nullptr; }
151         virtual InsetMathBrace          * asBraceInset()          { return nullptr; }
152         virtual InsetMathBrace const    * asBraceInset() const    { return nullptr; }
153         virtual InsetMathChar const     * asCharInset() const     { return nullptr; }
154         virtual InsetMathClass const    * asClassInset() const    { return nullptr; }
155         virtual InsetMathDelim          * asDelimInset()          { return nullptr; }
156         virtual InsetMathDelim const    * asDelimInset() const    { return nullptr; }
157         virtual InsetMathFracBase       * asFracBaseInset()       { return nullptr; }
158         virtual InsetMathFracBase const * asFracBaseInset() const { return nullptr; }
159         virtual InsetMathFrac           * asFracInset()           { return nullptr; }
160         virtual InsetMathFrac const     * asFracInset() const     { return nullptr; }
161         virtual InsetMathFont           * asFontInset()           { return nullptr; }
162         virtual InsetMathFont const     * asFontInset() const     { return nullptr; }
163         virtual InsetMathGrid           * asGridInset()           { return nullptr; }
164         virtual InsetMathGrid const     * asGridInset() const     { return nullptr; }
165         virtual InsetMathHull           * asHullInset()           { return nullptr; }
166         virtual InsetMathHull const     * asHullInset() const     { return nullptr; }
167         virtual InsetMathMacro               * asMacro()               { return nullptr; }
168         virtual InsetMathMacro const         * asMacro() const         { return nullptr; }
169         virtual InsetMathMacroTemplate       * asMacroTemplate()       { return nullptr; }
170         virtual InsetMathMacroTemplate const * asMacroTemplate() const { return nullptr; }
171         virtual InsetMathMatrix const   * asMatrixInset() const   { return nullptr; }
172         virtual InsetMathNest           * asNestInset()           { return nullptr; }
173         virtual InsetMathNest const     * asNestInset() const     { return nullptr; }
174         virtual InsetMathScript         * asScriptInset()         { return nullptr; }
175         virtual InsetMathScript const   * asScriptInset() const   { return nullptr; }
176         virtual InsetMathSpace          * asSpaceInset()          { return nullptr; }
177         virtual InsetMathSpace const    * asSpaceInset() const    { return nullptr; }
178         virtual InsetMathString         * asStringInset()         { return nullptr; }
179         virtual InsetMathString const   * asStringInset() const   { return nullptr; }
180         virtual InsetMathSubstack       * asSubstackInset()       { return nullptr; }
181         virtual InsetMathSubstack const * asSubstackInset() const { return nullptr; }
182         virtual InsetMathSymbol const   * asSymbolInset() const   { return nullptr; }
183         virtual InsetMathUnknown        * asUnknownInset()        { return nullptr; }
184         virtual InsetMathUnknown const  * asUnknownInset() const  { return nullptr; }
185         virtual InsetMathRef            * asRefInset()            { return nullptr; }
186         virtual InsetMathSpecialChar const * asSpecialCharInset() const { return nullptr; }
187
188         /// The class of the math object (used primarily for spacing)
189         virtual MathClass mathClass() const { return MC_ORD; }
190         /// Add this inset to a math row. Return true if contents got added
191         virtual bool addToMathRow(MathRow &, MetricsInfo & mi) const;
192         /// Hook that is run before metrics computation starts
193         virtual void beforeMetrics() const {}
194         /// Hook that is run after metrics computation
195         virtual void afterMetrics() const {}
196         /// Hook that is run before actual drawing
197         virtual void beforeDraw(PainterInfo const &) const {}
198         /// Hook that is run after drawing
199         virtual void afterDraw(PainterInfo const &) const {}
200
201         /// will this get written as a single block in {..}
202         virtual bool extraBraces() const { return false; }
203
204         /// return the content as char if the inset is able to do so
205         virtual char_type getChar() const { return 0; }
206
207         /// Whether the inset allows \(no)limits
208         bool allowsLimitsChange() const { return mathClass() == MC_OP; }
209         /// The default limits value
210         virtual Limits defaultLimits() const { return NO_LIMITS; }
211         /// whether the inset has limit-like sub/superscript
212         virtual Limits limits() const { return AUTO_LIMITS; }
213         /// sets types of sub/superscripts
214         virtual void limits(Limits) {}
215         /// write limits status for LaTeX and LyX code
216         void writeLimits(WriteStream & os) const;
217
218         /// replace things by other things
219         virtual void replace(ReplaceData &) {}
220         /// do we contain a given subsequence?
221         virtual bool contains(MathData const &) const { return false; }
222         /// access to the lock (only nest array have one)
223         virtual bool lock() const { return false; }
224         /// access to the lock (only nest array have one)
225         virtual void lock(bool) {}
226
227         // Indicate that we do not want to hide the normal version of
228         // write(). This is to shut off a clang warning.
229         using Inset::write;
230         /// write LaTeX and LyX code
231         virtual void write(WriteStream & os) const;
232         /// write normalized content
233         virtual void normalize(NormalStream &) const;
234         /// write content as something readable by Maple
235         virtual void maple(MapleStream &) const;
236         /// write content as something readable by Maxima
237         virtual void maxima(MaximaStream &) const;
238         /// write content as something readable by Mathematica
239         virtual void mathematica(MathematicaStream &) const;
240         /// write content as MathML
241         virtual void mathmlize(MathStream &) const;
242         /// write content as HTML, best we can.
243         /// the idea for this, and some of the details, come from
244         /// eLyXer, written by Alex Fernandez. no code is borrowed. rather,
245         /// we try to mimic how eLyXer outputs some math.
246         virtual void htmlize(HtmlStream &) const;
247         /// write content as something readable by Octave
248         virtual void octave(OctaveStream &) const;
249
250         /// plain text output in ucs4 encoding
251         int plaintext(odocstringstream &, OutputParams const &, size_t) const;
252
253         /// dump content to stderr for debugging
254         virtual void dump() const;
255
256         /// LyXInset stuff
257         virtual bool numberedType() const { return false; }
258         /// hull type
259         virtual HullType getType() const;
260         /// change type
261         virtual void mutate(HullType /*newtype*/) {}
262
263         /// math stuff usually isn't allowed in text mode
264         virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
265
266         /// Italic correction as described in InsetMathScript.h
267         virtual int kerning(BufferView const *) const { return 0; }
268         ///
269         bool isInToc() const { return true; }
270         ///
271         InsetCode lyxCode() const { return MATH_CODE; }
272         ///
273         uid_type id() const { return this; }
274 };
275
276 ///
277 std::ostream & operator<<(std::ostream &, MathAtom const &);
278 ///
279 odocstream & operator<<(odocstream &, MathAtom const &);
280
281 // initialize math
282 void initMath();
283
284
285 } // namespace lyx
286
287 #endif