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"
22 #include "support/gettext.h"
23 #include "support/lstrings.h"
28 using namespace lyx::support;
33 InsetMathSize::InsetMathSize(Buffer * buf, latexkeys const * l)
34 : InsetMathNest(buf, 1), key_(l), style_(Styles(convert<int>(l->extra)))
38 Inset * InsetMathSize::clone() const
40 return new InsetMathSize(*this);
44 void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
46 StyleChanger dummy(mi.base, style_);
47 cell(0).metrics(mi, dim);
52 void InsetMathSize::draw(PainterInfo & pi, int x, int y) const
54 StyleChanger dummy(pi.base, style_);
55 cell(0).draw(pi, x + 1, y);
56 drawMarkers(pi, x, y);
60 void InsetMathSize::write(WriteStream & os) const
62 MathEnsurer ensurer(os);
63 os << "{\\" << key_->name << ' ' << cell(0) << '}';
67 // From the MathML documentation:
68 // MathML uses two attributes, displaystyle and scriptlevel, to control
69 // orthogonal presentation features that TeX encodes into one "style"
70 // attribute with values \displaystyle, \textstyle, \scriptstyle, and
71 // \scriptscriptstyle. The corresponding values of displaystyle and scriptlevel
72 // for those TeX styles would be "true" and "0", "false" and "0", "false" and "1",
73 // and "false" and "2", respectively.
74 void InsetMathSize::mathmlize(MathStream & ms) const
76 string const & name = to_utf8(key_->name);
77 bool dispstyle = (name == "displaystyle");
79 if (name == "scriptstyle")
81 else if (name == "scriptscriptstyle")
84 attrs << "displaystyle='" << (dispstyle ? "true" : "false")
85 << "' scriptlevel='" << scriptlevel << "'";
86 ms << MTag("mstyle", attrs.str()) << ">"
87 << cell(0) << ETag("mstyle");
91 void InsetMathSize::htmlize(HtmlStream & os) const
93 string const & name = to_utf8(key_->name);
94 os << MTag("span", "class='" + name + "'")
95 << cell(0) << ETag("span");
99 void InsetMathSize::normalize(NormalStream & os) const
101 os << '[' << key_->name << ' ' << cell(0) << ']';
105 void InsetMathSize::infoize(odocstream & os) const
107 os << bformat(_("Size: %1$s"), key_->name);
111 void InsetMathSize::validate(LaTeXFeatures & features) const
113 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
114 features.addCSSSnippet(
115 "span.displaystyle, span.textstyle{font-size: normal;}\n"
116 "span.scriptstyle {font-size: small;}\n"
117 "span.scriptscriptstyle {font-size: x-small;}");
118 InsetMathNest::validate(features);