3 #include "math_symbolinset.h"
4 #include "math_mathmlstream.h"
5 #include "math_streamstr.h"
6 #include "math_support.h"
7 #include "math_parser.h"
8 #include "LaTeXFeatures.h"
15 MathSymbolInset::MathSymbolInset(const latexkeys * l)
20 MathSymbolInset::MathSymbolInset(const char * name)
21 : sym_(in_word_set(name)), h_(0)
25 MathSymbolInset::MathSymbolInset(string const & name)
26 : sym_(in_word_set(name.c_str())), h_(0)
31 MathInset * MathSymbolInset::clone() const
33 return new MathSymbolInset(*this);
37 MathTextCodes MathSymbolInset::code() const
39 switch (sym_->token) {
58 MathTextCodes MathSymbolInset::code2() const
60 if (sym_->token == LM_TK_CMEX)
61 return LM_TC_BOLDSYMB;
67 string MathSymbolInset::name() const
73 void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
77 MathTextCodes c = code();
78 if (sym_->latex_font_id > 0 && math_font_available(c)) {
79 whichFont(font, c, mi_);
80 mathed_char_dim(font, char(sym_->latex_font_id), ascent_, descent_, width_);
81 if (c == LM_TC_CMEX) {
82 h_ = 4 * descent_ / 5;
87 if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB)) {
88 whichFont(font, code2(), mi_);
89 mathed_char_dim(font, char(sym_->id), ascent_, descent_, width_);
91 whichFont(font, LM_TC_TEX, mi_);
92 mathed_string_dim(font, sym_->name, ascent_, descent_, width_);
100 void MathSymbolInset::draw(Painter & pain, int x, int y) const
104 MathTextCodes Code = code();
106 if (sym_->latex_font_id > 0 && math_font_available(Code)) {
107 whichFont(font, Code, mi_);
108 drawChar(pain, font, x, y - h_, char(sym_->latex_font_id));
109 } else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB)){
110 whichFont(font, code2(), mi_);
111 drawChar(pain, font, x, y, char(sym_->id));
113 whichFont(font, LM_TC_TEX, mi_);
114 drawStr(pain, font, x, y, sym_->name);
119 bool MathSymbolInset::isRelOp() const
121 return sym_->type == "mathrel";
125 bool MathSymbolInset::isScriptable() const
127 return mi_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
131 bool MathSymbolInset::takesLimits() const
133 return sym_->token == LM_TK_CMEX;
136 void MathSymbolInset::validate(LaTeXFeatures & features) const
138 if (sym_->token == LM_TK_MSA || sym_->token == LM_TK_MSB)
139 features.require("amssymb");
142 void MathSymbolInset::normalize(NormalStream & os) const
144 os << "[symbol " << name() << "]";
148 void MathSymbolInset::maplize(MapleStream & os) const
150 if (name() == "cdot")
157 char const * MathMLtype(string const & s)
165 bool MathSymbolInset::match(MathInset * p) const
167 MathSymbolInset const * q = p->asSymbolInset();
168 return q && name() == q->name();
172 void MathSymbolInset::mathmlize(MathMLStream & os) const
174 char const * type = MathMLtype(sym_->type);
175 os << '<' << type << "> ";
176 if (sym_->xmlname == "x") // unknown so far
180 os << " </" << type << '>';
184 void MathSymbolInset::octavize(OctaveStream & os) const
186 if (name() == "cdot")
193 void MathSymbolInset::write(WriteStream & os) const
195 os << '\\' << name() << ' ';
199 void MathSymbolInset::infoize(ostream & os) const
201 os << '\\' << name();