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
|
|
|
|
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
|
|
|
|
2016-05-30 08:33:35 +00:00
|
|
|
MathClass InsetMath::mathClass() const
|
|
|
|
{
|
|
|
|
return MC_ORD;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-28 12:13:36 +00:00
|
|
|
bool InsetMath::addToMathRow(MathRow & mrow, MetricsInfo & ) const
|
2016-11-16 14:07:00 +00:00
|
|
|
{
|
2016-12-02 14:58:39 +00:00
|
|
|
MathRow::Element e(MathRow::INSET, mathClass());
|
2016-11-16 14:07:00 +00:00
|
|
|
e.inset = this;
|
|
|
|
mrow.push_back(e);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-11-14 17:01:56 +00:00
|
|
|
void InsetMath::metricsMarkers(MetricsInfo & mi, Dimension & dim,
|
|
|
|
int framesize) const
|
|
|
|
{
|
|
|
|
if (!mi.base.macro_nesting)
|
|
|
|
Inset::metricsMarkers(dim, framesize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMath::metricsMarkers2(MetricsInfo & mi, Dimension & dim,
|
|
|
|
int framesize) const
|
|
|
|
{
|
|
|
|
if (!mi.base.macro_nesting)
|
|
|
|
Inset::metricsMarkers2(dim, framesize);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMath::drawMarkers(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
if (!pi.base.macro_nesting)
|
|
|
|
Inset::drawMarkers(pi, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void InsetMath::drawMarkers2(PainterInfo & pi, int x, int y) const
|
|
|
|
{
|
|
|
|
if (!pi.base.macro_nesting)
|
|
|
|
Inset::drawMarkers2(pi, x, y);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2016-11-16 14:07:00 +00:00
|
|
|
|
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
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-03-08 19:52:18 +00:00
|
|
|
int InsetMath::plaintext(odocstringstream &,
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2009-12-31 15:46:39 +00:00
|
|
|
void InsetMath::mathmlize(MathStream & os) const
|
2001-11-07 08:51:35 +00:00
|
|
|
{
|
2009-12-31 18:40:20 +00:00
|
|
|
os << "<!-- " << from_utf8(insetName(lyxCode())) << " -->";
|
2009-12-16 14:53:23 +00:00
|
|
|
os << MTag("mi");
|
2007-05-28 22:27:45 +00:00
|
|
|
NormalStream ns(os.os());
|
|
|
|
normalize(ns);
|
2009-12-16 14:53:23 +00:00
|
|
|
os << 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
|