math_macrotemplate.h \
math_macrotable.C \
math_macrotable.h \
+ math_mathmlstream.C \
+ math_mathmlstream.h \
math_matrixinset.C \
math_matrixinset.h \
math_metricsinfo.h \
}
-bool needAsterisk(MathAtom const & a, MathAtom const & b)
+bool needAsterisk(MathAtom const &, MathAtom const &)
{
return false;
}
}
-string MathArray::octavize() const
+void MathArray::octavize(OctaveStream & os) const
{
MathArray ar = glueChars();
- string res;
for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
MathInset const * p = it->nucleus();
if (MathScriptInset const * q = ar.asScript(it)) {
- res += q->octavize(p);
+ q->octavize(p, os);
++it;
} else
- res += p->octavize();
+ p->octavize(os);
}
- return res;
}
-string MathArray::maplize() const
+void MathArray::maplize(MapleStream & os) const
{
MathArray ar = glueChars();
- string res;
for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
MathInset const * p = it->nucleus();
if (MathScriptInset const * q = ar.asScript(it)) {
- res += q->maplize(p);
+ q->maplize(p, os);
++it;
} else
- res += p->maplize();
+ p->maplize(os);
}
- return res;
}
-string MathArray::mathmlize() const
+void MathArray::mathmlize(MathMLStream & os) const
{
MathArray ar = glueChars();
- string res;
+ os << "<mrow>";
for (const_iterator it = ar.begin(); it != ar.end(); ++it) {
MathInset const * p = it->nucleus();
if (MathScriptInset const * q = ar.asScript(it)) {
- res += q->mathmlize(p);
+ q->mathmlize(p, os);
++it;
} else
- res += p->mathmlize();
+ p->mathmlize(os);
}
- return res;
+ os << "</mrow>";
}
class MathMacro;
class MathWriteInfo;
class MathMetricsInfo;
+class MathMLStream;
+class MapleStream;
+class OctaveStream;
class LaTeXFeatures;
#ifdef __GNUG__
MathArray guessAsterisks() const;
/// interface to Octave
- string octavize() const;
+ void octavize(OctaveStream &) const;
/// interface to Maple
- string maplize() const;
+ void maplize(MapleStream &) const;
/// interface to MathML
- string mathmlize() const;
+ void mathmlize(MathMLStream &) const;
///
bool isMatrix() const;
std::ostream & operator<<(std::ostream & os, MathArray const & ar);
+
#endif
MathArray pipeThroughMaple(string const & extra, MathArray const & ar)
{
- string header =
- "readlib(latex):\n"
- "`latex/csname_font` := ``:\n"
- "`latex/latex/*` := subs(`\\,`=`\\cdot `,eval(`latex/latex/*`)):\n";
+ string header = "readlib(latex):\n";
+
+ // remove the \\it for variable names
//"#`latex/csname_font` := `\\it `:"
+ header +=
+ "`latex/csname_font` := ``:\n";
+
+ // export matrices in (...) instead of [...]
+ header +=
+ "`latex/latex/matrix` := "
+ "subs(`[`=`(`, `]`=`)`,"
+ "eval(`latex/latex/matrix`)):\n";
+
+ // replace \\cdots with proper '*'
+ header +=
+ "`latex/latex/*` := "
+ "subs(`\\,`=`\\cdot `,"
+ "eval(`latex/latex/*`)):\n";
+
//"#`latex/latex/symbol` "
// " := subs((\\'_\\' = \\'`\\_`\\',eval(`latex/latex/symbol`)): ";
string trailer = "quit;";
- string expr = ar.maplize();
+ ostringstream os;
+ MapleStream ms(os);
+ ms << ar;
+ string expr = os.str();
for (int i = 0; i < 100; ++i) { // at most 100 attempts
// try to fix missing '*' the hard way by using mint
MathArray pipeThroughOctave(string const &, MathArray const & ar)
{
- string expr = ar.octavize();
+ ostringstream os;
+ OctaveStream vs(os);
+ vs << ar;
+ string expr = os.str();
string out;
for (int i = 0; i < 100; ++i) { // at most 100 attempts
int InsetFormula::linuxdoc(Buffer const * buf, ostream & os) const
{
- return ascii(buf, os, 0);
+ return docbook(buf, os);
}
int InsetFormula::docbook(Buffer const * buf, ostream & os) const
{
- return ascii(buf, os, 0);
+ MathMLStream ms(os);
+ ms << "<equation><alt>";
+ int res = ascii(buf, ms.os_, 0);
+ ms << "</alt>\n<mml>" << par_.nucleus() << "<mml></equation>";
+ return res + 1;
}
}
-string MathDelimInset::octavize() const
+void MathDelimInset::octavize(OctaveStream & os) const
{
if (left_ == "|" && right_ == "|")
- return "det(" + cell(0).octavize() + ")";
- return left_ + cell(0).octavize() + right_;
+ os << "det(" << cell(0) << ")";
+ else
+ os << left_.c_str() << cell(0) << right_.c_str();
}
-string MathDelimInset::maplize() const
+void MathDelimInset::maplize(MapleStream & os) const
{
if (left_ == "|" && right_ == "|") {
if (cell(0).isMatrix())
- return "linalg[det](" + cell(0).maplize() + ")";
+ os << "linalg[det](" << cell(0) << ")";
else
- return "abs(" + cell(0).maplize() + ")";
+ os << "abs(" << cell(0) << ")";
}
- return left_ + cell(0).maplize() + right_;
+ else
+ os << left_.c_str() << cell(0) << right_.c_str();
}
///
bool isMatrix() const;
///
- string octavize() const;
+ void octavize(OctaveStream &) const;
///
- string maplize() const;
+ void maplize(MapleStream &) const;
private:
///
int dw() const;
}
-string MathExFuncInset::octavize() const
+void MathExFuncInset::octavize(OctaveStream & os) const
{
- return name_ + '(' + cell(0).octavize() + ')';
+ os << name_.c_str() << '(' << cell(0) << ')';
}
///
void draw(Painter &, int x, int y) const;
///
- string octavize() const;
+ void octavize(OctaveStream &) const;
private:
///
}
-string MathFracInset::maplize() const
+void MathFracInset::maplize(MapleStream & os) const
{
- return '(' + cell(0).maplize() + '/' + cell(1).maplize() + ')';
+ os << '(' << cell(0) << '/' << cell(1) << ')';
+}
+
+
+void MathFracInset::mathmlize(MathMLStream & os) const
+{
+ os << "<mfrac>" << cell(0) << cell(1) << "</mfrac>";
}
///
void draw(Painter &, int x, int y) const;
///
- string maplize() const;
+ void maplize(MapleStream &) const;
+ ///
+ void mathmlize(MathMLStream &) const;
public:
///
const bool atop_;
}
-string MathGridInset::octavize() const
+void MathGridInset::octavize(OctaveStream & os) const
{
- string res;
- res += '[';
+ os << '[';
for (row_type row = 0; row < nrows(); ++row) {
if (row)
- res += ';';
- res += '[';
- for (col_type col = 0; col < ncols(); ++col) {
- res += cell(index(row, col)).octavize();
- res += ' ';
- }
- res += ']';
+ os << ';';
+ os << '[';
+ for (col_type col = 0; col < ncols(); ++col)
+ os << cell(index(row, col)) << ' ';
+ os <<']';
}
- res += ']';
- return res;
+ os <<']';
}
-string MathGridInset::maplize() const
+void MathGridInset::maplize(MapleStream & os) const
{
- string res = "array([";
+ os << "array([";
for (row_type row = 0; row < nrows(); ++row) {
if (row)
- res += ',';
- res += '[';
+ os << ',';
+ os << '[';
for (col_type col = 0; col < ncols(); ++col) {
if (col)
- res += ',';
- res += cell(index(row, col)).maplize();
+ os << ',';
+ os << cell(index(row, col));
}
- res += ']';
+ os << ']';
}
- res += "])";
- return res;
+ os << "])";
}
void setDefaults();
///
- string octavize() const;
+ void octavize(OctaveStream &) const;
///
- string maplize() const;
+ void maplize(MapleStream &) const;
protected:
/// returns proper 'end of line' code for LaTeX
}
-string MathInset::octavize() const
+void MathInset::octavize(OctaveStream & os) const
{
- ostringstream os;
- writeNormal(os);
- return os.str();
- return string();
+ writeNormal(os.os_);
}
-string MathInset::maplize() const
+void MathInset::maplize(MapleStream & os) const
{
- return octavize();
+ writeNormal(os.os_);
}
-string MathInset::mathmlize() const
+void MathInset::mathmlize(MathMLStream & os) const
{
- return string();
+ writeNormal(os.os_);
}
#include "xarray.h"
#include "math_defs.h"
-#include "LString.h"
+#include "math_mathmlstream.h"
/** Abstract base class for all math objects.
A math insets is for use of the math editor only, it isn't a
virtual void handleFont(MathTextCodes) {}
///
- virtual string octavize() const;
+ virtual void octavize(OctaveStream &) const;
///
- virtual string maplize() const;
+ virtual void maplize(MapleStream &) const;
///
- virtual string mathmlize() const;
+ virtual void mathmlize(MathMLStream &) const;
};
std::ostream & operator<<(std::ostream &, MathInset const &);
--- /dev/null
+
+#include "math_inset.h"
+#include "math_mathmlstream.h"
+
+
+MathMLStream & MathMLStream::operator<<(MathInset const * p)
+{
+ p->mathmlize(*this);
+ return *this;
+}
+
+
+MathMLStream & MathMLStream::operator<<(MathArray const & ar)
+{
+ ar.mathmlize(*this);
+ return *this;
+}
+
+
+MathMLStream & MathMLStream::operator<<(char const * s)
+{
+ os_ << s;
+ return *this;
+}
+
+
+MathMLStream & MathMLStream::operator<<(char c)
+{
+ os_ << c;
+ return *this;
+}
+
+
+
+
+MapleStream & MapleStream::operator<<(MathInset const * p)
+{
+ p->maplize(*this);
+ return *this;
+}
+
+
+MapleStream & MapleStream::operator<<(MathArray const & ar)
+{
+ ar.maplize(*this);
+ return *this;
+}
+
+
+MapleStream & MapleStream::operator<<(char const * s)
+{
+ os_ << s;
+ return *this;
+}
+
+
+MapleStream & MapleStream::operator<<(char c)
+{
+ os_ << c;
+ return *this;
+}
+
+
+
+
+OctaveStream & OctaveStream::operator<<(MathInset const * p)
+{
+ p->octavize(*this);
+ return *this;
+}
+
+
+OctaveStream & OctaveStream::operator<<(MathArray const & ar)
+{
+ ar.octavize(*this);
+ return *this;
+}
+
+
+OctaveStream & OctaveStream::operator<<(char const * s)
+{
+ os_ << s;
+ return *this;
+}
+
+
+OctaveStream & OctaveStream::operator<<(char c)
+{
+ os_ << c;
+ return *this;
+}
+
--- /dev/null
+#ifndef MATH_MATH_MLSTREAM
+#define MATH_MATH_MLSTREAM
+
+#include <iosfwd>
+
+
+struct MathMLStream {
+ ///
+ explicit MathMLStream(std::ostream & os) : os_(os) {}
+ ///
+ std::ostream & os_;
+ ///
+ MathMLStream & operator<<(MathInset const *);
+ ///
+ MathMLStream & operator<<(MathArray const &);
+ ///
+ MathMLStream & operator<<(char const *);
+ ///
+ MathMLStream & operator<<(char);
+};
+
+
+struct MapleStream {
+ ///
+ explicit MapleStream(std::ostream & os) : os_(os) {}
+ ///
+ std::ostream & os_;
+ ///
+ MapleStream & operator<<(MathInset const *);
+ ///
+ MapleStream & operator<<(MathArray const &);
+ ///
+ MapleStream & operator<<(char const *);
+ ///
+ MapleStream & operator<<(char);
+};
+
+
+struct OctaveStream {
+ ///
+ explicit OctaveStream(std::ostream & os) : os_(os) {}
+ ///
+ std::ostream & os_;
+ ///
+ OctaveStream & operator<<(MathInset const *);
+ ///
+ OctaveStream & operator<<(MathArray const &);
+ ///
+ OctaveStream & operator<<(char const *);
+ ///
+ OctaveStream & operator<<(char);
+};
+
+#endif
}
-string MathRootInset::octavize() const
+void MathRootInset::octavize(OctaveStream & os) const
{
- return "root(" + cell(1).octavize() + ',' + cell(0).octavize() + ')';
+ os << "root(" << cell(1) << ',' << cell(0) <<')';
+}
+
+
+void MathRootInset::mathmlize(MathMLStream & os) const
+{
+ os << "<mroot>" << cell(1) << cell(0) << "</mroot>";
}
///
bool idxDown(int & idx, int & pos) const;
///
- string octavize() const;
+ void mathmlize(MathMLStream &) const;
+ ///
+ void octavize(OctaveStream &) const;
};
#endif
}
-string MathScriptInset::maplize(MathInset const * nuc) const
+void MathScriptInset::maplize(MathInset const * nuc, MapleStream & os) const
{
- string res;
if (nuc)
- res += nuc->maplize();
+ os << nuc;
if (hasDown() && down().data_.size())
- res += "[" + down().data_.maplize() + "]";
+ os << '[' << down().data_ << ']';
if (hasUp() && up().data_.size())
- res += "^(" + up().data_.maplize() + ")";
- return res;
+ os << "^(" << up().data_ << ')';
}
-string MathScriptInset::octavize(MathInset const * nuc) const
+void MathScriptInset::octavize(MathInset const * nuc, OctaveStream & os) const
{
- return maplize(nuc);
+ if (nuc)
+ os << nuc;
+ if (hasDown() && down().data_.size())
+ os << '[' << down().data_ << ']';
+ if (hasUp() && up().data_.size())
+ os << "^(" << up().data_ << ')';
}
-string MathScriptInset::mathmlize(MathInset const * nuc) const
+void MathScriptInset::mathmlize(MathInset const * nuc, MathMLStream & os) const
{
+ bool d = hasDown() && down().data_.size();
+ bool u = hasUp() && up().data_.size();
+
+ if (u)
+ os << "<sup>";
+
+ if (d)
+ os << "<sub>";
+
if (nuc)
- return nuc->mathmlize();
- return string();
+ os << nuc;
+ else
+ os << "<mrow/>";
+
+ if (d)
+ os << down().data_ << "</sub>";
+
+ if (u)
+ os << up().data_ << "</sup>";
}
void ensure(bool up);
///
- virtual string octavize(MathInset const * nuc) const;
+ void octavize(MathInset const * nuc, OctaveStream & os) const;
///
- virtual string maplize(MathInset const * nuc) const;
+ void maplize(MathInset const * nuc, MapleStream & os) const;
///
- virtual string mathmlize(MathInset const * nuc) const;
+ void mathmlize(MathInset const * nuc, MathMLStream & os) const;
public:
/// returns x offset for main part
}
-string MathSqrtInset::maplize() const
+void MathSqrtInset::maplize(MapleStream & os) const
{
- return "sqrt(" + cell(0).maplize() + ')';
+ os << "sqrt(" << cell(0) << ')';
+}
+
+
+void MathSqrtInset::mathmlize(MathMLStream & os) const
+{
+ os << "<msqrt>" << cell(0) << "</msqrt>";
}
///
void metrics(MathMetricsInfo const & st) const;
///
- string maplize() const;
+ void maplize(MapleStream &) const;
+ ///
+ void mathmlize(MathMLStream &) const;
};
#endif
}
-string MathStringInset::octavize() const
+void MathStringInset::maplize(MapleStream & os) const
{
- return maplize();
+ if (code_ != LM_TC_VAR || str_.size() <= 1) {
+ os << str_.c_str();
+ return;
+ }
+
+ // insert '*' between adjacent chars if type is LM_TC_VAR
+ os << str_[0];
+ for (string::size_type i = 1; i < str_.size(); ++i)
+ os << '*' << str_[i];
}
-string MathStringInset::maplize() const
+void MathStringInset::octavize(OctaveStream & os) const
{
- if (code_ != LM_TC_VAR)
- return str_;
- if (str_.size() <= 1)
- return str_;
- string res;
+ if (code_ != LM_TC_VAR || str_.size() <= 1) {
+ os << str_.c_str();
+ return;
+ }
// insert '*' between adjacent chars if type is LM_TC_VAR
- res += str_[0];
- for (string::size_type i = 1; i < str_.size(); ++i) {
- res += '*';
- res += str_[i];
- }
- return res;
+ os << str_[0];
+ for (string::size_type i = 1; i < str_.size(); ++i)
+ os << '*' << str_[i];
+}
+
+
+void MathStringInset::mathmlize(MathMLStream & os) const
+{
+ if (code_ == LM_TC_VAR)
+ os << "<mi>" << str_.c_str() << "</mi>";
+ else if (code_ == LM_TC_CONST)
+ os << "<mn>" << str_.c_str() << "</mn>";
+ else if (code_ == LM_TC_RM || code_ == LM_TC_TEXTRM)
+ os << "<mtext>" << str_.c_str() << "</mtext>";
+ else
+ os << str_.c_str();
}
///
int width() const;
///
- string & str();
+ void octavize(OctaveStream &) const;
///
- string octavize() const;
+ void maplize(MapleStream &) const;
///
- string maplize() const;
+ void mathmlize(MathMLStream &) const;
private:
/// the string
}
-string MathSymbolInset::octavize() const
+void MathSymbolInset::maplize(MapleStream & os) const
{
if (sym_->name == "cdot")
- return "*";
- return sym_->name;
+ os << '*';
+ else
+ os << sym_->name.c_str();
}
-string MathSymbolInset::maplize() const
+void MathSymbolInset::mathmlize(MathMLStream & os) const
{
- if (sym_->name == "cdot")
- return "*";
- return sym_->name;
+ os << sym_->name.c_str();
}
-string MathSymbolInset::mathmlize() const
+void MathSymbolInset::octavize(OctaveStream & os) const
{
- return sym_->name;
+ if (sym_->name == "cdot")
+ os << '*';
+ else
+ os << sym_->name.c_str();
}
+
+
bool takesLimits() const;
///
- string octavize() const;
+ void maplize(MapleStream &) const;
///
- string maplize() const;
+ void mathmlize(MathMLStream &) const;
///
- string mathmlize() const;
+ void octavize(OctaveStream &) const;
private:
///
MathTextCodes code() const;