2 * \file InsetMathSymbol.cpp
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"
24 #include "support/textutils.h"
32 InsetMathSymbol::InsetMathSymbol(latexkeys const * l)
33 : sym_(l), h_(0), scriptable_(false)
37 InsetMathSymbol::InsetMathSymbol(char const * name)
38 : sym_(in_word_set(from_ascii(name))), h_(0), scriptable_(false)
42 InsetMathSymbol::InsetMathSymbol(docstring const & name)
43 : sym_(in_word_set(name)), h_(0), scriptable_(false)
47 auto_ptr<Inset> InsetMathSymbol::doClone() const
49 return auto_ptr<Inset>(new InsetMathSymbol(*this));
53 docstring InsetMathSymbol::name() const
59 bool InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
61 //lyxerr << "metrics: symbol: '" << sym_->name
62 // << "' in font: '" << sym_->inset
63 // << "' drawn as: '" << sym_->draw
64 // << "'" << std::endl;
66 int const em = mathed_char_width(mi.base.font, 'M');
67 FontSetChanger dummy(mi.base, sym_->inset);
68 mathed_string_dim(mi.base.font, sym_->draw, dim);
69 docstring::const_reverse_iterator rit = sym_->draw.rbegin();
70 kerning_ = mathed_char_kerning(mi.base.font, *rit);
71 // correct height for broken cmex and wasy font
72 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
77 // seperate things a bit
79 dim.wid += static_cast<int>(0.5 * em + 0.5);
81 dim.wid += static_cast<int>(0.1667 * em + 0.5);
84 if (mi.base.style == LM_ST_DISPLAY)
85 if (sym_->inset == "cmex" || sym_->inset == "esint" ||
86 sym_->extra == "funclim")
97 void InsetMathSymbol::draw(PainterInfo & pi, int x, int y) const
99 //lyxerr << "metrics: symbol: '" << sym_->name
100 // << "' in font: '" << sym_->inset
101 // << "' drawn as: '" << sym_->draw
102 // << "'" << std::endl;
103 int const em = mathed_char_width(pi.base.font, 'M');
105 x += static_cast<int>(0.25*em+0.5);
107 x += static_cast<int>(0.0833*em+0.5);
109 FontSetChanger dummy(pi.base, sym_->inset.c_str());
110 pi.draw(x, y - h_, sym_->draw);
114 bool InsetMathSymbol::isRelOp() const
116 return sym_->extra == "mathrel";
120 bool InsetMathSymbol::isOrdAlpha() const
122 return sym_->extra == "mathord" || sym_->extra == "mathalpha";
126 bool InsetMathSymbol::isScriptable() const
132 bool InsetMathSymbol::takesLimits() const
135 sym_->inset == "cmex" ||
136 sym_->inset == "lyxboldsymb" ||
137 sym_->inset == "esint" ||
138 sym_->extra == "funclim";
142 void InsetMathSymbol::validate(LaTeXFeatures & features) const
144 if (!sym_->requires.empty())
145 features.require(to_utf8(sym_->requires));
149 void InsetMathSymbol::normalize(NormalStream & os) const
151 os << "[symbol " << name() << ']';
155 void InsetMathSymbol::maple(MapleStream & os) const
157 if (name() == "cdot")
159 else if (name() == "infty")
165 void InsetMathSymbol::maxima(MaximaStream & os) const
167 if (name() == "cdot")
169 else if (name() == "infty")
171 else if (name() == "pi")
178 void InsetMathSymbol::mathematica(MathematicaStream & os) const
180 if ( name() == "pi") { os << "Pi"; return;}
181 if ( name() == "infty") { os << "Infinity"; return;}
182 if ( name() == "cdot") { os << '*'; return;}
187 char const * MathMLtype(docstring const & s)
195 void InsetMathSymbol::mathmlize(MathStream & os) const
197 char const * type = MathMLtype(sym_->extra);
198 os << '<' << type << "> ";
199 if (sym_->xmlname == "x") // unknown so far
203 os << " </" << type << '>';
207 void InsetMathSymbol::octave(OctaveStream & os) const
209 if (name() == "cdot")
216 void InsetMathSymbol::write(WriteStream & os) const
218 os << '\\' << name();
220 // $,#, etc. In theory the restriction based on catcodes, but then
221 // we do not handle catcodes very well, let alone cat code changes,
222 // so being outside the alpha range is good enough.
223 if (name().size() == 1 && !isAlphaASCII(name()[0]))
226 os.pendingSpace(true);
230 void InsetMathSymbol::infoize2(odocstream & os) const
232 os << "Symbol: " << name();