]> git.lyx.org Git - features.git/commitdiff
translate '\int_0^1 e^x dx' to 'int(e^(x),x=0..1)'
authorAndré Pönitz <poenitz@gmx.net>
Fri, 9 Nov 2001 16:27:44 +0000 (16:27 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 9 Nov 2001 16:27:44 +0000 (16:27 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@2999 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/math_atom.C
src/mathed/math_atom.h
src/mathed/math_data.C
src/mathed/math_data.h
src/mathed/math_exintinset.C
src/mathed/math_exintinset.h
src/mathed/math_extern.C
src/mathed/math_mathmlstream.C
src/mathed/math_stringinset.h
src/mathed/math_symbolinset.C

index cfb2e9bbff0c9509fcba29d568ed6c68f59750e4..8a47a3e7239766fdcfc785bd5f8b2db736f84890 100644 (file)
@@ -85,6 +85,12 @@ MathInset * MathAtom::nucleus() const
 }
 
 
+bool MathAtom::hasNucleus() const
+{
+       return nucleus_;
+}
+
+
 MathInset * MathAtom::operator->() const
 {
        return nucleus();
index 8713c4113b17823d2acd64df1338df8af3a98d44..543a861ecfe6ac427d7156a3418cb79aba596f6b 100644 (file)
@@ -43,6 +43,8 @@ public:
        ///
        void reset(MathInset * p);
        ///
+       bool hasNucleus() const;
+       ///
        MathInset * nucleus() const;
        ///
        MathInset * operator->() const;
index 987dc0ff132f6f30b5b1cfa57fa32e1daef5216d..e6caaab34acb9ed21c3dcd2390a3c72ab197a746 100644 (file)
@@ -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);
index f47d9dac015ff36e44aa27ff6e217db1a1134bf4..83c3383d4422e5a41e93c88030793acc33c9c4f2 100644 (file)
@@ -93,6 +93,11 @@ public:
        ///
        MathAtom & back();
 
+       ///
+       MathAtom & front();
+       ///
+       MathAtom const & front() const;
+
        ///
        void dump() const;
        ///
index 2ad11b39df7c60a731f24554eb4539426c2b64a2..0168fd9cb31a64e2249f014286510f99edce875d 100644 (file)
@@ -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_;
+}
+
index c92497a3b920ae129c4f6674cd17c33930995232..8e14e1c7a9b5f8a56a3f11d8ce434167e342fff2 100644 (file)
 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_;
        ///
index 947ce0ebc54c2357f5bd318ccdaf563c5c8cab53..b966b5ac03f16dd67f8a4e6d548d081fe2f6ff27 100644 (file)
@@ -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";
 }
 
 
index 5e5dccd145f16fa23bddf8086eb4111fdfbd0553..eb697eaaa0ca131342c08b838b53d78eece2cdaa 100644 (file)
@@ -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;           
 }
 
index 85c97fc5818948aff3f16b9d8ee798a6d200fce2..1a63f7c7721ffac77be71d32187c4ec2c79115b3 100644 (file)
@@ -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;
        ///
index 38ad5673ede1b2c91abc834e5bfeb860644898a2..4d731c6bfab2347dc7e0ae5f19befb6976cc414d 100644 (file)
@@ -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);