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