2003-08-19 13:00:56 +00:00
|
|
|
/**
|
2007-04-25 03:01:35 +00:00
|
|
|
* \file InsetMath.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.
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
* \author Alejandro Aguilar Sierra
|
2008-11-14 15:58:50 +00:00
|
|
|
* \author André Pönitz
|
1999-09-27 18:44:28 +00:00
|
|
|
*
|
2003-08-19 13:00:56 +00:00
|
|
|
* Full author contact details are available in file CREDITS.
|
1999-09-27 18:44:28 +00:00
|
|
|
*/
|
|
|
|
|
2002-09-11 09:14:57 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2006-09-17 09:14:18 +00:00
|
|
|
#include "InsetMath.h"
|
2007-04-26 16:05:57 +00:00
|
|
|
#include "MathData.h"
|
2016-11-16 14:07:00 +00:00
|
|
|
#include "MathRow.h"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "MathStream.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
|
2016-11-14 17:01:56 +00:00
|
|
|
#include "MetricsInfo.h"
|
|
|
|
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/debug.h"
|
2007-11-05 23:46:17 +00:00
|
|
|
#include "support/docstream.h"
|
2008-02-18 07:14:42 +00:00
|
|
|
#include "support/gettext.h"
|
2016-11-14 17:01:56 +00:00
|
|
|
#include "support/lassert.h"
|
2005-07-15 08:51:34 +00:00
|
|
|
#include "support/lstrings.h"
|
2007-04-02 15:21:36 +00:00
|
|
|
#include "support/textutils.h"
|
2005-07-15 08:51:34 +00:00
|
|
|
|
2006-08-17 13:23:08 +00:00
|
|
|
|
2007-12-12 10:16:00 +00:00
|
|
|
using namespace std;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2007-11-29 21:10:35 +00:00
|
|
|
namespace lyx {
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2020-10-31 17:18:51 +00:00
|
|
|
HullType hullType(docstring const & name)
|
2020-10-26 18:16:28 +00:00
|
|
|
{
|
2020-10-31 17:18:51 +00:00
|
|
|
if (name == "none") return hullNone;
|
|
|
|
if (name == "simple") return hullSimple;
|
|
|
|
if (name == "equation") return hullEquation;
|
|
|
|
if (name == "eqnarray") return hullEqnArray;
|
|
|
|
if (name == "align") return hullAlign;
|
|
|
|
if (name == "alignat") return hullAlignAt;
|
|
|
|
if (name == "xalignat") return hullXAlignAt;
|
|
|
|
if (name == "xxalignat") return hullXXAlignAt;
|
|
|
|
if (name == "multline") return hullMultline;
|
|
|
|
if (name == "gather") return hullGather;
|
|
|
|
if (name == "flalign") return hullFlAlign;
|
|
|
|
if (name == "regexp") return hullRegexp;
|
|
|
|
lyxerr << "unknown hull type '" << to_utf8(name) << "'" << endl;
|
2020-10-26 18:16:28 +00:00
|
|
|
return hullUnknown;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
docstring hullName(HullType type)
|
|
|
|
{
|
|
|
|
switch (type) {
|
|
|
|
case hullNone: return from_ascii("none");
|
|
|
|
case hullSimple: return from_ascii("simple");
|
|
|
|
case hullEquation: return from_ascii("equation");
|
|
|
|
case hullEqnArray: return from_ascii("eqnarray");
|
|
|
|
case hullAlign: return from_ascii("align");
|
|
|
|
case hullAlignAt: return from_ascii("alignat");
|
|
|
|
case hullXAlignAt: return from_ascii("xalignat");
|
|
|
|
case hullXXAlignAt: return from_ascii("xxalignat");
|
|
|
|
case hullMultline: return from_ascii("multline");
|
|
|
|
case hullGather: return from_ascii("gather");
|
|
|
|
case hullFlAlign: return from_ascii("flalign");
|
|
|
|
case hullRegexp: return from_ascii("regexp");
|
|
|
|
case hullUnknown:
|
|
|
|
lyxerr << "unknown hull type" << endl;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return from_ascii("none");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2011-03-28 22:33:04 +00:00
|
|
|
docstring InsetMath::name() const
|
|
|
|
{
|
|
|
|
return from_utf8("Unknown");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData & InsetMath::cell(idx_type)
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2009-11-08 11:45:46 +00:00
|
|
|
static MathData dummyCell(&buffer());
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR0("I don't have any cell");
|
2001-08-03 17:10:22 +00:00
|
|
|
return dummyCell;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-04-26 16:05:57 +00:00
|
|
|
MathData const & InsetMath::cell(idx_type) const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2007-04-26 16:05:57 +00:00
|
|
|
static MathData dummyCell;
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR0("I don't have any cell");
|
2001-08-03 17:10:22 +00:00
|
|
|
return dummyCell;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
2001-08-03 09:54:48 +00:00
|
|
|
|
2020-12-02 15:13:32 +00:00
|
|
|
marker_type InsetMath::marker(BufferView const *) const
|
2017-01-06 08:52:10 +00:00
|
|
|
{
|
2020-12-02 15:13:32 +00:00
|
|
|
return nargs() > 0 ? marker_type::MARKER : marker_type::NO_MARKER;
|
2017-01-06 08:52:10 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-01-05 12:25:28 +00:00
|
|
|
bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & mi) const
|
2016-11-16 14:07:00 +00:00
|
|
|
{
|
2017-01-05 12:25:28 +00:00
|
|
|
MathRow::Element e(mi, MathRow::INSET, mathClass());
|
2016-11-16 14:07:00 +00:00
|
|
|
e.inset = this;
|
2020-12-02 15:13:32 +00:00
|
|
|
e.marker = mi.base.macro_nesting ? marker_type::NO_MARKER : marker(mi.base.bv);
|
2016-11-16 14:07:00 +00:00
|
|
|
mrow.push_back(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-07-19 17:56:07 +00:00
|
|
|
/// write LaTeX and LyX code
|
|
|
|
void InsetMath::writeLimits(WriteStream & os) const
|
|
|
|
{
|
|
|
|
if (limits() == LIMITS) {
|
|
|
|
os << "\\limits";
|
|
|
|
os.pendingSpace(true);
|
|
|
|
} else if (limits() == NO_LIMITS) {
|
2020-09-09 08:35:35 +00:00
|
|
|
os << "\\nolimits";
|
2020-07-19 17:56:07 +00:00
|
|
|
os.pendingSpace(true);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMath::dump() const
|
2001-06-25 00:06:33 +00:00
|
|
|
{
|
2003-08-02 11:30:30 +00:00
|
|
|
lyxerr << "---------------------------------------------" << endl;
|
2006-10-21 00:16:43 +00:00
|
|
|
odocstringstream os;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexrowstream ots(os);
|
2015-10-07 03:13:21 +00:00
|
|
|
WriteStream wi(ots, false, true, WriteStream::wsDefault);
|
2001-10-19 11:25:48 +00:00
|
|
|
write(wi);
|
2006-10-21 00:16:43 +00:00
|
|
|
lyxerr << to_utf8(os.str());
|
2003-08-02 11:30:30 +00:00
|
|
|
lyxerr << "\n---------------------------------------------" << endl;
|
2001-06-25 00:06:33 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMath::metricsT(TextMetricsInfo const &, Dimension &) const
|
2002-03-18 11:45:53 +00:00
|
|
|
{
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR0("InsetMath::metricsT(Text) called directly!");
|
2002-03-18 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMath::drawT(TextPainter &, int, int) const
|
2002-03-18 11:45:53 +00:00
|
|
|
{
|
2007-11-29 21:10:35 +00:00
|
|
|
LYXERR0("InsetMath::drawT(Text) called directly!");
|
2002-03-18 11:45:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMath::write(WriteStream & os) const
|
2002-08-05 07:09:11 +00:00
|
|
|
{
|
2008-06-17 11:10:43 +00:00
|
|
|
MathEnsurer ensurer(os);
|
2006-10-22 10:15:23 +00:00
|
|
|
docstring const s = name();
|
|
|
|
os << "\\" << s;
|
2005-07-15 08:51:34 +00:00
|
|
|
// We need an extra ' ' unless this is a single-char-non-ASCII name
|
|
|
|
// or anything non-ASCII follows
|
2007-04-02 15:21:36 +00:00
|
|
|
if (s.size() != 1 || isAlphaASCII(s[0]))
|
2005-07-15 08:51:34 +00:00
|
|
|
os.pendingSpace(true);
|
2008-06-16 14:32:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-07-03 17:53:14 +00:00
|
|
|
int InsetMath::plaintext(odocstringstream &,
|
2013-03-08 19:52:18 +00:00
|
|
|
OutputParams const &, size_t) const
|
2007-02-20 18:19:31 +00:00
|
|
|
{
|
2007-02-24 15:06:04 +00:00
|
|
|
// all math plain text output shall take place in InsetMathHull
|
2013-04-25 21:27:10 +00:00
|
|
|
LATTEST(false);
|
2007-02-24 15:06:04 +00:00
|
|
|
return 0;
|
2007-02-20 18:19:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMath::normalize(NormalStream & os) const
|
2001-08-06 17:20:26 +00:00
|
|
|
{
|
2006-10-22 10:15:23 +00:00
|
|
|
os << '[' << name() << "] ";
|
2001-08-06 17:20:26 +00:00
|
|
|
}
|
2001-11-07 08:51:35 +00:00
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMath::octave(OctaveStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
NormalStream ns(os.os());
|
2001-11-09 08:35:57 +00:00
|
|
|
normalize(ns);
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMath::maple(MapleStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
NormalStream ns(os.os());
|
2001-11-09 08:35:57 +00:00
|
|
|
normalize(ns);
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMath::maxima(MaximaStream & os) const
|
2002-10-28 17:15:19 +00:00
|
|
|
{
|
|
|
|
MapleStream ns(os.os());
|
2003-02-14 14:30:09 +00:00
|
|
|
maple(ns);
|
2002-10-28 17:15:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
void InsetMath::mathematica(MathematicaStream & os) const
|
2002-07-01 11:17:14 +00:00
|
|
|
{
|
|
|
|
NormalStream ns(os.os());
|
|
|
|
normalize(ns);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-12-26 19:02:46 +00:00
|
|
|
void InsetMath::mathmlize(MathMLStream & ms) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
|
|
|
|
ms << MTag("mi");
|
|
|
|
NormalStream ns(ms.os());
|
2007-05-28 22:27:45 +00:00
|
|
|
normalize(ns);
|
2019-05-09 23:52:07 +00:00
|
|
|
ms << ETag("mi");
|
2001-11-07 08:51:35 +00:00
|
|
|
}
|
2002-06-24 15:37:14 +00:00
|
|
|
|
|
|
|
|
2010-03-29 22:52:13 +00:00
|
|
|
void InsetMath::htmlize(HtmlStream & os) const
|
|
|
|
{
|
|
|
|
os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
|
|
|
|
os << MTag("span", "style='color: red;'");
|
|
|
|
NormalStream ns(os.os());
|
|
|
|
normalize(ns);
|
|
|
|
os << ETag("span");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-09-16 18:11:38 +00:00
|
|
|
HullType InsetMath::getType() const
|
2002-07-08 06:39:40 +00:00
|
|
|
{
|
2006-09-03 16:14:51 +00:00
|
|
|
return hullNone;
|
2002-07-08 06:39:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-12-12 19:28:07 +00:00
|
|
|
ostream & operator<<(ostream & os, MathAtom const & at)
|
2006-10-19 16:51:30 +00:00
|
|
|
{
|
2006-10-21 00:16:43 +00:00
|
|
|
odocstringstream oss;
|
2016-09-04 02:02:47 +00:00
|
|
|
otexrowstream ots(oss);
|
2015-10-07 03:13:21 +00:00
|
|
|
WriteStream wi(ots, false, false, WriteStream::wsDefault);
|
2006-10-19 16:51:30 +00:00
|
|
|
at->write(wi);
|
2006-10-21 00:16:43 +00:00
|
|
|
return os << to_utf8(oss.str());
|
2006-10-19 16:51:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
odocstream & operator<<(odocstream & os, MathAtom const & at)
|
2002-09-11 09:14:57 +00:00
|
|
|
{
|
2016-09-04 02:02:47 +00:00
|
|
|
otexrowstream ots(os);
|
2015-10-07 03:13:21 +00:00
|
|
|
WriteStream wi(ots, false, false, WriteStream::wsDefault);
|
2002-09-11 09:14:57 +00:00
|
|
|
at->write(wi);
|
|
|
|
return os;
|
|
|
|
}
|
2006-10-21 00:16:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
} // namespace lyx
|