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 "MathStream.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)
55 if (name_ == "gathered")
57 if (name_ == "aligned" || name_ == "align")
58 return (col & 1) ? 'l' : 'r';
59 if (name_ == "alignedat")
60 return (col & 1) ? 'l' : 'r';
65 void InsetMathSplit::draw(PainterInfo & pi, int x, int y) const
67 InsetMathGrid::draw(pi, x, y);
68 setPosCache(pi, x, y);
72 bool InsetMathSplit::getStatus(Cursor & cur, FuncRequest const & cmd,
73 FuncStatus & flag) const
75 switch (cmd.action()) {
76 case LFUN_TABULAR_FEATURE: {
77 string s = cmd.getArg(0);
78 if (s == "add-vline-left" || s == "add-vline-right") {
80 from_utf8(N_("Can't add vertical grid lines in '%1$s'")),
82 flag.setEnabled(false);
90 return InsetMathGrid::getStatus(cur, cmd, flag);
94 void InsetMathSplit::write(WriteStream & ws) const
96 MathEnsurer ensurer(ws);
100 if (!numbered_ && name_ == "align")
101 suffix = from_ascii("*");
102 ws << "\\begin{" << name_ << suffix << '}';
103 bool open = ws.startOuterRow();
104 if (name_ != "split" && name_ != "align" && verticalAlignment() != 'c')
105 ws << '[' << verticalAlignment() << ']';
106 if (name_ == "alignedat")
107 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
108 InsetMathGrid::write(ws);
111 ws << "\\end{" << name_ << suffix << "}\n";
117 void InsetMathSplit::infoize(odocstream & os) const
119 docstring name = name_;
120 name[0] = support::uppercase(name[0]);
121 if (name_ == "align" && !numbered_)
128 void InsetMathSplit::mathmlize(MathStream & ms) const
130 // split, gathered, aligned, alignedat
131 // At the moment, those seem to display just fine without any
132 // special treatment.
134 // lgathered and rgathered could use the proper alignment, but
135 // it's not clear how to do that without copying a lot of code.
136 // One idea would be to wrap the table in an <mrow>, and set the
137 // alignment there via CSS.
138 // FIXME how to handle numbered and unnumbered align?
139 InsetMathGrid::mathmlize(ms);
143 void InsetMathSplit::htmlize(HtmlStream & ms) const
145 // split, gathered, aligned, alignedat
146 // At the moment, those seem to display just fine without any
147 // special treatment.
149 // lgathered and rgathered could use the proper alignment.
150 // FIXME how to handle numbered and unnumbered align?
151 InsetMathGrid::htmlize(ms);
155 void InsetMathSplit::validate(LaTeXFeatures & features) const
157 if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
158 name_ == "alignedat" || name_ == "align")
159 features.require("amsmath");
160 else if (name_ == "lgathered" || name_ == "rgathered")
161 features.require("mathtools");
162 InsetMathGrid::validate(features);