2001-12-05 08:04:20 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-07-27 10:08:04 +00:00
|
|
|
#include "math_symbolinset.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"
|
2001-11-08 12:15:12 +00:00
|
|
|
#include "math_support.h"
|
2001-11-09 18:02:20 +00:00
|
|
|
#include "math_parser.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
|
|
|
|
2001-07-12 07:18:29 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::ostream;
|
|
|
|
|
|
|
|
|
2001-07-27 10:08:04 +00:00
|
|
|
MathSymbolInset::MathSymbolInset(const latexkeys * l)
|
2001-10-31 10:54:34 +00:00
|
|
|
: sym_(l), h_(0)
|
|
|
|
{}
|
2001-02-13 13:28:32 +00:00
|
|
|
|
|
|
|
|
2001-11-09 16:27:44 +00:00
|
|
|
MathSymbolInset::MathSymbolInset(const char * name)
|
|
|
|
: sym_(in_word_set(name)), h_(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-12-05 08:04:20 +00:00
|
|
|
MathSymbolInset::MathSymbolInset(string const & name)
|
|
|
|
: sym_(in_word_set(name.c_str())), h_(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2001-11-09 16:27:44 +00:00
|
|
|
|
2001-07-27 10:08:04 +00:00
|
|
|
MathInset * MathSymbolInset::clone() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2001-07-27 10:08:04 +00:00
|
|
|
return new MathSymbolInset(*this);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-09 14:23:44 +00:00
|
|
|
string MathSymbolInset::name() const
|
|
|
|
{
|
|
|
|
return sym_->name;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathSymbolInset::metrics(MathMetricsInfo & mi) const
|
|
|
|
{
|
|
|
|
//lyxerr << "metrics: symbol: '" << sym_->name
|
|
|
|
// << "' in font: '" << sym_->inset
|
|
|
|
// << "' drawn as: '" << sym_->draw
|
|
|
|
// << "'\n";
|
|
|
|
MathFontSetChanger dummy(mi.base, sym_->inset.c_str());
|
2002-07-11 11:27:24 +00:00
|
|
|
mathed_string_dim(mi.base.font, sym_->draw, dim_);
|
|
|
|
// correct height for broken cmex and wasy font
|
2002-07-10 06:12:00 +00:00
|
|
|
if (sym_->inset == "cmex" || sym_->inset == "wasy") {
|
2002-07-11 11:27:24 +00:00
|
|
|
h_ = 4 * dim_.d / 5;
|
|
|
|
dim_.a += h_;
|
|
|
|
dim_.d -= h_;
|
2001-08-30 22:42:26 +00:00
|
|
|
}
|
2001-10-31 10:54:34 +00:00
|
|
|
if (isRelOp())
|
2002-07-11 11:27:24 +00:00
|
|
|
dim_.w += 6;
|
2002-07-08 13:03:37 +00:00
|
|
|
// seperate things a bit
|
2002-07-11 11:27:24 +00:00
|
|
|
dim_.w += 2;
|
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;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
void MathSymbolInset::draw(MathPainterInfo & 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
|
|
|
|
// << "'\n";
|
2001-10-31 10:54:34 +00:00
|
|
|
if (isRelOp())
|
2002-03-19 16:55:58 +00:00
|
|
|
x += 3;
|
2002-07-10 10:46:37 +00:00
|
|
|
x += 1;
|
2002-05-30 07:09:54 +00:00
|
|
|
MathFontSetChanger dummy(pi.base, sym_->inset.c_str());
|
|
|
|
drawStr(pi, pi.base.font, x, y - h_, sym_->draw);
|
2001-02-13 13:28:32 +00:00
|
|
|
}
|
2001-08-09 08:53:16 +00:00
|
|
|
|
|
|
|
|
|
|
|
bool MathSymbolInset::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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathSymbolInset::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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
bool MathSymbolInset::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
|
|
|
|
2002-01-18 14:27:54 +00:00
|
|
|
void MathSymbolInset::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
2002-05-30 07:09:54 +00:00
|
|
|
if (sym_->inset == "msa" || sym_->inset == "msb")
|
2002-01-18 14:27:54 +00:00
|
|
|
features.require("amssymb");
|
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
2002-05-30 07:09:54 +00:00
|
|
|
|
2001-11-09 14:23:44 +00:00
|
|
|
void MathSymbolInset::normalize(NormalStream & os) const
|
|
|
|
{
|
2001-12-05 08:04:20 +00:00
|
|
|
os << "[symbol " << name() << "]";
|
2001-11-09 14:23:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathSymbolInset::maplize(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
|
|
|
}
|
|
|
|
|
2002-07-01 11:17:14 +00:00
|
|
|
void MathSymbolInset::mathematicize(MathematicaStream & os) const
|
|
|
|
{
|
|
|
|
if ( name() == "pi") { os << "Pi"; return;}
|
|
|
|
if ( name() == "infty") { os << "Infinity"; return;}
|
|
|
|
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";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-09 10:22:35 +00:00
|
|
|
bool MathSymbolInset::match(MathAtom const & at) const
|
2001-11-16 12:00:27 +00:00
|
|
|
{
|
2002-08-09 10:22:35 +00:00
|
|
|
MathSymbolInset const * q = at->asSymbolInset();
|
2001-11-16 12:00:27 +00:00
|
|
|
return q && name() == q->name();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathSymbolInset::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
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
void MathSymbolInset::octavize(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
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathSymbolInset::write(WriteStream & os) const
|
|
|
|
{
|
2001-12-05 08:04:20 +00:00
|
|
|
os << '\\' << name() << ' ';
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
void MathSymbolInset::infoize(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
|
|
|
}
|