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"
19 #include "FuncRequest.h"
20 #include "FuncStatus.h"
21 #include "LaTeXFeatures.h"
22 #include "MetricsInfo.h"
24 #include "support/gettext.h"
25 #include "support/lstrings.h"
33 using support::bformat;
36 InsetMathSubstack::InsetMathSubstack(Buffer * buf)
37 : InsetMathGrid(buf, 1, 1)
41 Inset * InsetMathSubstack::clone() const
43 return new InsetMathSubstack(*this);
47 void InsetMathSubstack::metrics(MetricsInfo & mi, Dimension & dim) const
49 Changer dummy2 = mi.base.changeEnsureMath();
50 Changer dummy = mi.base.changeArray();
51 InsetMathGrid::metrics(mi, dim);
55 void InsetMathSubstack::draw(PainterInfo & pi, int x, int y) const
57 Changer dummy2 = pi.base.changeEnsureMath();
58 Changer dummy = pi.base.changeArray();
59 InsetMathGrid::draw(pi, x + 1, y);
63 void InsetMathSubstack::doDispatch(Cursor & cur, FuncRequest & cmd)
65 switch (cmd.action()) {
66 case LFUN_TABULAR_FEATURE: {
67 string s = cmd.getArg(0);
68 if (s == "append-column" || s == "delete-column"
69 || s == "add-vline-left" || s == "add-vline-right") {
77 InsetMathGrid::doDispatch(cur, cmd);
81 bool InsetMathSubstack::getStatus(Cursor & cur, FuncRequest const & cmd,
82 FuncStatus & flag) const
84 switch (cmd.action()) {
85 case LFUN_TABULAR_FEATURE: {
86 string s = cmd.getArg(0);
87 if (s == "add-vline-left" || s == "add-vline-right") {
89 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
90 from_utf8("substack")));
91 flag.setEnabled(false);
94 // in contrary to \subarray, the columns in \substack
95 // are always centered and this cannot be changed
96 if (s == "align-left" || s == "align-right") {
98 from_utf8(N_("Can't change horizontal alignment in '%1$s'")),
99 from_utf8("substack")));
100 flag.setEnabled(false);
103 // disallow changing number of columns
104 if (s == "append-column" || s == "delete-column") {
105 flag.setEnabled(false);
106 flag.message(bformat(
107 from_utf8(N_("Changing number of columns not allowed in "
108 "'%1$s'")), from_utf8("substack")));
117 return InsetMathGrid::getStatus(cur, cmd, flag);
121 void InsetMathSubstack::infoize(odocstream & os) const
127 void InsetMathSubstack::write(TeXMathStream & os) const
129 MathEnsurer ensurer(os);
133 bool open = os.startOuterRow();
134 InsetMathGrid::write(os);
141 void InsetMathSubstack::normalize(NormalStream & os) const
144 InsetMathGrid::normalize(os);
149 void InsetMathSubstack::maple(MapleStream & os) const
152 InsetMathGrid::maple(os);
157 void InsetMathSubstack::mathmlize(MathMLStream & ms) const
159 // Output the substack as a standard grid.
160 InsetMathGrid::mathmlize(ms);
164 void InsetMathSubstack::htmlize(HtmlStream & os) const
166 os << MTag("span", "class='substack'");
167 for (row_type row = 0; row < nrows(); ++row)
168 os << MTag("span") << cell(index(row, 0)) << ETag("span");
173 void InsetMathSubstack::validate(LaTeXFeatures & features) const
175 if (features.runparams().isLaTeX())
176 features.require("amsmath");
177 else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
178 features.addCSSSnippet(
179 "span.substack{display: inline-block; vertical-align: middle; text-align:center; font-size: 75%;}\n"
180 "span.substack span{display: block;}");
182 InsetMathGrid::validate(features);