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_INSET_MODIFY: {
77 istringstream is(to_utf8(cmd.argument()));
83 if (s == "add-vline-left" || s == "add-vline-right") {
85 from_utf8(N_("Can't add vertical grid lines in '%1$s'")), name_));
86 flag.setEnabled(false);
94 return InsetMathGrid::getStatus(cur, cmd, flag);
98 void InsetMathSplit::write(WriteStream & ws) const
100 MathEnsurer ensurer(ws);
104 if (!numbered_ && name_ == "align")
105 suffix = from_ascii("*");
106 ws << "\\begin{" << name_ << suffix << '}';
107 if (name_ != "split" && name_ != "align" && verticalAlignment() != 'c')
108 ws << '[' << verticalAlignment() << ']';
109 if (name_ == "alignedat")
110 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
111 InsetMathGrid::write(ws);
114 ws << "\\end{" << name_ << suffix << "}\n";
118 void InsetMathSplit::infoize(odocstream & os) const
120 docstring name = name_;
121 name[0] = support::uppercase(name[0]);
122 if (name_ == "align" && !numbered_)
129 void InsetMathSplit::mathmlize(MathStream & ms) const
131 // split, gathered, aligned, alignedat
132 // At the moment, those seem to display just fine without any
133 // special treatment.
135 // lgathered and rgathered could use the proper alignment, but
136 // it's not clear how to do that without copying a lot of code.
137 // One idea would be to wrap the table in an <mrow>, and set the
138 // alignment there via CSS.
139 // FIXME how to handle numbered and unnumbered align?
140 InsetMathGrid::mathmlize(ms);
144 void InsetMathSplit::htmlize(HtmlStream & ms) const
146 // split, gathered, aligned, alignedat
147 // At the moment, those seem to display just fine without any
148 // special treatment.
150 // lgathered and rgathered could use the proper alignment.
151 // FIXME how to handle numbered and unnumbered align?
152 InsetMathGrid::htmlize(ms);
156 void InsetMathSplit::validate(LaTeXFeatures & features) const
158 if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
159 name_ == "alignedat" || name_ == "align")
160 features.require("amsmath");
161 else if (name_ == "lgathered" || name_ == "rgathered")
162 features.require("mathtools");
163 InsetMathGrid::validate(features);