2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetMathDelim.C
|
2003-08-19 13:00:56 +00:00
|
|
|
|
* This file is part of LyX, the document processor.
|
|
|
|
|
* Licence details can be found in the file COPYING.
|
|
|
|
|
*
|
|
|
|
|
* \author Alejandro Aguilar Sierra
|
|
|
|
|
* \author Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-08-17 11:08:55 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathDelim.h"
|
|
|
|
|
#include "MathData.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
|
#include "MathStream.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathStream.h"
|
|
|
|
|
#include "MathSupport.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
2006-12-04 10:45:43 +00:00
|
|
|
|
#include "frontends/FontMetrics.h"
|
2001-10-29 15:45:24 +00:00
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
|
namespace lyx {
|
|
|
|
|
|
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
using std::max;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2002-06-25 13:19:50 +00:00
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
static docstring convertDelimToLatexName(docstring const & name)
|
2002-06-25 13:19:50 +00:00
|
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
|
if (name.size() == 1) {
|
|
|
|
|
char_type const c = name[0];
|
|
|
|
|
if (c == '<' || c == '(' || c == '[' || c == '.'
|
|
|
|
|
|| c == '>' || c == ')' || c == ']' || c == '/' || c == '|')
|
|
|
|
|
return name;
|
|
|
|
|
}
|
2002-11-27 10:30:28 +00:00
|
|
|
|
return '\\' + name + ' ';
|
2002-06-25 13:19:50 +00:00
|
|
|
|
}
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
InsetMathDelim::InsetMathDelim(docstring const & l, docstring const & r)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
: InsetMathNest(1), left_(l), right_(r)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathDelim::InsetMathDelim
|
2006-10-22 10:15:23 +00:00
|
|
|
|
(docstring const & l, docstring const & r, MathArray const & ar)
|
2006-09-16 18:11:38 +00:00
|
|
|
|
: InsetMathNest(1), left_(l), right_(r)
|
2002-06-25 13:19:50 +00:00
|
|
|
|
{
|
|
|
|
|
cell(0) = ar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetMathDelim::doClone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetMathDelim(*this));
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDelim::write(WriteStream & os) const
|
2001-08-09 15:19:31 +00:00
|
|
|
|
{
|
2002-02-14 12:38:02 +00:00
|
|
|
|
os << "\\left" << convertDelimToLatexName(left_) << cell(0)
|
|
|
|
|
<< "\\right" << convertDelimToLatexName(right_);
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDelim::normalize(NormalStream & os) const
|
2001-10-24 16:10:38 +00:00
|
|
|
|
{
|
2002-02-14 12:38:02 +00:00
|
|
|
|
os << "[delim " << convertDelimToLatexName(left_) << ' '
|
|
|
|
|
<< convertDelimToLatexName(right_) << ' ' << cell(0) << ']';
|
2001-10-24 16:10:38 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool InsetMathDelim::metrics(MetricsInfo & mi, Dimension & dim) const
|
2001-08-15 06:53:25 +00:00
|
|
|
|
{
|
2002-08-02 14:29:42 +00:00
|
|
|
|
cell(0).metrics(mi);
|
2006-12-04 10:45:43 +00:00
|
|
|
|
Dimension t = theFontMetrics(mi.base.font).dimension('I');
|
2003-05-27 13:55:03 +00:00
|
|
|
|
int h0 = (t.asc + t.des) / 2;
|
|
|
|
|
int a0 = max(cell(0).ascent(), t.asc) - h0;
|
|
|
|
|
int d0 = max(cell(0).descent(), t.des) + h0;
|
2003-05-28 13:22:36 +00:00
|
|
|
|
dw_ = cell(0).height() / 5;
|
|
|
|
|
if (dw_ > 8)
|
|
|
|
|
dw_ = 8;
|
|
|
|
|
if (dw_ < 4)
|
|
|
|
|
dw_ = 4;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
dim.wid = cell(0).width() + 2 * dw_ + 8;
|
|
|
|
|
dim.asc = max(a0, d0) + h0;
|
|
|
|
|
dim.des = max(a0, d0) - h0;
|
|
|
|
|
if (dim_ == dim)
|
|
|
|
|
return false;
|
|
|
|
|
dim_ = dim;
|
|
|
|
|
return true;
|
2001-08-15 06:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDelim::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2003-05-28 13:22:36 +00:00
|
|
|
|
int const b = y - dim_.asc;
|
|
|
|
|
cell(0).draw(pi, x + dw_ + 4, y);
|
|
|
|
|
mathed_draw_deco(pi, x + 4, b, dw_, dim_.height(), left_);
|
|
|
|
|
mathed_draw_deco(pi, x + dim_.width() - dw_ - 4,
|
|
|
|
|
b, dw_, dim_.height(), right_);
|
2005-04-04 22:11:53 +00:00
|
|
|
|
setPosCache(pi, x, y);
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathDelim::isParenthesis() const
|
2001-11-09 10:44:24 +00:00
|
|
|
|
{
|
|
|
|
|
return left_ == "(" && right_ == ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathDelim::isBrackets() const
|
2001-11-09 10:44:24 +00:00
|
|
|
|
{
|
|
|
|
|
return left_ == "[" && right_ == "]";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathDelim::isAbs() const
|
2001-11-09 10:44:24 +00:00
|
|
|
|
{
|
|
|
|
|
return left_ == "|" && right_ == "|";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDelim::maple(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2001-11-09 10:44:24 +00:00
|
|
|
|
if (isAbs()) {
|
2002-08-08 17:11:30 +00:00
|
|
|
|
if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "linalg[det](" << cell(0) << ')';
|
2001-11-07 10:21:51 +00:00
|
|
|
|
else
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "abs(" << cell(0) << ')';
|
2001-11-07 10:21:51 +00:00
|
|
|
|
}
|
2001-11-07 17:30:26 +00:00
|
|
|
|
else
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << left_ << cell(0) << right_;
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
2001-11-07 10:21:51 +00:00
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDelim::maxima(MaximaStream & os) const
|
2002-10-28 17:15:19 +00:00
|
|
|
|
{
|
|
|
|
|
if (isAbs()) {
|
|
|
|
|
if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "determinant(" << cell(0) << ')';
|
2002-10-28 17:15:19 +00:00
|
|
|
|
else
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "abs(" << cell(0) << ')';
|
2002-10-28 17:15:19 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
os << left_ << cell(0) << right_;
|
|
|
|
|
}
|
|
|
|
|
|
2002-10-28 13:10:12 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDelim::mathematica(MathematicaStream & os) const
|
2002-07-01 11:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
if (isAbs()) {
|
2002-08-08 17:11:30 +00:00
|
|
|
|
if (cell(0).size() == 1 && cell(0).front()->asMatrixInset())
|
2002-07-01 11:17:14 +00:00
|
|
|
|
os << "Det" << cell(0) << ']';
|
|
|
|
|
else
|
|
|
|
|
os << "Abs[" << cell(0) << ']';
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
os << left_ << cell(0) << right_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathDelim::mathmlize(MathStream & os) const
|
2001-11-07 18:15:24 +00:00
|
|
|
|
{
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << "<fenced open=\"" << left_ << "\" close=\""
|
|
|
|
|
<< right_ << "\">" << cell(0) << "</fenced>";
|
2001-11-07 18:15:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathDelim::octave(OctaveStream & os) const
|
2001-11-07 18:15:24 +00:00
|
|
|
|
{
|
2001-11-09 10:44:24 +00:00
|
|
|
|
if (isAbs())
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "det(" << cell(0) << ')';
|
2001-11-07 18:15:24 +00:00
|
|
|
|
else
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << left_ << cell(0) << right_;
|
2001-11-07 18:15:24 +00:00
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|