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"
22 #include "support/lassert.h"
28 Inset * InsetMathUnderset::clone() const
30 return new InsetMathUnderset(*this);
34 void InsetMathUnderset::metrics(MetricsInfo & mi, Dimension & dim) const
36 Changer dummy2 = mi.base.changeEnsureMath();
38 cell(0).metrics(mi, dim0);
39 Changer dummy = mi.base.changeScript();
41 cell(1).metrics(mi, dim1);
42 dim.wid = max(dim1.width(), dim0.width()) + 4;
43 dim.asc = dim0.ascent();
44 dim.des = dim0.descent() + dim1.height() + 4;
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 & dim1 = cell(1).dimension(*pi.base.bv);
53 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
54 int m = x + dim.wid / 2;
55 int yo = y + dim0.descent() + dim1.ascent() + 1;
56 cell(0).draw(pi, m - dim0.width() / 2, y);
57 Changer dummy = pi.base.changeScript();
58 cell(1).draw(pi, m - dim1.width() / 2, yo);
62 bool InsetMathUnderset::idxFirst(Cursor & cur) const
64 LASSERT(&cur.inset() == this, return false);
71 bool InsetMathUnderset::idxLast(Cursor & cur) const
73 LASSERT(&cur.inset() == this, return false);
75 cur.pos() = cur.lastpos();
80 void InsetMathUnderset::write(TeXMathStream & os) const
82 MathEnsurer ensurer(os);
85 os << "\\underset{" << cell(1) << "}{" << cell(0) << '}';
89 void InsetMathUnderset::normalize(NormalStream & os) const
91 os << "[underset " << cell(1) << ' ' << cell(0) << ']';
95 void InsetMathUnderset::mathmlize(MathMLStream & ms) const
97 ms << "<" << from_ascii(ms.namespacedTag("munder")) << " accent='false'>"
99 << "</" << from_ascii(ms.namespacedTag("munder")) << ">";
103 void InsetMathUnderset::htmlize(HtmlStream & os) const
105 os << MTag("span", "class='underset'")
106 << MTag("span") << cell(1) << ETag("span")
107 << MTag("span", "class='bottom'") << cell(0) << ETag("span")
112 void InsetMathUnderset::validate(LaTeXFeatures & features) const
114 if (features.runparams().isLaTeX())
115 features.require("amsmath");
116 else if (features.runparams().math_flavor == OutputParams::MathAsHTML)
117 features.addCSSSnippet(
118 "span.underset{display: inline-block; vertical-align: top; text-align:center;}\n"
119 "span.underset span {display: block;}\n"
120 "span.bottom{font-size: 66%;}");
122 InsetMathNest::validate(features);