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
36 cell(1).metrics(mi, dim1);
37 Changer dummy = mi.base.changeFrac();
39 cell(0).metrics(mi, dim0);
40 dim.wid = max(dim0.width(), dim1.width()) + 4;
41 dim.asc = dim1.ascent();
42 dim.des = dim1.descent() + dim0.height() + 4;
47 void InsetMathUnderset::draw(PainterInfo & pi, int x, int y) const
49 Dimension const dim = dimension(*pi.base.bv);
50 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
51 Dimension const & dim1 = cell(1).dimension(*pi.base.bv);
52 int m = x + dim.wid / 2;
53 int yo = y + dim1.descent() + dim0.ascent() + 1;
54 cell(1).draw(pi, m - dim1.width() / 2, y);
55 Changer dummy = pi.base.changeFrac();
56 cell(0).draw(pi, m - dim0.width() / 2, yo);
57 drawMarkers(pi, x, y);
61 bool InsetMathUnderset::idxFirst(Cursor & cur) const
69 bool InsetMathUnderset::idxLast(Cursor & cur) const
72 cur.pos() = cur.lastpos();
77 bool InsetMathUnderset::idxUpDown(Cursor & cur, bool up) const
79 idx_type target = up; // up ? 1 : 0, since upper cell has idx 1
80 if (cur.idx() == target)
83 cur.pos() = cur.cell().x2pos(&cur.bv(), cur.x_target());
88 void InsetMathUnderset::write(WriteStream & os) const
90 MathEnsurer ensurer(os);
93 os << "\\underset{" << cell(0) << "}{" << cell(1) << '}';
97 void InsetMathUnderset::normalize(NormalStream & os) const
99 os << "[underset " << cell(0) << ' ' << cell(1) << ']';
103 void InsetMathUnderset::mathmlize(MathStream & ms) const
105 ms << "<munder accent='false'>" << cell(1) << cell(0) << "</munder>";
109 void InsetMathUnderset::htmlize(HtmlStream & os) const
111 os << MTag("span", "class='underset'")
112 << MTag("span") << cell(0) << ETag("span")
113 << MTag("span", "class='bottom'") << cell(1) << ETag("span")
118 void InsetMathUnderset::validate(LaTeXFeatures & features) const
120 if (features.runparams().isLaTeX())
121 features.require("amsmath");
122 else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
123 features.addCSSSnippet(
124 "span.underset{display: inline-block; vertical-align: top; text-align:center;}\n"
125 "span.underset span {display: block;}\n"
126 "span.bottom{font-size: 66%;}");
128 InsetMathNest::validate(features);