]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathMatrix.cpp
Fix #7549, due to a problem in exporting to plaintext a
[lyx.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 "MathStream.h"
16
17 #include "support/convert.h"
18
19 using namespace std;
20
21 namespace lyx {
22
23 InsetMathMatrix::InsetMathMatrix(InsetMathGrid const & p, 
24                         docstring const & left, docstring const & right)
25         : InsetMathGrid(p), left_(left), right_(right)
26 {}
27
28
29 Inset * InsetMathMatrix::clone() const
30 {
31         return new InsetMathMatrix(*this);
32 }
33
34
35 void InsetMathMatrix::write(WriteStream & os) const
36 {
37         InsetMathGrid::write(os);
38 }
39
40
41 void InsetMathMatrix::normalize(NormalStream & os) const
42 {
43         InsetMathGrid::normalize(os);
44 }
45
46
47 void InsetMathMatrix::maple(MapleStream & os) const
48 {
49         os << "matrix(" << int(nrows()) << ',' << int(ncols()) << ",[";
50         for (idx_type idx = 0; idx < nargs(); ++idx) {
51                 if (idx)
52                         os << ',';
53                 os << cell(idx);
54         }
55         os << "])";
56 }
57
58
59 void InsetMathMatrix::maxima(MaximaStream & os) const
60 {
61         os << "matrix(";
62         for (row_type row = 0; row < nrows(); ++row) {
63                 if (row)
64                         os << ',';
65                 os << '[';
66                 for (col_type col = 0; col < ncols(); ++col) {
67                         if (col)
68                                 os << ',';
69                         os << cell(index(row, col));
70                 }
71                 os << ']';
72         }
73         os << ')';
74 }
75
76
77 void InsetMathMatrix::mathematica(MathematicaStream & os) const
78 {
79         os << '{';
80         for (row_type row = 0; row < nrows(); ++row) {
81                 if (row)
82                         os << ',';
83                 os << '{';
84                 for (col_type col = 0; col < ncols(); ++col) {
85                         if (col)
86                                 os << ',';
87                         os << cell(index(row, col));
88                 }
89                 os << '}';
90         }
91         os << '}';
92 }
93
94
95 void InsetMathMatrix::mathmlize(MathStream & os) const
96 {
97         os << "<mo form='prefix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
98            << left_ << "</mo>";
99         os << MTag("mtable");
100         for (row_type row = 0; row < nrows(); ++row) {
101                 os << MTag("mtr");
102                 for (col_type col = 0; col < ncols(); ++col)
103                         os << MTag("mtd") << cell(index(row, col)) << ETag("mtd");
104                 os << ETag("mtr");
105         }
106         os << ETag("mtable");
107         os << "<mo form='postfix' fence='true' stretchy='true' symmetric='true' lspace='thinmathspace'>"
108            << right_ << "</mo>";
109 }
110
111
112 void InsetMathMatrix::htmlize(HtmlStream & os) const
113 {
114         os << MTag("table", "class='matrix'") << '\n';
115
116         // we do not print the delimiters but instead try to hack them
117         string const rows = convert<string>(nrows());
118         string const lattrib = 
119                         "class='ldelim' rowspan='" + rows + "'";
120         string const rattrib = 
121                         "class='rdelim' rowspan='" + rows + "'";
122         
123         for (row_type row = 0; row < nrows(); ++row) {
124                 os << MTag("tr") << '\n';
125                 if (row == 0)
126                         os << MTag("td", lattrib) << ETag("td") << '\n';
127                 for (col_type col = 0; col < ncols(); ++col)
128                         os << MTag("td") << cell(index(row, col)) << ETag("td") << '\n';
129                 if (row == 0)
130                         os << MTag("td", rattrib) << ETag("td") << '\n';
131                 os << ETag("tr") << '\n';
132         }
133         os << ETag("table") << '\n';
134 }
135
136
137 void InsetMathMatrix::octave(OctaveStream & os) const
138 {
139         os << '[';
140         for (row_type row = 0; row < nrows(); ++row) {
141                 if (row)
142                         os << ';';
143                 os << '[';
144                 for (col_type col = 0; col < ncols(); ++col)
145                         os << cell(index(row, col)) << ' ';
146                 os << ']';
147         }
148         os << ']';
149 }
150
151
152 } // namespace lyx