2002-09-11 09:14:57 +00:00
|
|
|
|
2001-12-02 17:03:46 +00:00
|
|
|
#include <config.h>
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
#include "math_mathmlstream.h"
|
2001-12-02 17:03:46 +00:00
|
|
|
#include "math_inset.h"
|
2001-11-09 08:35:57 +00:00
|
|
|
#include "math_extern.h"
|
2002-08-22 11:57:58 +00:00
|
|
|
#include "debug.h"
|
2002-01-14 13:04:06 +00:00
|
|
|
#include "support/lyxalgo.h"
|
2002-08-09 11:17:35 +00:00
|
|
|
#include "support/LOstream.h"
|
2001-12-05 08:04:20 +00:00
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
using std::ostream;
|
2002-05-28 11:13:01 +00:00
|
|
|
using std::strlen;
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2002-08-30 08:36:35 +00:00
|
|
|
namespace {
|
|
|
|
|
2002-12-01 22:59:25 +00:00
|
|
|
bool isAlpha(char c)
|
2002-08-30 08:36:35 +00:00
|
|
|
{
|
|
|
|
return ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2002-02-16 15:59:55 +00:00
|
|
|
|
2002-08-22 10:04:11 +00:00
|
|
|
WriteStream::WriteStream(ostream & os, bool fragile, bool latex)
|
|
|
|
: os_(os), fragile_(fragile), firstitem_(false), latex_(latex),
|
|
|
|
pendingspace_(false), line_(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
|
|
WriteStream::WriteStream(ostream & os)
|
|
|
|
: os_(os), fragile_(false), firstitem_(false), latex_(false),
|
|
|
|
pendingspace_(false), line_(0)
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-08-22 11:57:58 +00:00
|
|
|
WriteStream::~WriteStream()
|
|
|
|
{
|
|
|
|
if (pendingspace_)
|
|
|
|
os_ << ' ';
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-22 10:04:11 +00:00
|
|
|
void WriteStream::addlines(unsigned int n)
|
|
|
|
{
|
|
|
|
line_ += n;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-22 11:57:58 +00:00
|
|
|
void WriteStream::pendingSpace(bool how)
|
|
|
|
{
|
|
|
|
pendingspace_ = how;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-08-22 10:04:11 +00:00
|
|
|
WriteStream & operator<<(WriteStream & ws, MathAtom const & at)
|
|
|
|
{
|
|
|
|
at->write(ws);
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WriteStream & operator<<(WriteStream & ws, MathArray const & ar)
|
|
|
|
{
|
|
|
|
write(ar, ws);
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WriteStream & operator<<(WriteStream & ws, char const * s)
|
|
|
|
{
|
2002-10-16 15:32:34 +00:00
|
|
|
if (ws.pendingSpace() && strlen(s) > 0) {
|
|
|
|
if (isAlpha(s[0]))
|
|
|
|
ws.os() << ' ';
|
|
|
|
ws.pendingSpace(false);
|
|
|
|
}
|
2002-08-22 10:04:11 +00:00
|
|
|
ws.os() << s;
|
|
|
|
ws.addlines(int(lyx::count(s, s + strlen(s), '\n')));
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WriteStream & operator<<(WriteStream & ws, char c)
|
|
|
|
{
|
|
|
|
if (ws.pendingSpace()) {
|
2002-08-30 08:36:35 +00:00
|
|
|
if (isAlpha(c))
|
2002-08-22 13:02:14 +00:00
|
|
|
ws.os() << ' ';
|
2002-08-22 10:04:11 +00:00
|
|
|
ws.pendingSpace(false);
|
|
|
|
}
|
|
|
|
ws.os() << c;
|
|
|
|
if (c == '\n')
|
|
|
|
ws.addlines(1);
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WriteStream & operator<<(WriteStream & ws, int i)
|
|
|
|
{
|
|
|
|
ws.os() << i;
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
WriteStream & operator<<(WriteStream & ws, unsigned int i)
|
|
|
|
{
|
|
|
|
ws.os() << i;
|
|
|
|
return ws;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2002-02-16 15:59:55 +00:00
|
|
|
MathMLStream::MathMLStream(ostream & os)
|
2001-11-09 18:02:20 +00:00
|
|
|
: os_(os), tab_(0), line_(0), lastchar_(0)
|
2001-11-08 12:06:56 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
|
2002-08-08 17:11:30 +00:00
|
|
|
MathMLStream & operator<<(MathMLStream & ms, MathAtom const & at)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2002-08-08 17:11:30 +00:00
|
|
|
at->mathmlize(ms);
|
2001-12-03 16:24:50 +00:00
|
|
|
return ms;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
MathMLStream & operator<<(MathMLStream & ms, MathArray const & ar)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
mathmlize(ar, ms);
|
|
|
|
return ms;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
MathMLStream & operator<<(MathMLStream & ms, char const * s)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
ms.os() << s;
|
|
|
|
return ms;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
MathMLStream & operator<<(MathMLStream & ms, char c)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
ms.os() << c;
|
|
|
|
return ms;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
MathMLStream & operator<<(MathMLStream & ms, MTag const & t)
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
++ms.tab();
|
|
|
|
ms.cr();
|
|
|
|
ms.os() << '<' << t.tag_ << '>';
|
|
|
|
return ms;
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
MathMLStream & operator<<(MathMLStream & ms, ETag const & t)
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
ms.cr();
|
|
|
|
if (ms.tab() > 0)
|
|
|
|
--ms.tab();
|
|
|
|
ms.os() << "</" << t.tag_ << '>';
|
|
|
|
return ms;
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void MathMLStream::cr()
|
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
os() << '\n';
|
|
|
|
for (int i = 0; i < tab(); ++i)
|
|
|
|
os() << ' ';
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
2001-11-07 17:30:26 +00:00
|
|
|
|
|
|
|
|
2002-08-08 17:11:30 +00:00
|
|
|
MapleStream & operator<<(MapleStream & ms, MathAtom const & at)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2003-02-14 14:30:09 +00:00
|
|
|
at->maple(ms);
|
2001-12-03 16:24:50 +00:00
|
|
|
return ms;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
MapleStream & operator<<(MapleStream & ms, MathArray const & ar)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2003-02-14 14:30:09 +00:00
|
|
|
maple(ar, ms);
|
2001-12-03 16:24:50 +00:00
|
|
|
return ms;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
MapleStream & operator<<(MapleStream & ms, char const * s)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
ms.os() << s;
|
|
|
|
return ms;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
MapleStream & operator<<(MapleStream & ms, char c)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
ms.os() << c;
|
|
|
|
return ms;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
MapleStream & operator<<(MapleStream & ms, int i)
|
2001-11-09 08:35:57 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
ms.os() << i;
|
|
|
|
return ms;
|
2001-11-09 08:35:57 +00:00
|
|
|
}
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
|
2002-07-01 11:17:14 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2002-10-28 17:15:19 +00:00
|
|
|
MaximaStream & operator<<(MaximaStream & ms, MathAtom const & at)
|
|
|
|
{
|
2003-02-14 14:30:09 +00:00
|
|
|
at->maxima(ms);
|
2002-10-28 17:15:19 +00:00
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MaximaStream & operator<<(MaximaStream & ms, MathArray const & ar)
|
|
|
|
{
|
2003-02-14 14:30:09 +00:00
|
|
|
maxima(ar, ms);
|
2002-10-28 17:15:19 +00:00
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MaximaStream & operator<<(MaximaStream & ms, char const * s)
|
|
|
|
{
|
|
|
|
ms.os() << s;
|
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MaximaStream & operator<<(MaximaStream & ms, char c)
|
|
|
|
{
|
|
|
|
ms.os() << c;
|
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MaximaStream & operator<<(MaximaStream & ms, int i)
|
|
|
|
{
|
|
|
|
ms.os() << i;
|
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2002-08-08 17:11:30 +00:00
|
|
|
MathematicaStream & operator<<(MathematicaStream & ms, MathAtom const & at)
|
2002-07-01 11:17:14 +00:00
|
|
|
{
|
2003-02-14 14:30:09 +00:00
|
|
|
at->mathematica(ms);
|
2002-07-01 11:17:14 +00:00
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathematicaStream & operator<<(MathematicaStream & ms, MathArray const & ar)
|
|
|
|
{
|
2003-02-14 14:30:09 +00:00
|
|
|
mathematica(ar, ms);
|
2002-07-01 11:17:14 +00:00
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathematicaStream & operator<<(MathematicaStream & ms, char const * s)
|
|
|
|
{
|
|
|
|
ms.os() << s;
|
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathematicaStream & operator<<(MathematicaStream & ms, char c)
|
|
|
|
{
|
|
|
|
ms.os() << c;
|
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
MathematicaStream & operator<<(MathematicaStream & ms, int i)
|
|
|
|
{
|
|
|
|
ms.os() << i;
|
|
|
|
return ms;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
2001-11-07 17:30:26 +00:00
|
|
|
|
2002-08-08 17:11:30 +00:00
|
|
|
OctaveStream & operator<<(OctaveStream & ns, MathAtom const & at)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2003-02-14 14:30:09 +00:00
|
|
|
at->octave(ns);
|
2001-12-03 16:24:50 +00:00
|
|
|
return ns;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
OctaveStream & operator<<(OctaveStream & ns, MathArray const & ar)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2003-02-14 14:30:09 +00:00
|
|
|
octave(ar, ns);
|
2001-12-03 16:24:50 +00:00
|
|
|
return ns;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
OctaveStream & operator<<(OctaveStream & ns, char const * s)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
ns.os() << s;
|
|
|
|
return ns;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
OctaveStream & operator<<(OctaveStream & ns, char c)
|
2001-11-07 17:30:26 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
ns.os() << c;
|
|
|
|
return ns;
|
2001-11-07 17:30:26 +00:00
|
|
|
}
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
|
2002-04-24 17:07:42 +00:00
|
|
|
OctaveStream & operator<<(OctaveStream & ns, int i)
|
|
|
|
{
|
|
|
|
ns.os() << i;
|
|
|
|
return ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
2002-08-08 17:11:30 +00:00
|
|
|
NormalStream & operator<<(NormalStream & ns, MathAtom const & at)
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2002-08-08 17:11:30 +00:00
|
|
|
at->normalize(ns);
|
2001-12-03 16:24:50 +00:00
|
|
|
return ns;
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
NormalStream & operator<<(NormalStream & ns, MathArray const & ar)
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
normalize(ar, ns);
|
|
|
|
return ns;
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
NormalStream & operator<<(NormalStream & ns, char const * s)
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
ns.os() << s;
|
|
|
|
return ns;
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-12-03 16:24:50 +00:00
|
|
|
NormalStream & operator<<(NormalStream & ns, char c)
|
2001-11-08 12:06:56 +00:00
|
|
|
{
|
2001-12-03 16:24:50 +00:00
|
|
|
ns.os() << c;
|
|
|
|
return ns;
|
2001-11-08 12:06:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-07-11 09:34:58 +00:00
|
|
|
NormalStream & operator<<(NormalStream & ns, int i)
|
|
|
|
{
|
|
|
|
ns.os() << i;
|
|
|
|
return ns;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2001-11-08 12:06:56 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////
|