8 #include "math_symbolinset.h"
9 #include "math_mathmlstream.h"
10 #include "math_streamstr.h"
11 #include "math_support.h"
12 #include "math_parser.h"
13 #include "LaTeXFeatures.h"
16 MathSymbolInset::MathSymbolInset(const latexkeys * l)
21 MathSymbolInset::MathSymbolInset(const char * name)
22 : sym_(in_word_set(name)), h_(0)
26 MathSymbolInset::MathSymbolInset(string const & name)
27 : sym_(in_word_set(name.c_str())), h_(0)
32 MathInset * MathSymbolInset::clone() const
34 return new MathSymbolInset(*this);
38 string MathSymbolInset::name() const
44 void MathSymbolInset::metrics(MathMetricsInfo & mi) const
46 //lyxerr << "metrics: symbol: '" << sym_->name
47 // << "' in font: '" << sym_->inset
48 // << "' drawn as: '" << sym_->draw
51 MathFontSetChanger dummy(mi.base, sym_->inset.c_str());
52 mathed_string_dim(mi.base.font, sym_->draw, dim_);
53 // correct height for broken cmex and wasy font
54 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
59 // seperate things a bit
60 int const em = mathed_char_width(mi.base.font, 'M');
62 dim_.w += static_cast<int>(0.5*em+0.5);
64 dim_.w += static_cast<int>(0.15*em+0.5);
67 if (mi.base.style == LM_ST_DISPLAY)
68 if (sym_->inset == "cmex" || sym_->extra == "funclim")
73 void MathSymbolInset::draw(MathPainterInfo & pi, int x, int y) const
75 //lyxerr << "metrics: symbol: '" << sym_->name
76 // << "' in font: '" << sym_->inset
77 // << "' drawn as: '" << sym_->draw
79 int const em = mathed_char_width(pi.base.font, 'M');
81 x += static_cast<int>(0.25*em+0.5);
83 x += static_cast<int>(0.075*em+0.5);
85 MathFontSetChanger dummy(pi.base, sym_->inset.c_str());
86 drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
90 bool MathSymbolInset::isRelOp() const
92 return sym_->extra == "mathrel";
96 bool MathSymbolInset::isScriptable() const
102 bool MathSymbolInset::takesLimits() const
105 sym_->inset == "cmex" ||
106 sym_->inset == "lyxboldsymb" ||
107 sym_->extra == "funclim";
111 void MathSymbolInset::validate(LaTeXFeatures & features) const
113 if (sym_->inset == "msa" || sym_->inset == "msb")
114 features.require("amssymb");
118 void MathSymbolInset::normalize(NormalStream & os) const
120 os << "[symbol " << name() << "]";
124 void MathSymbolInset::maplize(MapleStream & os) const
126 if (name() == "cdot")
128 else if (name() == "infty")
134 void MathSymbolInset::mathematicize(MathematicaStream & os) const
136 if ( name() == "pi") { os << "Pi"; return;}
137 if ( name() == "infty") { os << "Infinity"; return;}
142 char const * MathMLtype(string const & s)
150 bool MathSymbolInset::match(MathAtom const & at) const
152 MathSymbolInset const * q = at->asSymbolInset();
153 return q && name() == q->name();
157 void MathSymbolInset::mathmlize(MathMLStream & os) const
159 char const * type = MathMLtype(sym_->extra);
160 os << '<' << type << "> ";
161 if (sym_->xmlname == "x") // unknown so far
165 os << " </" << type << '>';
169 void MathSymbolInset::octavize(OctaveStream & os) const
171 if (name() == "cdot")
178 void MathSymbolInset::write(WriteStream & os) const
180 os << '\\' << name();
181 os.pendingSpace(true);
185 void MathSymbolInset::infoize(std::ostream & os) const
187 os << "Symbol: " << name();