]> git.lyx.org Git - lyx.git/blob - src/mathed/InsetMathString.C
Fix bug 2789 (as discussed)
[lyx.git] / src / mathed / InsetMathString.C
1 /**
2  * \file InsetMathString.C
3  * This file is part of LyX, the document processor.
4  * Licence details can be found in the file COPYING.
5  *
6  * \author André Pönitz
7  *
8  * Full author contact details are available in file CREDITS.
9  */
10
11 #include <config.h>
12
13 #include "InsetMathString.h"
14 #include "MathMLStream.h"
15 #include "MathStream.h"
16 #include "MathSupport.h"
17
18 using lyx::docstring;
19
20 using std::string;
21 using std::auto_ptr;
22
23
24 InsetMathString::InsetMathString(string const & s)
25         : str_(s)
26 {}
27
28
29 auto_ptr<InsetBase> InsetMathString::doClone() const
30 {
31         return auto_ptr<InsetBase>(new InsetMathString(*this));
32 }
33
34
35 void InsetMathString::metrics(MetricsInfo & mi, Dimension & dim) const
36 {
37         mathed_string_dim(mi.base.font, str_, dim);
38 }
39
40
41 void InsetMathString::draw(PainterInfo & pi, int x, int y) const
42 {
43         //lyxerr << "drawing '" << str_ << "' code: " << code_ << endl;
44         docstring dstr(str_.begin(), str_.end());
45         pi.draw(x, y, dstr);
46 }
47
48
49 void InsetMathString::normalize(NormalStream & os) const
50 {
51         os << "[string " << str_ << ' ' << "mathalpha" << ']';
52 }
53
54
55 void InsetMathString::maple(MapleStream & os) const
56 {
57         if (/*code_ != LM_TC_VAR ||*/ str_.size() <= 1) {
58                 os << ' ' << str_ << ' ';
59                 return;
60         }
61
62         // insert '*' between adjacent chars if type is LM_TC_VAR
63         os << str_[0];
64         for (string::size_type i = 1; i < str_.size(); ++i)
65                 os << str_[i];
66 }
67
68
69 void InsetMathString::mathematica(MathematicaStream & os) const
70 {
71         os << ' ' << str_ << ' ';
72 }
73
74
75 void InsetMathString::octave(OctaveStream & os) const
76 {
77         if (/*code_ != LM_TC_VAR ||*/ str_.size() <= 1) {
78                 os << ' ' << str_ << ' ';
79                 return;
80         }
81
82         // insert '*' between adjacent chars if type is LM_TC_VAR
83         os << str_[0];
84         for (string::size_type i = 1; i < str_.size(); ++i)
85                 os << str_[i];
86 }
87
88
89 void InsetMathString::mathmlize(MathMLStream & os) const
90 {
91 /*
92         if (code_ == LM_TC_VAR)
93                 os << "<mi> " << str_ << " </mi>";
94         else if (code_ == LM_TC_CONST)
95                 os << "<mn> " << str_ << " </mn>";
96         else if (code_ == LM_TC_RM || code_ == LM_TC_TEXTRM)
97                 os << "<mtext> " << str_ <<  " </mtext>";
98         else
99 */
100                 os << str_;
101 }
102
103
104 void InsetMathString::write(WriteStream & os) const
105 {
106         os << str_;
107 }