From 7534cb5d5e65c05875d6feaf9c34eb7ca691bb72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Tue, 30 Jul 2002 17:51:19 +0000 Subject: [PATCH] re-adjust math-extern heuristics to new super/subscript inset git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4810 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/math_braceinset.C | 24 +++++++ src/mathed/math_braceinset.h | 10 ++- src/mathed/math_exintinset.C | 1 + src/mathed/math_extern.C | 116 ++++++++++++++++++---------------- src/mathed/math_scriptinset.C | 12 ++-- 5 files changed, 103 insertions(+), 60 deletions(-) diff --git a/src/mathed/math_braceinset.C b/src/mathed/math_braceinset.C index 29edda531d..9d9ee6f139 100644 --- a/src/mathed/math_braceinset.C +++ b/src/mathed/math_braceinset.C @@ -65,6 +65,30 @@ void MathBraceInset::normalize(NormalStream & os) const } +void MathBraceInset::maplize(MapleStream & os) const +{ + os << cell(0); +} + + +void MathBraceInset::octavize(OctaveStream & os) const +{ + os << cell(0); +} + + +void MathBraceInset::mathmlize(MathMLStream & os) const +{ + os << MTag("mrow") << cell(0) << ETag("mrow"); +} + + +void MathBraceInset::mathematicize(MathematicaStream & os) const +{ + os << cell(0); +} + + void MathBraceInset::infoize(std::ostream & os) const { os << "Nested Block: "; diff --git a/src/mathed/math_braceinset.h b/src/mathed/math_braceinset.h index 4cb6705957..b1133d3b31 100644 --- a/src/mathed/math_braceinset.h +++ b/src/mathed/math_braceinset.h @@ -23,13 +23,21 @@ public: /// we write extra braces in any case... bool extraBraces() const { return true; } /// + void metrics(MathMetricsInfo & mi) const; + /// void draw(MathPainterInfo &, int x, int y) const; /// void write(WriteStream & os) const; /// write normalized content void normalize(NormalStream & ns) const; /// - void metrics(MathMetricsInfo & mi) const; + void maplize(MapleStream &) const; + /// + void mathematicize(MathematicaStream &) const; + /// + void octavize(OctaveStream &) const; + /// + void mathmlize(MathMLStream &) const; /// void infoize(std::ostream & os) const; diff --git a/src/mathed/math_exintinset.C b/src/mathed/math_exintinset.C index 47a44edde6..97754e10f2 100644 --- a/src/mathed/math_exintinset.C +++ b/src/mathed/math_exintinset.C @@ -74,6 +74,7 @@ void MathExIntInset::maplize(MapleStream & os) const os << ')'; } + void MathExIntInset::mathematicize(MathematicaStream & os) const { if ( symbol_ == "int" ) diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index 00055dec73..e691543517 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -498,6 +498,17 @@ bool testIntSymbol(MathInset * p) } +bool testIntegral(MathInset * p) +{ + return + testIntSymbol(p) || + ( p->asScriptInset() + && p->asScriptInset()->nuc().size() + && testIntSymbol(p->asScriptInset()->nuc().back().nucleus()) ); +} + + + bool testIntDiff(MathInset * p) { return testString(p, "d"); @@ -516,40 +527,27 @@ void extractIntegrals(MathArray & ar) for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) { MathArray::iterator it = ar.begin() + i; - // is this a integral name? - if (!testIntSymbol(it->nucleus())) - continue; - // search 'd' MathArray::iterator jt = - endNestSearch(it, ar.end(), testIntSymbol, testIntDiff); + endNestSearch(it, ar.end(), testIntegral, testIntDiff); // something sensible found? if (jt == ar.end()) continue; - // create a proper inset as replacement - MathExIntInset * p = new MathExIntInset("int"); - - // collect subscript if any - MathArray::iterator st = it + 1; - if (st != ar.end()) - if (MathScriptInset * sub = (*st)->asScriptInset()) - if (sub->hasDown()) { - p->cell(2) = sub->down().data(); - ++st; - } - - // collect superscript if any - if (st != ar.end()) - if (MathScriptInset * sup = (*st)->asScriptInset()) - if (sup->hasUp()) { - p->cell(3) = sup->up().data(); - ++st; - } + // is this a integral name? + if (!testIntegral(it->nucleus())) + continue; // core ist part from behind the scripts to the 'd' - p->cell(0) = MathArray(st, jt); + MathExIntInset * p = new MathExIntInset("int"); + + // handle scripts if available + if (!testIntSymbol(it->nucleus())) { + p->cell(2) = it->nucleus()->asScriptInset()->down().data(); + p->cell(3) = it->nucleus()->asScriptInset()->up().data(); + } + p->cell(0) = MathArray(it + 1, jt); // use the "thing" behind the 'd' as differential MathArray::iterator tt = extractArgument(p->cell(1), jt + 1, ar.end()); @@ -573,6 +571,21 @@ bool testEqualSign(MathAtom const & at) } +bool testSumSymbol(MathInset * p) +{ + return testSymbol(p, "sum"); +} + + +bool testSum(MathInset * p) +{ + return + testSumSymbol(p) || + ( p->asScriptInset() + && p->asScriptInset()->nuc().size() + && testSumSymbol(p->asScriptInset()->nuc().back().nucleus()) ); +} + // replace '\sum' ['_^'] f(x) sequences by a real MathExIntInset // assume 'extractDelims' ran before @@ -587,43 +600,36 @@ void extractSums(MathArray & ar) MathArray::iterator it = ar.begin() + i; // is this a sum name? - if (!testSymbol(it->nucleus(), "sum")) + if (!testSum(it->nucleus())) continue; // create a proper inset as replacement MathExIntInset * p = new MathExIntInset("sum"); // collect lower bound and summation index - MathArray::iterator st = it + 1; - if (st != ar.end()) - if (MathScriptInset * sub = (*st)->asScriptInset()) - if (sub->hasDown()) { - // try to figure out the summation index from the subscript - MathArray & ar = sub->down().data(); - MathArray::iterator it = - find_if(ar.begin(), ar.end(), &testEqualSign); - if (it != ar.end()) { - // we found a '=', use everything in front of that as index, - // and everything behind as lower index - p->cell(1) = MathArray(ar.begin(), it); - p->cell(2) = MathArray(it + 1, ar.end()); - } else { - // use everything as summation index, don't use scripts. - p->cell(1) = ar; - } - ++st; - } + MathScriptInset * sub = (*it)->asScriptInset(); + if (sub && sub->hasDown()) { + // try to figure out the summation index from the subscript + MathArray & ar = sub->down().data(); + MathArray::iterator xt = + find_if(ar.begin(), ar.end(), &testEqualSign); + if (xt != ar.end()) { + // we found a '=', use everything in front of that as index, + // and everything behind as lower index + p->cell(1) = MathArray(ar.begin(), xt); + p->cell(2) = MathArray(xt + 1, ar.end()); + } else { + // use everything as summation index, don't use scripts. + p->cell(1) = ar; + } + } // collect upper bound - if (st != ar.end()) - if (MathScriptInset * sup = (*st)->asScriptInset()) - if (sup->hasUp()) { - p->cell(3) = sup->up().data(); - ++st; - } + if (sub && sub->hasUp()) + p->cell(3) = sub->up().data(); - // use some behind the script as core - MathArray::iterator tt = extractArgument(p->cell(0), st, ar.end()); + // use something behind the script as core + MathArray::iterator tt = extractArgument(p->cell(0), it + 1, ar.end()); // cleanup ar.erase(it + 1, tt); @@ -809,14 +815,14 @@ void extractLims(MathArray & ar) void extractStructure(MathArray & ar) { + extractIntegrals(ar); + extractSums(ar); splitScripts(ar); extractNumbers(ar); extractMatrices(ar); extractDelims(ar); extractFunctions(ar); extractDets(ar); - extractIntegrals(ar); - extractSums(ar); extractDiff(ar); extractExps(ar); extractLims(ar); diff --git a/src/mathed/math_scriptinset.C b/src/mathed/math_scriptinset.C index fb29ee2030..ce1b4bef4b 100644 --- a/src/mathed/math_scriptinset.C +++ b/src/mathed/math_scriptinset.C @@ -368,9 +368,11 @@ void MathScriptInset::normalize(NormalStream & os) const bool d = hasDown() && down().size(); bool u = hasUp() && up().size(); - if (u) + if (u && d) + os << "[subsup "; + else if (u) os << "[sup "; - if (d) + else if (d) os << "[sub "; if (nuc().size()) @@ -378,9 +380,11 @@ void MathScriptInset::normalize(NormalStream & os) const else os << "[par]"; - if (d) + if (u && d) + os << down().data() << ' ' << up().data() << ']'; + else if (d) os << down().data() << ']'; - if (u) + else if (u) os << up().data() << ']'; }