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"
28 MathSymbolInset::MathSymbolInset(latexkeys const * l)
33 MathSymbolInset::MathSymbolInset(char const * name)
34 : sym_(in_word_set(name)), h_(0)
38 MathSymbolInset::MathSymbolInset(string const & name)
39 : sym_(in_word_set(name.c_str())), h_(0)
43 auto_ptr<InsetBase> MathSymbolInset::doClone() const
45 return auto_ptr<InsetBase>(new MathSymbolInset(*this));
49 string MathSymbolInset::name() const
55 void MathSymbolInset::metrics(MetricsInfo & mi, Dimension & dim) const
57 //lyxerr << "metrics: symbol: '" << sym_->name
58 // << "' in font: '" << sym_->inset
59 // << "' drawn as: '" << sym_->draw
60 // << "'" << std::endl;
62 int const em = mathed_char_width(mi.base.font, 'M');
63 FontSetChanger dummy(mi.base, sym_->inset.c_str());
64 mathed_string_dim(mi.base.font, sym_->draw, dim);
65 // correct height for broken cmex and wasy font
66 #if defined(__APPLE__) && defined(__GNUC__)
67 if (sym_->inset == "cmex") {
72 } else if (sym_->inset == "wasy") {
78 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
84 // seperate things a bit
86 dim.wid += static_cast<int>(0.5 * em + 0.5);
88 dim.wid += static_cast<int>(0.1667 * em + 0.5);
91 if (mi.base.style == LM_ST_DISPLAY)
92 if (sym_->inset == "cmex" || sym_->extra == "funclim")
99 void MathSymbolInset::draw(PainterInfo & pi, int x, int y) const
101 //lyxerr << "metrics: symbol: '" << sym_->name
102 // << "' in font: '" << sym_->inset
103 // << "' drawn as: '" << sym_->draw
104 // << "'" << std::endl;
105 int const em = mathed_char_width(pi.base.font, 'M');
107 x += static_cast<int>(0.25*em+0.5);
109 x += static_cast<int>(0.0833*em+0.5);
111 FontSetChanger dummy(pi.base, sym_->inset.c_str());
112 pi.draw(x, y - h_, sym_->draw);
116 bool MathSymbolInset::isRelOp() const
118 return sym_->extra == "mathrel";
122 bool MathSymbolInset::isScriptable() const
128 bool MathSymbolInset::takesLimits() const
131 sym_->inset == "cmex" ||
132 sym_->inset == "lyxboldsymb" ||
133 sym_->extra == "funclim";
137 void MathSymbolInset::validate(LaTeXFeatures & features) const
139 if (!sym_->requires.empty())
140 features.require(sym_->requires);
144 void MathSymbolInset::normalize(NormalStream & os) const
146 os << "[symbol " << name() << ']';
150 void MathSymbolInset::maple(MapleStream & os) const
152 if (name() == "cdot")
154 else if (name() == "infty")
160 void MathSymbolInset::maxima(MaximaStream & os) const
162 if (name() == "cdot")
164 else if (name() == "infty")
171 void MathSymbolInset::mathematica(MathematicaStream & os) const
173 if ( name() == "pi") { os << "Pi"; return;}
174 if ( name() == "infty") { os << "Infinity"; return;}
179 char const * MathMLtype(string const & s)
187 void MathSymbolInset::mathmlize(MathMLStream & os) const
189 char const * type = MathMLtype(sym_->extra);
190 os << '<' << type << "> ";
191 if (sym_->xmlname == "x") // unknown so far
195 os << " </" << type << '>';
199 void MathSymbolInset::octave(OctaveStream & os) const
201 if (name() == "cdot")
208 void MathSymbolInset::write(WriteStream & os) const
210 os << '\\' << name();
211 os.pendingSpace(true);
215 void MathSymbolInset::infoize2(std::ostream & os) const
217 os << "Symbol: " << name();