2 * \file InsetMathDelim.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 "InsetMathDelim.h"
16 #include "MathMLStream.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
30 string convertDelimToLatexName(string const & name)
50 return '\\' + name + ' ';
57 InsetMathDelim::InsetMathDelim(string const & l, string const & r)
58 : InsetMathNest(1), left_(l), right_(r)
62 InsetMathDelim::InsetMathDelim
63 (string const & l, string const & r, MathArray const & ar)
64 : InsetMathNest(1), left_(l), right_(r)
70 auto_ptr<InsetBase> InsetMathDelim::doClone() const
72 return auto_ptr<InsetBase>(new InsetMathDelim(*this));
76 void InsetMathDelim::write(WriteStream & os) const
78 os << "\\left" << convertDelimToLatexName(left_) << cell(0)
79 << "\\right" << convertDelimToLatexName(right_);
83 void InsetMathDelim::normalize(NormalStream & os) const
85 os << "[delim " << convertDelimToLatexName(left_) << ' '
86 << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
90 void InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
94 mathed_char_dim(mi.base.font, 'I', t);
95 int h0 = (t.asc + t.des) / 2;
96 int a0 = max(cell(0).ascent(), t.asc) - h0;
97 int d0 = max(cell(0).descent(), t.des) + h0;
98 dw_ = cell(0).height() / 5;
103 dim_.wid = cell(0).width() + 2 * dw_ + 8;
104 dim_.asc = max(a0, d0) + h0;
105 dim_.des = max(a0, d0) - h0;
110 void InsetMathDelim::draw(PainterInfo & pi, int x, int y) const
112 int const b = y - dim_.asc;
113 cell(0).draw(pi, x + dw_ + 4, y);
114 mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
115 mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
116 b, dw_, dim_.height(), right_);
117 setPosCache(pi, x, y);
121 bool InsetMathDelim::isParenthesis() const
123 return left_ == "(" && right_ == ")";
127 bool InsetMathDelim::isBrackets() const
129 return left_ == "[" && right_ == "]";
133 bool InsetMathDelim::isAbs() const
135 return left_ == "|" && right_ == "|";
139 void InsetMathDelim::maple(MapleStream & os) const
142 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
143 os << "linalg[det](" << cell(0) << ')';
145 os << "abs(" << cell(0) << ')';
148 os << left_ << cell(0) << right_;
151 void InsetMathDelim::maxima(MaximaStream & os) const
154 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
155 os << "determinant(" << cell(0) << ')';
157 os << "abs(" << cell(0) << ')';
160 os << left_ << cell(0) << right_;
164 void InsetMathDelim::mathematica(MathematicaStream & os) const
167 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
168 os << "Det" << cell(0) << ']';
170 os << "Abs[" << cell(0) << ']';
173 os << left_ << cell(0) << right_;
177 void InsetMathDelim::mathmlize(MathMLStream & os) const
179 os << "<fenced open=\"" << left_ << "\" close=\""
180 << right_ << "\">" << cell(0) << "</fenced>";
184 void InsetMathDelim::octave(OctaveStream & os) const
187 os << "det(" << cell(0) << ')';
189 os << left_ << cell(0) << right_;