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