2 * \file InsetMathUnderset.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 "InsetMathUnderset.h"
16 #include "MathStream.h"
19 #include "LaTeXFeatures.h"
20 #include "MetricsInfo.h"
27 Inset * InsetMathUnderset::clone() const
29 return new InsetMathUnderset(*this);
33 void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & dim) const
35 Changer dummy2 = mi.base.changeEnsureMath();
37 cell(1).metrics(mi, dim1);
38 Changer dummy = mi.base.changeFrac();
40 cell(0).metrics(mi, dim0);
41 dim.wid = max(dim0.width(), dim1.width()) + 4;
42 dim.asc = dim1.ascent();
43 dim.des = dim1.descent() + dim0.height() + 4;
44 metricsMarkers(mi, dim);
48 void InsetMathUnderset::draw(PainterInfo & pi, int x, int y) const
50 Changer dummy2 = pi.base.changeEnsureMath();
51 Dimension const dim = dimension(*pi.base.bv);
52 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
53 Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
54 int m = x + dim.wid / 2;
55 int yo = y + dim1.descent() + dim0.ascent() + 1;
56 cell(1).draw(pi, m - dim1.width() / 2, y);
57 Changer dummy = pi.base.changeFrac();
58 cell(0).draw(pi, m - dim0.width() / 2, yo);
59 drawMarkers(pi, x, y);
63 bool InsetMathUnderset::idxFirst(Cursor & cur) const
71 bool InsetMathUnderset::idxLast(Cursor & cur) const
74 cur.pos() = cur.lastpos();
79 bool InsetMathUnderset::idxUpDown(Cursor & cur, bool up) const
81 idx_type target = up; // up ? 1 : 0, since upper cell has idx 1
82 if (cur.idx() == target)
85 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target());
90 void InsetMathUnderset::write(WriteStream & os) const
92 MathEnsurer ensurer(os);
95 os << "\\underset{" << cell(0) << "}{" << cell(1) << '}';
99 void InsetMathUnderset::normalize(NormalStream & os) const
101 os << "[underset " << cell(0) << ' ' << cell(1) << ']';
105 void InsetMathUnderset::mathmlize(MathStream & ms) const
107 ms << "<munder accent='false'>" << cell(1) << cell(0) << "</munder>";
111 void InsetMathUnderset::htmlize(HtmlStream & os) const
113 os << MTag("span", "class='underset'")
114 << MTag("span") << cell(0) << ETag("span")
115 << MTag("span", "class='bottom'") << cell(1) << ETag("span")
120 void InsetMathUnderset::validate(LaTeXFeatures & features) const
122 if (features.runparams().isLaTeX())
123 features.require("amsmath");
124 else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
125 features.addCSSSnippet(
126 "span.underset{display: inline-block; vertical-align: top; text-align:center;}\n"
127 "span.underset span {display: block;}\n"
128 "span.bottom{font-size: 66%;}");
130 InsetMathNest::validate(features);