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"
25 static docstring convertDelimToLatexName(docstring const & name)
27 if (name.size() == 1) {
28 char_type const c = name[0];
29 if (c == '<' || c == '(' || c == '[' || c == '.'
30 || c == '>' || c == ')' || c == ']' || c == '/' || c == '|')
33 return '\\' + name + ' ';
37 InsetMathDelim::InsetMathDelim(docstring const & l, docstring const & r)
38 : InsetMathNest(1), left_(l), right_(r)
42 InsetMathDelim::InsetMathDelim
43 (docstring const & l, docstring const & r, MathData const & ar)
44 : InsetMathNest(1), left_(l), right_(r)
50 Inset * InsetMathDelim::clone() const
52 return new InsetMathDelim(*this);
56 void InsetMathDelim::write(WriteStream & os) const
58 os << "\\left" << convertDelimToLatexName(left_) << cell(0)
59 << "\\right" << convertDelimToLatexName(right_);
63 void InsetMathDelim::normalize(NormalStream & os) const
65 os << "[delim " << convertDelimToLatexName(left_) << ' '
66 << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
70 void InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
74 cell(0).metrics(mi, dim0);
75 Dimension t = theFontMetrics(mi.base.font).dimension('I');
76 int h0 = (t.asc + t.des) / 2;
77 int a0 = max(dim0.asc, t.asc) - h0;
78 int d0 = max(dim0.des, t.des) + h0;
79 dw_ = dim0.height() / 5;
84 dim.wid = dim0.width() + 2 * dw_ + 8;
85 dim.asc = max(a0, d0) + h0;
86 dim.des = max(a0, d0) - h0;
87 // Cache the inset dimension.
92 void InsetMathDelim::draw(PainterInfo & pi, int x, int y) const
94 Dimension const dim = dimension(*pi.base.bv);
95 int const b = y - dim.asc;
96 cell(0).draw(pi, x + dw_ + 4, y);
97 mathed_draw_deco(pi, x + 4, b, dw_, dim.height(), left_);
98 mathed_draw_deco(pi, x + dim.width() - dw_ - 4,
99 b, dw_, dim.height(), right_);
100 setPosCache(pi, x, y);
104 bool InsetMathDelim::isParenthesis() const
106 return left_ == "(" && right_ == ")";
110 bool InsetMathDelim::isBrackets() const
112 return left_ == "[" && right_ == "]";
116 bool InsetMathDelim::isAbs() const
118 return left_ == "|" && right_ == "|";
122 void InsetMathDelim::maple(MapleStream & os) const
125 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
126 os << "linalg[det](" << cell(0) << ')';
128 os << "abs(" << cell(0) << ')';
131 os << left_ << cell(0) << right_;
135 void InsetMathDelim::maxima(MaximaStream & os) const
138 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
139 os << "determinant(" << cell(0) << ')';
141 os << "abs(" << cell(0) << ')';
144 os << left_ << cell(0) << right_;
148 void InsetMathDelim::mathematica(MathematicaStream & os) const
151 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
152 os << "Det" << cell(0) << ']';
154 os << "Abs[" << cell(0) << ']';
157 os << left_ << cell(0) << right_;
161 void InsetMathDelim::mathmlize(MathStream & os) const
163 os << "<fenced open=\"" << left_ << "\" close=\""
164 << right_ << "\">" << cell(0) << "</fenced>";
168 void InsetMathDelim::octave(OctaveStream & os) const
171 os << "det(" << cell(0) << ')';
173 os << left_ << cell(0) << right_;