From 80357480fefb30e8fcda9b6081df8e8720a91975 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Andr=C3=A9=20P=C3=B6nitz?= Date: Fri, 12 Jul 2002 11:21:21 +0000 Subject: [PATCH] make \lim work for math-extern git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4619 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/mathed/Makefile.am | 2 + src/mathed/math_diffinset.C | 1 + src/mathed/math_extern.C | 76 +++++++++++++++++++++++++++++++----- src/mathed/math_liminset.C | 63 ++++++++++++++++++++++++++++++ src/mathed/math_liminset.h | 33 ++++++++++++++++ src/mathed/math_macrotable.C | 15 ------- 6 files changed, 165 insertions(+), 25 deletions(-) create mode 100644 src/mathed/math_liminset.C create mode 100644 src/mathed/math_liminset.h diff --git a/src/mathed/Makefile.am b/src/mathed/Makefile.am index ace3629e13..cad384f547 100644 --- a/src/mathed/Makefile.am +++ b/src/mathed/Makefile.am @@ -79,6 +79,8 @@ libmathed_la_SOURCES = \ math_kerninset.h \ math_lefteqninset.C \ math_lefteqninset.h \ + math_liminset.C \ + math_liminset.h \ math_macro.C \ math_macro.h \ math_macroarg.C \ diff --git a/src/mathed/math_diffinset.C b/src/mathed/math_diffinset.C index 0fb261878f..f6122c4cf9 100644 --- a/src/mathed/math_diffinset.C +++ b/src/mathed/math_diffinset.C @@ -55,6 +55,7 @@ void MathDiffInset::maplize(MapleStream & os) const os << ')'; } + void MathDiffInset::mathematicize(MathematicaStream & os) const { os << "Dt["; diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index df6de81e29..80f2df0d12 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -12,6 +12,7 @@ #include "math_exfuncinset.h" #include "math_exintinset.h" #include "math_fracinset.h" +#include "math_liminset.h" #include "math_matrixinset.h" #include "math_mathmlstream.h" #include "math_numberinset.h" @@ -442,7 +443,7 @@ void extractDelims(MathArray & ar) void extractFunctions(MathArray & ar) { // we need at least two items... - if (ar.size() <= 1) + if (ar.size() < 2) return; //lyxerr << "\nFunctions from: " << ar << "\n"; @@ -522,7 +523,7 @@ bool testIntDiff(MathInset * p) void extractIntegrals(MathArray & ar) { // we need at least three items... - if (ar.size() <= 2) + if (ar.size() < 3) return; //lyxerr << "\nIntegrals from: " << ar << "\n"; @@ -579,11 +580,6 @@ void extractIntegrals(MathArray & ar) // search sums // -bool testSumSymbol(MathInset * p) -{ - return testSymbol(p, "sum"); -} - bool testEqualSign(MathAtom const & at) { @@ -597,15 +593,15 @@ bool testEqualSign(MathAtom const & at) void extractSums(MathArray & ar) { // we need at least two items... - if (ar.size() <= 1) + if (ar.size() < 2) return; //lyxerr << "\nSums from: " << ar << "\n"; - for (MathArray::size_type i = 0; i + 1< ar.size(); ++i) { + for (MathArray::size_type i = 0; i + 1 < ar.size(); ++i) { MathArray::iterator it = ar.begin() + i; // is this a sum name? - if (!testSumSymbol(it->nucleus())) + if (!testSymbol(it->nucleus(), "sum")) continue; // create a proper inset as replacement @@ -761,6 +757,65 @@ void extractDiff(MathArray & ar) } +// +// search limits +// + + +bool testRightArrow(MathAtom const & at) +{ + return + testSymbol(at.nucleus(), "to") || + testSymbol(at.nucleus(), "rightarrow"); +} + + + +// replace '\lim_{x->x0} f(x)' sequences by a real MathLimInset +// assume 'extractDelims' ran before +void extractLims(MathArray & ar) +{ + // we need at least three items... + if (ar.size() < 3) + return; + + //lyxerr << "\nLimits from: " << ar << "\n"; + for (MathArray::size_type i = 0; i + 2 < ar.size(); ++i) { + MathArray::iterator it = ar.begin() + i; + + // is this a limit function? + if (!testSymbol(it->nucleus(), "lim")) + continue; + + // the next one must be a subscript (without superscript) + MathScriptInset * sub = (*(it + 1))->asScriptInset(); + if (!sub || !sub->hasDown() || sub->hasUp()) + continue; + + // and it must contain a -> symbol + MathArray & s = sub->down().data(); + MathArray::iterator st = find_if(s.begin(), s.end(), &testRightArrow); + if (st == s.end()) + continue; + + // the -> splits the subscript int x and x0 + MathArray x = MathArray(s, 0, st - s.begin()); + MathArray x0 = MathArray(s, st - s.begin() + 1, s.size()); + + // use something behind the script as core + MathArray f; + MathArray::iterator tt = extractArgument(f, it + 2, ar.end()); + + // create a proper inset as replacement + MathLimInset * p = new MathLimInset(f, x, x0); + + // cleanup + ar.erase(it + 1, tt); + (*it).reset(p); + } + //lyxerr << "\nLimits to: " << ar << "\n"; +} + // // combine searches @@ -778,6 +833,7 @@ void extractStructure(MathArray & ar) extractSums(ar); extractDiff(ar); extractExps(ar); + extractLims(ar); extractStrings(ar); } diff --git a/src/mathed/math_liminset.C b/src/mathed/math_liminset.C new file mode 100644 index 0000000000..5c1b1d8a4b --- /dev/null +++ b/src/mathed/math_liminset.C @@ -0,0 +1,63 @@ +#include "math_liminset.h" +#include "math_support.h" +#include "math_mathmlstream.h" +#include "math_symbolinset.h" +#include "debug.h" + + +MathLimInset::MathLimInset + (MathArray const & f, MathArray const & x, MathArray const & x0) + : MathNestInset(3) +{ + cell(0) = f; + cell(1) = x; + cell(2) = x0; +} + + +MathInset * MathLimInset::clone() const +{ + return new MathLimInset(*this); +} + + +void MathLimInset::normalize(NormalStream & os) const +{ + os << "[lim " << cell(0) << ' ' << cell(1) << ' ' << cell(2) << ']'; +} + + +void MathLimInset::metrics(MathMetricsInfo &) const +{ + lyxerr << "should not happen\n"; +} + + +void MathLimInset::draw(MathPainterInfo &, int, int) const +{ + lyxerr << "should not happen\n"; +} + + +void MathLimInset::maplize(MapleStream & os) const +{ + os << "limit(" << cell(0) << ',' << cell(1) << '=' << cell(2) << ')'; +} + + +void MathLimInset::mathematicize(MathematicaStream & os) const +{ + os << "Lim[" << cell(0) << ',' << cell(1) << ',' << cell(2) << ']'; +} + + +void MathLimInset::mathmlize(MathMLStream & os) const +{ + os << "lim(" << cell(0) << ',' << cell(1) << ',' << cell(2) << ')'; +} + + +void MathLimInset::write(WriteStream &) const +{ + lyxerr << "should not happen\n"; +} diff --git a/src/mathed/math_liminset.h b/src/mathed/math_liminset.h new file mode 100644 index 0000000000..c1ecb90fdb --- /dev/null +++ b/src/mathed/math_liminset.h @@ -0,0 +1,33 @@ +// -*- C++ -*- +#ifndef MATH_LIMINSET_H +#define MATH_LIMINSET_H + +// lim_{x->x0} f(x) in one block +// for interfacing external programs + +#include "math_nestinset.h" + +class MathLimInset : public MathNestInset { +public: + /// + MathLimInset(MathArray const & f, MathArray const & x, MathArray const & x0); + /// + MathInset * clone() const; + /// + void metrics(MathMetricsInfo & mi) const; + /// + void draw(MathPainterInfo & pi, int x, int y) const; + + /// + void normalize(NormalStream &) const; + /// + void maplize(MapleStream &) const; + /// + void mathematicize(MathematicaStream &) const; + /// + void mathmlize(MathMLStream &) const; + /// + void write(WriteStream & os) const; +}; + +#endif diff --git a/src/mathed/math_macrotable.C b/src/mathed/math_macrotable.C index b7cd35d2d3..e52da89534 100644 --- a/src/mathed/math_macrotable.C +++ b/src/mathed/math_macrotable.C @@ -93,17 +93,6 @@ void MathMacroTable::builtinMacros() // fontmath.ltx - define("\\def\\lnot{\\neg}"); - define("\\def\\land{\\wedge}"); - define("\\def\\lor{\\vee}"); - define("\\def\\ne{\\neq}"); - define("\\def\\le{\\leq}"); - define("\\def\\ge{\\geq}"); - define("\\def\\owns{\\ni}"); - define("\\def\\gets{\\leftarrow}"); - define("\\def\\to{\\rightarrow}"); - define("\\def\\|{\\Vert}"); - define("\\def\\longleftrightarrow{\\leftarrow\\kern-8mu\\rightarrow}"); define("\\def\\Longleftrightarrow{\\Leftarrow\\kern-8mu\\Rightarrow}"); define("\\def\\doteq{\\stackrel{\\cdot}{\\=}}"); @@ -133,8 +122,6 @@ void MathMacroTable::builtinMacros() define("\\def\\dashrightarrow{\\lyxdabar\\lyxdabar\\lyxright}"); define("\\def\\dashleftarrow{\\lyxleft\\lyxdabar\\lyxdabar}"); define("\\def\\dasharrow{\\dashrightarrow}"); - define("\\def\\Box{\\square}"); - define("\\def\\Diamond{\\lozenge}"); define("\\def\\leadsto{\\rightsquigarrow}"); // amssymb.sty @@ -143,8 +130,6 @@ void MathMacroTable::builtinMacros() define("\\def\\Doteq{\\doteqdot}"); define("\\def\\doublecup{\\Cup}"); define("\\def\\doublecap{\\Cap}"); - define("\\def\\llless{\\lll}"); - define("\\def\\gggtr{\\ggg}"); //} //if (math_font_available(LM_TC_MSB)) { -- 2.39.2