]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathExInt.cpp
ae687bb678ef97b7bf70bb1b8c5785a37f64593e
[lyx.git] / src / mathed / InsetMathExInt.cpp
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 #include "MathData.h"
15 #include "MathStream.h"
16 #include "MathStream.h"
17 #include "InsetMathSymbol.h"
18
19 #include "support/debug.h"
20 #include "support/docstring.h"
21
22
23 namespace lyx {
24
25 InsetMathExInt::InsetMathExInt(Buffer * buf, docstring const & name)
26         : InsetMathNest(buf, 4), symbol_(name)
27 {}
28
29 // 0 - core
30 // 1 - diff
31 // 2 - lower
32 // 3 - upper
33
34
35 Inset * InsetMathExInt::clone() const
36 {
37         return new InsetMathExInt(*this);
38 }
39
40
41 void InsetMathExInt::symbol(docstring const & symbol)
42 {
43         symbol_ = symbol;
44 }
45
46
47 bool InsetMathExInt::hasScripts() const
48 {
49         // take empty upper bound as "no scripts"
50         return !cell(3).empty();
51 }
52
53
54
55 void InsetMathExInt::normalize(NormalStream & os) const
56 {
57         os << '[' << symbol_ << ' ' << cell(0) << ' ' << cell(1) << ' '
58            << cell(2) << ' ' << cell(3) << ']';
59 }
60
61
62 void InsetMathExInt::metrics(MetricsInfo &, Dimension &) const
63 {
64         LYXERR0("should not happen");
65 }
66
67
68 void InsetMathExInt::draw(PainterInfo &, int, int) const
69 {
70         LYXERR0("should not happen");
71 }
72
73
74 bool InsetMathExInt::isExIntOperator(docstring const & name)
75 {
76         std::string const & sname = to_utf8(name);
77         return sname == "sum" || sname == "prod";
78 }
79
80
81 void InsetMathExInt::maple(MapleStream & os) const
82 {
83         // FIXME Products and the like may need special treatment.
84         os << symbol_ << '(';
85         if (cell(0).size())
86                 os << cell(0);
87         else
88                 os << '1';
89         os << ',' << cell(1);
90         if (hasScripts())
91                 os << '=' << cell(2) << ".." << cell(3);
92         os << ')';
93 }
94
95
96 void InsetMathExInt::maxima(MaximaStream & os) const
97 {
98         // FIXME Products and the like may need special treatment.
99         if (symbol_ == "int")
100                 os << "integrate(";
101         else
102                 os << symbol_ << '(';
103
104         if (cell(0).size())
105                 os << cell(0) << ',';
106         else
107                 os << '1' << ',';
108         if (hasScripts())
109                 os << cell(1) << ',' << cell(2) << ',' << cell(3) << ')';
110         else
111                 os << cell(1) << ')';
112 }
113
114
115 void InsetMathExInt::mathematica(MathematicaStream & os) const
116 {
117         // FIXME Products and the like may need special treatment.
118         if (symbol_ == "int")
119                 os << "Integrate[";
120         else if (symbol_ == "sum")
121                 os << "Sum[";
122         else
123                 os << symbol_ << '[';
124
125         if (cell(0).size())
126                 os << cell(0) << ',';
127         else
128                 os << '1' << ',';
129         if (hasScripts())
130                 os << '{' << cell(1) << ',' << cell(2) << ',' << cell(3) << "}]";
131         else
132                 os << cell(1) << ']';
133 }
134
135
136 void InsetMathExInt::mathmlize(MathStream & os) const
137 {
138         InsetMathSymbol sym(symbol_);
139         if (isExIntOperator(symbol_)) {
140                 bool const lower = !cell(1).empty();
141                 bool const upper = !cell(3).empty();
142                 if (lower && upper)
143                         os << MTag("msubsup");
144                 else if (lower)
145                         os << MTag("msub");
146                 else if (upper)
147                         os << MTag("msup");
148                 os << MTag("mrow");
149                 sym.mathmlize(os);
150                 os << ETag("mrow");
151                 if (lower) {
152                         os << MTag("mrow");
153                         os << cell(1);
154                         if (!cell(2).empty())
155                                 os << MTag("mo") << "=" << ETag("mo") 
156                                    << cell(2);
157                         os << ETag("mrow");
158                 }
159                 if (upper)
160                         os << MTag("mrow") << cell(3) << ETag("mrow");
161                 if (lower && upper)
162                         os << ETag("msubsup");
163                 else if (lower)
164                         os << ETag("msub");
165                 else if (upper)
166                         os << ETag("msup");
167                 os << cell(0);
168                 return;
169         }
170         // some kind of integral
171         bool const lower = !cell(2).empty();
172         bool const upper = !cell(3).empty();
173         if (lower && upper)
174                 os << MTag("msubsup");
175         else if (lower)
176                 os << MTag("msub");
177         else if (upper)
178                 os << MTag("msup");
179         os << MTag("mrow");
180         sym.mathmlize(os);
181         os << ETag("mrow");
182         if (lower)
183                 os << MTag("mrow") << cell(2) << ETag("mrow");
184         if (upper)
185                 os << MTag("mrow") << cell(3) << ETag("mrow");
186         if (lower && upper)
187                 os << ETag("msubsup");
188         else if (lower)
189                 os << ETag("msub");
190         else if (upper)
191                 os << ETag("msup");
192         os << cell(0) << "<mo> &InvisibleTimes; </mo>"
193            << MTag("mrow") << "<mo> &DifferentialD; </mo>"
194            << cell(1) << ETag("mrow");
195 }
196
197
198 void InsetMathExInt::write(WriteStream &) const
199 {
200         LYXERR0("should not happen");
201 }
202
203 } // namespace lyx