]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathSize.cpp
Allow toggling (no)limits only after mathop symbol
[lyx.git] / src / mathed / InsetMathSize.cpp
1 /**
2  * \file InsetMathSize.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathSize.h"
14
15 #include "LaTeXFeatures.h"
16 #include "MathData.h"
17 #include "MathParser.h"
18 #include "MathStream.h"
19 #include "output_xhtml.h"
20
21 #include "support/convert.h"
22 #include "support/gettext.h"
23 #include "support/lstrings.h"
24
25 #include <string>
26 #include <ostream>
27
28 using namespace lyx::support;
29 using namespace std;
30
31 namespace lyx {
32
33 InsetMathSize::InsetMathSize(Buffer * buf, latexkeys const * l)
34         : InsetMathNest(buf, 1), key_(l),
35           style_(MathStyle(convert<int>(l->extra)))
36 {}
37
38
39 Inset * InsetMathSize::clone() const
40 {
41         return new InsetMathSize(*this);
42 }
43
44
45 void InsetMathSize::metrics(MetricsInfo & mi, Dimension & dim) const
46 {
47         Changer dummy2 = mi.base.changeEnsureMath();
48         Changer dummy = mi.base.font.changeStyle(style_);
49         cell(0).metrics(mi, dim);
50 }
51
52
53 void InsetMathSize::draw(PainterInfo & pi, int x, int y) const
54 {
55         Changer dummy2 = pi.base.changeEnsureMath();
56         Changer dummy = pi.base.font.changeStyle(style_);
57         cell(0).draw(pi, x, y);
58 }
59
60
61 void InsetMathSize::write(WriteStream & os) const
62 {
63         MathEnsurer ensurer(os);
64         os << "{\\" << key_->name << ' ' << cell(0) << '}';
65 }
66
67
68 // From the MathML documentation:
69 //      MathML uses two attributes, displaystyle and scriptlevel, to control
70 //      orthogonal presentation features that TeX encodes into one "style"
71 //      attribute with values \displaystyle, \textstyle, \scriptstyle, and
72 //      \scriptscriptstyle. The corresponding values of displaystyle and scriptlevel
73 //      for those TeX styles would be "true" and "0", "false" and "0", "false" and "1",
74 //      and "false" and "2", respectively.
75 void InsetMathSize::mathmlize(MathStream & ms) const
76 {
77         string const & name = to_utf8(key_->name);
78         bool dispstyle = (name == "displaystyle");
79         int scriptlevel = 0;
80         if (name == "scriptstyle")
81                 scriptlevel = 1;
82         else if (name == "scriptscriptstyle")
83                 scriptlevel = 2;
84         stringstream attrs;
85         attrs << "displaystyle='" << (dispstyle ? "true" : "false")
86                 << "' scriptlevel='" << scriptlevel << "'";
87         ms << MTag("mstyle", attrs.str()) << cell(0) << ETag("mstyle");
88 }
89
90
91 void InsetMathSize::htmlize(HtmlStream & os) const
92 {
93         string const & name = to_utf8(key_->name);
94         os <<   MTag("span", "class='" + name + "'")
95                         << cell(0) << ETag("span");
96 }
97
98
99 void InsetMathSize::normalize(NormalStream & os) const
100 {
101         os << '[' << key_->name << ' ' << cell(0) << ']';
102 }
103
104
105 void InsetMathSize::infoize(odocstream & os) const
106 {
107         os << bformat(_("Size: %1$s"), key_->name);
108 }
109
110
111 void InsetMathSize::validate(LaTeXFeatures & features) const
112 {
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);
119 }
120
121 } // namespace lyx