]> git.lyx.org Git - features.git/blob - src/mathed/InsetMathExInt.cpp
Introduce a return value for mathmlize(). We will need this to be able
[features.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 "MathExtern.h"
16 #include "MathStream.h"
17 #include "MathStream.h"
18 #include "InsetMathSymbol.h"
19
20 #include "support/debug.h"
21 #include "support/docstring.h"
22
23
24 namespace lyx {
25
26 InsetMathExInt::InsetMathExInt(Buffer * buf, docstring const & name)
27         : InsetMathNest(buf, 4), symbol_(name)
28 {}
29
30 // 0 - core
31 // 1 - diff
32 // 2 - lower
33 // 3 - upper
34
35
36 Inset * InsetMathExInt::clone() const
37 {
38         return new InsetMathExInt(*this);
39 }
40
41
42 void InsetMathExInt::symbol(docstring const & symbol)
43 {
44         symbol_ = symbol;
45 }
46
47
48 bool InsetMathExInt::hasScripts() const
49 {
50         // take empty upper bound as "no scripts"
51         return !cell(3).empty();
52 }
53
54
55
56 void InsetMathExInt::normalize(NormalStream & os) const
57 {
58         os << '[' << symbol_ << ' ' << cell(0) << ' ' << cell(1) << ' '
59            << cell(2) << ' ' << cell(3) << ']';
60 }
61
62
63 void InsetMathExInt::metrics(MetricsInfo &, Dimension &) const
64 {
65         LYXERR0("should not happen");
66 }
67
68
69 void InsetMathExInt::draw(PainterInfo &, int, int) const
70 {
71         LYXERR0("should not happen");
72 }
73
74
75 void InsetMathExInt::maple(MapleStream & os) const
76 {
77         os << symbol_ << '(';
78         if (cell(0).size())
79                 os << cell(0);
80         else
81                 os << '1';
82         os << ',' << cell(1);
83         if (hasScripts())
84                 os << '=' << cell(2) << ".." << cell(3);
85         os << ')';
86 }
87
88
89 void InsetMathExInt::maxima(MaximaStream & os) const
90 {
91         if (symbol_ == "int")
92                 os << "integrate(";
93         else
94                 os << symbol_ << '(';
95
96         if (cell(0).size())
97                 os << cell(0) << ',';
98         else
99                 os << '1' << ',';
100         if (hasScripts())
101                 os << cell(1) << ',' << cell(2) << ',' << cell(3) << ')';
102         else
103                 os << cell(1) << ')';
104 }
105
106 void InsetMathExInt::mathematica(MathematicaStream & os) const
107 {
108         if (symbol_ == "int")
109                 os << "Integrate[";
110         else if (symbol_ == "sum")
111                 os << "Sum[";
112         else
113                 os << symbol_ << '[';
114
115         if (cell(0).size())
116                 os << cell(0) << ',';
117         else
118                 os << '1' << ',';
119         if (hasScripts())
120                 os << '{' << cell(1) << ',' << cell(2) << ',' << cell(3) << "}]";
121         else
122                 os << cell(1) << ']';
123 }
124
125
126 docstring InsetMathExInt::mathmlize(MathStream & os) const
127 {
128         // At the moment, we are not extracting sums and the like for MathML.
129         // If we should decide to do so later, then we'll need to re-merge
130         // r32566 and r32568.
131         // So right now this only handles integrals.
132         InsetMathSymbol sym(symbol_);
133         bool const lower = !cell(2).empty();
134         bool const upper = !cell(3).empty();
135         if (lower && upper)
136                 os << MTag("msubsup");
137         else if (lower)
138                 os << MTag("msub");
139         else if (upper)
140                 os << MTag("msup");
141         os << MTag("mrow");
142         sym.mathmlize(os);
143         os << ETag("mrow");
144         if (lower)
145                 os << MTag("mrow") << cell(2) << ETag("mrow");
146         if (upper)
147                 os << MTag("mrow") << cell(3) << ETag("mrow");
148         if (lower && upper)
149                 os << ETag("msubsup");
150         else if (lower)
151                 os << ETag("msub");
152         else if (upper)
153                 os << ETag("msup");
154         docstring rv = lyx::mathmlize(cell(0), os);
155         os << "<mo> &InvisibleTimes; </mo>"
156            << MTag("mrow") << "<mo> &DifferentialD; </mo>"
157            << cell(1) << ETag("mrow");
158         return rv;
159 }
160
161
162 void InsetMathExInt::write(WriteStream &) const
163 {
164         LYXERR0("should not happen");
165 }
166
167
168 } // namespace lyx