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