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_support.h"
16 #include "math_mathmlstream.h"
17 #include "math_streamstr.h"
25 string convertDelimToLatexName(string const & name)
45 return '\\' + name + ' ';
52 MathDelimInset::MathDelimInset(string const & l, string const & r)
53 : MathNestInset(1), left_(l), right_(r)
57 MathDelimInset::MathDelimInset
58 (string const & l, string const & r, MathArray const & ar)
59 : MathNestInset(1), left_(l), right_(r)
65 auto_ptr<InsetBase> MathDelimInset::clone() const
67 return auto_ptr<InsetBase>(new MathDelimInset(*this));
71 void MathDelimInset::write(WriteStream & os) const
73 os << "\\left" << convertDelimToLatexName(left_) << cell(0)
74 << "\\right" << convertDelimToLatexName(right_);
78 void MathDelimInset::normalize(NormalStream & os) const
80 os << "[delim " << convertDelimToLatexName(left_) << ' '
81 << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
85 void MathDelimInset::metrics(MetricsInfo & mi, Dimension & dim) const
89 mathed_char_dim(mi.base.font, 'I', t);
90 int h0 = (t.asc + t.des) / 2;
91 int a0 = max(cell(0).ascent(), t.asc) - h0;
92 int d0 = max(cell(0).descent(), t.des) + h0;
93 dw_ = cell(0).height() / 5;
98 dim_.wid = cell(0).width() + 2 * dw_ + 8;
99 dim_.asc = max(a0, d0) + h0;
100 dim_.des = max(a0, d0) - h0;
105 void MathDelimInset::draw(PainterInfo & pi, int x, int y) const
107 int const b = y - dim_.asc;
108 cell(0).draw(pi, x + dw_ + 4, y);
109 mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
110 mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
111 b, dw_, dim_.height(), right_);
115 bool MathDelimInset::isParanthesis() const
117 return left_ == "(" && right_ == ")";
121 bool MathDelimInset::isBrackets() const
123 return left_ == "[" && right_ == "]";
127 bool MathDelimInset::isAbs() const
129 return left_ == "|" && right_ == "|";
133 void MathDelimInset::maple(MapleStream & os) const
136 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
137 os << "linalg[det](" << cell(0) << ')';
139 os << "abs(" << cell(0) << ')';
142 os << left_ << cell(0) << right_;
145 void MathDelimInset::maxima(MaximaStream & os) const
148 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
149 os << "determinant(" << cell(0) << ')';
151 os << "abs(" << cell(0) << ')';
154 os << left_ << cell(0) << right_;
158 void MathDelimInset::mathematica(MathematicaStream & os) const
161 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
162 os << "Det" << cell(0) << ']';
164 os << "Abs[" << cell(0) << ']';
167 os << left_ << cell(0) << right_;
171 void MathDelimInset::mathmlize(MathMLStream & os) const
173 os << "<fenced open=\"" << left_ << "\" close=\""
174 << right_ << "\">" << cell(0) << "</fenced>";
178 void MathDelimInset::octave(OctaveStream & os) const
181 os << "det(" << cell(0) << ')';
183 os << left_ << cell(0) << right_;