From 86c2cf6f65d126a73bff901f5dd8e6e711481fd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 9 Nov 2001 16:27:44 +0000 Subject: [PATCH] translate '\int_0^1 e^x dx' to 'int(e^(x),x=0..1)' git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2999 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_atom.C | 6 ++++ src/mathed/math_atom.h | 2 ++ src/mathed/math_data.C | 12 +++++++ src/mathed/math_data.h | 5 +++ src/mathed/math_exintinset.C | 60 +++++++++++++++++++++++++++++----- src/mathed/math_exintinset.h | 19 ++++++++--- src/mathed/math_extern.C | 35 +++++++++++++------- src/mathed/math_mathmlstream.C | 26 ++++++++++++--- src/mathed/math_stringinset.h | 2 +- src/mathed/math_symbolinset.C | 6 ++++ 10 files changed, 143 insertions(+), 30 deletions(-) diff --git a/src/mathed/math_atom.C b/src/mathed/math_atom.C index cfb2e9bbff..8a47a3e723 100644 --- a/src/mathed/math_atom.C +++ b/src/mathed/math_atom.C @@ -85,6 +85,12 @@ MathInset * MathAtom::nucleus() const } +bool MathAtom::hasNucleus() const +{ + return nucleus_; +} + + MathInset * MathAtom::operator->() const { return nucleus(); diff --git a/src/mathed/math_atom.h b/src/mathed/math_atom.h index 8713c4113b..543a861ecf 100644 --- a/src/mathed/math_atom.h +++ b/src/mathed/math_atom.h @@ -43,6 +43,8 @@ public: /// void reset(MathInset * p); /// + bool hasNucleus() const; + /// MathInset * nucleus() const; /// MathInset * operator->() const; diff --git a/src/mathed/math_data.C b/src/mathed/math_data.C index 987dc0ff13..e6caaab34a 100644 --- a/src/mathed/math_data.C +++ b/src/mathed/math_data.C @@ -136,6 +136,18 @@ MathAtom & MathArray::back() } +MathAtom & MathArray::front() +{ + return bf_.front(); +} + + +MathAtom const & MathArray::front() const +{ + return bf_.front(); +} + + void MathArray::dump2() const { NormalStream ns(lyxerr); diff --git a/src/mathed/math_data.h b/src/mathed/math_data.h index f47d9dac01..83c3383d44 100644 --- a/src/mathed/math_data.h +++ b/src/mathed/math_data.h @@ -93,6 +93,11 @@ public: /// MathAtom & back(); + /// + MathAtom & front(); + /// + MathAtom const & front() const; + /// void dump() const; /// diff --git a/src/mathed/math_exintinset.C b/src/mathed/math_exintinset.C index 2ad11b39df..0168fd9cb3 100644 --- a/src/mathed/math_exintinset.C +++ b/src/mathed/math_exintinset.C @@ -5,10 +5,8 @@ #include "math_symbolinset.h" -MathExIntInset::MathExIntInset(MathScriptInset const & scripts, - MathArray const & core, MathArray const & diff) - : int_(new MathSymbolInset("int")), - scripts_(scripts), core_(core), diff_(diff) +MathExIntInset::MathExIntInset() + : int_(new MathSymbolInset("int")) {} @@ -18,16 +16,45 @@ MathInset * MathExIntInset::clone() const } -void MathExIntInset::write(WriteStream & os) const +void MathExIntInset::differential(MathArray const & ar) { - scripts_.write(int_.nucleus(), os); - os << core_ << "d" << diff_; + diff_ = ar; } +void MathExIntInset::core(MathArray const & ar) +{ + core_ = ar; +} + + +void MathExIntInset::scripts(MathAtom const & at) +{ + scripts_ = at; +} + + +void MathExIntInset::symbol(MathAtom const & at) +{ + int_ = at; +} + + +bool MathExIntInset::hasScripts() const +{ + return scripts_.hasNucleus(); +} + + + void MathExIntInset::normalize(NormalStream & os) const { - //os << "[int " << scripts_ << ' ' << core_ << ' ' << diff_ << ']' + os << "[int "; + if (hasScripts()) + os << scripts_.nucleus(); + else + os << "{}"; + os << ' ' << core_ << ' ' << diff_ << ']'; } @@ -45,10 +72,25 @@ void MathExIntInset::draw(Painter &, int, int) const void MathExIntInset::maplize(MapleStream & os) const { - //os << name_.c_str() << '(' << cell(0) << ')'; + os << int_.nucleus() << '(' << core_ << ',' << diff_; + if (hasScripts()) { + MathScriptInset * p = scripts_->asScriptInset(); + os << '=' << p->down().data_ << ".." << p->up().data_; + } + os << ')'; } + void MathExIntInset::mathmlize(MathMLStream & os) const { //os << name_.c_str() << '(' << cell(0) << ')'; } + + +void MathExIntInset::write(WriteStream & os) const +{ + if (hasScripts()) + os << scripts_.nucleus(); + os << core_ << "d" << diff_; +} + diff --git a/src/mathed/math_exintinset.h b/src/mathed/math_exintinset.h index c92497a3b9..8e14e1c7a9 100644 --- a/src/mathed/math_exintinset.h +++ b/src/mathed/math_exintinset.h @@ -10,26 +10,37 @@ class MathExIntInset : public MathInset { public: /// - MathExIntInset(MathScriptInset const &, MathArray const &, MathArray const &); + MathExIntInset(); /// MathInset * clone() const; /// + void differential(MathArray const &); + /// + void core(MathArray const &); + /// + void scripts(MathAtom const &); + /// + void symbol(MathAtom const &); + /// + bool hasScripts() const; + /// void metrics(MathMetricsInfo const & st) const; /// void draw(Painter &, int x, int y) const; - /// - void write(WriteStream & os) const; + /// void normalize(NormalStream &) const; /// void maplize(MapleStream &) const; /// void mathmlize(MathMLStream &) const; + /// + void write(WriteStream & os) const; private: /// MathAtom int_; /// - MathScriptInset scripts_; + MathAtom scripts_; /// MathArray core_; /// diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index 947ce0ebc5..b966b5ac03 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -269,14 +269,6 @@ bool differentialTest(MathInset * p) } -MathInset * intReplacement(const MathArray & ar) -{ - MathDelimInset * del = new MathDelimInset("(", ")"); - del->cell(0) = ar; - return del; -} - - // replace '\int' ['_^'] x 'd''x'(...)' sequences by a real MathExIntInset // assume 'extractDelims' ran before void extractIntegrals(MathArray & ar) @@ -298,12 +290,33 @@ void extractIntegrals(MathArray & ar) endNestSearch(it, ar.end(), intSymbolTest, differentialTest); // create a proper inset as replacement - MathInset * p = intReplacement(MathArray(it + 1, jt)); + MathExIntInset * p = new MathExIntInset; - // replace the original stuff by the new inset - ar.erase(it + 1, jt + 1); + // collect scripts + MathArray::iterator st = it + 1; + if ((*st)->asScriptInset()) { + p->scripts(*st); + p->core(MathArray(st + 1, jt)); + } else { + p->core(MathArray(st, jt)); + } + + // is the differential just 'd' oder 'dsomething'? + // and replace the original stuff by the new inset + string s = extractString(jt->nucleus()); + MathArray diff; + if (s.size() == 1 && jt + 1 != ar.end()) { + // use the next atom as differential + diff.push_back(*(jt + 1)); + ar.erase(it + 1, jt + 2); + } else { + diff.push_back(MathAtom(new MathStringInset(s.substr(1)))); + ar.erase(it + 1, jt + 1); + } + p->differential(diff); (*it).reset(p); } + lyxerr << "\nIntegrals to: " << ar << "\n"; } diff --git a/src/mathed/math_mathmlstream.C b/src/mathed/math_mathmlstream.C index 5e5dccd145..eb697eaaa0 100644 --- a/src/mathed/math_mathmlstream.C +++ b/src/mathed/math_mathmlstream.C @@ -2,6 +2,7 @@ #include "math_inset.h" #include "math_mathmlstream.h" #include "math_extern.h" +#include "debug.h" MathMLStream::MathMLStream(std::ostream & os) @@ -11,7 +12,10 @@ MathMLStream::MathMLStream(std::ostream & os) MathMLStream & MathMLStream::operator<<(MathInset const * p) { - p->mathmlize(*this); + if (p) + p->mathmlize(*this); + else + lyxerr << "MathMLStream::operator<<(NULL) called\n"; return *this; } @@ -70,7 +74,10 @@ void MathMLStream::cr() MapleStream & MapleStream::operator<<(MathInset const * p) { - p->maplize(*this); + if (p) + p->maplize(*this); + else + lyxerr << "MathMLStream::operator<<(NULL) called\n"; return *this; } @@ -108,7 +115,10 @@ MapleStream & MapleStream::operator<<(int i) OctaveStream & OctaveStream::operator<<(MathInset const * p) { - p->octavize(*this); + if (p) + p->octavize(*this); + else + lyxerr << "MathMLStream::operator<<(NULL) called\n"; return *this; } @@ -139,7 +149,10 @@ OctaveStream & OctaveStream::operator<<(char c) NormalStream & NormalStream::operator<<(MathInset const * p) { - p->normalize(*this); + if (p) + p->normalize(*this); + else + lyxerr << "MathMLStream::operator<<(NULL) called\n"; return *this; } @@ -182,7 +195,10 @@ WriteStream::WriteStream(std::ostream & os_) WriteStream & WriteStream::operator<<(MathInset const * p) { - p->write(*this); + if (p) + p->write(*this); + else + lyxerr << "MathMLStream::operator<<(NULL) called\n"; return *this; } diff --git a/src/mathed/math_stringinset.h b/src/mathed/math_stringinset.h index 85c97fc581..1a63f7c772 100644 --- a/src/mathed/math_stringinset.h +++ b/src/mathed/math_stringinset.h @@ -15,7 +15,7 @@ class MathStringInset : public MathInset { public: /// - MathStringInset(string const & s, MathTextCodes t); + MathStringInset(string const & s, MathTextCodes t = LM_TC_TEXTRM); /// MathInset * clone() const; /// diff --git a/src/mathed/math_symbolinset.C b/src/mathed/math_symbolinset.C index 38ad5673ed..4d731c6bfa 100644 --- a/src/mathed/math_symbolinset.C +++ b/src/mathed/math_symbolinset.C @@ -10,6 +10,12 @@ MathSymbolInset::MathSymbolInset(const latexkeys * l) {} +MathSymbolInset::MathSymbolInset(const char * name) + : sym_(in_word_set(name)), h_(0) +{} + + + MathInset * MathSymbolInset::clone() const { return new MathSymbolInset(*this);