2 * \file math_symbolinset.C
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 "math_symbolinset.h"
14 #include "dimension.h"
15 #include "math_mathmlstream.h"
16 #include "math_streamstr.h"
17 #include "math_support.h"
18 #include "math_parser.h"
19 #include "math_atom.h"
20 #include "LaTeXFeatures.h"
28 MathSymbolInset::MathSymbolInset(latexkeys const * l)
33 MathSymbolInset::MathSymbolInset(char const * name)
34 : sym_(in_word_set(name)), h_(0)
38 MathSymbolInset::MathSymbolInset(string const & name)
39 : sym_(in_word_set(name.c_str())), h_(0)
43 auto_ptr<InsetBase> MathSymbolInset::clone() const
45 return auto_ptr<InsetBase>(new MathSymbolInset(*this));
49 string MathSymbolInset::name() const
55 void MathSymbolInset::metrics(MetricsInfo & mi, Dimension & dim) const
57 //lyxerr << "metrics: symbol: '" << sym_->name
58 // << "' in font: '" << sym_->inset
59 // << "' drawn as: '" << sym_->draw
60 // << "'" << std::endl;
62 int const em = mathed_char_width(mi.base.font, 'M');
63 FontSetChanger dummy(mi.base, sym_->inset.c_str());
64 mathed_string_dim(mi.base.font, sym_->draw, dim);
65 // correct height for broken cmex and wasy font
66 #if defined(__APPLE__) && defined(__GNUC__)
67 if (sym_->inset == "cmex") {
72 } else if (sym_->inset == "wasy") {
78 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
84 // seperate things a bit
86 dim.wid += static_cast<int>(0.5 * em + 0.5);
88 dim.wid += static_cast<int>(0.1667 * em + 0.5);
91 if (mi.base.style == LM_ST_DISPLAY)
92 if (sym_->inset == "cmex" || sym_->extra == "funclim")
97 void MathSymbolInset::draw(PainterInfo & pi, int x, int y) const
99 //lyxerr << "metrics: symbol: '" << sym_->name
100 // << "' in font: '" << sym_->inset
101 // << "' drawn as: '" << sym_->draw
102 // << "'" << std::endl;
103 int const em = mathed_char_width(pi.base.font, 'M');
105 x += static_cast<int>(0.25*em+0.5);
107 x += static_cast<int>(0.0833*em+0.5);
109 FontSetChanger dummy(pi.base, sym_->inset.c_str());
110 drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
114 bool MathSymbolInset::isRelOp() const
116 return sym_->extra == "mathrel";
120 bool MathSymbolInset::isScriptable() const
126 bool MathSymbolInset::takesLimits() const
129 sym_->inset == "cmex" ||
130 sym_->inset == "lyxboldsymb" ||
131 sym_->extra == "funclim";
135 void MathSymbolInset::validate(LaTeXFeatures & features) const
137 if (sym_->inset == "msa" || sym_->inset == "msb")
138 features.require("amssymb");
142 void MathSymbolInset::normalize(NormalStream & os) const
144 os << "[symbol " << name() << ']';
148 void MathSymbolInset::maple(MapleStream & os) const
150 if (name() == "cdot")
152 else if (name() == "infty")
158 void MathSymbolInset::maxima(MaximaStream & os) const
160 if (name() == "cdot")
162 else if (name() == "infty")
169 void MathSymbolInset::mathematica(MathematicaStream & os) const
171 if ( name() == "pi") { os << "Pi"; return;}
172 if ( name() == "infty") { os << "Infinity"; return;}
177 char const * MathMLtype(string const & s)
185 void MathSymbolInset::mathmlize(MathMLStream & os) const
187 char const * type = MathMLtype(sym_->extra);
188 os << '<' << type << "> ";
189 if (sym_->xmlname == "x") // unknown so far
193 os << " </" << type << '>';
197 void MathSymbolInset::octave(OctaveStream & os) const
199 if (name() == "cdot")
206 void MathSymbolInset::write(WriteStream & os) const
208 os << '\\' << name();
209 os.pendingSpace(true);
213 void MathSymbolInset::infoize2(std::ostream & os) const
215 os << "Symbol: " << name();