2 * \file math_symbolinset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
8 * Full author contact details are available in file CREDITS.
13 #include "math_symbolinset.h"
14 #include "dimension.h"
15 #include "math_mathmlstream.h"
16 #include "math_streamstr.h"
17 #include "math_support.h"
18 #include "math_parser.h"
19 #include "math_atom.h"
20 #include "LaTeXFeatures.h"
27 MathSymbolInset::MathSymbolInset(latexkeys const * l)
32 MathSymbolInset::MathSymbolInset(char const * name)
33 : sym_(in_word_set(name)), h_(0)
37 MathSymbolInset::MathSymbolInset(string const & name)
38 : sym_(in_word_set(name.c_str())), h_(0)
42 auto_ptr<InsetBase> MathSymbolInset::clone() const
44 return auto_ptr<InsetBase>(new MathSymbolInset(*this));
48 string MathSymbolInset::name() const
54 void MathSymbolInset::metrics(MetricsInfo & mi, Dimension & dim) const
56 //lyxerr << "metrics: symbol: '" << sym_->name
57 // << "' in font: '" << sym_->inset
58 // << "' drawn as: '" << sym_->draw
59 // << "'" << std::endl;
61 int const em = mathed_char_width(mi.base.font, 'M');
62 FontSetChanger dummy(mi.base, sym_->inset.c_str());
63 mathed_string_dim(mi.base.font, sym_->draw, dim);
64 // correct height for broken cmex and wasy font
65 #if defined(__APPLE__) && defined(__GNUC__)
66 if (sym_->inset == "cmex") {
67 h_ = 4 * dim_.des / 5;
71 } else if (sym_->inset == "wasy") {
77 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
83 // seperate things a bit
85 dim.wid += static_cast<int>(0.5 * em + 0.5);
87 dim.wid += static_cast<int>(0.1667 * em + 0.5);
90 if (mi.base.style == LM_ST_DISPLAY)
91 if (sym_->inset == "cmex" || sym_->extra == "funclim")
96 void MathSymbolInset::draw(PainterInfo & pi, int x, int y) const
98 //lyxerr << "metrics: symbol: '" << sym_->name
99 // << "' in font: '" << sym_->inset
100 // << "' drawn as: '" << sym_->draw
101 // << "'" << std::endl;
102 int const em = mathed_char_width(pi.base.font, 'M');
104 x += static_cast<int>(0.25*em+0.5);
106 x += static_cast<int>(0.0833*em+0.5);
108 FontSetChanger dummy(pi.base, sym_->inset.c_str());
109 drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
113 bool MathSymbolInset::isRelOp() const
115 return sym_->extra == "mathrel";
119 bool MathSymbolInset::isScriptable() const
125 bool MathSymbolInset::takesLimits() const
128 sym_->inset == "cmex" ||
129 sym_->inset == "lyxboldsymb" ||
130 sym_->extra == "funclim";
134 void MathSymbolInset::validate(LaTeXFeatures & features) const
136 if (sym_->inset == "msa" || sym_->inset == "msb")
137 features.require("amssymb");
141 void MathSymbolInset::normalize(NormalStream & os) const
143 os << "[symbol " << name() << ']';
147 void MathSymbolInset::maple(MapleStream & os) const
149 if (name() == "cdot")
151 else if (name() == "infty")
157 void MathSymbolInset::maxima(MaximaStream & os) const
159 if (name() == "cdot")
161 else if (name() == "infty")
168 void MathSymbolInset::mathematica(MathematicaStream & os) const
170 if ( name() == "pi") { os << "Pi"; return;}
171 if ( name() == "infty") { os << "Infinity"; return;}
176 char const * MathMLtype(string const & s)
184 bool MathSymbolInset::match(MathAtom const & at) const
186 MathSymbolInset const * q = at->asSymbolInset();
187 return q && name() == q->name();
191 void MathSymbolInset::mathmlize(MathMLStream & os) const
193 char const * type = MathMLtype(sym_->extra);
194 os << '<' << type << "> ";
195 if (sym_->xmlname == "x") // unknown so far
199 os << " </" << type << '>';
203 void MathSymbolInset::octave(OctaveStream & os) const
205 if (name() == "cdot")
212 void MathSymbolInset::write(WriteStream & os) const
214 os << '\\' << name();
215 os.pendingSpace(true);
219 void MathSymbolInset::infoize2(std::ostream & os) const
221 os << "Symbol: " << name();