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"
29 MathSymbolInset::MathSymbolInset(latexkeys const * l)
30 : sym_(l), h_(0), width_(0), scriptable_(false)
34 MathSymbolInset::MathSymbolInset(char const * name)
35 : sym_(in_word_set(name)), h_(0), width_(0), scriptable_(false)
39 MathSymbolInset::MathSymbolInset(string const & name)
40 : sym_(in_word_set(name.c_str())), h_(0), width_(0), scriptable_(false)
44 auto_ptr<InsetBase> MathSymbolInset::doClone() const
46 return auto_ptr<InsetBase>(new MathSymbolInset(*this));
50 string MathSymbolInset::name() const
56 void MathSymbolInset::metrics(MetricsInfo & mi, Dimension & dim) const
58 //lyxerr << "metrics: symbol: '" << sym_->name
59 // << "' in font: '" << sym_->inset
60 // << "' drawn as: '" << sym_->draw
61 // << "'" << std::endl;
63 int const em = mathed_char_width(mi.base.font, 'M');
64 FontSetChanger dummy(mi.base, sym_->inset.c_str());
65 mathed_string_dim(mi.base.font, sym_->draw, dim);
66 // correct height for broken cmex and wasy font
67 #if defined(__APPLE__) && defined(__GNUC__)
68 if (sym_->inset == "cmex") {
73 } else if (sym_->inset == "wasy") {
79 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
85 // seperate things a bit
87 dim.wid += static_cast<int>(0.5 * em + 0.5);
89 dim.wid += static_cast<int>(0.1667 * em + 0.5);
92 if (mi.base.style == LM_ST_DISPLAY)
93 if (sym_->inset == "cmex" || sym_->extra == "funclim")
100 void MathSymbolInset::draw(PainterInfo & pi, int x, int y) const
102 //lyxerr << "metrics: symbol: '" << sym_->name
103 // << "' in font: '" << sym_->inset
104 // << "' drawn as: '" << sym_->draw
105 // << "'" << std::endl;
106 int const em = mathed_char_width(pi.base.font, 'M');
108 x += static_cast<int>(0.25*em+0.5);
110 x += static_cast<int>(0.0833*em+0.5);
112 FontSetChanger dummy(pi.base, sym_->inset.c_str());
113 string const sym = sym_->draw;
114 docstring const dsym(sym.begin(), sym.end());
115 pi.draw(x, y - h_, dsym);
119 bool MathSymbolInset::isRelOp() const
121 return sym_->extra == "mathrel";
125 bool MathSymbolInset::isScriptable() const
131 bool MathSymbolInset::takesLimits() const
134 sym_->inset == "cmex" ||
135 sym_->inset == "lyxboldsymb" ||
136 sym_->extra == "funclim";
140 void MathSymbolInset::validate(LaTeXFeatures & features) const
142 if (!sym_->requires.empty())
143 features.require(sym_->requires);
147 void MathSymbolInset::normalize(NormalStream & os) const
149 os << "[symbol " << name() << ']';
153 void MathSymbolInset::maple(MapleStream & os) const
155 if (name() == "cdot")
157 else if (name() == "infty")
163 void MathSymbolInset::maxima(MaximaStream & os) const
165 if (name() == "cdot")
167 else if (name() == "infty")
174 void MathSymbolInset::mathematica(MathematicaStream & os) const
176 if ( name() == "pi") { os << "Pi"; return;}
177 if ( name() == "infty") { os << "Infinity"; return;}
182 char const * MathMLtype(string const & s)
190 void MathSymbolInset::mathmlize(MathMLStream & os) const
192 char const * type = MathMLtype(sym_->extra);
193 os << '<' << type << "> ";
194 if (sym_->xmlname == "x") // unknown so far
198 os << " </" << type << '>';
202 void MathSymbolInset::octave(OctaveStream & os) const
204 if (name() == "cdot")
211 void MathSymbolInset::write(WriteStream & os) const
213 os << '\\' << name();
214 os.pendingSpace(true);
218 void MathSymbolInset::infoize2(std::ostream & os) const
220 os << "Symbol: " << name();