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"
26 MathSymbolInset::MathSymbolInset(latexkeys const * l)
31 MathSymbolInset::MathSymbolInset(char const * name)
32 : sym_(in_word_set(name)), h_(0)
36 MathSymbolInset::MathSymbolInset(string const & name)
37 : sym_(in_word_set(name.c_str())), h_(0)
41 auto_ptr<InsetBase> MathSymbolInset::clone() const
43 return auto_ptr<InsetBase>(new MathSymbolInset(*this));
47 string MathSymbolInset::name() const
53 void MathSymbolInset::metrics(MetricsInfo & mi, Dimension & dim) const
55 //lyxerr << "metrics: symbol: '" << sym_->name
56 // << "' in font: '" << sym_->inset
57 // << "' drawn as: '" << sym_->draw
60 int const em = mathed_char_width(mi.base.font, 'M');
61 FontSetChanger dummy(mi.base, sym_->inset.c_str());
62 mathed_string_dim(mi.base.font, sym_->draw, dim);
63 // correct height for broken cmex and wasy font
64 #if defined(__APPLE__) && defined(__GNUC__)
65 if (sym_->inset == "cmex") {
66 h_ = 4 * dim_.des / 5;
70 } else if (sym_->inset == "wasy") {
76 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
82 // seperate things a bit
84 dim.wid += static_cast<int>(0.5 * em + 0.5);
86 dim.wid += static_cast<int>(0.1667 * em + 0.5);
89 if (mi.base.style == LM_ST_DISPLAY)
90 if (sym_->inset == "cmex" || sym_->extra == "funclim")
95 void MathSymbolInset::draw(PainterInfo & pi, int x, int y) const
97 //lyxerr << "metrics: symbol: '" << sym_->name
98 // << "' in font: '" << sym_->inset
99 // << "' drawn as: '" << sym_->draw
101 int const em = mathed_char_width(pi.base.font, 'M');
103 x += static_cast<int>(0.25*em+0.5);
105 x += static_cast<int>(0.0833*em+0.5);
107 FontSetChanger dummy(pi.base, sym_->inset.c_str());
108 drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
112 bool MathSymbolInset::isRelOp() const
114 return sym_->extra == "mathrel";
118 bool MathSymbolInset::isScriptable() const
124 bool MathSymbolInset::takesLimits() const
127 sym_->inset == "cmex" ||
128 sym_->inset == "lyxboldsymb" ||
129 sym_->extra == "funclim";
133 void MathSymbolInset::validate(LaTeXFeatures & features) const
135 if (sym_->inset == "msa" || sym_->inset == "msb")
136 features.require("amssymb");
140 void MathSymbolInset::normalize(NormalStream & os) const
142 os << "[symbol " << name() << ']';
146 void MathSymbolInset::maple(MapleStream & os) const
148 if (name() == "cdot")
150 else if (name() == "infty")
156 void MathSymbolInset::maxima(MaximaStream & os) const
158 if (name() == "cdot")
160 else if (name() == "infty")
167 void MathSymbolInset::mathematica(MathematicaStream & os) const
169 if ( name() == "pi") { os << "Pi"; return;}
170 if ( name() == "infty") { os << "Infinity"; return;}
175 char const * MathMLtype(string const & s)
183 bool MathSymbolInset::match(MathAtom const & at) const
185 MathSymbolInset const * q = at->asSymbolInset();
186 return q && name() == q->name();
190 void MathSymbolInset::mathmlize(MathMLStream & os) const
192 char const * type = MathMLtype(sym_->extra);
193 os << '<' << type << "> ";
194 if (sym_->xmlname == "x") // unknown so far
198 os << " </" << type << '>';
202 void MathSymbolInset::octave(OctaveStream & os) const
204 if (name() == "cdot")
211 void MathSymbolInset::write(WriteStream & os) const
213 os << '\\' << name();
214 os.pendingSpace(true);
218 void MathSymbolInset::infoize2(std::ostream & os) const
220 os << "Symbol: " << name();