2 * \file InsetMathRoot.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS.
14 #include "InsetMathRoot.h"
17 #include "MathStream.h"
20 #include "LaTeXFeatures.h"
21 #include "MetricsInfo.h"
23 #include "frontends/Painter.h"
31 InsetMathRoot::InsetMathRoot(Buffer * buf)
32 : InsetMathNest(buf, 2)
36 Inset * InsetMathRoot::clone() const
38 return new InsetMathRoot(*this);
42 void InsetMathRoot::metrics(MetricsInfo & mi, Dimension & dim) const
44 InsetMathNest::metrics(mi);
45 Dimension const & dim0 = cell(0).dimension(*mi.base.bv);
46 Dimension const & dim1 = cell(1).dimension(*mi.base.bv);
47 dim.asc = max(dim0.ascent() + 5, dim1.ascent()) + 2;
48 dim.des = max(dim0.descent() - 5, dim1.descent()) + 2;
49 dim.wid = dim0.width() + dim1.width() + 10;
54 void InsetMathRoot::draw(PainterInfo & pi, int x, int y) const
56 Dimension const & dim0 = cell(0).dimension(*pi.base.bv);
57 int const w = dim0.width();
59 cell(0).draw(pi, x, y - 5 - dim0.descent());
61 cell(1).draw(pi, x + w + 8, y);
62 Dimension const dim = dimension(*pi.base.bv);
63 int const a = dim.ascent();
64 int const d = dim.descent();
67 pi.pain.line(x + dim.width(), y - a + 1,
68 x + w + 4, y - a + 1, pi.base.font.color());
69 xp[0] = x + w + 4; yp[0] = y - a + 1;
70 xp[1] = x + w; yp[1] = y + d;
71 xp[2] = x + w - 2; yp[2] = y + (d - a)/2 + 2;
72 xp[3] = x + w - 5; yp[3] = y + (d - a)/2 + 4;
73 pi.pain.lines(xp, yp, 4, pi.base.font.color());
74 drawMarkers(pi, x, y);
78 void InsetMathRoot::write(WriteStream & os) const
80 MathEnsurer ensurer(os);
81 os << "\\sqrt[" << cell(0) << "]{" << cell(1) << '}';
85 void InsetMathRoot::normalize(NormalStream & os) const
87 os << "[root " << cell(0) << ' ' << cell(1) << ']';
91 bool InsetMathRoot::idxUpDown(Cursor & cur, bool up) const
93 Cursor::idx_type const target = up ? 0 : 1;
94 if (cur.idx() == target)
97 cur.pos() = up ? cur.lastpos() : 0;
102 void InsetMathRoot::maple(MapleStream & os) const
104 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
108 void InsetMathRoot::mathematica(MathematicaStream & os) const
110 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
114 void InsetMathRoot::octave(OctaveStream & os) const
116 os << '(' << cell(1) << ")^(1/(" << cell(0) <<"))";
120 void InsetMathRoot::mathmlize(MathStream & os) const
122 os << MTag("mroot") << cell(1) << cell(0) << ETag("mroot");
126 void InsetMathRoot::htmlize(HtmlStream & os) const
128 os << MTag("span", "class='root'")
129 << MTag("sup") << cell(0) << ETag("sup")
130 << from_ascii("√")
131 << MTag("span", "class='rootof'") << cell(1) << ETag("span")
136 void InsetMathRoot::validate(LaTeXFeatures & features) const
138 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
139 features.addCSSSnippet(
140 "span.rootof{border-top: thin solid black;}\n"
141 "span.root sup{font-size: 75%;}");
142 InsetMathNest::validate(features);