]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSubstack.cpp
Account for old versions of Pygments
[lyx.git] / src / mathed / InsetMathSubstack.cpp
1 /**
2  * \file InsetMathSubstack.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathSubstack.h"
14
15 #include "MathData.h"
16 #include "MathStream.h"
17
18 #include "FuncRequest.h"
19 #include "FuncStatus.h"
20 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
22
23 #include "support/gettext.h"
24 #include "support/lstrings.h"
25
26 #include <ostream>
27
28 using namespace std;
29
30 namespace lyx {
31
32 using support::bformat;
33
34
35 InsetMathSubstack::InsetMathSubstack(Buffer * buf)
36         : InsetMathGrid(buf, 1, 1)
37 {}
38
39
40 Inset * InsetMathSubstack::clone() const
41 {
42         return new InsetMathSubstack(*this);
43 }
44
45
46 void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
47 {
48         Changer dummy2 = mi.base.changeEnsureMath();
49         Changer dummy = mi.base.changeArray();
50         InsetMathGrid::metrics(mi, dim);
51 }
52
53
54 void InsetMathSubstack::draw(PainterInfo & pi, int x, int y) const
55 {
56         Changer dummy2 = pi.base.changeEnsureMath();
57         Changer dummy = pi.base.changeArray();
58         InsetMathGrid::draw(pi, x + 1, y);
59 }
60
61
62 bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd,
63                 FuncStatus & flag) const
64 {
65         switch (cmd.action()) {
66         case LFUN_TABULAR_FEATURE: {
67                 string s = cmd.getArg(0);
68                 if (s == "add-vline-left" || s == "add-vline-right") {
69                         flag.message(bformat(
70                                 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
71                                 from_utf8("substack")));
72                         flag.setEnabled(false);
73                         return true;
74                 }
75                 // in contrary to \subarray, the columns in \substack
76                 // are always centered and this cannot be changed
77                 if (s == "align-left" || s == "align-right") {
78                         flag.message(bformat(
79                                 from_utf8(N_("Can't change horizontal alignment in '%1$s'")),
80                                 from_utf8("substack")));
81                         flag.setEnabled(false);
82                         return true;
83                 }
84                 break;
85         }
86
87         default:
88                 break;
89         }
90         return InsetMathGrid::getStatus(cur, cmd, flag);
91 }
92
93
94 void InsetMathSubstack::infoize(odocstream & os) const
95 {
96         os << "Substack ";
97 }
98
99
100 void InsetMathSubstack::write(WriteStream & os) const
101 {
102         MathEnsurer ensurer(os);
103         os << "\\substack{";
104         bool open = os.startOuterRow();
105         InsetMathGrid::write(os);
106         os << "}\n";
107         if (open)
108                 os.startOuterRow();
109 }
110
111
112 void InsetMathSubstack::normalize(NormalStream & os) const
113 {
114         os << "[substack ";
115         InsetMathGrid::normalize(os);
116         os << ']';
117 }
118
119
120 void InsetMathSubstack::maple(MapleStream & os) const
121 {
122         os << "substack(";
123         InsetMathGrid::maple(os);
124         os << ')';
125 }
126
127
128 void InsetMathSubstack::mathmlize(MathStream & os) const
129 {
130         int movers = 0;
131         row_type const numrows = nrows();
132         for (row_type row = 0; row < nrows(); ++row) {
133                 if (row < numrows - 1) {
134                         movers ++;
135                         os << MTag("munder");
136                 }
137                 os << MTag("mrow") << cell(index(row, 0)) << ETag("mrow");
138         }
139         for (int i = 1; i <= movers; ++i)
140                 os << ETag("munder");
141 }
142
143
144 void InsetMathSubstack::htmlize(HtmlStream & os) const
145 {
146         os << MTag("span", "class='substack'");
147         for (row_type row = 0; row < nrows(); ++row)
148                 os << MTag("span") << cell(index(row, 0)) << ETag("span");
149         os << ETag("span");
150 }
151
152
153 void InsetMathSubstack::validate(LaTeXFeatures & features) const
154 {
155         if (features.runparams().isLaTeX())
156                 features.require("amsmath");
157         else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
158                 features.addCSSSnippet(
159                         "span.substack{display: inline-block; vertical-align: middle; text-align:center; font-size: 75%;}\n"
160                         "span.substack span{display: block;}");
161
162         InsetMathGrid::validate(features);
163 }
164
165
166 } // namespace lyx