2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMathSymbol.cpp
|
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.
|
|
|
|
*
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
2003-08-19 13:00:56 +00:00
|
|
|
*
|
|
|
|
* 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"
|
2007-11-29 17:57:06 +00:00
|
|
|
|
2007-04-26 04:41:58 +00:00
|
|
|
#include "Dimension.h"
|
2007-11-29 17:57:06 +00:00
|
|
|
#include "LaTeXFeatures.h"
|
|
|
|
#include "MathAtom.h"
|
|
|
|
#include "MathParser.h"
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "MathStream.h"
|
|
|
|
#include "MathSupport.h"
|
2007-05-11 14:17:53 +00:00
|
|
|
|
2007-11-29 07:04:28 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-29 17:57:06 +00:00
|
|
|
#include "support/docstream.h"
|
2007-04-02 15:21:36 +00:00
|
|
|
#include "support/textutils.h"
|
2006-10-21 00:16:43 +00:00
|
|
|
|
2003-07-25 17:11:25 +00:00
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
namespace lyx {
|
2003-05-28 13:22:36 +00:00
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
InsetMathSymbol::InsetMathSymbol(latexkeys const * l)
|
2007-05-11 14:17:53 +00:00
|
|
|
: sym_(l), h_(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)
|
2007-05-11 14:17:53 +00:00
|
|
|
: sym_(in_word_set(from_ascii(name))), h_(0), scriptable_(false)
|
2001-11-09 16:27:44 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2006-10-22 10:15:23 +00:00
|
|
|
InsetMathSymbol::InsetMathSymbol(docstring const & name)
|
2007-05-11 14:17:53 +00:00
|
|
|
: sym_(in_word_set(name)), h_(0), scriptable_(false)
|
2001-12-05 08:04:20 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2007-08-30 18:03:17 +00:00
|
|
|
Inset * InsetMathSymbol::clone() const
|
2001-02-13 13:28:32 +00:00
|
|
|
{
|
2007-08-30 18:03:17 +00:00
|
|
|
return 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;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-09-21 20:39:47 +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
|
2007-12-12 19:28:07 +00:00
|
|
|
// << "'" << endl;
|
2002-10-17 13:15:25 +00:00
|
|
|
|
2011-01-01 19:24:16 +00:00
|
|
|
bool const italic_upcase_greek = sym_->inset == "cmr" &&
|
|
|
|
sym_->extra == "mathalpha" &&
|
|
|
|
mi.base.fontname == "mathit";
|
|
|
|
docstring const font = italic_upcase_greek ? from_ascii("cmm") : sym_->inset;
|
2007-05-11 14:17:53 +00:00
|
|
|
int const em = mathed_char_width(mi.base.font, 'M');
|
2011-01-01 19:24:16 +00:00
|
|
|
FontSetChanger dummy(mi.base, font);
|
2007-05-11 14:17:53 +00:00
|
|
|
mathed_string_dim(mi.base.font, sym_->draw, dim);
|
|
|
|
docstring::const_reverse_iterator rit = sym_->draw.rbegin();
|
|
|
|
kerning_ = mathed_char_kerning(mi.base.font, *rit);
|
|
|
|
// correct height for broken cmex and wasy font
|
|
|
|
if (sym_->inset == "cmex" || sym_->inset == "wasy") {
|
|
|
|
h_ = 4 * dim.des / 5;
|
|
|
|
dim.asc += h_;
|
|
|
|
dim.des -= h_;
|
2001-08-30 22:42:26 +00:00
|
|
|
}
|
2007-05-11 14:17:53 +00:00
|
|
|
// seperate things a bit
|
|
|
|
if (isRelOp())
|
|
|
|
dim.wid += static_cast<int>(0.5 * em + 0.5);
|
|
|
|
else
|
|
|
|
dim.wid += static_cast<int>(0.1667 * em + 0.5);
|
2006-11-09 14:47:56 +00:00
|
|
|
|
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;
|
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
|
2007-12-12 19:28:07 +00:00
|
|
|
// << "'" << endl;
|
2011-01-01 19:24:16 +00:00
|
|
|
|
|
|
|
bool const italic_upcase_greek = sym_->inset == "cmr" &&
|
|
|
|
sym_->extra == "mathalpha" &&
|
|
|
|
pi.base.fontname == "mathit";
|
|
|
|
docstring const font = italic_upcase_greek ? from_ascii("cmm") : sym_->inset;
|
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
|
|
|
|
2011-01-01 19:24:16 +00:00
|
|
|
FontSetChanger dummy(pi.base, font);
|
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::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
|
|
|
|
2009-11-14 16:21:33 +00:00
|
|
|
// FIXME This will likely need some work.
|
2006-10-22 10:15:23 +00:00
|
|
|
char const * MathMLtype(docstring const & s)
|
2001-11-09 18:02:20 +00:00
|
|
|
{
|
2009-11-14 16:21:33 +00:00
|
|
|
if (s == "mathord")
|
|
|
|
return "mi";
|
|
|
|
return "mo";
|
2001-11-09 18:02:20 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-31 15:46:39 +00:00
|
|
|
void InsetMathSymbol::mathmlize(MathStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2010-03-30 00:24:54 +00:00
|
|
|
// FIXME We may need to do more interesting things
|
|
|
|
// with MathMLtype.
|
2002-05-30 07:09:54 +00:00
|
|
|
char const * type = MathMLtype(sym_->extra);
|
2001-11-09 18:55:03 +00:00
|
|
|
os << '<' << type << "> ";
|
2009-11-14 16:21:33 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 22:51:02 +00:00
|
|
|
void InsetMathSymbol::htmlize(HtmlStream & os, bool spacing) const
|
2010-03-30 00:24:54 +00:00
|
|
|
{
|
|
|
|
// FIXME We may need to do more interesting things
|
|
|
|
// with MathMLtype.
|
|
|
|
char const * type = MathMLtype(sym_->extra);
|
|
|
|
bool op = (std::string(type) == "mo");
|
|
|
|
|
|
|
|
if (sym_->xmlname == "x")
|
|
|
|
// unknown so far
|
|
|
|
os << ' ' << name() << ' ';
|
2010-03-30 22:51:02 +00:00
|
|
|
else if (op && spacing)
|
2010-03-30 00:24:54 +00:00
|
|
|
os << ' ' << sym_->xmlname << ' ';
|
|
|
|
else
|
|
|
|
os << sym_->xmlname;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-03-30 22:51:02 +00:00
|
|
|
void InsetMathSymbol::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
htmlize(os, true);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
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
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
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.
|
2007-04-02 15:21:36 +00:00
|
|
|
if (name().size() == 1 && !isAlphaASCII(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
|
|
|
{
|
2007-11-28 22:12:03 +00:00
|
|
|
os << from_ascii("Symbol: ") << name();
|
2002-01-16 14:24:38 +00:00
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
2010-03-30 22:51:02 +00:00
|
|
|
void InsetMathSymbol::validate(LaTeXFeatures & features) const
|
|
|
|
{
|
|
|
|
// this is not really the ideal place to do this, but we can't
|
|
|
|
// validate in InsetMathExInt.
|
2010-03-31 18:24:52 +00:00
|
|
|
if (features.runparams().math_flavor == OutputParams::MathAsHTML
|
2010-03-30 22:51:02 +00:00
|
|
|
&& sym_->name == from_ascii("int")) {
|
|
|
|
features.addPreambleSnippet("<style type=\"text/css\">\n"
|
|
|
|
"span.limits{display: inline-block; vertical-align: middle; text-align:center; font-size: 75%;}\n"
|
|
|
|
"span.limits span{display: block;}\n"
|
|
|
|
"span.intsym{font-size: 150%;}\n"
|
|
|
|
"sub.limit{font-size: 75%;}\n"
|
|
|
|
"sup.limit{font-size: 75%;}\n"
|
|
|
|
"</style>");
|
|
|
|
} else {
|
|
|
|
if (!sym_->requires.empty())
|
|
|
|
features.require(to_utf8(sym_->requires));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2006-10-21 00:16:43 +00:00
|
|
|
} // namespace lyx
|