]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMath.cpp
Natbib authoryear uses (Ref1; Ref2) by default.
[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(odocstringstream &, 
88         OutputParams const &, size_t) const
89 {
90         // all math plain text output shall take place in InsetMathHull
91         LATTEST(false);
92         return 0;
93 }
94
95
96 void InsetMath::normalize(NormalStream & os) const
97 {
98         os << '[' << name() << "] ";
99 }
100
101
102 void InsetMath::octave(OctaveStream & os) const
103 {
104         NormalStream ns(os.os());
105         normalize(ns);
106 }
107
108
109 void InsetMath::maple(MapleStream & os) const
110 {
111         NormalStream ns(os.os());
112         normalize(ns);
113 }
114
115
116 void InsetMath::maxima(MaximaStream & os) const
117 {
118         MapleStream ns(os.os());
119         maple(ns);
120 }
121
122
123 void InsetMath::mathematica(MathematicaStream & os) const
124 {
125         NormalStream ns(os.os());
126         normalize(ns);
127 }
128
129
130 void InsetMath::mathmlize(MathStream & os) const
131 {
132         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
133         os << MTag("mi");
134         NormalStream ns(os.os());
135         normalize(ns);
136         os << ETag("mi");
137 }
138
139
140 void InsetMath::htmlize(HtmlStream & os) const
141 {
142         os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
143         os << MTag("span", "style='color: red;'");
144         NormalStream ns(os.os());
145         normalize(ns);
146         os << ETag("span");
147 }
148
149
150 HullType InsetMath::getType() const
151 {
152         return hullNone;
153 }
154
155
156 ostream & operator<<(ostream & os, MathAtom const & at)
157 {
158         odocstringstream oss;
159         WriteStream wi(oss, false, false, WriteStream::wsDefault);
160         at->write(wi);
161         return os << to_utf8(oss.str());
162 }
163
164
165 odocstream & operator<<(odocstream & os, MathAtom const & at)
166 {
167         WriteStream wi(os, false, false, WriteStream::wsDefault);
168         at->write(wi);
169         return os;
170 }
171
172
173 } // namespace lyx