X-Git-Url: https://git.lyx.org/gitweb/?a=blobdiff_plain;f=src%2Fmathed%2Fmath_extern.C;h=502c640e2d2d236725422e4b5f67f7bedd49e667;hb=e093e5e80c334995a77445c8e66a9f3c9594dda1;hp=3cf02b2bd2838d417bbe536b00dc50f208ccd5d8;hpb=2b8ef58dc021912b2862328b9000cfe37578ea37;p=lyx.git diff --git a/src/mathed/math_extern.C b/src/mathed/math_extern.C index 3cf02b2bd2..502c640e2d 100644 --- a/src/mathed/math_extern.C +++ b/src/mathed/math_extern.C @@ -4,18 +4,19 @@ #include +#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.