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 bool open = ws.startOuterRow();
108 if (name_ != "split" && name_ != "align" && verticalAlignment() != 'c')
109 ws << '[' << verticalAlignment() << ']';
110 if (name_ == "alignedat")
111 ws << '{' << static_cast<unsigned int>((ncols() + 1)/2) << '}';
112 InsetMathGrid::write(ws);
115 ws << "\\end{" << name_ << suffix << "}\n";
121 void InsetMathSplit::infoize(odocstream & os) const
123 docstring name = name_;
124 name[0] = support::uppercase(name[0]);
125 if (name_ == "align" && !numbered_)
132 void InsetMathSplit::mathmlize(MathStream & ms) const
134 // split, gathered, aligned, alignedat
135 // At the moment, those seem to display just fine without any
136 // special treatment.
138 // lgathered and rgathered could use the proper alignment, but
139 // it's not clear how to do that without copying a lot of code.
140 // One idea would be to wrap the table in an <mrow>, and set the
141 // alignment there via CSS.
142 // FIXME how to handle numbered and unnumbered align?
143 InsetMathGrid::mathmlize(ms);
147 void InsetMathSplit::htmlize(HtmlStream & ms) const
149 // split, gathered, aligned, alignedat
150 // At the moment, those seem to display just fine without any
151 // special treatment.
153 // lgathered and rgathered could use the proper alignment.
154 // FIXME how to handle numbered and unnumbered align?
155 InsetMathGrid::htmlize(ms);
159 void InsetMathSplit::validate(LaTeXFeatures & features) const
161 if (name_ == "split" || name_ == "gathered" || name_ == "aligned" ||
162 name_ == "alignedat" || name_ == "align")
163 features.require("amsmath");
164 else if (name_ == "lgathered" || name_ == "rgathered")
165 features.require("mathtools");
166 InsetMathGrid::validate(features);