4 #include "math_symbolinset.h"
5 #include "math_mathmlstream.h"
6 #include "math_streamstr.h"
7 #include "math_support.h"
8 #include "math_parser.h"
9 #include "LaTeXFeatures.h"
12 MathSymbolInset::MathSymbolInset(const latexkeys * l)
17 MathSymbolInset::MathSymbolInset(const char * name)
18 : sym_(in_word_set(name)), h_(0)
22 MathSymbolInset::MathSymbolInset(string const & name)
23 : sym_(in_word_set(name.c_str())), h_(0)
28 MathInset * MathSymbolInset::clone() const
30 return new MathSymbolInset(*this);
34 string MathSymbolInset::name() const
40 void MathSymbolInset::metrics(MathMetricsInfo & mi) const
42 //lyxerr << "metrics: symbol: '" << sym_->name
43 // << "' in font: '" << sym_->inset
44 // << "' drawn as: '" << sym_->draw
47 int const em = mathed_char_width(mi.base.font, 'M');
48 MathFontSetChanger dummy(mi.base, sym_->inset.c_str());
49 mathed_string_dim(mi.base.font, sym_->draw, dim_);
50 // correct height for broken cmex and wasy font
51 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
56 // seperate things a bit
58 dim_.w += static_cast<int>(0.5*em+0.5);
60 dim_.w += static_cast<int>(0.1667*em+0.5);
63 if (mi.base.style == LM_ST_DISPLAY)
64 if (sym_->inset == "cmex" || sym_->extra == "funclim")
69 void MathSymbolInset::draw(MathPainterInfo & pi, int x, int y) const
71 //lyxerr << "metrics: symbol: '" << sym_->name
72 // << "' in font: '" << sym_->inset
73 // << "' drawn as: '" << sym_->draw
75 int const em = mathed_char_width(pi.base.font, 'M');
77 x += static_cast<int>(0.25*em+0.5);
79 x += static_cast<int>(0.0833*em+0.5);
81 MathFontSetChanger dummy(pi.base, sym_->inset.c_str());
82 drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
86 bool MathSymbolInset::isRelOp() const
88 return sym_->extra == "mathrel";
92 bool MathSymbolInset::isScriptable() const
98 bool MathSymbolInset::takesLimits() const
101 sym_->inset == "cmex" ||
102 sym_->inset == "lyxboldsymb" ||
103 sym_->extra == "funclim";
107 void MathSymbolInset::validate(LaTeXFeatures & features) const
109 if (sym_->inset == "msa" || sym_->inset == "msb")
110 features.require("amssymb");
114 void MathSymbolInset::normalize(NormalStream & os) const
116 os << "[symbol " << name() << ']';
120 void MathSymbolInset::maple(MapleStream & os) const
122 if (name() == "cdot")
124 else if (name() == "infty")
130 void MathSymbolInset::maxima(MaximaStream & os) const
132 if (name() == "cdot")
134 else if (name() == "infty")
141 void MathSymbolInset::mathematica(MathematicaStream & os) const
143 if ( name() == "pi") { os << "Pi"; return;}
144 if ( name() == "infty") { os << "Infinity"; return;}
149 char const * MathMLtype(string const & s)
157 bool MathSymbolInset::match(MathAtom const & at) const
159 MathSymbolInset const * q = at->asSymbolInset();
160 return q && name() == q->name();
164 void MathSymbolInset::mathmlize(MathMLStream & os) const
166 char const * type = MathMLtype(sym_->extra);
167 os << '<' << type << "> ";
168 if (sym_->xmlname == "x") // unknown so far
172 os << " </" << type << '>';
176 void MathSymbolInset::octave(OctaveStream & os) const
178 if (name() == "cdot")
185 void MathSymbolInset::write(WriteStream & os) const
187 os << '\\' << name();
188 os.pendingSpace(true);
192 void MathSymbolInset::infoize2(std::ostream & os) const
194 os << "Symbol: " << name();