]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.cpp
Fix bug #8782.
[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 void InsetMath::dump() const
53 {
54         lyxerr << "---------------------------------------------" << endl;
55         odocstringstream os;
56         TexRow texrow(false);
57         otexrowstream ots(os,texrow);
58         WriteStream wi(ots, false, true, WriteStream::wsDefault);
59         write(wi);
60         lyxerr << to_utf8(os.str());
61         lyxerr << "\n---------------------------------------------" << endl;
62 }
63
64
65 void InsetMath::metricsT(TextMetricsInfo const &, Dimension &) const
66 {
67         LYXERR0("InsetMath::metricsT(Text) called directly!");
68 }
69
70
71 void InsetMath::drawT(TextPainter &, int, int) const
72 {
73         LYXERR0("InsetMath::drawT(Text) called directly!");
74 }
75
76
77 void InsetMath::write(WriteStream & os) const
78 {
79         MathEnsurer ensurer(os);
80         docstring const s = name();
81         os << "\\" << s;
82         // We need an extra ' ' unless this is a single-char-non-ASCII name
83         // or anything non-ASCII follows
84         if (s.size() != 1 || isAlphaASCII(s[0]))
85                 os.pendingSpace(true);
86 }
87
88
89 int InsetMath::plaintext(odocstringstream &, 
90         OutputParams const &, size_t) const
91 {
92         // all math plain text output shall take place in InsetMathHull
93         LATTEST(false);
94         return 0;
95 }
96
97
98 void InsetMath::normalize(NormalStream & os) const
99 {
100         os << '[' << name() << "] ";
101 }
102
103
104 void InsetMath::octave(OctaveStream & os) const
105 {
106         NormalStream ns(os.os());
107         normalize(ns);
108 }
109
110
111 void InsetMath::maple(MapleStream & os) const
112 {
113         NormalStream ns(os.os());
114         normalize(ns);
115 }
116
117
118 void InsetMath::maxima(MaximaStream & os) const
119 {
120         MapleStream ns(os.os());
121         maple(ns);
122 }
123
124
125 void InsetMath::mathematica(MathematicaStream & os) const
126 {
127         NormalStream ns(os.os());
128         normalize(ns);
129 }
130
131
132 void InsetMath::mathmlize(MathStream & os) const
133 {
134         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
135         os << MTag("mi");
136         NormalStream ns(os.os());
137         normalize(ns);
138         os << ETag("mi");
139 }
140
141
142 void InsetMath::htmlize(HtmlStream & os) const
143 {
144         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
145         os << MTag("span", "style='color: red;'");
146         NormalStream ns(os.os());
147         normalize(ns);
148         os << ETag("span");
149 }
150
151
152 HullType InsetMath::getType() const
153 {
154         return hullNone;
155 }
156
157
158 ostream & operator<<(ostream & os, MathAtom const & at)
159 {
160         odocstringstream oss;
161         TexRow texrow(false);
162         otexrowstream ots(oss,texrow);
163         WriteStream wi(ots, false, false, WriteStream::wsDefault);
164         at->write(wi);
165         return os << to_utf8(oss.str());
166 }
167
168
169 odocstream & operator<<(odocstream & os, MathAtom const & at)
170 {
171         TexRow texrow(false);
172         otexrowstream ots(os,texrow);
173         WriteStream wi(ots, false, false, WriteStream::wsDefault);
174         at->write(wi);
175         return os;
176 }
177
178
179 } // namespace lyx