2003-08-19 13:00:56 +00:00
|
|
|
|
/**
|
2006-09-17 09:14:18 +00:00
|
|
|
|
* \file InsetMathSymbol.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 Andr<EFBFBD> P<EFBFBD>nitz
|
|
|
|
|
*
|
|
|
|
|
* Full author contact details are available in file CREDITS.
|
|
|
|
|
*/
|
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
|
#include <config.h>
|
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "InsetMathSymbol.h"
|
2003-06-02 10:03:27 +00:00
|
|
|
|
#include "dimension.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#include "MathMLStream.h"
|
|
|
|
|
#include "MathStream.h"
|
|
|
|
|
#include "MathSupport.h"
|
|
|
|
|
#include "MathParser.h"
|
|
|
|
|
#include "MathAtom.h"
|
2002-01-18 14:27:54 +00:00
|
|
|
|
#include "LaTeXFeatures.h"
|
2001-11-09 14:23:44 +00:00
|
|
|
|
#include "debug.h"
|
2001-02-14 15:00:50 +00:00
|
|
|
|
|
2006-08-13 22:54:59 +00:00
|
|
|
|
using lyx::docstring;
|
2003-10-02 15:46:33 +00:00
|
|
|
|
|
2003-10-06 15:43:21 +00:00
|
|
|
|
using std::string;
|
2003-07-25 17:11:25 +00:00
|
|
|
|
using std::auto_ptr;
|
|
|
|
|
|
2003-05-28 13:22:36 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathSymbol::InsetMathSymbol(latexkeys const * l)
|
2006-07-09 16:35:20 +00:00
|
|
|
|
: sym_(l), h_(0), width_(0), scriptable_(false)
|
2001-10-31 10:54:34 +00:00
|
|
|
|
{}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathSymbol::InsetMathSymbol(char const * name)
|
2006-07-09 16:35:20 +00:00
|
|
|
|
: sym_(in_word_set(name)), h_(0), width_(0), scriptable_(false)
|
2001-11-09 16:27:44 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
InsetMathSymbol::InsetMathSymbol(string const & name)
|
2006-07-09 16:35:20 +00:00
|
|
|
|
: sym_(in_word_set(name.c_str())), h_(0), width_(0), scriptable_(false)
|
2001-12-05 08:04:20 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
auto_ptr<InsetBase> InsetMathSymbol::doClone() const
|
2001-02-13 13:28:32 +00:00
|
|
|
|
{
|
2006-09-16 18:11:38 +00:00
|
|
|
|
return auto_ptr<InsetBase>(new InsetMathSymbol(*this));
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
string InsetMathSymbol::name() const
|
2001-11-09 14:23:44 +00:00
|
|
|
|
{
|
|
|
|
|
return sym_->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::metrics(MetricsInfo & mi, Dimension & dim) const
|
2002-05-30 07:09:54 +00:00
|
|
|
|
{
|
|
|
|
|
//lyxerr << "metrics: symbol: '" << sym_->name
|
|
|
|
|
// << "' in font: '" << sym_->inset
|
|
|
|
|
// << "' drawn as: '" << sym_->draw
|
2003-10-02 15:46:33 +00:00
|
|
|
|
// << "'" << std::endl;
|
2002-10-17 13:15:25 +00:00
|
|
|
|
|
2002-10-28 10:39:12 +00:00
|
|
|
|
int const em = mathed_char_width(mi.base.font, 'M');
|
2003-03-21 14:20:48 +00:00
|
|
|
|
FontSetChanger dummy(mi.base, sym_->inset.c_str());
|
2006-10-17 14:46:45 +00:00
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
mathed_string_dim(mi.base.font, lyx::from_utf8(sym_->draw), dim);
|
2002-07-11 11:27:24 +00:00
|
|
|
|
// correct height for broken cmex and wasy font
|
2003-09-24 10:26:02 +00:00
|
|
|
|
#if defined(__APPLE__) && defined(__GNUC__)
|
|
|
|
|
if (sym_->inset == "cmex") {
|
2004-01-07 16:40:30 +00:00
|
|
|
|
h_ = 4 * dim.des / 5;
|
|
|
|
|
dim.asc += 0*h_;
|
|
|
|
|
dim.des -= h_;
|
|
|
|
|
h_ = dim.asc;
|
2003-09-24 10:26:02 +00:00
|
|
|
|
} else if (sym_->inset == "wasy") {
|
|
|
|
|
h_ = 4 * dim.des / 5;
|
|
|
|
|
dim.asc += h_;
|
|
|
|
|
dim.des -= h_;
|
|
|
|
|
}
|
|
|
|
|
#else
|
2002-07-10 06:12:00 +00:00
|
|
|
|
if (sym_->inset == "cmex" || sym_->inset == "wasy") {
|
2003-05-28 13:22:36 +00:00
|
|
|
|
h_ = 4 * dim.des / 5;
|
|
|
|
|
dim.asc += h_;
|
|
|
|
|
dim.des -= h_;
|
2001-08-30 22:42:26 +00:00
|
|
|
|
}
|
2003-09-24 10:26:02 +00:00
|
|
|
|
#endif
|
2002-07-08 13:03:37 +00:00
|
|
|
|
// seperate things a bit
|
2002-10-21 13:38:02 +00:00
|
|
|
|
if (isRelOp())
|
2003-05-28 13:22:36 +00:00
|
|
|
|
dim.wid += static_cast<int>(0.5 * em + 0.5);
|
2002-10-17 13:15:25 +00:00
|
|
|
|
else
|
2003-05-28 13:22:36 +00:00
|
|
|
|
dim.wid += static_cast<int>(0.1667 * em + 0.5);
|
2002-06-18 15:44:30 +00:00
|
|
|
|
|
|
|
|
|
scriptable_ = false;
|
|
|
|
|
if (mi.base.style == LM_ST_DISPLAY)
|
|
|
|
|
if (sym_->inset == "cmex" || sym_->extra == "funclim")
|
|
|
|
|
scriptable_ = true;
|
2004-02-03 11:21:08 +00:00
|
|
|
|
|
|
|
|
|
width_ = dim.wid;
|
2001-06-25 00:06:33 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::draw(PainterInfo & pi, int x, int y) const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
|
//lyxerr << "metrics: symbol: '" << sym_->name
|
|
|
|
|
// << "' in font: '" << sym_->inset
|
|
|
|
|
// << "' drawn as: '" << sym_->draw
|
2003-10-02 15:46:33 +00:00
|
|
|
|
// << "'" << std::endl;
|
2002-10-21 13:38:02 +00:00
|
|
|
|
int const em = mathed_char_width(pi.base.font, 'M');
|
2001-10-31 10:54:34 +00:00
|
|
|
|
if (isRelOp())
|
2002-10-17 13:15:25 +00:00
|
|
|
|
x += static_cast<int>(0.25*em+0.5);
|
|
|
|
|
else
|
2002-10-28 10:39:12 +00:00
|
|
|
|
x += static_cast<int>(0.0833*em+0.5);
|
2002-10-17 13:15:25 +00:00
|
|
|
|
|
2003-03-21 14:20:48 +00:00
|
|
|
|
FontSetChanger dummy(pi.base, sym_->inset.c_str());
|
2006-10-17 14:46:45 +00:00
|
|
|
|
// FIXME UNICODE
|
|
|
|
|
pi.draw(x, y - h_, lyx::from_utf8(sym_->draw));
|
2001-02-13 13:28:32 +00:00
|
|
|
|
}
|
2001-08-09 08:53:16 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathSymbol::isRelOp() const
|
2002-03-21 17:42:56 +00:00
|
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
|
return sym_->extra == "mathrel";
|
2001-08-30 22:42:26 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathSymbol::isScriptable() const
|
2001-09-11 10:58:17 +00:00
|
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
|
return scriptable_;
|
2001-09-11 10:58:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
bool InsetMathSymbol::takesLimits() const
|
2001-08-30 22:42:26 +00:00
|
|
|
|
{
|
2002-06-18 15:44:30 +00:00
|
|
|
|
return
|
|
|
|
|
sym_->inset == "cmex" ||
|
|
|
|
|
sym_->inset == "lyxboldsymb" ||
|
|
|
|
|
sym_->extra == "funclim";
|
2001-08-09 08:53:16 +00:00
|
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::validate(LaTeXFeatures & features) const
|
2002-01-18 14:27:54 +00:00
|
|
|
|
{
|
2005-06-07 17:21:51 +00:00
|
|
|
|
if (!sym_->requires.empty())
|
|
|
|
|
features.require(sym_->requires);
|
2002-01-18 14:27:54 +00:00
|
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::normalize(NormalStream & os) const
|
2001-11-09 14:23:44 +00:00
|
|
|
|
{
|
2002-11-27 10:30:28 +00:00
|
|
|
|
os << "[symbol " << name() << ']';
|
2001-11-09 14:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::maple(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2001-11-09 14:23:44 +00:00
|
|
|
|
if (name() == "cdot")
|
2001-11-07 17:30:26 +00:00
|
|
|
|
os << '*';
|
2002-06-25 13:19:50 +00:00
|
|
|
|
else if (name() == "infty")
|
|
|
|
|
os << "infinity";
|
2001-11-07 17:30:26 +00:00
|
|
|
|
else
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << name();
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::maxima(MaximaStream & os) const
|
2002-10-28 17:15:19 +00:00
|
|
|
|
{
|
|
|
|
|
if (name() == "cdot")
|
|
|
|
|
os << '*';
|
|
|
|
|
else if (name() == "infty")
|
2006-09-02 01:57:36 +00:00
|
|
|
|
os << "inf";
|
|
|
|
|
else if (name() == "pi")
|
|
|
|
|
os << "%pi";
|
2002-10-28 17:15:19 +00:00
|
|
|
|
else
|
|
|
|
|
os << name();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::mathematica(MathematicaStream & os) const
|
2002-07-01 11:17:14 +00:00
|
|
|
|
{
|
|
|
|
|
if ( name() == "pi") { os << "Pi"; return;}
|
|
|
|
|
if ( name() == "infty") { os << "Infinity"; return;}
|
2006-09-02 01:57:36 +00:00
|
|
|
|
if ( name() == "cdot") { os << '*'; return;}
|
2002-07-01 11:17:14 +00:00
|
|
|
|
os << name();
|
|
|
|
|
}
|
|
|
|
|
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
2001-11-09 18:02:20 +00:00
|
|
|
|
char const * MathMLtype(string const & s)
|
|
|
|
|
{
|
|
|
|
|
if (s == "mathop")
|
|
|
|
|
return "mo";
|
|
|
|
|
return "mi";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::mathmlize(MathMLStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
|
char const * type = MathMLtype(sym_->extra);
|
2001-11-09 18:55:03 +00:00
|
|
|
|
os << '<' << type << "> ";
|
|
|
|
|
if (sym_->xmlname == "x") // unknown so far
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << name();
|
2001-11-09 18:55:03 +00:00
|
|
|
|
else
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << sym_->xmlname;
|
2001-11-09 18:55:03 +00:00
|
|
|
|
os << " </" << type << '>';
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::octave(OctaveStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
|
{
|
2001-11-09 14:23:44 +00:00
|
|
|
|
if (name() == "cdot")
|
2001-11-07 17:30:26 +00:00
|
|
|
|
os << '*';
|
|
|
|
|
else
|
2001-12-05 08:04:20 +00:00
|
|
|
|
os << name();
|
2001-11-09 14:23:44 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::write(WriteStream & os) const
|
2001-11-09 14:23:44 +00:00
|
|
|
|
{
|
2002-08-22 10:04:11 +00:00
|
|
|
|
os << '\\' << name();
|
|
|
|
|
os.pendingSpace(true);
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
|
void InsetMathSymbol::infoize2(std::ostream & os) const
|
2002-01-16 14:24:38 +00:00
|
|
|
|
{
|
2002-07-08 13:03:37 +00:00
|
|
|
|
os << "Symbol: " << name();
|
2002-01-16 14:24:38 +00:00
|
|
|
|
}
|