2 * \file InsetMathString.cpp
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "InsetMathString.h"
14 #include "MathStream.h"
15 #include "MathSupport.h"
19 #include "support/gettext.h"
24 InsetMathString::InsetMathString(docstring const & s)
29 Inset * InsetMathString::clone() const
31 return new InsetMathString(*this);
35 void InsetMathString::metrics(MetricsInfo & mi, Dimension & dim) const
37 mathed_string_dim(mi.base.font, str_, dim);
41 void InsetMathString::draw(PainterInfo & pi, int x, int y) const
47 void InsetMathString::normalize(NormalStream & os) const
49 os << "[string " << str_ << ' ' << "mathalpha" << ']';
53 void InsetMathString::maple(MapleStream & os) const
55 if (/*code_ != LM_TC_VAR ||*/ str_.size() <= 1) {
56 os << ' ' << str_ << ' ';
60 // insert '*' between adjacent chars if type is LM_TC_VAR
62 for (size_t i = 1; i < str_.size(); ++i)
67 void InsetMathString::mathematica(MathematicaStream & os) const
69 os << ' ' << str_ << ' ';
73 void InsetMathString::octave(OctaveStream & os) const
75 if (/*code_ != LM_TC_VAR ||*/ str_.size() <= 1) {
76 os << ' ' << str_ << ' ';
80 // insert '*' between adjacent chars if type is LM_TC_VAR
82 for (size_t i = 1; i < str_.size(); ++i)
87 void InsetMathString::mathmlize(MathStream & os) const
90 if (code_ == LM_TC_VAR)
91 os << "<mi> " << str_ << " </mi>";
92 else if (code_ == LM_TC_CONST)
93 os << "<mn> " << str_ << " </mn>";
94 else if (code_ == LM_TC_RM || code_ == LM_TC_TEXTRM)
95 os << "<mtext> " << str_ << " </mtext>";
102 void InsetMathString::write(WriteStream & os) const
109 // We need the latex macros defined in the unicodesymbols file.
110 // As they do not depend on the encoding, simply use the first
111 // available encoding.
112 Encodings::const_iterator encit = encodings.begin();
113 bool can_encode = encit != encodings.end();
115 docstring::const_iterator cit = str_.begin();
116 docstring::const_iterator end = str_.end();
118 bool in_mathsym = false;
120 char_type const c = *cit;
127 os << docstring(1, c);
128 } else if (can_encode) {
133 os << encit->latexChar(c, true);
135 throw EncodingException(c);
137 } catch (EncodingException & e) {
139 // FIXME: this is OK for View->Source
140 // but math preview will likely fail.
141 os << "<" << _("LyX Warning: ")
142 << _("uncodable character") << " '";
143 os << docstring(1, e.failed_char);