From 4da1f8e66fb8b9edb6200c3eaae0177a5de4a2ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 9 Nov 2001 18:02:20 +0000 Subject: [PATCH] simple MathML output for integrals git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@3000 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_defs.h | 11 ------ src/mathed/math_exintinset.C | 8 ++++- src/mathed/math_extern.C | 4 +++ src/mathed/math_gridinset.C | 61 +++++++++++++++++++++------------- src/mathed/math_gridinset.h | 6 ++-- src/mathed/math_hash.C | 13 +------- src/mathed/math_hullinset.C | 12 +++---- src/mathed/math_hullinset.h | 8 ++--- src/mathed/math_mathmlstream.C | 2 +- src/mathed/math_mathmlstream.h | 2 ++ src/mathed/math_matrixinset.C | 9 +---- src/mathed/math_parser.h | 2 +- src/mathed/math_stringinset.C | 6 ++-- src/mathed/math_symbolinset.C | 15 +++++++-- 14 files changed, 82 insertions(+), 77 deletions(-) diff --git a/src/mathed/math_defs.h b/src/mathed/math_defs.h index 64b62b6550..a787878d85 100644 --- a/src/mathed/math_defs.h +++ b/src/mathed/math_defs.h @@ -118,15 +118,4 @@ enum MathInsetTypes { LM_OT_MAX }; - -/// -enum MathSymbolTypes { - /// - LMB_NONE = 0, - /// - LMB_RELATION, - /// - LMB_OPERATOR -}; - #endif diff --git a/src/mathed/math_exintinset.C b/src/mathed/math_exintinset.C index 0168fd9cb3..2002a6fdd1 100644 --- a/src/mathed/math_exintinset.C +++ b/src/mathed/math_exintinset.C @@ -83,7 +83,13 @@ void MathExIntInset::maplize(MapleStream & os) const void MathExIntInset::mathmlize(MathMLStream & os) const { - //os << name_.c_str() << '(' << cell(0) << ')'; + if (hasScripts()) + scripts_->asScriptInset()->mathmlize(int_.nucleus(), os); + else + int_->mathmlize(os); + os << core_ << "" + << MTag("mrow") << "" + << diff_ << ETag("mrow"); } diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index b966b5ac03..6a9d302313 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -289,6 +289,10 @@ void extractIntegrals(MathArray & ar) MathArray::iterator jt = endNestSearch(it, ar.end(), intSymbolTest, differentialTest); + // something sensible found? + if (jt == ar.end()) + continue; + // create a proper inset as replacement MathExIntInset * p = new MathExIntInset; diff --git a/src/mathed/math_gridinset.C b/src/mathed/math_gridinset.C index dac3caa54d..f6eaa1144b 100644 --- a/src/mathed/math_gridinset.C +++ b/src/mathed/math_gridinset.C @@ -262,29 +262,6 @@ void MathGridInset::draw(Painter & pain, int x, int y) const } -void MathGridInset::write(WriteStream & os) const -{ - for (row_type row = 0; row < nrows(); ++row) { - for (col_type col = 0; col < ncols(); ++col) - os << cell(index(row, col)) << eocString(col).c_str(); - os << eolString(row).c_str(); - } -} - - -void MathGridInset::normalize(NormalStream & os) const -{ - os << "[grid "; - for (row_type row = 0; row < nrows(); ++row) { - os << "[row "; - for (col_type col = 0; col < ncols(); ++col) - os << "[cell " << cell(index(row, col)) << ']'; - os << ']'; - } - os << ']'; -} - - string MathGridInset::eolString(row_type row) const { if (row + 1 == nrows()) @@ -583,3 +560,41 @@ std::vector return res; } + + +void MathGridInset::normalize(NormalStream & os) const +{ + os << "[grid "; + for (row_type row = 0; row < nrows(); ++row) { + os << "[row "; + for (col_type col = 0; col < ncols(); ++col) + os << "[cell " << cell(index(row, col)) << ']'; + os << ']'; + } + os << ']'; +} + + +void MathGridInset::mathmlize(MathMLStream & os) const +{ + os << MTag("mtable"); + for (row_type row = 0; row < nrows(); ++row) { + os << MTag("mtr"); + for (col_type col = 0; col < ncols(); ++col) + os << cell(index(row, col)); + os << ETag("mtr"); + } + os << ETag("mtable"); +} + + +void MathGridInset::write(WriteStream & os) const +{ + for (row_type row = 0; row < nrows(); ++row) { + for (col_type col = 0; col < ncols(); ++col) + os << cell(index(row, col)) << eocString(col).c_str(); + os << eolString(row).c_str(); + } +} + + diff --git a/src/mathed/math_gridinset.h b/src/mathed/math_gridinset.h index 687b3fec03..9567068798 100644 --- a/src/mathed/math_gridinset.h +++ b/src/mathed/math_gridinset.h @@ -149,14 +149,12 @@ public: void write(WriteStream & os) const; /// void normalize(NormalStream &) const; -/* /// - void maplize(MapleStream &) const; + //void maplize(MapleStream &) const; /// void mathmlize(MathMLStream &) const; /// - void octavize(OctaveStream &) const; -*/ + //void octavize(OctaveStream &) const; protected: /// returns proper 'end of line' code for LaTeX diff --git a/src/mathed/math_hash.C b/src/mathed/math_hash.C index df468ddb29..dc1de913e5 100644 --- a/src/mathed/math_hash.C +++ b/src/mathed/math_hash.C @@ -160,16 +160,6 @@ MathTokenEnum tokenEnum(const string & font) } -MathSymbolTypes symbolType(const string & type) -{ - if (type == "mathrel") - return LMB_RELATION; - if (type == "mathbin") - return LMB_OPERATOR; - return LMB_NONE; -} - - void readSymbols(string const & filename) { LyXLex lex(0, 0); @@ -184,7 +174,7 @@ void readSymbols(string const & filename) if (lex.next()) tmp.id = lex.getInteger(); if (lex.next()) - tmp.type = symbolType(lex.getString()); + tmp.type = lex.getString(); if (theWordList.find(tmp.name) != theWordList.end()) lyxerr << "readSymbols: token " << tmp.name << " already exists.\n"; @@ -201,7 +191,6 @@ void initSymbols() tmp.name = p->name; tmp.token = p->token; tmp.id = p->id; - tmp.type = LMB_NONE; tmp.latex_font_id = 0; theWordList[p->name] = tmp; } diff --git a/src/mathed/math_hullinset.C b/src/mathed/math_hullinset.C index 08c8dc1926..9ab4bf1223 100644 --- a/src/mathed/math_hullinset.C +++ b/src/mathed/math_hullinset.C @@ -185,12 +185,6 @@ void MathHullInset::draw(Painter & pain, int x, int y) const } -void MathHullInset::mathmlize(MathMLStream & os) const -{ - MathGridInset::mathmlize(os); -} - - string MathHullInset::label(row_type row) const { return label_[row]; @@ -673,3 +667,9 @@ void MathHullInset::normalize(NormalStream & os) const } +void MathHullInset::mathmlize(MathMLStream & os) const +{ + MathGridInset::mathmlize(os); +} + + diff --git a/src/mathed/math_hullinset.h b/src/mathed/math_hullinset.h index af063231ce..d3e4dea56a 100644 --- a/src/mathed/math_hullinset.h +++ b/src/mathed/math_hullinset.h @@ -25,10 +25,6 @@ public: /// MathInset * clone() const; /// - void write(WriteStream & os) const; - /// - void normalize(NormalStream &) const; - /// void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; @@ -79,7 +75,11 @@ public: /// MathInsetTypes getType() const; /// + void write(WriteStream & os) const; + /// void mathmlize(MathMLStream &) const; + /// + void normalize(NormalStream &) const; private: /// diff --git a/src/mathed/math_mathmlstream.C b/src/mathed/math_mathmlstream.C index eb697eaaa0..0ea5e316da 100644 --- a/src/mathed/math_mathmlstream.C +++ b/src/mathed/math_mathmlstream.C @@ -6,7 +6,7 @@ MathMLStream::MathMLStream(std::ostream & os) - : os_(os), tab_(0), line_(0) + : os_(os), tab_(0), line_(0), lastchar_(0) {} diff --git a/src/mathed/math_mathmlstream.h b/src/mathed/math_mathmlstream.h index 1af4f9ec77..245d6dc084 100644 --- a/src/mathed/math_mathmlstream.h +++ b/src/mathed/math_mathmlstream.h @@ -46,6 +46,8 @@ struct MathMLStream { int tab_; /// int line_; + /// + char lastchar_; }; diff --git a/src/mathed/math_matrixinset.C b/src/mathed/math_matrixinset.C index d8a02da555..1f43e5a9b0 100644 --- a/src/mathed/math_matrixinset.C +++ b/src/mathed/math_matrixinset.C @@ -45,14 +45,7 @@ void MathMatrixInset::maplize(MapleStream & os) const void MathMatrixInset::mathmlize(MathMLStream & os) const { - os << MTag("mtable"); - for (row_type row = 0; row < nrows(); ++row) { - os << MTag("mtr"); - for (col_type col = 0; col < ncols(); ++col) - os << cell(index(row, col)); - os << ETag("mtr"); - } - os << ETag("mtable"); + MathGridInset::mathmlize(os); } diff --git a/src/mathed/math_parser.h b/src/mathed/math_parser.h index 8fe33a3a11..44420f370b 100644 --- a/src/mathed/math_parser.h +++ b/src/mathed/math_parser.h @@ -129,7 +129,7 @@ struct latexkeys { /// unsigned char latex_font_id; /// - MathSymbolTypes type; + string type; }; diff --git a/src/mathed/math_stringinset.C b/src/mathed/math_stringinset.C index b36639e0ba..9f896fd289 100644 --- a/src/mathed/math_stringinset.C +++ b/src/mathed/math_stringinset.C @@ -101,11 +101,11 @@ void MathStringInset::octavize(OctaveStream & os) const void MathStringInset::mathmlize(MathMLStream & os) const { if (code_ == LM_TC_VAR) - os << "" << str_.c_str() << ""; + os << " " << str_.c_str() << " "; else if (code_ == LM_TC_CONST) - os << "" << str_.c_str() << ""; + os << " " << str_.c_str() << " "; else if (code_ == LM_TC_RM || code_ == LM_TC_TEXTRM) - os << "" << str_.c_str() << ""; + os << " " << str_.c_str() << " "; else os << str_.c_str(); } diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 4d731c6bfa..b2855ac9f2 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -1,7 +1,7 @@ #include "math_symbolinset.h" -#include "math_parser.h" #include "math_mathmlstream.h" #include "math_support.h" +#include "math_parser.h" #include "debug.h" @@ -96,7 +96,7 @@ void MathSymbolInset::draw(Painter & pain, int x, int y) const bool MathSymbolInset::isRelOp() const { - return sym_->type == LMB_RELATION; + return sym_->type == "mathrel"; } @@ -127,9 +127,18 @@ void MathSymbolInset::maplize(MapleStream & os) const } +char const * MathMLtype(string const & s) +{ + if (s == "mathop") + return "mo"; + return "mi"; +} + + void MathSymbolInset::mathmlize(MathMLStream & os) const { - os << name().c_str(); + char const * type = MathMLtype(sym_->type); + os << '<' << type << "> " << name().c_str() << " '; }