3 #include "math_deliminset.h"
4 #include "math_parser.h"
5 #include "math_support.h"
6 #include "math_mathmlstream.h"
7 #include "math_streamstr.h"
8 #include "math_extern.h"
15 string convertDelimToLatexName(string const & name)
35 return '\\' + name + ' ';
42 MathDelimInset::MathDelimInset(string const & l, string const & r)
43 : MathNestInset(1), left_(l), right_(r)
47 MathDelimInset::MathDelimInset
48 (string const & l, string const & r, MathArray const & ar)
49 : MathNestInset(1), left_(l), right_(r)
55 InsetBase * MathDelimInset::clone() const
57 return new MathDelimInset(*this);
61 void MathDelimInset::write(WriteStream & os) const
63 os << "\\left" << convertDelimToLatexName(left_) << cell(0)
64 << "\\right" << convertDelimToLatexName(right_);
68 void MathDelimInset::normalize(NormalStream & os) const
70 os << "[delim " << convertDelimToLatexName(left_) << ' '
71 << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
75 void MathDelimInset::metrics(MetricsInfo & mi, Dimension & dim) const
79 mathed_char_dim(mi.base.font, 'I', t);
80 int h0 = (t.asc + t.des) / 2;
81 int a0 = max(cell(0).ascent(), t.asc) - h0;
82 int d0 = max(cell(0).descent(), t.des) + h0;
83 dw_ = cell(0).height() / 5;
88 dim_.wid = cell(0).width() + 2 * dw_ + 8;
89 dim_.asc = max(a0, d0) + h0;
90 dim_.des = max(a0, d0) - h0;
95 void MathDelimInset::draw(PainterInfo & pi, int x, int y) const
97 int const b = y - dim_.asc;
98 cell(0).draw(pi, x + dw_ + 4, y);
99 mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
100 mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
101 b, dw_, dim_.height(), right_);
105 bool MathDelimInset::isParanthesis() const
107 return left_ == "(" && right_ == ")";
111 bool MathDelimInset::isBrackets() const
113 return left_ == "[" && right_ == "]";
117 bool MathDelimInset::isAbs() const
119 return left_ == "|" && right_ == "|";
123 void MathDelimInset::maple(MapleStream & os) const
126 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
127 os << "linalg[det](" << cell(0) << ')';
129 os << "abs(" << cell(0) << ')';
132 os << left_ << cell(0) << right_;
135 void MathDelimInset::maxima(MaximaStream & os) const
138 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
139 os << "determinant(" << cell(0) << ')';
141 os << "abs(" << cell(0) << ')';
144 os << left_ << cell(0) << right_;
148 void MathDelimInset::mathematica(MathematicaStream & os) const
151 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
152 os << "Det" << cell(0) << ']';
154 os << "Abs[" << cell(0) << ']';
157 os << left_ << cell(0) << right_;
161 void MathDelimInset::mathmlize(MathMLStream & os) const
163 os << "<fenced open=\"" << left_ << "\" close=\""
164 << right_ << "\">" << cell(0) << "</fenced>";
168 void MathDelimInset::octave(OctaveStream & os) const
171 os << "det(" << cell(0) << ')';
173 os << left_ << cell(0) << right_;