3 #include "math_symbolinset.h"
5 #include "math_mathmlstream.h"
6 #include "math_streamstr.h"
7 #include "math_support.h"
8 #include "math_parser.h"
10 #include "LaTeXFeatures.h"
14 MathSymbolInset::MathSymbolInset(latexkeys const * l)
19 MathSymbolInset::MathSymbolInset(char const * name)
20 : sym_(in_word_set(name)), h_(0)
24 MathSymbolInset::MathSymbolInset(string const & name)
25 : sym_(in_word_set(name.c_str())), h_(0)
30 InsetBase * MathSymbolInset::clone() const
32 return new MathSymbolInset(*this);
36 string MathSymbolInset::name() const
42 void MathSymbolInset::metrics(MetricsInfo & mi, Dimension & dim) const
44 //lyxerr << "metrics: symbol: '" << sym_->name
45 // << "' in font: '" << sym_->inset
46 // << "' drawn as: '" << sym_->draw
49 int const em = mathed_char_width(mi.base.font, 'M');
50 FontSetChanger dummy(mi.base, sym_->inset.c_str());
51 mathed_string_dim(mi.base.font, sym_->draw, dim);
52 // correct height for broken cmex and wasy font
53 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
58 // seperate things a bit
60 dim.wid += static_cast<int>(0.5 * em + 0.5);
62 dim.wid += static_cast<int>(0.1667 * em + 0.5);
65 if (mi.base.style == LM_ST_DISPLAY)
66 if (sym_->inset == "cmex" || sym_->extra == "funclim")
71 void MathSymbolInset::draw(PainterInfo & pi, int x, int y) const
73 //lyxerr << "metrics: symbol: '" << sym_->name
74 // << "' in font: '" << sym_->inset
75 // << "' drawn as: '" << sym_->draw
77 int const em = mathed_char_width(pi.base.font, 'M');
79 x += static_cast<int>(0.25*em+0.5);
81 x += static_cast<int>(0.0833*em+0.5);
83 FontSetChanger dummy(pi.base, sym_->inset.c_str());
84 drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
88 bool MathSymbolInset::isRelOp() const
90 return sym_->extra == "mathrel";
94 bool MathSymbolInset::isScriptable() const
100 bool MathSymbolInset::takesLimits() const
103 sym_->inset == "cmex" ||
104 sym_->inset == "lyxboldsymb" ||
105 sym_->extra == "funclim";
109 void MathSymbolInset::validate(LaTeXFeatures & features) const
111 if (sym_->inset == "msa" || sym_->inset == "msb")
112 features.require("amssymb");
116 void MathSymbolInset::normalize(NormalStream & os) const
118 os << "[symbol " << name() << ']';
122 void MathSymbolInset::maple(MapleStream & os) const
124 if (name() == "cdot")
126 else if (name() == "infty")
132 void MathSymbolInset::maxima(MaximaStream & os) const
134 if (name() == "cdot")
136 else if (name() == "infty")
143 void MathSymbolInset::mathematica(MathematicaStream & os) const
145 if ( name() == "pi") { os << "Pi"; return;}
146 if ( name() == "infty") { os << "Infinity"; return;}
151 char const * MathMLtype(string const & s)
159 bool MathSymbolInset::match(MathAtom const & at) const
161 MathSymbolInset const * q = at->asSymbolInset();
162 return q && name() == q->name();
166 void MathSymbolInset::mathmlize(MathMLStream & os) const
168 char const * type = MathMLtype(sym_->extra);
169 os << '<' << type << "> ";
170 if (sym_->xmlname == "x") // unknown so far
174 os << " </" << type << '>';
178 void MathSymbolInset::octave(OctaveStream & os) const
180 if (name() == "cdot")
187 void MathSymbolInset::write(WriteStream & os) const
189 os << '\\' << name();
190 os.pendingSpace(true);
194 void MathSymbolInset::infoize2(std::ostream & os) const
196 os << "Symbol: " << name();