2 * \file InsetMathDelim.cpp
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 "MathStream.h"
17 #include "MathStream.h"
18 #include "MathSupport.h"
20 #include "frontends/FontMetrics.h"
30 static docstring convertDelimToLatexName(docstring const & name)
32 if (name.size() == 1) {
33 char_type const c = name[0];
34 if (c == '<' || c == '(' || c == '[' || c == '.'
35 || c == '>' || c == ')' || c == ']' || c == '/' || c == '|')
38 return '\\' + name + ' ';
42 InsetMathDelim::InsetMathDelim(docstring const & l, docstring const & r)
43 : InsetMathNest(1), left_(l), right_(r)
47 InsetMathDelim::InsetMathDelim
48 (docstring const & l, docstring const & r, MathData const & ar)
49 : InsetMathNest(1), left_(l), right_(r)
55 auto_ptr<Inset> InsetMathDelim::doClone() const
57 return auto_ptr<Inset>(new InsetMathDelim(*this));
61 void InsetMathDelim::write(WriteStream & os) const
63 os << "\\left" << convertDelimToLatexName(left_) << cell(0)
64 << "\\right" << convertDelimToLatexName(right_);
68 void InsetMathDelim::normalize(NormalStream & os) const
70 os << "[delim " << convertDelimToLatexName(left_) << ' '
71 << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
75 bool InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
78 Dimension t = theFontMetrics(mi.base.font).dimension('I');
79 int h0 = (t.asc + t.des) / 2;
80 int a0 = max(cell(0).ascent(), t.asc) - h0;
81 int d0 = max(cell(0).descent(), t.des) + h0;
82 dw_ = cell(0).height() / 5;
87 dim.wid = cell(0).width() + 2 * dw_ + 8;
88 dim.asc = max(a0, d0) + h0;
89 dim.des = max(a0, d0) - h0;
97 void InsetMathDelim::draw(PainterInfo & pi, int x, int y) const
99 int const b = y - dim_.asc;
100 cell(0).draw(pi, x + dw_ + 4, y);
101 mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
102 mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
103 b, dw_, dim_.height(), right_);
104 setPosCache(pi, x, y);
108 bool InsetMathDelim::isParenthesis() const
110 return left_ == "(" && right_ == ")";
114 bool InsetMathDelim::isBrackets() const
116 return left_ == "[" && right_ == "]";
120 bool InsetMathDelim::isAbs() const
122 return left_ == "|" && right_ == "|";
126 void InsetMathDelim::maple(MapleStream & os) const
129 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
130 os << "linalg[det](" << cell(0) << ')';
132 os << "abs(" << cell(0) << ')';
135 os << left_ << cell(0) << right_;
139 void InsetMathDelim::maxima(MaximaStream & os) const
142 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
143 os << "determinant(" << cell(0) << ')';
145 os << "abs(" << cell(0) << ')';
148 os << left_ << cell(0) << right_;
152 void InsetMathDelim::mathematica(MathematicaStream & os) const
155 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
156 os << "Det" << cell(0) << ']';
158 os << "Abs[" << cell(0) << ']';
161 os << left_ << cell(0) << right_;
165 void InsetMathDelim::mathmlize(MathStream & os) const
167 os << "<fenced open=\"" << left_ << "\" close=\""
168 << right_ << "\">" << cell(0) << "</fenced>";
172 void InsetMathDelim::octave(OctaveStream & os) const
175 os << "det(" << cell(0) << ')';
177 os << left_ << cell(0) << right_;