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"
27 string convertDelimToLatexName(string const & name)
47 return '\\' + name + ' ';
54 MathDelimInset::MathDelimInset(string const & l, string const & r)
55 : MathNestInset(1), left_(l), right_(r)
59 MathDelimInset::MathDelimInset
60 (string const & l, string const & r, MathArray const & ar)
61 : MathNestInset(1), left_(l), right_(r)
67 auto_ptr<InsetBase> MathDelimInset::doClone() const
69 return auto_ptr<InsetBase>(new MathDelimInset(*this));
73 void MathDelimInset::write(WriteStream & os) const
75 os << "\\left" << convertDelimToLatexName(left_) << cell(0)
76 << "\\right" << convertDelimToLatexName(right_);
80 void MathDelimInset::normalize(NormalStream & os) const
82 os << "[delim " << convertDelimToLatexName(left_) << ' '
83 << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
87 void MathDelimInset::metrics(MetricsInfo & mi, Dimension & dim) const
91 mathed_char_dim(mi.base.font, 'I', t);
92 int h0 = (t.asc + t.des) / 2;
93 int a0 = max(cell(0).ascent(), t.asc) - h0;
94 int d0 = max(cell(0).descent(), t.des) + h0;
95 dw_ = cell(0).height() / 5;
100 dim_.wid = cell(0).width() + 2 * dw_ + 8;
101 dim_.asc = max(a0, d0) + h0;
102 dim_.des = max(a0, d0) - h0;
107 void MathDelimInset::draw(PainterInfo & pi, int x, int y) const
109 int const b = y - dim_.asc;
110 cell(0).draw(pi, x + dw_ + 4, y);
111 mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
112 mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
113 b, dw_, dim_.height(), right_);
117 bool MathDelimInset::isParanthesis() const
119 return left_ == "(" && right_ == ")";
123 bool MathDelimInset::isBrackets() const
125 return left_ == "[" && right_ == "]";
129 bool MathDelimInset::isAbs() const
131 return left_ == "|" && right_ == "|";
135 void MathDelimInset::maple(MapleStream & os) const
138 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
139 os << "linalg[det](" << cell(0) << ')';
141 os << "abs(" << cell(0) << ')';
144 os << left_ << cell(0) << right_;
147 void MathDelimInset::maxima(MaximaStream & os) const
150 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
151 os << "determinant(" << cell(0) << ')';
153 os << "abs(" << cell(0) << ')';
156 os << left_ << cell(0) << right_;
160 void MathDelimInset::mathematica(MathematicaStream & os) const
163 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
164 os << "Det" << cell(0) << ']';
166 os << "Abs[" << cell(0) << ']';
169 os << left_ << cell(0) << right_;
173 void MathDelimInset::mathmlize(MathMLStream & os) const
175 os << "<fenced open=\"" << left_ << "\" close=\""
176 << right_ << "\">" << cell(0) << "</fenced>";
180 void MathDelimInset::octave(OctaveStream & os) const
183 os << "det(" << cell(0) << ')';
185 os << left_ << cell(0) << right_;