2 * \file InsetMathSubstack.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathSubstack.h"
16 #include "MathStream.h"
18 #include "FuncRequest.h"
19 #include "FuncStatus.h"
20 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
23 #include "support/gettext.h"
24 #include "support/lstrings.h"
32 using support::bformat;
35 InsetMathSubstack::InsetMathSubstack(Buffer * buf)
36 : InsetMathGrid(buf, 1, 1)
40 Inset * InsetMathSubstack::clone() const
42 return new InsetMathSubstack(*this);
46 void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
48 Changer dummy = mi.base.changeStyle(LM_ST_TEXT, mi.base.style == LM_ST_DISPLAY);
49 InsetMathGrid::metrics(mi, dim);
53 void InsetMathSubstack::draw(PainterInfo & pi, int x, int y) const
55 Changer dummy = pi.base.changeStyle(LM_ST_TEXT, pi.base.style == LM_ST_DISPLAY);
56 InsetMathGrid::draw(pi, x + 1, y);
60 bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd,
61 FuncStatus & flag) const
63 switch (cmd.action()) {
64 case LFUN_TABULAR_FEATURE: {
65 string s = cmd.getArg(0);
66 if (s == "add-vline-left" || s == "add-vline-right") {
68 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
69 from_utf8("substack")));
70 flag.setEnabled(false);
73 // in contrary to \subarray, the columns in \substack
74 // are always centered and this cannot be changed
75 if (s == "align-left" || s == "align-right") {
77 from_utf8(N_("Can't change horizontal alignment in '%1$s'")),
78 from_utf8("substack")));
79 flag.setEnabled(false);
88 return InsetMathGrid::getStatus(cur, cmd, flag);
92 void InsetMathSubstack::infoize(odocstream & os) const
98 void InsetMathSubstack::write(WriteStream & os) const
100 MathEnsurer ensurer(os);
102 bool open = os.startOuterRow();
103 InsetMathGrid::write(os);
110 void InsetMathSubstack::normalize(NormalStream & os) const
113 InsetMathGrid::normalize(os);
118 void InsetMathSubstack::maple(MapleStream & os) const
121 InsetMathGrid::maple(os);
126 void InsetMathSubstack::mathmlize(MathStream & os) const
129 row_type const numrows = nrows();
130 for (row_type row = 0; row < nrows(); ++row) {
131 if (row < numrows - 1) {
133 os << MTag("munder");
135 os << MTag("mrow") << cell(index(row, 0)) << ETag("mrow");
137 for (int i = 1; i <= movers; ++i)
138 os << ETag("munder");
142 void InsetMathSubstack::htmlize(HtmlStream & os) const
144 os << MTag("span", "class='substack'");
145 for (row_type row = 0; row < nrows(); ++row)
146 os << MTag("span") << cell(index(row, 0)) << ETag("span");
151 void InsetMathSubstack::validate(LaTeXFeatures & features) const
153 if (features.runparams().isLaTeX())
154 features.require("amsmath");
155 else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
156 features.addCSSSnippet(
157 "span.substack{display: inline-block; vertical-align: middle; text-align:center; font-size: 75%;}\n"
158 "span.substack span{display: block;}");
160 InsetMathGrid::validate(features);