]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathExtern.cpp
Fix bug #7106: iterator out of range while copying multi-row math.
[lyx.git] / src / mathed / MathExtern.cpp
index 3d85c02a89e2e3acc607f9b413cd103092663846..ce055ea33670a96c97c5bc9b177ff1f63ffcb1fd 100644 (file)
@@ -54,6 +54,7 @@ namespace lyx {
 namespace {
 
 enum ExternalMath {
+       HTML,
        MAPLE,
        MAXIMA,
        MATHEMATICA,
@@ -80,6 +81,7 @@ typedef bool TestItemFunc(MathAtom const &);
 typedef MathAtom ReplaceArgumentFunc(const MathData & ar);
 
 
+
 // try to extract a super/subscript
 // modify iterator position to point behind the thing
 bool extractScript(MathData & ar,
@@ -117,7 +119,9 @@ MathData::iterator extractArgument(MathData & ar,
        // something delimited _is_ an argument
        if ((*pos)->asDelimInset()) {
                // leave out delimiters if this is a function argument
-               if (function && kind != MATHML) {
+               // unless we are doing MathML, in which case we do want
+               // the delimiters
+               if (function && kind != MATHML && kind != HTML) {
                        MathData const & arg = (*pos)->asDelimInset()->cell(0);
                        MathData::const_iterator cur = arg.begin();
                        MathData::const_iterator end = arg.end();
@@ -355,7 +359,7 @@ void splitScripts(MathData & ar)
                        // leave alone sums and integrals
                        InsetMathSymbol const * sym =
                                script->nuc().front()->asSymbolInset();
-                       if (sym && (InsetMathExInt::isExIntOperator(sym->name()) || sym->name() == "int"))
+                       if (sym && (sym->name() == "sum" || sym->name() == "int"))
                                continue;
                }
 
@@ -704,29 +708,25 @@ bool testEqualSign(MathAtom const & at)
 }
 
 
-bool testSumLikeSymbol(MathAtom const & p)
+bool testSumSymbol(MathAtom const & p)
 {
-       return InsetMathExInt::isExIntOperator(p->name());
+       return testSymbol(p, from_ascii("sum"));
 }
 
 
-docstring testSumLike(MathAtom const & at)
+bool testSum(MathAtom const & at)
 {
-       if (testSumLikeSymbol(at))
-               return at->name();
-       if ( at->asScriptInset()
+       return
+        testSumSymbol(at) ||
+               ( at->asScriptInset()
                  && at->asScriptInset()->nuc().size()
-                       && testSumLikeSymbol(at->asScriptInset()->nuc().back()) )
-               return at->asScriptInset()->nuc().back()->name();
-       return docstring();
+                       && testSumSymbol(at->asScriptInset()->nuc().back()) );
 }
 
 
 // replace '\sum' ['_^'] f(x) sequences by a real InsetMathExInt
-// and similar things, like \prod. The things we extract are 
-// determined by InsetMathExInt::isExIntOperator().
 // assume 'extractDelims' ran before
-void extractSumLike(MathData & ar)
+void extractSums(MathData & ar)
 {
        // we need at least two items...
        if (ar.size() < 2)
@@ -739,12 +739,11 @@ void extractSumLike(MathData & ar)
                MathData::iterator it = ar.begin() + i;
 
                // is this a sum name?
-               docstring const opname = testSumLike(ar[i]);
-               if (opname.empty())
+               if (!testSum(ar[i]))
                        continue;
 
                // create a proper inset as replacement
-               auto_ptr<InsetMathExInt> p(new InsetMathExInt(buf, opname));
+               auto_ptr<InsetMathExInt> p(new InsetMathExInt(buf, from_ascii("sum")));
 
                // collect lower bound and summation index
                InsetMathScript const * sub = ar[i]->asScriptInset();
@@ -950,19 +949,22 @@ void extractLims(MathData & ar)
 void extractStructure(MathData & ar, ExternalMath kind)
 {
        //lyxerr << "\nStructure from: " << ar << endl;
-       splitScripts(ar);
+       if (kind != MATHML && kind != HTML)
+               splitScripts(ar);
        extractDelims(ar);
        extractIntegrals(ar, kind);
-       extractSumLike(ar);
+       if (kind != MATHML && kind != HTML)
+               extractSums(ar);
        extractNumbers(ar);
        extractMatrices(ar);
        extractFunctions(ar, kind);
-       extractDets(ar);
-       extractDiff(ar);
-       extractExps(ar);
-       extractLims(ar);
-       if (kind != MATHML)
+       if (kind != MATHML && kind != HTML) {
+               extractDets(ar);
+               extractDiff(ar);
+               extractExps(ar);
+               extractLims(ar);
                extractStrings(ar);
+       }
        //lyxerr << "\nStructure to: " << ar << endl;
 }
 
@@ -1417,18 +1419,37 @@ void mathmlize(MathData const & dat, MathStream & os)
 {
        MathData ar = dat;
        extractStructure(ar, MATHML);
-       if (ar.size() == 0)
-               os << "<mrow/>";
-       else if (ar.size() == 1)
+       if (ar.size() == 0) {
+               if (!os.inText())
+                       os << "<mrow/>";
+       } else if (ar.size() == 1)
                os << ar.front();
        else {
-               os << MTag("mrow");
+               if (!os.inText())
+                       os << MTag("mrow");
                for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
                        (*it)->mathmlize(os);
-               os << ETag("mrow");
+               if (!os.inText())
+                       os << ETag("mrow");
        }
 }
 
+
+void htmlize(MathData const & dat, HtmlStream & os)
+{
+       MathData ar = dat;
+       extractStructure(ar, HTML);
+       if (ar.size() == 0) 
+               return;
+       if (ar.size() == 1) {
+               os << ar.front();
+               return;
+       }
+       for (MathData::const_iterator it = ar.begin(); it != ar.end(); ++it)
+               (*it)->htmlize(os);
+}
+
+
 // convert this inset somehow to a number
 bool extractNumber(MathData const & ar, int & i)
 {
@@ -1478,7 +1499,7 @@ MathData pipeThroughExtern(string const & lang, docstring const & extra,
        }
 
        // run external sript
-       string out = captureOutput(file.absFilename(), data);
+       string out = captureOutput(file.absFileName(), data);
        MathData res;
        mathed_parse_cell(res, from_utf8(out));
        return res;