2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
|
|
|
|
* \file math_deliminset.C
|
|
|
|
|
* 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>
|
|
|
|
|
|
2001-02-13 13:28:32 +00:00
|
|
|
|
#include "math_deliminset.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "math_data.h"
|
2001-11-08 12:06:56 +00:00
|
|
|
|
#include "math_mathmlstream.h"
|
2001-12-05 08:04:20 +00:00
|
|
|
|
#include "math_streamstr.h"
|
2003-09-07 21:25:37 +00:00
|
|
|
|
#include "math_support.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
2001-10-29 15:45:24 +00:00
|
|
|
|
|
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
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
string convertDelimToLatexName(string const & name)
|
|
|
|
|
{
|
2002-06-25 14:29:24 +00:00
|
|
|
|
if (name == "<")
|
|
|
|
|
return name;
|
2002-06-25 13:19:50 +00:00
|
|
|
|
if (name == "(")
|
|
|
|
|
return name;
|
|
|
|
|
if (name == "[")
|
|
|
|
|
return name;
|
|
|
|
|
if (name == ".")
|
|
|
|
|
return name;
|
2002-06-25 14:29:24 +00:00
|
|
|
|
if (name == ">")
|
|
|
|
|
return name;
|
2002-06-25 13:19:50 +00:00
|
|
|
|
if (name == ")")
|
|
|
|
|
return name;
|
|
|
|
|
if (name == "]")
|
|
|
|
|
return name;
|
|
|
|
|
if (name == "/")
|
|
|
|
|
return name;
|
|
|
|
|
if (name == "|")
|
|
|
|
|
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
|
|
|
|
|
2001-09-12 12:51:55 +00:00
|
|
|
|
MathDelimInset::MathDelimInset(string const & l, string const & r)
|
2001-08-03 17:10:22 +00:00
|
|
|
|
: MathNestInset(1), left_(l), right_(r)
|
2001-06-25 00:06:33 +00:00
|
|
|
|
{}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
|
|
2002-06-25 13:19:50 +00:00
|
|
|
|
MathDelimInset::MathDelimInset
|
|
|
|
|
(string const & l, string const & r, MathArray const & ar)
|
|
|
|
|
: MathNestInset(1), left_(l), right_(r)
|
|
|
|
|
{
|
|
|
|
|
cell(0) = ar;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2004-11-23 23:04:52 +00:00
|
|
|
|
auto_ptr<InsetBase> MathDelimInset::doClone() const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2003-07-25 17:11:25 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new MathDelimInset(*this));
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
|
void MathDelimInset::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-09 08:35:57 +00:00
|
|
|
|
void MathDelimInset::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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-06-02 10:03:27 +00:00
|
|
|
|
void MathDelimInset::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);
|
2002-07-11 11:27:24 +00:00
|
|
|
|
Dimension t;
|
|
|
|
|
mathed_char_dim(mi.base.font, 'I', t);
|
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;
|
|
|
|
|
dim_.wid = cell(0).width() + 2 * dw_ + 8;
|
2003-05-27 13:55:03 +00:00
|
|
|
|
dim_.asc = max(a0, d0) + h0;
|
|
|
|
|
dim_.des = max(a0, d0) - h0;
|
2003-06-02 10:03:27 +00:00
|
|
|
|
dim = dim_;
|
2001-08-15 06:53:25 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
void MathDelimInset::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_);
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
|
|
|
|
|
2001-11-09 10:44:24 +00:00
|
|
|
|
bool MathDelimInset::isParanthesis() const
|
|
|
|
|
{
|
|
|
|
|
return left_ == "(" && right_ == ")";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathDelimInset::isBrackets() const
|
|
|
|
|
{
|
|
|
|
|
return left_ == "[" && right_ == "]";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
bool MathDelimInset::isAbs() const
|
|
|
|
|
{
|
|
|
|
|
return left_ == "|" && right_ == "|";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathDelimInset::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
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathDelimInset::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
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathDelimInset::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_;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2001-11-07 18:15:24 +00:00
|
|
|
|
void MathDelimInset::mathmlize(MathMLStream & os) const
|
|
|
|
|
{
|
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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2003-02-14 14:30:09 +00:00
|
|
|
|
void MathDelimInset::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
|
|
|
|
}
|