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 "MathSupport.h"
19 #include "frontends/FontMetrics.h"
24 static docstring convertDelimToLatexName(docstring const & name)
26 if (name.size() == 1) {
27 char_type const c = name[0];
28 if (c == '<' || c == '(' || c == '[' || c == '.'
29 || c == '>' || c == ')' || c == ']' || c == '/' || c == '|')
32 return '\\' + name + ' ';
36 InsetMathDelim::InsetMathDelim(docstring const & l, docstring const & r)
37 : InsetMathNest(1), left_(l), right_(r)
41 InsetMathDelim::InsetMathDelim
42 (docstring const & l, docstring const & r, MathData const & ar)
43 : InsetMathNest(1), left_(l), right_(r)
49 Inset * InsetMathDelim::clone() const
51 return new InsetMathDelim(*this);
55 void InsetMathDelim::write(WriteStream & os) const
57 os << "\\left" << convertDelimToLatexName(left_) << cell(0)
58 << "\\right" << convertDelimToLatexName(right_);
62 void InsetMathDelim::normalize(NormalStream & os) const
64 os << "[delim " << convertDelimToLatexName(left_) << ' '
65 << convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
69 void InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
73 cell(0).metrics(mi, dim0);
74 Dimension t = theFontMetrics(mi.base.font).dimension('I');
75 int h0 = (t.asc + t.des) / 2;
76 int a0 = max(dim0.asc, t.asc) - h0;
77 int d0 = max(dim0.des, t.des) + h0;
78 dw_ = dim0.height() / 5;
83 dim.wid = dim0.width() + 2 * dw_ + 8;
84 dim.asc = max(a0, d0) + h0;
85 dim.des = max(a0, d0) - h0;
86 // Cache the inset dimension.
91 void InsetMathDelim::draw(PainterInfo & pi, int x, int y) const
93 Dimension const dim = dimension(*pi.base.bv);
94 int const b = y - dim.asc;
95 cell(0).draw(pi, x + dw_ + 4, y);
96 mathed_draw_deco(pi, x + 4, b, dw_, dim.height(), left_);
97 mathed_draw_deco(pi, x + dim.width() - dw_ - 4,
98 b, dw_, dim.height(), right_);
99 setPosCache(pi, x, y);
103 bool InsetMathDelim::isParenthesis() const
105 return left_ == "(" && right_ == ")";
109 bool InsetMathDelim::isBrackets() const
111 return left_ == "[" && right_ == "]";
115 bool InsetMathDelim::isAbs() const
117 return left_ == "|" && right_ == "|";
121 void InsetMathDelim::maple(MapleStream & os) const
124 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
125 os << "linalg[det](" << cell(0) << ')';
127 os << "abs(" << cell(0) << ')';
130 os << left_ << cell(0) << right_;
134 void InsetMathDelim::maxima(MaximaStream & os) const
137 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
138 os << "determinant(" << cell(0) << ')';
140 os << "abs(" << cell(0) << ')';
143 os << left_ << cell(0) << right_;
147 void InsetMathDelim::mathematica(MathematicaStream & os) const
150 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
151 os << "Det" << cell(0) << ']';
153 os << "Abs[" << cell(0) << ']';
156 os << left_ << cell(0) << right_;
160 void InsetMathDelim::mathmlize(MathStream & os) const
162 os << "<fenced open=\"" << left_ << "\" close=\""
163 << right_ << "\">" << cell(0) << "</fenced>";
167 void InsetMathDelim::octave(OctaveStream & os) const
170 os << "det(" << cell(0) << ')';
172 os << left_ << cell(0) << right_;