]> git.lyx.org Git - lyx.git/blobdiff - src/mathed/MathExtern.cpp
Another warning.
[lyx.git] / src / mathed / MathExtern.cpp
index 95432cc4b08460f414cdf561e9ca1254d7f33a77..ce055ea33670a96c97c5bc9b177ff1f63ffcb1fd 100644 (file)
@@ -16,6 +16,7 @@
 
 #include "MathExtern.h"
 
+#include "InsetMathAMSArray.h"
 #include "InsetMathArray.h"
 #include "InsetMathChar.h"
 #include "InsetMathDelim.h"
@@ -53,6 +54,7 @@ namespace lyx {
 namespace {
 
 enum ExternalMath {
+       HTML,
        MAPLE,
        MAXIMA,
        MATHEMATICA,
@@ -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();
@@ -193,20 +197,31 @@ void extractMatrices(MathData & ar)
        //lyxerr << "\nMatrices from: " << ar << endl;
        // first pass for explicitly delimited stuff
        for (size_t i = 0; i < ar.size(); ++i) {
-               if (!ar[i]->asDelimInset())
+               InsetMathDelim const * const inset = ar[i]->asDelimInset();
+               if (!inset)
                        continue;
-               MathData const & arr = ar[i]->asDelimInset()->cell(0);
+               MathData const & arr = inset->cell(0);
                if (arr.size() != 1)
                        continue;
                if (!arr.front()->asGridInset())
                        continue;
-               ar[i] = MathAtom(new InsetMathMatrix(*(arr.front()->asGridInset())));
+               ar[i] = MathAtom(new InsetMathMatrix(*(arr.front()->asGridInset()), 
+                                inset->left_, inset->right_));
        }
 
        // second pass for AMS "pmatrix" etc
-       for (size_t i = 0; i < ar.size(); ++i)
-               if (ar[i]->asAMSArrayInset())
-                       ar[i] = MathAtom(new InsetMathMatrix(*(ar[i]->asGridInset())));
+       for (size_t i = 0; i < ar.size(); ++i) {
+               InsetMathAMSArray const * const inset = ar[i]->asAMSArrayInset();
+               if (inset) {
+                       string left = inset->name_left();
+                       if (left == "Vert")
+                               left = "[";
+                       string right = inset->name_right();
+                       if (right == "Vert")
+                               right = "]";
+                       ar[i] = MathAtom(new InsetMathMatrix(*inset, from_ascii(left), from_ascii(right)));
+               }
+       }
        //lyxerr << "\nMatrices to: " << ar << endl;
 }
 
@@ -934,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);
-       extractSums(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;
 }
 
@@ -1401,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)
 {
@@ -1462,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;