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
This commit is contained in:
André Pönitz 2001-11-09 16:27:44 +00:00
parent 9f6cfd81ce
commit 86c2cf6f65
10 changed files with 143 additions and 30 deletions

View File

@ -85,6 +85,12 @@ MathInset * MathAtom::nucleus() const
}
bool MathAtom::hasNucleus() const
{
return nucleus_;
}
MathInset * MathAtom::operator->() const
{
return nucleus();

View File

@ -43,6 +43,8 @@ public:
///
void reset(MathInset * p);
///
bool hasNucleus() const;
///
MathInset * nucleus() const;
///
MathInset * operator->() const;

View 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);

View File

@ -93,6 +93,11 @@ public:
///
MathAtom & back();
///
MathAtom & front();
///
MathAtom const & front() const;
///
void dump() const;
///

View 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_;
}

View File

@ -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_;
///

View 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
// 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";
}

View 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)
{
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)
{
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)
{
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)
{
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)
{
if (p)
p->write(*this);
else
lyxerr << "MathMLStream::operator<<(NULL) called\n";
return *this;
}

View 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;
///

View 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);