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"
16 string convertDelimToLatexName(string const & name)
36 return '\\' + name + ' ';
43 MathDelimInset::MathDelimInset(string const & l, string const & r)
44 : MathNestInset(1), left_(l), right_(r)
48 MathDelimInset::MathDelimInset
49 (string const & l, string const & r, MathArray const & ar)
50 : MathNestInset(1), left_(l), right_(r)
56 auto_ptr<InsetBase> MathDelimInset::clone() const
58 return auto_ptr<InsetBase>(new MathDelimInset(*this));
62 void MathDelimInset::write(WriteStream & os) const
64 os << "\\left" << convertDelimToLatexName(left_) << cell(0)
65 << "\\right" << convertDelimToLatexName(right_);
69 void MathDelimInset::normalize(NormalStream & os) const
71 os << "[delim " << convertDelimToLatexName(left_) << ' '
72 << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
76 void MathDelimInset::metrics(MetricsInfo & mi, Dimension & dim) const
80 mathed_char_dim(mi.base.font, 'I', t);
81 int h0 = (t.asc + t.des) / 2;
82 int a0 = max(cell(0).ascent(), t.asc) - h0;
83 int d0 = max(cell(0).descent(), t.des) + h0;
84 dw_ = cell(0).height() / 5;
89 dim_.wid = cell(0).width() + 2 * dw_ + 8;
90 dim_.asc = max(a0, d0) + h0;
91 dim_.des = max(a0, d0) - h0;
96 void MathDelimInset::draw(PainterInfo & pi, int x, int y) const
98 int const b = y - dim_.asc;
99 cell(0).draw(pi, x + dw_ + 4, y);
100 mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
101 mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
102 b, dw_, dim_.height(), right_);
106 bool MathDelimInset::isParanthesis() const
108 return left_ == "(" && right_ == ")";
112 bool MathDelimInset::isBrackets() const
114 return left_ == "[" && right_ == "]";
118 bool MathDelimInset::isAbs() const
120 return left_ == "|" && right_ == "|";
124 void MathDelimInset::maple(MapleStream & os) const
127 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
128 os << "linalg[det](" << cell(0) << ')';
130 os << "abs(" << cell(0) << ')';
133 os << left_ << cell(0) << right_;
136 void MathDelimInset::maxima(MaximaStream & os) const
139 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
140 os << "determinant(" << cell(0) << ')';
142 os << "abs(" << cell(0) << ')';
145 os << left_ << cell(0) << right_;
149 void MathDelimInset::mathematica(MathematicaStream & os) const
152 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
153 os << "Det" << cell(0) << ']';
155 os << "Abs[" << cell(0) << ']';
158 os << left_ << cell(0) << right_;
162 void MathDelimInset::mathmlize(MathMLStream & os) const
164 os << "<fenced open=\"" << left_ << "\" close=\""
165 << right_ << "\">" << cell(0) << "</fenced>";
169 void MathDelimInset::octave(OctaveStream & os) const
172 os << "det(" << cell(0) << ')';
174 os << left_ << cell(0) << right_;