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"
16 MathSymbolInset::MathSymbolInset(latexkeys const * l)
21 MathSymbolInset::MathSymbolInset(char const * 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)
31 auto_ptr<InsetBase> MathSymbolInset::clone() const
33 return auto_ptr<InsetBase>(new MathSymbolInset(*this));
37 string MathSymbolInset::name() const
43 void MathSymbolInset::metrics(MetricsInfo & mi, Dimension & dim) const
45 //lyxerr << "metrics: symbol: '" << sym_->name
46 // << "' in font: '" << sym_->inset
47 // << "' drawn as: '" << sym_->draw
50 int const em = mathed_char_width(mi.base.font, 'M');
51 FontSetChanger 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
61 dim.wid += static_cast<int>(0.5 * em + 0.5);
63 dim.wid += static_cast<int>(0.1667 * em + 0.5);
66 if (mi.base.style == LM_ST_DISPLAY)
67 if (sym_->inset == "cmex" || sym_->extra == "funclim")
72 void MathSymbolInset::draw(PainterInfo & pi, int x, int y) const
74 //lyxerr << "metrics: symbol: '" << sym_->name
75 // << "' in font: '" << sym_->inset
76 // << "' drawn as: '" << sym_->draw
78 int const em = mathed_char_width(pi.base.font, 'M');
80 x += static_cast<int>(0.25*em+0.5);
82 x += static_cast<int>(0.0833*em+0.5);
84 FontSetChanger dummy(pi.base, sym_->inset.c_str());
85 drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
89 bool MathSymbolInset::isRelOp() const
91 return sym_->extra == "mathrel";
95 bool MathSymbolInset::isScriptable() const
101 bool MathSymbolInset::takesLimits() const
104 sym_->inset == "cmex" ||
105 sym_->inset == "lyxboldsymb" ||
106 sym_->extra == "funclim";
110 void MathSymbolInset::validate(LaTeXFeatures & features) const
112 if (sym_->inset == "msa" || sym_->inset == "msb")
113 features.require("amssymb");
117 void MathSymbolInset::normalize(NormalStream & os) const
119 os << "[symbol " << name() << ']';
123 void MathSymbolInset::maple(MapleStream & os) const
125 if (name() == "cdot")
127 else if (name() == "infty")
133 void MathSymbolInset::maxima(MaximaStream & os) const
135 if (name() == "cdot")
137 else if (name() == "infty")
144 void MathSymbolInset::mathematica(MathematicaStream & os) const
146 if ( name() == "pi") { os << "Pi"; return;}
147 if ( name() == "infty") { os << "Infinity"; return;}
152 char const * MathMLtype(string const & s)
160 bool MathSymbolInset::match(MathAtom const & at) const
162 MathSymbolInset const * q = at->asSymbolInset();
163 return q && name() == q->name();
167 void MathSymbolInset::mathmlize(MathMLStream & os) const
169 char const * type = MathMLtype(sym_->extra);
170 os << '<' << type << "> ";
171 if (sym_->xmlname == "x") // unknown so far
175 os << " </" << type << '>';
179 void MathSymbolInset::octave(OctaveStream & os) const
181 if (name() == "cdot")
188 void MathSymbolInset::write(WriteStream & os) const
190 os << '\\' << name();
191 os.pendingSpace(true);
195 void MathSymbolInset::infoize2(std::ostream & os) const
197 os << "Symbol: " << name();