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"
12 MathSymbolInset::MathSymbolInset(const latexkeys * l)
17 MathSymbolInset::MathSymbolInset(const char * name)
18 : sym_(in_word_set(name)), h_(0)
22 MathSymbolInset::MathSymbolInset(string const & name)
23 : sym_(in_word_set(name.c_str())), h_(0)
28 MathInset * MathSymbolInset::clone() const
30 return new MathSymbolInset(*this);
34 MathTextCodes MathSymbolInset::code() const
55 MathTextCodes MathSymbolInset::code2() const
57 if (sym_->token == LM_TK_CMEX)
58 return LM_TC_BOLDSYMB;
64 string MathSymbolInset::name() const
70 void MathSymbolInset::metrics(MathMetricsInfo const & mi) const
73 MathTextCodes c = code();
74 if (sym_->latex_font_id > 0 && math_font_available(c)) {
75 mathed_char_dim(c, mi_, sym_->latex_font_id, ascent_, descent_, width_);
76 if (c == LM_TC_CMEX) {
77 h_ = 4 * descent_ / 5;
82 if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
83 mathed_char_dim(code2(), mi_, sym_->id, ascent_, descent_, width_);
85 mathed_string_dim(LM_TC_TEX, mi_, sym_->name, ascent_, descent_, width_);
88 width_ += mathed_char_width(LM_TC_TEX, mi_, 'I');
92 void MathSymbolInset::draw(Painter & pain, int x, int y) const
95 x += mathed_char_width(LM_TC_TEX, mi_, 'I') / 2;
96 MathTextCodes Code = code();
97 if (sym_->latex_font_id > 0 && math_font_available(Code))
98 drawChar(pain, Code, mi_, x, y - h_, sym_->latex_font_id);
99 else if (sym_->id > 0 && sym_->id < 255 && math_font_available(LM_TC_SYMB))
100 drawChar(pain, code2(), mi_, x, y, sym_->id);
102 drawStr(pain, LM_TC_TEX, mi_, x, y, sym_->name);
106 bool MathSymbolInset::isRelOp() const
108 return sym_->type == "mathrel";
112 bool MathSymbolInset::isScriptable() const
114 return mi_.style == LM_ST_DISPLAY && sym_->token == LM_TK_CMEX;
118 bool MathSymbolInset::takesLimits() const
120 return sym_->token == LM_TK_CMEX;
123 void MathSymbolInset::validate(LaTeXFeatures & features) const
125 if (sym_->token == LM_TK_MSA || sym_->token == LM_TK_MSB)
126 features.require("amssymb");
129 void MathSymbolInset::normalize(NormalStream & os) const
131 os << "[symbol " << name() << "]";
135 void MathSymbolInset::maplize(MapleStream & os) const
137 if (name() == "cdot")
144 char const * MathMLtype(string const & s)
152 bool MathSymbolInset::match(MathInset * p) const
154 MathSymbolInset const * q = p->asSymbolInset();
155 return q && name() == q->name();
159 void MathSymbolInset::mathmlize(MathMLStream & os) const
161 char const * type = MathMLtype(sym_->type);
162 os << '<' << type << "> ";
163 if (sym_->xmlname == "x") // unknown so far
167 os << " </" << type << '>';
171 void MathSymbolInset::octavize(OctaveStream & os) const
173 if (name() == "cdot")
180 void MathSymbolInset::write(WriteStream & os) const
182 os << '\\' << name() << ' ';
186 void MathSymbolInset::infoize(std::ostream & os) const
188 os << '\\' << name();