]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.h
Preserve \inputencoding value when switching to non-TeX fonts.
[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
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
46 the math objects.
47
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.
53
54 */
55
56 class Cursor;
57 class OutputParams;
58 class MetricsInfo;
59
60 class InsetMathArray;
61 class InsetMathAMSArray;
62 class InsetMathBrace;
63 class InsetMathChar;
64 class InsetMathDelim;
65 class InsetMathFracBase;
66 class InsetMathFrac;
67 class InsetMathFont;
68 class InsetMathGrid;
69 class InsetMathHull;
70 class InsetMathMatrix;
71 class InsetMathNest;
72 class InsetMathScript;
73 class InsetMathString;
74 class InsetMathSpace;
75 class InsetMathSpecialChar;
76 class InsetMathSymbol;
77 class InsetMathSubstack;
78 class InsetMathUnknown;
79 class InsetMathRef;
80
81 class HtmlStream;
82 class NormalStream;
83 class OctaveStream;
84 class MapleStream;
85 class MaximaStream;
86 class MathematicaStream;
87 class MathStream;
88 class WriteStream;
89
90 class MathData;
91 class InsetMathMacroTemplate;
92 class InsetMathMacro;
93 class MathRow;
94 class TextPainter;
95 class TextMetricsInfo;
96 class ReplaceData;
97
98 /// Type of unique identifiers for math insets (used in TexRow)
99 typedef void const * uid_type;
100
101
102 class InsetMath : public Inset {
103 public:
104         ///
105         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; }
112         ///
113         virtual docstring name() const;
114
115         /// this is overridden by specific insets
116         virtual mode_type currentMode() const { return MATH_MODE; }
117
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;
122
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;
128
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;
133
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; }
174
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 {}
187
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; }
192
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; }
197
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) {}
206
207         // Indicate that we do not want to hide the normal version of
208         // write(). This is to shut off a clang warning.
209         using Inset::write;
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;
229
230         /// plain text output in ucs4 encoding
231         int plaintext(odocstringstream &, OutputParams const &, size_t) const;
232
233         /// dump content to stderr for debugging
234         virtual void dump() const;
235
236         /// LyXInset stuff
237         virtual bool numberedType() const { return false; }
238         /// hull type
239         virtual HullType getType() const;
240         /// change type
241         virtual void mutate(HullType /*newtype*/) {}
242
243         /// math stuff usually isn't allowed in text mode
244         virtual bool allowedIn(mode_type mode) const { return mode == MATH_MODE; }
245
246         /// Italic correction as described in InsetMathScript.h
247         virtual int kerning(BufferView const *) const { return 0; }
248         ///
249         bool isInToc() const { return true; }
250         ///
251         InsetCode lyxCode() const { return MATH_CODE; }
252         ///
253         uid_type id() const { return this; }
254 };
255
256 ///
257 std::ostream & operator<<(std::ostream &, MathAtom const &);
258 ///
259 odocstream & operator<<(odocstream &, MathAtom const &);
260
261 // initialize math
262 void initMath();
263
264
265 } // namespace lyx
266
267 #endif