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"
17 #include "MathStream.h"
18 #include "MathSupport.h"
19 #include "MetricsInfo.h"
21 #include "support/docstring.h"
23 #include "frontends/FontMetrics.h"
29 static docstring
convertDelimToLatexName(docstring
const & name
)
31 if (name
.size() == 1) {
32 char_type
const c
= name
[0];
33 if (c
== '<' || c
== '(' || c
== '[' || c
== '.'
34 || c
== '>' || c
== ')' || c
== ']' || c
== '/' || c
== '|')
37 return '\\' + name
+ ' ';
41 InsetMathDelim::InsetMathDelim(Buffer
* buf
, docstring
const & l
,
43 : InsetMathNest(buf
, 1), left_(l
), right_(r
)
47 InsetMathDelim::InsetMathDelim(Buffer
* buf
, docstring
const & l
, docstring
const & r
,
49 : InsetMathNest(buf
, 1), left_(l
), right_(r
)
55 Inset
* InsetMathDelim::clone() const
57 return new InsetMathDelim(*this);
61 void InsetMathDelim::write(WriteStream
& os
) const
63 MathEnsurer
ensurer(os
);
64 os
<< "\\left" << convertDelimToLatexName(left_
) << cell(0)
65 << "\\right" << convertDelimToLatexName(right_
);
69 void InsetMathDelim::normalize(NormalStream
& os
) const
71 os
<< "[delim " << convertDelimToLatexName(left_
) << ' '
72 << convertDelimToLatexName(right_
) << ' ' << cell(0) << ']';
76 void InsetMathDelim::metrics(MetricsInfo
& mi
, Dimension
& dim
) const
79 cell(0).metrics(mi
, dim0
);
80 Dimension t
= theFontMetrics(mi
.base
.font
).dimension('I');
81 int h0
= (t
.asc
+ t
.des
) / 2;
82 int a0
= max(dim0
.asc
, t
.asc
) - h0
;
83 int d0
= max(dim0
.des
, t
.des
) + h0
;
84 dw_
= dim0
.height() / 5;
89 dim
.wid
= dim0
.width() + 2 * dw_
+ 8;
90 dim
.asc
= max(a0
, d0
) + h0
;
91 dim
.des
= max(a0
, d0
) - h0
;
95 void InsetMathDelim::draw(PainterInfo
& pi
, int x
, int y
) const
97 Dimension
const dim
= dimension(*pi
.base
.bv
);
98 int const b
= y
- dim
.asc
;
99 cell(0).draw(pi
, x
+ dw_
+ 4, y
);
100 mathed_draw_deco(pi
, x
+ 4, b
, dw_
, dim
.height(), left_
);
101 mathed_draw_deco(pi
, x
+ dim
.width() - dw_
- 4,
102 b
, dw_
, dim
.height(), right_
);
103 setPosCache(pi
, x
, y
);
107 bool InsetMathDelim::isParenthesis() const
109 return left_
== "(" && right_
== ")";
113 bool InsetMathDelim::isBrackets() const
115 return left_
== "[" && right_
== "]";
119 bool InsetMathDelim::isAbs() const
121 return left_
== "|" && right_
== "|";
125 void InsetMathDelim::maple(MapleStream
& os
) const
128 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
129 os
<< "linalg[det](" << cell(0) << ')';
131 os
<< "abs(" << cell(0) << ')';
134 os
<< left_
<< cell(0) << right_
;
138 void InsetMathDelim::maxima(MaximaStream
& os
) const
141 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
142 os
<< "determinant(" << cell(0) << ')';
144 os
<< "abs(" << cell(0) << ')';
147 os
<< left_
<< cell(0) << right_
;
151 void InsetMathDelim::mathematica(MathematicaStream
& os
) const
154 if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
155 os
<< "Det" << cell(0) << ']';
157 os
<< "Abs[" << cell(0) << ']';
160 os
<< left_
<< cell(0) << right_
;
164 void InsetMathDelim::mathmlize(MathStream
& os
) const
166 os
<< "<fenced open=\"" << left_
<< "\" close=\""
167 << right_
<< "\">" << cell(0) << "</fenced>";
171 void InsetMathDelim::octave(OctaveStream
& os
) const
174 os
<< "det(" << cell(0) << ')';
176 os
<< left_
<< cell(0) << right_
;