2 * \file InsetMathBig.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 "InsetMathBig.h"
15 #include "Dimension.h"
16 #include "LaTeXFeatures.h"
18 #include "MathSupport.h"
19 #include "MathStream.h"
20 #include "MetricsInfo.h"
22 #include "frontends/FontMetrics.h"
24 #include "support/docstream.h"
25 #include "support/lstrings.h"
31 InsetMathBig::InsetMathBig(docstring const & name, docstring const & delim)
32 : name_(name), delim_(delim)
36 docstring InsetMathBig::name() const
42 MathClass InsetMathBig::mathClass() const
44 /* The class of the delimiter depends on the type (l, m, r, nothing).
45 * For example, the definition of \bigl in LaTeX sources is
46 * \def\bigl{\mathopen\big}
48 switch(name_.back()) {
61 Inset * InsetMathBig::clone() const
63 return new InsetMathBig(*this);
67 size_type InsetMathBig::size() const
69 // order: big Big bigg Bigg biggg Biggg
71 char_type const c = name_.back();
72 int const base_size = (c == 'l' || c == 'm' || c == 'r') ? 4 : 3;
73 return name_.front() == 'B' ?
74 2 * (name_.size() - base_size) + 1:
75 2 * (name_.size() - base_size);
79 double InsetMathBig::increase() const
81 // The formula used in amsmath.sty is
82 // 1.2 * (1.0 + size() * 0.5) - 1.0.
83 // We use a smaller step and a bigger offset because our base size
85 return (size() + 1) * 0.3;
89 void InsetMathBig::metrics(MetricsInfo & mi, Dimension & dim) const
91 Changer dummy = mi.base.changeEnsureMath();
92 double const h = theFontMetrics(mi.base.font).ascent('I');
93 double const f = increase();
95 dim.asc = int(h + f * h);
100 docstring InsetMathBig::word() const
102 // mathed_draw_deco does not use the leading backslash, so remove it
103 // (but don't use ltrim if this is the backslash delimiter).
104 // Replace \| by \Vert (equivalent in LaTeX), since mathed_draw_deco
105 // would treat it as |.
107 return from_ascii("Vert");
108 if (delim_ == "\\\\")
109 return from_ascii("\\");
110 return support::ltrim(delim_, "\\");
114 void InsetMathBig::draw(PainterInfo & pi, int x, int y) const
116 Changer dummy = pi.base.changeEnsureMath();
117 Dimension const dim = dimension(*pi.base.bv);
118 mathed_draw_deco(pi, x + 1, y - dim.ascent(), 4, dim.height(),
123 void InsetMathBig::write(TeXMathStream & os) const
125 MathEnsurer ensurer(os);
126 os << '\\' << name_ << delim_;
127 if (delim_[0] == '\\')
128 os.pendingSpace(true);
132 void InsetMathBig::normalize(NormalStream & os) const
134 os << '[' << name_ << ' ' << delim_ << ']';
138 void InsetMathBig::mathmlize(MathMLStream & ms) const
140 ms << MTagInline("mo", "fence='true' stretchy='true' symmetric='true'>")
141 << convertDelimToXMLEscape(delim_, ms.xmlMode())
146 void InsetMathBig::htmlize(HtmlStream & os) const
150 case 0: case 1: name = "big"; break;
151 case 2: case 3: name = "bigg"; break;
152 case 4: case 5: name = "biggg"; break;
153 default: name = "big"; break;
155 os << MTag("span", "class='" + name + "symbol'")
156 << convertDelimToXMLEscape(delim_, false)
161 void InsetMathBig::infoize2(odocstream & os) const
167 bool InsetMathBig::isBigInsetDelim(docstring const & delim)
169 // mathed_draw_deco must handle these
170 static char const * const delimiters[] = {
171 "(", ")", "\\{", "\\}", "\\lbrace", "\\rbrace", "[", "]",
172 "|", "/", "\\slash", "\\|", "\\vert", "\\Vert", "'",
173 "<", ">", "\\\\", "\\backslash",
174 "\\langle", "\\lceil", "\\lfloor",
175 "\\rangle", "\\rceil", "\\rfloor",
176 "\\llbracket", "\\rrbracket",
177 "\\downarrow", "\\Downarrow",
178 "\\uparrow", "\\Uparrow",
179 "\\updownarrow", "\\Updownarrow", ""
181 return support::findToken(delimiters, to_utf8(delim)) >= 0;
185 void InsetMathBig::validate(LaTeXFeatures & features) const
187 validate_math_word(features, word());
188 if (features.runparams().math_flavor == OutputParams::MathAsHTML)
189 features.addCSSSnippet(
190 "span.bigsymbol{font-size: 150%;}\n"
191 "span.biggsymbol{font-size: 200%;}\n"
192 "span.bigggsymbol{font-size: 225%;}");