2 * \file math_deliminset.C
3 * This file is part of LyX, the document processor.
4 * Licence details can be found in the file COPYING.
6 * \author Alejandro Aguilar Sierra
9 * Full author contact details are available in file CREDITS.
14 #include "math_deliminset.h"
15 #include "math_data.h"
16 #include "math_mathmlstream.h"
17 #include "math_streamstr.h"
18 #include "math_support.h"
26 string convertDelimToLatexName(string const & name)
46 return '\\' + name + ' ';
53 MathDelimInset::MathDelimInset(string const & l, string const & r)
54 : MathNestInset(1), left_(l), right_(r)
58 MathDelimInset::MathDelimInset
59 (string const & l, string const & r, MathArray const & ar)
60 : MathNestInset(1), left_(l), right_(r)
66 auto_ptr<InsetBase> MathDelimInset::clone() const
68 return auto_ptr<InsetBase>(new MathDelimInset(*this));
72 void MathDelimInset::write(WriteStream & os) const
74 os << "\\left" << convertDelimToLatexName(left_) << cell(0)
75 << "\\right" << convertDelimToLatexName(right_);
79 void MathDelimInset::normalize(NormalStream & os) const
81 os << "[delim " << convertDelimToLatexName(left_) << ' '
82 << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
86 void MathDelimInset::metrics(MetricsInfo & mi, Dimension & dim) const
90 mathed_char_dim(mi.base.font, 'I', t);
91 int h0 = (t.asc + t.des) / 2;
92 int a0 = max(cell(0).ascent(), t.asc) - h0;
93 int d0 = max(cell(0).descent(), t.des) + h0;
94 dw_ = cell(0).height() / 5;
99 dim_.wid = cell(0).width() + 2 * dw_ + 8;
100 dim_.asc = max(a0, d0) + h0;
101 dim_.des = max(a0, d0) - h0;
106 void MathDelimInset::draw(PainterInfo & pi, int x, int y) const
108 int const b = y - dim_.asc;
109 cell(0).draw(pi, x + dw_ + 4, y);
110 mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
111 mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
112 b, dw_, dim_.height(), right_);
116 bool MathDelimInset::isParanthesis() const
118 return left_ == "(" && right_ == ")";
122 bool MathDelimInset::isBrackets() const
124 return left_ == "[" && right_ == "]";
128 bool MathDelimInset::isAbs() const
130 return left_ == "|" && right_ == "|";
134 void MathDelimInset::maple(MapleStream & os) const
137 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
138 os << "linalg[det](" << cell(0) << ')';
140 os << "abs(" << cell(0) << ')';
143 os << left_ << cell(0) << right_;
146 void MathDelimInset::maxima(MaximaStream & os) const
149 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
150 os << "determinant(" << cell(0) << ')';
152 os << "abs(" << cell(0) << ')';
155 os << left_ << cell(0) << right_;
159 void MathDelimInset::mathematica(MathematicaStream & os) const
162 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
163 os << "Det" << cell(0) << ']';
165 os << "Abs[" << cell(0) << ']';
168 os << left_ << cell(0) << right_;
172 void MathDelimInset::mathmlize(MathMLStream & os) const
174 os << "<fenced open=\"" << left_ << "\" close=\""
175 << right_ << "\">" << cell(0) << "</fenced>";
179 void MathDelimInset::octave(OctaveStream & os) const
182 os << "det(" << cell(0) << ')';
184 os << left_ << cell(0) << right_;