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-10-22 10:15:23 +00:00
|
|
|
|
#include "MathStream.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
|
#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
|
|
|
|
|
2007-04-01 13:06:41 +00:00
|
|
|
|
#include <cctype>
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
namespace lyx {
|
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-10-22 10:15:23 +00:00
|
|
|
|
: sym_(in_word_set(from_ascii(name))), h_(0), width_(0), scriptable_(false)
|
2001-11-09 16:27:44 +00:00
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
InsetMathSymbol::InsetMathSymbol(docstring const & name)
|
|
|
|
|
: sym_(in_word_set(name)), 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-10-22 10:15:23 +00:00
|
|
|
|
docstring InsetMathSymbol::name() const
|
2001-11-09 14:23:44 +00:00
|
|
|
|
{
|
|
|
|
|
return sym_->name;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-11-28 15:15:49 +00:00
|
|
|
|
bool 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');
|
2006-10-22 10:15:23 +00:00
|
|
|
|
FontSetChanger dummy(mi.base, sym_->inset);
|
2006-10-21 11:15:37 +00:00
|
|
|
|
mathed_string_dim(mi.base.font, sym_->draw, dim);
|
2007-03-21 17:21:59 +00:00
|
|
|
|
docstring::const_reverse_iterator rit = sym_->draw.rbegin();
|
|
|
|
|
kerning_ = mathed_char_kerning(mi.base.font, *rit);
|
2002-07-11 11:27:24 +00:00
|
|
|
|
// correct height for broken cmex and wasy font
|
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
|
|
|
|
}
|
2006-11-09 14:47:56 +00:00
|
|
|
|
|
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)
|
2006-11-13 17:35:18 +00:00
|
|
|
|
if (sym_->inset == "cmex" || sym_->inset == "esint" ||
|
|
|
|
|
sym_->extra == "funclim")
|
2002-06-18 15:44:30 +00:00
|
|
|
|
scriptable_ = true;
|
2004-02-03 11:21:08 +00:00
|
|
|
|
|
|
|
|
|
width_ = dim.wid;
|
2006-11-28 15:15:49 +00:00
|
|
|
|
if (dim_ == dim)
|
|
|
|
|
return false;
|
|
|
|
|
dim_ = dim;
|
|
|
|
|
return true;
|
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-11-07 19:29:01 +00:00
|
|
|
|
pi.draw(x, y - h_, 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
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2007-03-23 02:12:48 +00:00
|
|
|
|
bool InsetMathSymbol::isOrdAlpha() const
|
|
|
|
|
{
|
|
|
|
|
return sym_->extra == "mathord" || sym_->extra == "mathalpha";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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" ||
|
2006-11-13 17:35:18 +00:00
|
|
|
|
sym_->inset == "esint" ||
|
2002-06-18 15:44:30 +00:00
|
|
|
|
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())
|
2006-10-22 10:15:23 +00:00
|
|
|
|
features.require(to_utf8(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
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
char const * MathMLtype(docstring const & s)
|
2001-11-09 18:02:20 +00:00
|
|
|
|
{
|
|
|
|
|
if (s == "mathop")
|
|
|
|
|
return "mo";
|
|
|
|
|
return "mi";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathSymbol::mathmlize(MathStream & 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();
|
2007-04-01 13:06:41 +00:00
|
|
|
|
|
|
|
|
|
// $,#, etc. In theory the restriction based on catcodes, but then
|
|
|
|
|
// we do not handle catcodes very well, let alone cat code changes,
|
|
|
|
|
// so being outside the alpha range is good enough.
|
|
|
|
|
if (name().size() == 1 && !std::isalpha(name()[0]))
|
2007-03-30 19:28:03 +00:00
|
|
|
|
return;
|
2007-04-01 13:06:41 +00:00
|
|
|
|
|
2002-08-22 10:04:11 +00:00
|
|
|
|
os.pendingSpace(true);
|
2001-11-07 08:51:35 +00:00
|
|
|
|
}
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
|
void InsetMathSymbol::infoize2(odocstream & 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
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|