2 * \file InsetMathSplit.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 "InsetMathSplit.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
19 #include "FuncRequest.h"
20 #include "FuncStatus.h"
21 #include "support/gettext.h"
22 #include "LaTeXFeatures.h"
24 #include "support/lstrings.h"
32 using support::bformat;
35 // FIXME: handle numbers in gui, currently they are only read and written
37 InsetMathSplit::InsetMathSplit(Buffer * buf, docstring const & name,
38 char valign, bool numbered)
39 : InsetMathGrid(buf, 1, 1, valign, docstring()), name_(name),
45 Inset * InsetMathSplit::clone() const
47 return new InsetMathSplit(*this);
51 char InsetMathSplit::defaultColAlign(col_type col)
53 if (name_ == "gathered")
55 if (name_ == "lgathered")
57 if (name_ == "rgathered")
62 || name_ == "alignedat")
63 return colAlign(hullAlign, col);
68 char InsetMathSplit::displayColAlign(idx_type idx) const
70 if (name_ == "gathered")
72 if (name_ == "lgathered")
74 if (name_ == "rgathered")
79 || name_ == "alignedat")
80 return colAlign(hullAlign, col(idx));
81 return InsetMathGrid::displayColAlign(idx);
85 int InsetMathSplit::displayColSpace(col_type col) const
87 if (name_ == "split" || name_ == "aligned" || name_ == "align")
88 return colSpace(hullAlign, col);
89 if (name_ == "alignedat")
90 return colSpace(hullAlignAt, col);
96 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
98 InsetMathGrid::draw(pi, x, y);
99 setPosCache(pi, x, y);
103 bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
104 FuncStatus & flag) const
106 switch (cmd.action()) {
107 case LFUN_TABULAR_FEATURE: {
108 string s = cmd.getArg(0);
109 if (s == "add-vline-left" || s == "add-vline-right") {
110 flag.message(bformat(
111 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
113 flag.setEnabled(false);
116 if (s == "align-left" || s == "align-center" || s == "align-right") {
117 flag.setEnabled(false);
125 return InsetMathGrid::getStatus(cur, cmd, flag);
129 void InsetMathSplit::write(WriteStream & ws) const
131 MathEnsurer ensurer(ws);
135 if (!numbered_ && name_ == "align")
136 suffix = from_ascii("*");
137 ws << "\\begin{" << name_ << suffix << '}';
138 bool open = ws.startOuterRow();
139 bool const hasArg(name_ == "alignedat");
140 if (name_ != "split" && name_ != "align") {
141 if (verticalAlignment() != 'c')
142 ws << '[' << verticalAlignment() << ']';
144 docstring const first(asString(cell(0)));
145 // prevent misinterpretation of the first character of
146 // the first cell as optional argument (bug 10361)
147 if (!first.empty() && first[0] == '[')
152 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
153 InsetMathGrid::write(ws);
156 ws << "\\end{" << name_ << suffix << "}\n";
162 void InsetMathSplit::infoize(odocstream & os) const
164 docstring name = name_;
165 name[0] = support::uppercase(name[0]);
166 if (name_ == "align" && !numbered_)
173 void InsetMathSplit::mathmlize(MathStream & ms) const
175 // split, gathered, aligned, alignedat
176 // At the moment, those seem to display just fine without any
177 // special treatment.
179 // lgathered and rgathered could use the proper alignment, but
180 // it's not clear how to do that without copying a lot of code.
181 // One idea would be to wrap the table in an <mrow>, and set the
182 // alignment there via CSS.
183 // FIXME how to handle numbered and unnumbered align?
184 InsetMathGrid::mathmlize(ms);
188 void InsetMathSplit::htmlize(HtmlStream & ms) const
190 // split, gathered, aligned, alignedat
191 // At the moment, those seem to display just fine without any
192 // special treatment.
194 // lgathered and rgathered could use the proper alignment.
195 // FIXME how to handle numbered and unnumbered align?
196 InsetMathGrid::htmlize(ms);
200 void InsetMathSplit::validate(LaTeXFeatures & features) const
202 if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
203 name_ == "alignedat" || name_ == "align")
204 features.require("amsmath");
205 else if (name_ == "lgathered" || name_ == "rgathered")
206 features.require("mathtools");
207 InsetMathGrid::validate(features);