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"
27 string convertDelimToLatexName(string const & name)
47 return '\\' + name + ' ';
54 InsetMathDelim::InsetMathDelim(string const & l, string const & r)
55 : InsetMathNest(1), left_(l), right_(r)
59 InsetMathDelim::InsetMathDelim
60 (string const & l, string const & r, MathArray const & ar)
61 : InsetMathNest(1), left_(l), right_(r)
67 auto_ptr<InsetBase> InsetMathDelim::doClone() const
69 return auto_ptr<InsetBase>(new InsetMathDelim(*this));
73 void InsetMathDelim::write(WriteStream & os) const
75 os << "\\left" << convertDelimToLatexName(left_) << cell(0)
76 << "\\right" << convertDelimToLatexName(right_);
80 void InsetMathDelim::normalize(NormalStream & os) const
82 os << "[delim " << convertDelimToLatexName(left_) << ' '
83 << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
87 void InsetMathDelim::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 InsetMathDelim::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_);
114 setPosCache(pi, x, y);
118 bool InsetMathDelim::isParenthesis() const
120 return left_ == "(" && right_ == ")";
124 bool InsetMathDelim::isBrackets() const
126 return left_ == "[" && right_ == "]";
130 bool InsetMathDelim::isAbs() const
132 return left_ == "|" && right_ == "|";
136 void InsetMathDelim::maple(MapleStream & os) const
139 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
140 os << "linalg[det](" << cell(0) << ')';
142 os << "abs(" << cell(0) << ')';
145 os << left_ << cell(0) << right_;
148 void InsetMathDelim::maxima(MaximaStream & os) const
151 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
152 os << "determinant(" << cell(0) << ')';
154 os << "abs(" << cell(0) << ')';
157 os << left_ << cell(0) << right_;
161 void InsetMathDelim::mathematica(MathematicaStream & os) const
164 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
165 os << "Det" << cell(0) << ']';
167 os << "Abs[" << cell(0) << ']';
170 os << left_ << cell(0) << right_;
174 void InsetMathDelim::mathmlize(MathMLStream & os) const
176 os << "<fenced open=\"" << left_ << "\" close=\""
177 << right_ << "\">" << cell(0) << "</fenced>";
181 void InsetMathDelim::octave(OctaveStream & os) const
184 os << "det(" << cell(0) << ')';
186 os << left_ << cell(0) << right_;