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"
|
2006-10-22 10:15:23 +00:00
|
|
|
#include "MathStream.h"
|
2001-02-13 13:28:32 +00:00
|
|
|
|
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"
|
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
|
|
|
|
2008-04-30 08:26:40 +00:00
|
|
|
#include "support/lassert.h"
|
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
|
|
|
|
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
|
|
|
|
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;
|
2009-08-07 05:25:22 +00:00
|
|
|
WriteStream wi(os, 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
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-02-27 20:43:16 +00:00
|
|
|
int InsetMath::plaintext(odocstream &, OutputParams const &) 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
|
2008-04-10 21:49:34 +00:00
|
|
|
LASSERT(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-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
|
|
|
|
|
|
|
|
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;
|
2009-08-07 05:25:22 +00:00
|
|
|
WriteStream wi(oss, 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
|
|
|
{
|
2009-08-07 05:25:22 +00:00
|
|
|
WriteStream wi(os, 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
|