]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.cpp
Set correctly the spacing between atoms in MathData
[lyx.git] / src / mathed / InsetMath.cpp
1 /**
2  * \file InsetMath.cpp
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author Alejandro Aguilar Sierra
7  * \author André Pönitz
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #include <config.h>
13
14 #include "InsetMath.h"
15 #include "MathData.h"
16 #include "MathRow.h"
17 #include "MathStream.h"
18
19 #include "support/debug.h"
20 #include "support/docstream.h"
21 #include "support/gettext.h"
22 #include "support/lstrings.h"
23 #include "support/textutils.h"
24
25 #include "support/lassert.h"
26
27 using namespace std;
28
29 namespace lyx {
30
31 docstring InsetMath::name() const
32 {
33         return from_utf8("Unknown");
34 }
35
36
37 MathData & InsetMath::cell(idx_type)
38 {
39         static MathData dummyCell(&buffer());
40         LYXERR0("I don't have any cell");
41         return dummyCell;
42 }
43
44
45 MathData const & InsetMath::cell(idx_type) const
46 {
47         static MathData dummyCell;
48         LYXERR0("I don't have any cell");
49         return dummyCell;
50 }
51
52
53 MathClass InsetMath::mathClass() const
54 {
55         return MC_ORD;
56 }
57
58
59 bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo const &) const
60 {
61         MathRow::Element e;
62         e.inset = this;
63         e.mclass = mathClass();
64         mrow.push_back(e);
65         return true;
66 }
67
68
69 void InsetMath::dump() const
70 {
71         lyxerr << "---------------------------------------------" << endl;
72         odocstringstream os;
73         otexrowstream ots(os);
74         WriteStream wi(ots, false, true, WriteStream::wsDefault);
75         write(wi);
76         lyxerr << to_utf8(os.str());
77         lyxerr << "\n---------------------------------------------" << endl;
78 }
79
80
81 void InsetMath::metricsT(TextMetricsInfo const &, Dimension &) const
82 {
83         LYXERR0("InsetMath::metricsT(Text) called directly!");
84 }
85
86
87 void InsetMath::drawT(TextPainter &, int, int) const
88 {
89         LYXERR0("InsetMath::drawT(Text) called directly!");
90 }
91
92
93 void InsetMath::write(WriteStream & os) const
94 {
95         MathEnsurer ensurer(os);
96         docstring const s = name();
97         os << "\\" << s;
98         // We need an extra ' ' unless this is a single-char-non-ASCII name
99         // or anything non-ASCII follows
100         if (s.size() != 1 || isAlphaASCII(s[0]))
101                 os.pendingSpace(true);
102 }
103
104
105 int InsetMath::plaintext(odocstringstream &, 
106         OutputParams const &, size_t) const
107 {
108         // all math plain text output shall take place in InsetMathHull
109         LATTEST(false);
110         return 0;
111 }
112
113
114 void InsetMath::normalize(NormalStream & os) const
115 {
116         os << '[' << name() << "] ";
117 }
118
119
120 void InsetMath::octave(OctaveStream & os) const
121 {
122         NormalStream ns(os.os());
123         normalize(ns);
124 }
125
126
127 void InsetMath::maple(MapleStream & os) const
128 {
129         NormalStream ns(os.os());
130         normalize(ns);
131 }
132
133
134 void InsetMath::maxima(MaximaStream & os) const
135 {
136         MapleStream ns(os.os());
137         maple(ns);
138 }
139
140
141 void InsetMath::mathematica(MathematicaStream & os) const
142 {
143         NormalStream ns(os.os());
144         normalize(ns);
145 }
146
147
148 void InsetMath::mathmlize(MathStream & os) const
149 {
150         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
151         os << MTag("mi");
152         NormalStream ns(os.os());
153         normalize(ns);
154         os << ETag("mi");
155 }
156
157
158 void InsetMath::htmlize(HtmlStream & os) const
159 {
160         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
161         os << MTag("span", "style='color: red;'");
162         NormalStream ns(os.os());
163         normalize(ns);
164         os << ETag("span");
165 }
166
167
168 HullType InsetMath::getType() const
169 {
170         return hullNone;
171 }
172
173
174 ostream & operator<<(ostream & os, MathAtom const & at)
175 {
176         odocstringstream oss;
177         otexrowstream ots(oss);
178         WriteStream wi(ots, false, false, WriteStream::wsDefault);
179         at->write(wi);
180         return os << to_utf8(oss.str());
181 }
182
183
184 odocstream & operator<<(odocstream & os, MathAtom const & at)
185 {
186         otexrowstream ots(os);
187         WriteStream wi(ots, false, false, WriteStream::wsDefault);
188         at->write(wi);
189         return os;
190 }
191
192
193 } // namespace lyx