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 void 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 defined(__APPLE__) && defined(__GNUC__)
69 if (sym_->inset == "cmex") {
74 } else if (sym_->inset == "wasy") {
80 if (sym_->inset == "cmex" || sym_->inset == "wasy") {
86 // seperate things a bit
88 dim.wid += static_cast<int>(0.5 * em + 0.5);
90 dim.wid += static_cast<int>(0.1667 * em + 0.5);
93 if (mi.base.style == LM_ST_DISPLAY)
94 if (sym_->inset == "cmex" || sym_->extra == "funclim")
101 void InsetMathSymbol::draw(PainterInfo & pi, int x, int y) const
103 //lyxerr << "metrics: symbol: '" << sym_->name
104 // << "' in font: '" << sym_->inset
105 // << "' drawn as: '" << sym_->draw
106 // << "'" << std::endl;
107 int const em = mathed_char_width(pi.base.font, 'M');
109 x += static_cast<int>(0.25*em+0.5);
111 x += static_cast<int>(0.0833*em+0.5);
113 FontSetChanger dummy(pi.base, sym_->inset.c_str());
115 docstring n(sym_->draw.begin(), sym_->draw.end());
116 pi.draw(x, y - h_, n);
120 bool InsetMathSymbol::isRelOp() const
122 return sym_->extra == "mathrel";
126 bool InsetMathSymbol::isScriptable() const
132 bool InsetMathSymbol::takesLimits() const
135 sym_->inset == "cmex" ||
136 sym_->inset == "lyxboldsymb" ||
137 sym_->extra == "funclim";
141 void InsetMathSymbol::validate(LaTeXFeatures & features) const
143 if (!sym_->requires.empty())
144 features.require(to_utf8(sym_->requires));
148 void InsetMathSymbol::normalize(NormalStream & os) const
150 os << "[symbol " << name() << ']';
154 void InsetMathSymbol::maple(MapleStream & os) const
156 if (name() == "cdot")
158 else if (name() == "infty")
164 void InsetMathSymbol::maxima(MaximaStream & os) const
166 if (name() == "cdot")
168 else if (name() == "infty")
170 else if (name() == "pi")
177 void InsetMathSymbol::mathematica(MathematicaStream & os) const
179 if ( name() == "pi") { os << "Pi"; return;}
180 if ( name() == "infty") { os << "Infinity"; return;}
181 if ( name() == "cdot") { os << '*'; return;}
186 char const * MathMLtype(docstring const & s)
194 void InsetMathSymbol::mathmlize(MathStream & os) const
196 char const * type = MathMLtype(sym_->extra);
197 os << '<' << type << "> ";
198 if (sym_->xmlname == "x") // unknown so far
202 os << " </" << type << '>';
206 void InsetMathSymbol::octave(OctaveStream & os) const
208 if (name() == "cdot")
215 void InsetMathSymbol::write(WriteStream & os) const
217 os << '\\' << name();
218 os.pendingSpace(true);
222 void InsetMathSymbol::infoize2(odocstream & os) const
224 os << "Symbol: " << name();