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"
21 // An inset for super- and subscripts or both. The 'nucleus' is always
22 // cell 0. If there is just one script, it's cell 1 and cell_1_is_up_
23 // is set accordingly. If both are used, cell 1 is up and cell 2 is down.
25 class InsetMathScript : public InsetMathNest {
27 /// create inset without scripts
28 explicit InsetMathScript(Buffer * buf);
29 /// create inset with single script
30 explicit InsetMathScript(Buffer * buf, bool up);
31 /// create inset with single script and given nucleus
32 InsetMathScript(Buffer * buf, MathAtom const & at, bool up);
34 mode_type currentMode() const override { return MATH_MODE; }
35 /// whether the inset has limit-like sub/superscript
36 Limits limits() const override;
37 /// sets types of sub/superscripts
38 void limits(Limits lim) override;
40 MathClass mathClass() const override;
42 void metrics(MetricsInfo & mi, Dimension & dim) const override;
44 void draw(PainterInfo & pi, int x, int y) const override;
46 void metricsT(TextMetricsInfo const & mi, Dimension & dim) const override;
48 void drawT(TextPainter & pi, int x, int y) const override;
50 /// move cursor backwards
51 bool idxBackward(Cursor & cur) const override;
52 /// move cursor forward
53 bool idxForward(Cursor & cur) const override;
54 /// move cursor up or down
55 bool idxUpDown(Cursor & cur, bool up) const override;
56 /// The index of the cell entered while moving backward
57 size_type lastIdx() const override { return 0; }
59 /// write LaTeX and Lyx code
60 void write(TeXMathStream & os) const override;
61 /// write normalized content
62 void normalize(NormalStream &) const override;
63 /// write content as something readable by Maple
64 void maple(MapleStream &) const override;
65 /// write content as something readable by Mathematica
66 void mathematica(MathematicaStream &) const override;
67 /// write content as MathML
68 void mathmlize(MathMLStream &) const override;
69 /// write content as HTML
70 void htmlize(HtmlStream &) const override;
71 /// write content as something readable by Octave
72 void octave(OctaveStream &) const override;
74 /// identifies scriptinsets
75 InsetMathScript const * asScriptInset() const override;
77 InsetMathScript * asScriptInset() override;
79 /// returns subscript. Always run 'hasDown' or 'has(false)' before!
80 MathData const & down() const;
81 /// returns subscript. Always run 'hasDown' or 'has(false)' before!
83 /// returns superscript. Always run 'hasUp' or 'has(true)' before!
84 MathData const & up() const;
85 /// returns superscript. Always run 'hasUp' or 'has(true)' before!
88 MathData const & nuc() const;
91 /// do we have a superscript?
93 /// do we have a subscript?
95 /// do we have a script?
96 bool has(bool up) const;
97 /// what idx has super/subscript?
98 idx_type idxOfScript(bool up) const;
100 void removeScript(bool up);
101 /// make sure a script is accessible
102 void ensure(bool up);
103 /// say that we have scripts
104 void infoize(odocstream & os) const override;
105 /// say whether we have displayed limits
106 void infoize2(odocstream & os) const override;
108 InsetCode lyxCode() const override { return MATH_SCRIPT_CODE; }
110 void validate(LaTeXFeatures &features) const override;
112 Inset * clone() const override;
113 /// returns x offset for main part
114 int dxx(BufferView const & bv) const;
115 /// returns width of nucleus if any
116 int nwid(BufferView const &) const;
117 /// returns y offset for either superscript or subscript
118 int dy01(BufferView const &, int asc, int des, int what) const;
119 /// returns y offset for superscript
120 int dy0(BufferView const &) const;
121 /// returns y offset for subscript
122 int dy1(BufferView const &) const;
123 /// returns x offset for superscript
124 int dx0(BufferView const & bv) const;
125 /// returns x offset for subscript
126 int dx1(BufferView const & bv) const;
127 /// returns ascent of nucleus if any
128 int nasc(BufferView const &) const;
129 /// returns descent of nucleus if any
130 int ndes(BufferView const &) const;
131 /// Italic correction: amount of displacement between subscript and
132 /// superscript in math mode as per Appendix G, rule 18f. A positive value
133 /// shifts the superscript to the right, and a negative value shifts the
134 /// subscript to the left.
135 int nker(BufferView const * bv) const;
136 /// do we we have to draw the scripts above/below nucleus?
137 bool hasLimits(FontInfo const &) const;
138 /// clean up empty cells and return true if a cell has been deleted.
139 bool notifyCursorLeaves(Cursor const & old, Cursor & cur) override;
141 /// possible subscript (index 0) and superscript (index 1)
143 /// remember whether we are in display mode (used by mathml output)
144 mutable bool has_limits_ = false;