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 em = mathed_char_width(mi.base.font, 'M');
62 // \not is a special case.
63 // It must have 0 width to align properly with the next symbol.
66 dim_.w += static_cast<int>(0.5*em+0.5);
68 dim_.w += static_cast<int>(0.15*em+0.5);
71 if (mi.base.style == LM_ST_DISPLAY)
72 if (sym_->inset == "cmex" || sym_->extra == "funclim")
77 void MathSymbolInset::draw(MathPainterInfo & pi, int x, int y) const
79 //lyxerr << "metrics: symbol: '" << sym_->name
80 // << "' in font: '" << sym_->inset
81 // << "' drawn as: '" << sym_->draw
83 int em = mathed_char_width(pi.base.font, 'M');
84 // Here we don't need a special case for \not, as it needs the same
85 // increase in x as the next symbol.
87 x += static_cast<int>(0.25*em+0.5);
89 x += static_cast<int>(0.075*em+0.5);
91 MathFontSetChanger dummy(pi.base, sym_->inset.c_str());
92 drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
96 bool MathSymbolInset::isRelOp() const
98 return sym_->extra == "mathrel";
102 bool MathSymbolInset::isScriptable() const
108 bool MathSymbolInset::takesLimits() const
111 sym_->inset == "cmex" ||
112 sym_->inset == "lyxboldsymb" ||
113 sym_->extra == "funclim";
117 void MathSymbolInset::validate(LaTeXFeatures & features) const
119 if (sym_->inset == "msa" || sym_->inset == "msb")
120 features.require("amssymb");
124 void MathSymbolInset::normalize(NormalStream & os) const
126 os << "[symbol " << name() << "]";
130 void MathSymbolInset::maplize(MapleStream & os) const
132 if (name() == "cdot")
134 else if (name() == "infty")
140 void MathSymbolInset::mathematicize(MathematicaStream & os) const
142 if ( name() == "pi") { os << "Pi"; return;}
143 if ( name() == "infty") { os << "Infinity"; return;}
148 char const * MathMLtype(string const & s)
156 bool MathSymbolInset::match(MathAtom const & at) const
158 MathSymbolInset const * q = at->asSymbolInset();
159 return q && name() == q->name();
163 void MathSymbolInset::mathmlize(MathMLStream & os) const
165 char const * type = MathMLtype(sym_->extra);
166 os << '<' << type << "> ";
167 if (sym_->xmlname == "x") // unknown so far
171 os << " </" << type << '>';
175 void MathSymbolInset::octavize(OctaveStream & os) const
177 if (name() == "cdot")
184 void MathSymbolInset::write(WriteStream & os) const
186 os << '\\' << name();
187 os.pendingSpace(true);
191 void MathSymbolInset::infoize(std::ostream & os) const
193 os << "Symbol: " << name();