]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_extern.C
try to fix rounding errors
[lyx.git] / src / mathed / math_extern.C
index 3cf02b2bd2838d417bbe536b00dc50f208ccd5d8..502c640e2d2d236725422e4b5f67f7bedd49e667 100644 (file)
@@ -4,18 +4,19 @@
 
 #include <algorithm>
 
+#include "math_amsarrayinset.h"
 #include "math_charinset.h"
 #include "math_deliminset.h"
 #include "math_diffinset.h"
 #include "math_exfuncinset.h"
 #include "math_exintinset.h"
-#include "math_funcinset.h"
 #include "math_fracinset.h"
 #include "math_matrixinset.h"
 #include "math_mathmlstream.h"
 #include "math_scriptinset.h"
 #include "math_stringinset.h"
 #include "math_symbolinset.h"
+#include "math_unknowninset.h"
 #include "Lsstream.h"
 #include "debug.h"
 
@@ -105,6 +106,8 @@ MathArray::iterator extractArgument(MathArray & ar,
 
 MathScriptInset const * asScript(MathArray::const_iterator it)
 {
+       if (!it->nucleus())
+               return 0;
        if (it->nucleus()->asScriptInset())
                return 0;
        ++it;
@@ -118,16 +121,10 @@ MathScriptInset const * asScript(MathArray::const_iterator it)
 // returns sequence of char with same code starting at it up to end
 // it might be less, though...
 MathArray::const_iterator charSequence(MathArray::const_iterator it,
-       MathArray::const_iterator end, string & s, MathTextCodes & c)
+       MathArray::const_iterator end, string & s)
 {
-       MathCharInset const * p = (*it)->asCharInset();
-       c = p->code();
-       for (; it != end; ++it) {
-               p = (*it)->asCharInset();
-               if (!p || p->code() != c)
-                       break;
-               s += p->getChar();
-       }
+       for (; it != end && (*it)->asCharInset(); ++it)
+               s += (*it)->getChar();
        return it;
 }
 
@@ -143,7 +140,7 @@ void extractStrings(MathArray & ar)
                // create proper string inset
                MathStringInset * p = new MathStringInset;
                MathArray::const_iterator
-                       jt = charSequence(it, ar.end(), p->str_, p->code_);
+                       jt = charSequence(it, ar.end(), p->str_);
 
                // clean up
                (*it).reset(p);
@@ -162,14 +159,23 @@ MathInset * singleItem(MathArray & ar)
 void extractMatrices(MathArray & ar)
 {
        //lyxerr << "\nMatrices from: " << ar << "\n";
+       // first pass for explicitly delimited stuff
        for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
                MathDelimInset * del = (*it)->asDelimInset();
                if (!del)
                        continue;
                MathInset * arr = singleItem(del->cell(0));
-               if (!arr || !arr->asArrayInset())
+               if (!arr || !arr->asGridInset())
+                       continue;
+               *it = MathAtom(new MathMatrixInset(*(arr->asGridInset())));
+       }
+
+       // second pass for AMS "pmatrix" etc
+       for (MathArray::iterator it = ar.begin(); it != ar.end(); ++it) {
+               MathAMSArrayInset * ams = (*it)->asAMSArrayInset();
+               if (!ams)
                        continue;
-               *it = MathAtom(new MathMatrixInset(*(arr->asArrayInset())));
+               *it = MathAtom(new MathMatrixInset(*ams));
        }
        //lyxerr << "\nMatrices to: " << ar << "\n";
 }
@@ -196,8 +202,17 @@ bool extractString(MathInset * p, string & str)
 bool extractNumber(MathArray const & ar, int & i)
 {
        string s;
-       MathTextCodes c;
-       charSequence(ar.begin(), ar.end(), s, c);
+       charSequence(ar.begin(), ar.end(), s);
+       istringstream is(s.c_str());
+       is >> i;
+       return is;
+}
+
+
+bool extractNumber(MathArray const & ar, double & i)
+{
+       string s;
+       charSequence(ar.begin(), ar.end(), s);
        istringstream is(s.c_str());
        is >> i;
        return is;
@@ -384,9 +399,9 @@ void extractFunctions(MathArray & ar)
 
                string name;
                // is it a function?
-               if ((*it)->asFuncInset()) {
+               if ((*it)->asUnknownInset()) {
                        // it certainly is if it is well known...
-                       name = (*it)->asFuncInset()->name();
+                       name = (*it)->asUnknownInset()->name();
                } else {
                        // is this a user defined function?
                        // it it probably not, if it doesn't have a name.