]> git.lyx.org Git - features.git/commitdiff
make \lim work for math-extern
authorAndré Pönitz <poenitz@gmx.net>
Fri, 12 Jul 2002 11:21:21 +0000 (11:21 +0000)
committerAndré Pönitz <poenitz@gmx.net>
Fri, 12 Jul 2002 11:21:21 +0000 (11:21 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@4619 a592a061-630c-0410-9148-cb99ea01b6c8

src/mathed/Makefile.am
src/mathed/math_diffinset.C
src/mathed/math_extern.C
src/mathed/math_liminset.C [new file with mode: 0644]
src/mathed/math_liminset.h [new file with mode: 0644]
src/mathed/math_macrotable.C

index ace3629e137362dde88f182b31c9a6b842f872db..cad384f547813d137f65f7832101e763309de7f2 100644 (file)
@@ -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 \
index 0fb261878f87a4caae2fb3f0709b7bd470b3820d..f6122c4cf972eb366cb22ab32c4e25828148ff57 100644 (file)
@@ -55,6 +55,7 @@ void MathDiffInset::maplize(MapleStream & os) const
        os << ')';
 }
 
+
 void MathDiffInset::mathematicize(MathematicaStream & os) const
 {
        os << "Dt[";
index df6de81e292464ea3c0fdae5cb4e6a95c492f7a7..80f2df0d121988e95f81f03eeedb03fb4fe9db5e 100644 (file)
@@ -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 (file)
index 0000000..5c1b1d8
--- /dev/null
@@ -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 (file)
index 0000000..c1ecb90
--- /dev/null
@@ -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
index b7cd35d2d36afc409ca0c60f704d8600dfc75b34..e52da895341b1fd5a8b03745434dd7df5e2eb73c 100644 (file)
@@ -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)) {