]> git.lyx.org Git - features.git/blob - src/mathed/InsetMathMatrix.cpp
Introduce a return value for mathmlize(). We will need this to be able
[features.git] / src / mathed / InsetMathMatrix.cpp
1 /**
2  * \file InsetMathMatrix.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 "InsetMathMatrix.h"
14 #include "MathData.h"
15 #include "MathExtern.h"
16 #include "MathStream.h"
17
18
19 namespace lyx {
20
21 InsetMathMatrix::InsetMathMatrix(InsetMathGrid const & p, 
22                         docstring const & left, docstring const & right)
23         : InsetMathGrid(p), left_(left), right_(right)
24 {}
25
26
27 Inset * InsetMathMatrix::clone() const
28 {
29         return new InsetMathMatrix(*this);
30 }
31
32
33 void InsetMathMatrix::write(WriteStream & os) const
34 {
35         InsetMathGrid::write(os);
36 }
37
38
39 void InsetMathMatrix::normalize(NormalStream & os) const
40 {
41         InsetMathGrid::normalize(os);
42 }
43
44
45 void InsetMathMatrix::maple(MapleStream & os) const
46 {
47         os << "matrix(" << int(nrows()) << ',' << int(ncols()) << ",[";
48         for (idx_type idx = 0; idx < nargs(); ++idx) {
49                 if (idx)
50                         os << ',';
51                 os << cell(idx);
52         }
53         os << "])";
54 }
55
56
57 void InsetMathMatrix::maxima(MaximaStream & os) const
58 {
59         os << "matrix(";
60         for (row_type row = 0; row < nrows(); ++row) {
61                 if (row)
62                         os << ',';
63                 os << '[';
64                 for (col_type col = 0; col < ncols(); ++col) {
65                         if (col)
66                                 os << ',';
67                         os << cell(index(row, col));
68                 }
69                 os << ']';
70         }
71         os << ')';
72 }
73
74
75 void InsetMathMatrix::mathematica(MathematicaStream & os) const
76 {
77         os << '{';
78         for (row_type row = 0; row < nrows(); ++row) {
79                 if (row)
80                         os << ',';
81                 os << '{';
82                 for (col_type col = 0; col < ncols(); ++col) {
83                         if (col)
84                                 os << ',';
85                         os << cell(index(row, col));
86                 }
87                 os << '}';
88         }
89         os << '}';
90 }
91
92
93 docstring InsetMathMatrix::mathmlize(MathStream & os) const
94 {
95         os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
96            << left_ << "</mo>";
97         os << MTag("mtable");
98         docstring rv;
99         for (row_type row = 0; row < nrows(); ++row) {
100                 os << MTag("mtr");
101                 for (col_type col = 0; col < ncols(); ++col) {
102                         os << MTag("mtd");
103                         rv += lyx::mathmlize(cell(index(row, col)), os);
104                         os << ETag("mtd");
105                 }
106                 os << ETag("mtr");
107         }
108         os << ETag("mtable");
109         os << "<mo form='postfix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
110            << right_ << "</mo>";
111         return rv;
112 }
113
114
115 void InsetMathMatrix::octave(OctaveStream & os) const
116 {
117         os << '[';
118         for (row_type row = 0; row < nrows(); ++row) {
119                 if (row)
120                         os << ';';
121                 os << '[';
122                 for (col_type col = 0; col < ncols(); ++col)
123                         os << cell(index(row, col)) << ' ';
124                 os << ']';
125         }
126         os << ']';
127 }
128
129
130 } // namespace lyx