]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/math_extern.C
oh well
[lyx.git] / src / mathed / math_extern.C
index 3cf02b2bd2838d417bbe536b00dc50f208ccd5d8..0e0a5280124af19ad0824db6fbbf10e2c252878a 100644 (file)
@@ -4,6 +4,7 @@
 
 #include <algorithm>
 
+#include "math_amsarrayinset.h"
 #include "math_charinset.h"
 #include "math_deliminset.h"
 #include "math_diffinset.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;
@@ -162,14 +165,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";
 }
@@ -204,6 +216,17 @@ bool extractNumber(MathArray const & ar, int & i)
 }
 
 
+bool extractNumber(MathArray const & ar, double & i)
+{
+       string s;
+       MathTextCodes c;
+       charSequence(ar.begin(), ar.end(), s, c);
+       istringstream is(s.c_str());
+       is >> i;
+       return is;
+}
+
+
 bool testString(MathInset * p, const string & str)
 {
        string s;