2 * \file InsetMathSize.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 "InsetMathSize.h"
15 #include "LaTeXFeatures.h"
17 #include "MathParser.h"
18 #include "MathStream.h"
19 #include "output_xhtml.h"
21 #include "support/convert.h"
30 InsetMathSize::InsetMathSize(Buffer * buf, latexkeys const * l)
31 : InsetMathNest(buf, 1), key_(l), style_(Styles(convert<int>(l->extra)))
35 Inset * InsetMathSize::clone() const
37 return new InsetMathSize(*this);
41 void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
43 StyleChanger dummy(mi.base, style_);
44 cell(0).metrics(mi, dim);
49 void InsetMathSize::draw(PainterInfo & pi, int x, int y) const
51 StyleChanger dummy(pi.base, style_);
52 cell(0).draw(pi, x + 1, y);
53 drawMarkers(pi, x, y);
57 void InsetMathSize::write(WriteStream & os) const
59 MathEnsurer ensurer(os);
60 os << "{\\" << key_->name << ' ' << cell(0) << '}';
64 // From the MathML documentation:
65 // MathML uses two attributes, displaystyle and scriptlevel, to control
66 // orthogonal presentation features that TeX encodes into one "style"
67 // attribute with values \displaystyle, \textstyle, \scriptstyle, and
68 // \scriptscriptstyle. The corresponding values of displaystyle and scriptlevel
69 // for those TeX styles would be "true" and "0", "false" and "0", "false" and "1",
70 // and "false" and "2", respectively.
71 void InsetMathSize::mathmlize(MathStream & ms) const
73 string const & name = to_utf8(key_->name);
74 bool dispstyle = (name == "displaystyle");
76 if (name == "scriptstyle")
78 else if (name == "scriptscriptstyle")
81 attrs << "displaystyle='" << (dispstyle ? "true" : "false")
82 << "' scriptlevel='" << scriptlevel << "'";
83 ms << MTag("mstyle", attrs.str()) << ">"
84 << cell(0) << ETag("mstyle");
88 void InsetMathSize::htmlize(HtmlStream & os) const
90 string const & name = to_utf8(key_->name);
91 os << MTag("span", "class='" + name + "'")
92 << cell(0) << ETag("span");
96 void InsetMathSize::normalize(NormalStream & os) const
98 os << '[' << key_->name << ' ' << cell(0) << ']';
102 void InsetMathSize::infoize(odocstream & os) const
104 os << "Size: " << key_->name;
108 void InsetMathSize::validate(LaTeXFeatures & features) const
110 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
111 features.addCSSSnippet(
112 "span.displaystyle, span.textstyle{font-size: normal;}\n"
113 "span.scriptstyle {font-size: small;}\n"
114 "span.scriptscriptstyle {font-size: x-small;}");
115 InsetMathNest::validate(features);