7 #include "math_deliminset.h"
8 #include "math_parser.h"
10 #include "support/LOstream.h"
11 #include "math_mathmlstream.h"
14 MathDelimInset::MathDelimInset(string const & l, string const & r)
15 : MathNestInset(1), left_(l), right_(r)
19 MathInset * MathDelimInset::clone() const
21 return new MathDelimInset(*this);
25 string MathDelimInset::latexName(string const & name)
41 return "\\" + name + " ";
45 void MathDelimInset::write(MathWriteInfo & os) const
47 os << "\\left" << latexName(left_).c_str() << cell(0)
48 << "\\right" << latexName(right_).c_str();
52 void MathDelimInset::writeNormal(NormalStream & os) const
54 os << "[delim " << latexName(left_).c_str() << ' '
55 << latexName(right_).c_str() << ' ' << cell(0) << ']';
59 int MathDelimInset::dw() const
70 void MathDelimInset::metrics(MathMetricsInfo const & mi) const
74 mathed_char_dim(LM_TC_VAR, mi, 'I', a, d, w);
76 int a0 = std::max(xcell(0).ascent(), a) - h0;
77 int d0 = std::max(xcell(0).descent(), d) + h0;
78 ascent_ = std::max(a0, d0) + h0;
79 descent_ = std::max(a0, d0) - h0;
80 width_ = xcell(0).width() + 2 * dw() + 4;
84 void MathDelimInset::draw(Painter & pain, int x, int y) const
87 int const b = y - ascent_;
88 xcell(0).draw(pain, x + w + 2, y);
89 mathed_draw_deco(pain, x + 1, b, w, height(), left_);
90 mathed_draw_deco(pain, x + width() - w - 1, b, w, height(), right_);
94 bool MathDelimInset::isMatrix() const
96 return left_ == "(" && right_ == ")" && cell(0).size() == 1 &&
97 cell(0).begin()->nucleus() && cell(0).begin()->nucleus()->asArrayInset();
101 void MathDelimInset::maplize(MapleStream & os) const
103 if (left_ == "|" && right_ == "|") {
104 if (cell(0).isMatrix())
105 os << "linalg[det](" << cell(0) << ")";
107 os << "abs(" << cell(0) << ")";
110 os << left_.c_str() << cell(0) << right_.c_str();
114 void MathDelimInset::mathmlize(MathMLStream & os) const
116 os << "<fenced open=\"" << left_.c_str() << "\" close=\""
117 << right_.c_str() << "\">" << cell(0) << "</fenced>";
121 void MathDelimInset::octavize(OctaveStream & os) const
123 if (left_ == "|" && right_ == "|")
124 os << "det(" << cell(0) << ")";
126 os << left_.c_str() << cell(0) << right_.c_str();