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 int const em = mathed_char_width(mi.base.font, 'M');
52 MathFontSetChanger dummy(mi.base, sym_->inset.c_str());
53 mathed_string_dim(mi.base.font, sym_->draw, dim_);
54 // correct height for broken cmex and wasy font
55 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
60 // seperate things a bit
62 dim_.w += static_cast<int>(0.5*em+0.5);
64 dim_.w += static_cast<int>(0.1667*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.0833*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::maximize(MaximaStream & os) const
136 if (name() == "cdot")
138 else if (name() == "infty")
145 void MathSymbolInset::mathematicize(MathematicaStream & os) const
147 if ( name() == "pi") { os << "Pi"; return;}
148 if ( name() == "infty") { os << "Infinity"; return;}
153 char const * MathMLtype(string const & s)
161 bool MathSymbolInset::match(MathAtom const & at) const
163 MathSymbolInset const * q = at->asSymbolInset();
164 return q && name() == q->name();
168 void MathSymbolInset::mathmlize(MathMLStream & os) const
170 char const * type = MathMLtype(sym_->extra);
171 os << '<' << type << "> ";
172 if (sym_->xmlname == "x") // unknown so far
176 os << " </" << type << '>';
180 void MathSymbolInset::octavize(OctaveStream & os) const
182 if (name() == "cdot")
189 void MathSymbolInset::write(WriteStream & os) const
191 os << '\\' << name();
192 os.pendingSpace(true);
196 void MathSymbolInset::infoize(std::ostream & os) const
198 os << "Symbol: " << name();