1 /**
2 * \file InsetMathExInt.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 "InsetMathExInt.h"
14
15 #include "LaTeXFeatures.h"
16 #include "MathData.h"
17 #include "MathStream.h"
18 #include "MathStream.h"
19 #include "InsetMathSymbol.h"
20
21 #include "support/debug.h"
22 #include "support/docstring.h"
23
24
25 namespace lyx {
26
InsetMathExInt(Buffer * buf,docstring const & name)27 InsetMathExInt::InsetMathExInt(Buffer * buf, docstring const & name)
28 : InsetMathNest(buf, 4), symbol_(name)
29 {}
30
31 // 0 - core
32 // 1 - diff
33 // 2 - lower
34 // 3 - upper
35
36
clone() const37 Inset * InsetMathExInt::clone() const
38 {
39 return new InsetMathExInt(*this);
40 }
41
42
symbol(docstring const & symbol)43 void InsetMathExInt::symbol(docstring const & symbol)
44 {
45 symbol_ = symbol;
46 }
47
48
hasScripts() const49 bool InsetMathExInt::hasScripts() const
50 {
51 // take empty upper bound as "no scripts"
52 return !cell(3).empty();
53 }
54
55
56
normalize(NormalStream & os) const57 void InsetMathExInt::normalize(NormalStream & os) const
58 {
59 os << '[' << symbol_ << ' ' << cell(0) << ' ' << cell(1) << ' '
60 << cell(2) << ' ' << cell(3) << ']';
61 }
62
63
metrics(MetricsInfo &,Dimension &) const64 void InsetMathExInt::metrics(MetricsInfo &, Dimension &) const
65 {
66 LYXERR0("should not happen");
67 }
68
69
draw(PainterInfo &,int,int) const70 void InsetMathExInt::draw(PainterInfo &, int, int) const
71 {
72 LYXERR0("should not happen");
73 }
74
75
maple(MapleStream & os) const76 void InsetMathExInt::maple(MapleStream & os) const
77 {
78 os << symbol_ << '(';
79 if (!cell(0).empty())
80 os << cell(0);
81 else
82 os << '1';
83 os << ',' << cell(1);
84 if (hasScripts())
85 os << '=' << cell(2) << ".." << cell(3);
86 os << ')';
87 }
88
89
maxima(MaximaStream & os) const90 void InsetMathExInt::maxima(MaximaStream & os) const
91 {
92 if (symbol_ == "int")
93 os << "integrate(";
94 else
95 os << symbol_ << '(';
96
97 if (!cell(0).empty())
98 os << cell(0) << ',';
99 else
100 os << '1' << ',';
101 if (hasScripts())
102 os << cell(1) << ',' << cell(2) << ',' << cell(3) << ')';
103 else
104 os << cell(1) << ')';
105 }
106
mathematica(MathematicaStream & os) const107 void InsetMathExInt::mathematica(MathematicaStream & os) const
108 {
109 if (symbol_ == "int")
110 os << "Integrate[";
111 else if (symbol_ == "sum")
112 os << "Sum[";
113 else
114 os << symbol_ << '[';
115
116 if (!cell(0).empty())
117 os << cell(0) << ',';
118 else
119 os << '1' << ',';
120 if (hasScripts())
121 os << '{' << cell(1) << ',' << cell(2) << ',' << cell(3) << "}]";
122 else
123 os << cell(1) << ']';
124 }
125
126
mathmlize(MathStream & os) const127 void InsetMathExInt::mathmlize(MathStream & os) const
128 {
129 // At the moment, we are not extracting sums and the like for MathML.
130 // If we should decide to do so later, then we'll need to re-merge
131 // r32566 and r32568.
132 // So right now this only handles integrals.
133 InsetMathSymbol sym(symbol_);
134 bool const lower = !cell(2).empty();
135 bool const upper = !cell(3).empty();
136 if (lower && upper)
137 os << MTag("msubsup");
138 else if (lower)
139 os << MTag("msub");
140 else if (upper)
141 os << MTag("msup");
142 os << MTag("mrow");
143 sym.mathmlize(os);
144 os << ETag("mrow");
145 if (lower)
146 os << MTag("mrow") << cell(2) << ETag("mrow");
147 if (upper)
148 os << MTag("mrow") << cell(3) << ETag("mrow");
149 if (lower && upper)
150 os << ETag("msubsup");
151 else if (lower)
152 os << ETag("msub");
153 else if (upper)
154 os << ETag("msup");
155 os << cell(0) << "<mo> ⁢ </mo>"
156 << MTag("mrow") << "<mo> ⅆ </mo>"
157 << cell(1) << ETag("mrow");
158 }
159
160
htmlize(HtmlStream & os) const161 void InsetMathExInt::htmlize(HtmlStream & os) const
162 {
163 // At the moment, we are not extracting sums and the like for HTML.
164 // So right now this only handles integrals.
165 InsetMathSymbol sym(symbol_);
166 bool const lower = !cell(2).empty();
167 bool const upper = !cell(3).empty();
168
169 os << MTag("span", "class='integral'")
170 << MTag("span", "class='intsym'");
171 sym.htmlize(os, false);
172 os << ETag("span");
173
174 if (lower && upper) {
175 os << MTag("span", "class='limits'")
176 << MTag("span") << cell(2) << ETag("span")
177 << MTag("span") << cell(3) << ETag("span")
178 << ETag("span");
179 } else if (lower)
180 os << MTag("sub", "class='limit'") << cell(2) << ETag("sub");
181 else if (upper)
182 os << MTag("sup", "class='limit'") << cell(3) << ETag("sup");
183 os << cell(0) << "<b>d</b>" << cell(1) << ETag("span");
184 }
185
186
write(WriteStream &) const187 void InsetMathExInt::write(WriteStream &) const
188 {
189 LYXERR0("should not happen");
190 }
191
192 } // namespace lyx
193