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