2 * \file InsetMathSymbol.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 "InsetMathSymbol.h"
14 #include "dimension.h"
15 #include "MathStream.h"
16 #include "MathStream.h"
17 #include "MathSupport.h"
18 #include "MathParser.h"
20 #include "LaTeXFeatures.h"
30 InsetMathSymbol::InsetMathSymbol(latexkeys const * l)
31 : sym_(l), h_(0), width_(0), scriptable_(false)
35 InsetMathSymbol::InsetMathSymbol(char const * name)
36 : sym_(in_word_set(from_ascii(name))), h_(0), width_(0), scriptable_(false)
40 InsetMathSymbol::InsetMathSymbol(docstring const & name)
41 : sym_(in_word_set(name)), h_(0), width_(0), scriptable_(false)
45 auto_ptr<InsetBase> InsetMathSymbol::doClone() const
47 return auto_ptr<InsetBase>(new InsetMathSymbol(*this));
51 docstring InsetMathSymbol::name() const
57 bool InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
59 //lyxerr << "metrics: symbol: '" << sym_->name
60 // << "' in font: '" << sym_->inset
61 // << "' drawn as: '" << sym_->draw
62 // << "'" << std::endl;
64 int const em = mathed_char_width(mi.base.font, 'M');
65 FontSetChanger dummy(mi.base, sym_->inset);
66 mathed_string_dim(mi.base.font, sym_->draw, dim);
67 // correct height for broken cmex and wasy font
68 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
74 // seperate things a bit
76 dim.wid += static_cast<int>(0.5 * em + 0.5);
78 dim.wid += static_cast<int>(0.1667 * em + 0.5);
81 if (mi.base.style == LM_ST_DISPLAY)
82 if (sym_->inset == "cmex" || sym_->inset == "esint" ||
83 sym_->extra == "funclim")
94 void InsetMathSymbol::draw(PainterInfo & pi, int x, int y) const
96 //lyxerr << "metrics: symbol: '" << sym_->name
97 // << "' in font: '" << sym_->inset
98 // << "' drawn as: '" << sym_->draw
99 // << "'" << std::endl;
100 int const em = mathed_char_width(pi.base.font, 'M');
102 x += static_cast<int>(0.25*em+0.5);
104 x += static_cast<int>(0.0833*em+0.5);
106 FontSetChanger dummy(pi.base, sym_->inset.c_str());
107 pi.draw(x, y - h_, sym_->draw);
111 bool InsetMathSymbol::isRelOp() const
113 return sym_->extra == "mathrel";
117 bool InsetMathSymbol::isScriptable() const
123 bool InsetMathSymbol::takesLimits() const
126 sym_->inset == "cmex" ||
127 sym_->inset == "lyxboldsymb" ||
128 sym_->inset == "esint" ||
129 sym_->extra == "funclim";
133 void InsetMathSymbol::validate(LaTeXFeatures & features) const
135 if (!sym_->requires.empty())
136 features.require(to_utf8(sym_->requires));
140 void InsetMathSymbol::normalize(NormalStream & os) const
142 os << "[symbol " << name() << ']';
146 void InsetMathSymbol::maple(MapleStream & os) const
148 if (name() == "cdot")
150 else if (name() == "infty")
156 void InsetMathSymbol::maxima(MaximaStream & os) const
158 if (name() == "cdot")
160 else if (name() == "infty")
162 else if (name() == "pi")
169 void InsetMathSymbol::mathematica(MathematicaStream & os) const
171 if ( name() == "pi") { os << "Pi"; return;}
172 if ( name() == "infty") { os << "Infinity"; return;}
173 if ( name() == "cdot") { os << '*'; return;}
178 char const * MathMLtype(docstring const & s)
186 void InsetMathSymbol::mathmlize(MathStream & os) const
188 char const * type = MathMLtype(sym_->extra);
189 os << '<' << type << "> ";
190 if (sym_->xmlname == "x") // unknown so far
194 os << " </" << type << '>';
198 void InsetMathSymbol::octave(OctaveStream & os) const
200 if (name() == "cdot")
207 void InsetMathSymbol::write(WriteStream & os) const
209 os << '\\' << name();
210 os.pendingSpace(true);
214 void InsetMathSymbol::infoize2(odocstream & os) const
216 os << "Symbol: " << name();