3 * \file InsetMathScript.h
4 * This file is part of LyX, the document processor.
5 * Licence details can be found in the file COPYING.
9 * Full author contact details are available in file CREDITS.
12 #ifndef MATH_SCRIPTINSET_H
13 #define MATH_SCRIPTINSET_H
15 #include "InsetMathNest.h"
16 #include "FontEnums.h"
22 // An inset for super- and subscripts or both. The 'nucleus' is always
23 // cell 0. If there is just one script, it's cell 1 and cell_1_is_up_
24 // is set accordingly. If both are used, cell 1 is up and cell 2 is down.
26 class InsetMathScript : public InsetMathNest {
28 /// create inset without scripts
29 explicit InsetMathScript(Buffer * buf);
30 /// create inset with single script
31 explicit InsetMathScript(Buffer * buf, bool up);
32 /// create inset with single script and given nucleus
33 InsetMathScript(Buffer * buf, MathAtom const & at, bool up);
35 mode_type currentMode() const override { return MATH_MODE; }
36 /// whether the inset has limit-like sub/superscript
37 Limits limits() const override;
38 /// sets types of sub/superscripts
39 void limits(Limits lim) override;
41 MathClass mathClass() const override;
43 void metrics(MetricsInfo & mi, Dimension & dim) const override;
45 void draw(PainterInfo & pi, int x, int y) const override;
47 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const override;
49 void drawT(TextPainter & pi, int x, int y) const override;
51 /// move cursor backwards
52 bool idxBackward(Cursor & cur) const override;
53 /// move cursor forward
54 bool idxForward(Cursor & cur) const override;
55 /// move cursor up or down
56 bool idxUpDown(Cursor & cur, bool up) const override;
57 /// The index of the cell entered while moving backward
58 size_type lastIdx() const override { return 0; }
60 /// write LaTeX and Lyx code
61 void write(TeXMathStream & os) const override;
62 /// write normalized content
63 void normalize(NormalStream &) const override;
64 /// write content as something readable by Maple
65 void maple(MapleStream &) const override;
66 /// write content as something readable by Mathematica
67 void mathematica(MathematicaStream &) const override;
68 /// write content as MathML
69 void mathmlize(MathMLStream &) const override;
70 /// write content as HTML
71 void htmlize(HtmlStream &) const override;
72 /// write content as something readable by Octave
73 void octave(OctaveStream &) const override;
75 /// identifies scriptinsets
76 InsetMathScript const * asScriptInset() const override;
78 InsetMathScript * asScriptInset() override;
80 /// returns subscript. Always run 'hasDown' or 'has(false)' before!
81 MathData const & down() const;
82 /// returns subscript. Always run 'hasDown' or 'has(false)' before!
84 /// returns superscript. Always run 'hasUp' or 'has(true)' before!
85 MathData const & up() const;
86 /// returns superscript. Always run 'hasUp' or 'has(true)' before!
89 MathData const & nuc() const;
92 /// do we have a superscript?
94 /// do we have a subscript?
96 /// do we have a script?
97 bool has(bool up) const;
98 /// what idx has super/subscript?
99 idx_type idxOfScript(bool up) const;
101 void removeScript(bool up);
102 /// make sure a script is accessible
103 void ensure(bool up);
104 /// say that we have scripts
105 void infoize(odocstream & os) const override;
106 /// say whether we have displayed limits
107 void infoize2(odocstream & os) const override;
109 InsetCode lyxCode() const override { return MATH_SCRIPT_CODE; }
111 void validate(LaTeXFeatures &features) const override;
113 Inset * clone() const override;
114 /// returns x offset for main part
115 int dxx(BufferView const & bv) const;
116 /// returns width of nucleus if any
117 int nwid(BufferView const &) const;
118 /// returns y offset for either superscript or subscript
119 int dy01(BufferView const &, int asc, int des, int what) const;
120 /// returns y offset for superscript
121 int dy0(BufferView const &) const;
122 /// returns y offset for subscript
123 int dy1(BufferView const &) const;
124 /// returns x offset for superscript
125 int dx0(BufferView const & bv) const;
126 /// returns x offset for subscript
127 int dx1(BufferView const & bv) const;
128 /// returns ascent of nucleus if any
129 int nasc(BufferView const &) const;
130 /// returns descent of nucleus if any
131 int ndes(BufferView const &) const;
132 /// Italic correction: amount of displacement between subscript and
133 /// superscript in math mode as per Appendix G, rule 18f. A positive value
134 /// shifts the superscript to the right, and a negative value shifts the
135 /// subscript to the left.
136 int nker(BufferView const * bv) const;
137 /// do we we have to draw the scripts above/below nucleus?
138 bool hasLimits(FontInfo const &) const;
140 bool hasLimits(MathStyle const &) const;
141 /// clean up empty cells and return true if a cell has been deleted.
142 bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
144 /// possible subscript (index 0) and superscript (index 1)
146 /// remember whether we are in display mode (used by mathml output)
147 mutable bool has_limits_ = false;