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