I recently tried the Computer Algebra System support in LyX and was
disappointed by the fact that it could not handle the simple formulas
you find in the attached cas.lyx file.

Looking at the sources I had the impression that CAS support was in
an unfinished state (sort of), so I tried to improve it.

Please find attached a patch which monotonically improves such support.
I tested it with octave, maxima, and mathematica.

-- 
Enrico


Log:
        * src/mathed/math_symbolinset.C
        (void MathSymbolInset::maxima):
                - newer maxima versions use inf instead of INF
                - add support for greek pi

        (void MathSymbolInset::mathematica):
                - add support for \cdot

        * src/mathed/math_stringinset.h
                - account for the const version of asStringInset()

        * src/mathed/math_extern.C
        (bool extractScript):
                - added bool superscript to formal parameters in order
                  to only extract superscripts

        (MathArray::iterator extractArgument):
                - leave out delimiters and a possible superscript
                  for function arguments

        (bool isKnownFunction):
        (bool extractFunctionName):
                - recognize standard and user defined function names

        (void splitScripts):
                - correctly split scripts as expected by other functions

        (MathAtom replaceDelims):
                - ranamed as replaceParenDelims

        (bool testOpenBracket):
        (bool testCloseBracket):
                - test for "[" and "]", respectively

        (MathAtom replaceBracketDelims):
                - replace something delimited by "[" and "]" with a
                  proper DelimInset

        (void extractDelims):
                - create a DelimInset for "[" and "]" delimiters, too

        (void extractFunctions):
                - improved recognition of function names

        (bool testTermDelimiter):
                - test for '+' or '-' as term delimiters

        (MathArray::iterator extractTerm):
                - extract a "term", i.e., something delimited by '+' or '-'

        (bool testDiffItem):
                - improved recognition of a "differential fraction"

        (void extractDiff):
                - call splitScripts() on numerator and denominator of a
                  differential fraction before analyzing them

        (void extractLims):
                - improved recognition of a limit function

        (void extractStructure):
                - reorganized order of searches

        (MathArray pipeThroughMaxima):
                - newer versions of maxima use simpsum instead of SIMPSUM

        (string fromMathematicaName):
                - translates from mathematica names

        (MathArray pipeThroughMathematica):
                - calls mathematica and collects its output

        (MathArray pipeThroughExtern):
                - add support for mathematica

        * src/mathed/math_numberinset.C
        * src/mathed/math_numberinset.h
        (void MathNumberInset::mathematica):
                - add support for mathematica

        * src/mathed/math_matrixinset.C
        * src/mathed/math_matrixinset.h
        (void MathMatrixInset::mathematica):
                - add support for mathematica

        * src/mathed/math_diffinset.C
        * src/mathed/math_diffinset.h
        (void MathDiffInset::maxima):
                - add support for maxima
        
        (void MathDiffInset::mathematica):
                - mathematica uses "D" and not "Dt" for normal derivatives

        * src/mathed/math_liminset.C
        * src/mathed/math_liminset.h
        (void MathLimInset::maxima):
                - add support for maxima

        (void MathLimInset::mathematica):
                - mathematica uses "Limit" and not "Lim" for limits

        * src/mathed/math_exfuncinset.C
        (string asMathematicaName):
                - added some more function names

#LyX 1.4.2 created this file. For more info see http://www.lyx.org/
\lyxformat 245
\begin_document
\begin_header
\textclass article
\language english
\inputencoding auto
\fontscheme default
\graphics default
\paperfontsize default
\papersize default
\use_geometry false
\use_amsmath 1
\cite_engine basic
\use_bibtopic false
\paperorientation portrait
\secnumdepth 3
\tocdepth 3
\paragraph_separation indent
\defskip medskip
\quotes_language english
\papercolumns 1
\papersides 1
\paperpagestyle default
\tracking_changes false
\output_changes false
\end_header

\begin_body

\begin_layout Standard
Place the cursor in a displayed formula an then select one of the external
 CAS programs capable of symbolic computation in 
\family sans
Edit
\family default
\SpecialChar \menuseparator

\family sans
Math
\family default
\SpecialChar \menuseparator

\family sans
Use Computer Algebra System
\family default
.
\end_layout

\begin_layout Standard
\begin_inset Formula \[
\sin x_{1}^{2}\]

\end_inset


\begin_inset Formula \[
\det\left(\begin{array}{cc}
a & b\\
c & d\end{array}\right)\]

\end_inset


\end_layout

\begin_layout Standard
\begin_inset Formula \[
\sum_{i=1}^{\infty}(\frac{1}{2})^{i}\]

\end_inset


\begin_inset Formula \[
\sum_{i=1}^{N}i\cdot(i+1)\]

\end_inset


\begin_inset Formula \[
\lim_{x\rightarrow0}(1+x)^{1/x}\]

\end_inset


\begin_inset Formula \[
\lim_{x\to0}x\csc x\]

\end_inset


\begin_inset Formula \[
\frac{d\sin^{2}x}{dx}\]

\end_inset


\begin_inset Formula \[
\frac{d^{2}}{dx^{2}}\sin x\]

\end_inset


\begin_inset Formula \[
\frac{\partial^{2}\sin(x+y)}{\partial x\partial y}\]

\end_inset


\end_layout

\end_body
\end_document
Index: src/mathed/math_symbolinset.C
===================================================================
--- src/mathed/math_symbolinset.C       (revision 14586)
+++ src/mathed/math_symbolinset.C       (working copy)
@@ -162,7 +162,9 @@
        if (name() == "cdot")
                os << '*';
        else if (name() == "infty")
-               os << "INF";
+               os << "inf";
+       else if (name() == "pi")
+               os << "%pi";
        else
                os << name();
 }
@@ -172,6 +174,7 @@
 {
        if ( name() == "pi")    { os << "Pi"; return;}
        if ( name() == "infty") { os << "Infinity"; return;}
+       if ( name() == "cdot")  { os << '*'; return;}
        os << name();
 }
 
Index: src/mathed/math_stringinset.h
===================================================================
--- src/mathed/math_stringinset.h       (revision 14586)
+++ src/mathed/math_stringinset.h       (working copy)
@@ -31,6 +31,8 @@
        std::string str() const { return str_; }
        ///
        MathStringInset * asStringInset() { return this; }
+       ///
+       MathStringInset const * asStringInset() const { return this; }
 
        ///
        void normalize(NormalStream &) const;
Index: src/mathed/math_extern.C
===================================================================
--- src/mathed/math_extern.C    (revision 14586)
+++ src/mathed/math_extern.C    (working copy)
@@ -22,6 +22,7 @@
 #include "math_diffinset.h"
 #include "math_exfuncinset.h"
 #include "math_exintinset.h"
+#include "math_fontinset.h"
 #include "math_fracinset.h"
 #include "math_liminset.h"
 #include "math_matrixinset.h"
@@ -34,6 +35,7 @@
 #include "debug.h"
 #include "support/filetools.h"
 #include "support/lstrings.h"
+#include "frontends/controllers/ControlMath.h"
 
 #include <algorithm>
 #include <sstream>
@@ -44,6 +46,8 @@
 using lyx::support::runCommand;
 using lyx::support::subst;
 
+using lyx::frontend::function_names;
+
 using std::string;
 using std::endl;
 using std::find_if;
@@ -74,7 +78,7 @@
 // try to extract a super/subscript
 // modify iterator position to point behind the thing
 bool extractScript(MathArray & ar,
-       MathArray::iterator & pos, MathArray::iterator last)
+       MathArray::iterator & pos, MathArray::iterator last, bool superscript)
 {
        // nothing to get here
        if (pos == last)
@@ -84,6 +88,10 @@
        if (!(*pos)->asScriptInset())
                return false;
 
+       // do we want superscripts only?
+       if (superscript && !(*pos)->asScriptInset()->hasUp())
+               return false;
+
        // it is a scriptinset, use it.
        ar.push_back(*pos);
        ++pos;
@@ -94,16 +102,31 @@
 // try to extract an "argument" to some function.
 // returns position behind the argument
 MathArray::iterator extractArgument(MathArray & ar,
-       MathArray::iterator pos, MathArray::iterator last, string const & = "")
+       MathArray::iterator pos, MathArray::iterator last, bool function = 
false)
 {
        // nothing to get here
        if (pos == last)
                return pos;
 
-       // something deliminited _is_ an argument
+       // something delimited _is_ an argument
        if ((*pos)->asDelimInset()) {
-               ar.push_back(*pos);
-               return pos + 1;
+               // leave out delimiters if this is a function argument
+               if (function) {
+                       MathArray const & arg = (*pos)->asDelimInset()->cell(0);
+                       MathArray::const_iterator cur = arg.begin();
+                       MathArray::const_iterator end = arg.end();
+                       while (cur != end)
+                               ar.push_back(*cur++);
+               } else
+                       ar.push_back(*pos);
+               ++pos;
+               if (pos == last)
+                       return pos;
+               // if there's one, get following superscript only if this
+               // isn't a function argument
+               if (!function)
+                       extractScript(ar, pos, last, true);
+               return pos;
        }
 
        // always take the first thing, no matter what it is
@@ -114,9 +137,9 @@
        if (pos == last)
                return pos;
 
-       // if the next item is a subscript, it most certainly belongs to the
-       // thing we have
-       extractScript(ar, pos, last);
+       // if the next item is a super/subscript, it most certainly belongs
+       // to the thing we have
+       extractScript(ar, pos, last, false);
        if (pos == last)
                return pos;
 
@@ -197,6 +220,39 @@
 }
 
 
+// is this a known function?
+bool isKnownFunction(string & str)
+{
+       for (int i = 0; *function_names[i]; ++i) {
+               if (str == function_names[i])
+                       return true;
+       }
+       return false;
+}
+
+
+// extract a function name from this inset
+bool extractFunctionName(MathAtom const & at, string & str)
+{
+       if (at->asSymbolInset()) {
+               str = at->asSymbolInset()->name();
+               return isKnownFunction(str);
+       }
+       if (at->asUnknownInset()) {
+               // assume it is well known...
+               str = at->name();
+               return true;
+       }
+       if (at->asFontInset() && at->name() == "mathrm") {
+               // assume it is well known...
+               MathArray const & ar = at->asFontInset()->cell(0);
+               str = charSequence(ar.begin(), ar.end());
+               return ar.size() == str.size();
+       }
+       return false;
+}
+
+
 // convert this inset somehow to a number
 bool extractNumber(MathArray const & ar, int & i)
 {
@@ -279,24 +335,42 @@
 {
        //lyxerr << "\nScripts from: " << ar << endl;
        for (size_t i = 0; i < ar.size(); ++i) {
-               // is this script inset?
-               if (!ar[i]->asScriptInset())
+               MathScriptInset const * script = ar[i]->asScriptInset();
+
+               // is this a script inset and do we also have a superscript?
+               if (!script || !script->hasUp())
                        continue;
 
-               // no problem if we don't have both...
-               if (!ar[i]->asScriptInset()->hasUp())
+               // we must have a nucleus if we only have a superscript
+               if (!script->hasDown() && script->nuc().size() == 0)
                        continue;
-               if (!ar[i]->asScriptInset()->hasDown())
-                       continue;
 
+               if (script->nuc().size() == 1) {
+                       // leave alone sums and integrals
+                       MathSymbolInset const * sym =
+                               script->nuc().front()->asSymbolInset();
+                       if (sym && (sym->name() == "sum" || sym->name() == 
"int"))
+                               continue;
+               }
+
                // create extra script inset and move superscript over
                MathScriptInset * p = ar[i].nucleus()->asScriptInset();
                auto_ptr<MathScriptInset> q(new MathScriptInset(true));
                swap(q->up(), p->up());
                p->removeScript(true);
 
+               // if we don't have a subscript, get rid of the ScriptInset
+               if (!script->hasDown()) {
+                       MathArray arg(p->nuc());
+                       MathArray::const_iterator it = arg.begin();
+                       MathArray::const_iterator et = arg.end();
+                       ar.erase(i);
+                       while (it != et)
+                               ar.insert(i++, *it++);
+               } else
+                       ++i;
+
                // insert new inset behind
-               ++i;
                ar.insert(i, MathAtom(q.release()));
        }
        //lyxerr << "\nScripts to: " << ar << endl;
@@ -390,7 +464,7 @@
 
 
 //
-// search deliminiters
+// search delimiters
 //
 
 bool testOpenParen(MathAtom const & at)
@@ -405,17 +479,36 @@
 }
 
 
-MathAtom replaceDelims(const MathArray & ar)
+MathAtom replaceParenDelims(const MathArray & ar)
 {
        return MathAtom(new MathDelimInset("(", ")", ar));
 }
 
 
-// replace '('...')' sequences by a real MathDelimInset
+bool testOpenBracket(MathAtom const & at)
+{
+       return testString(at, "[");
+}
+
+
+bool testCloseBracket(MathAtom const & at)
+{
+       return testString(at, "]");
+}
+
+
+MathAtom replaceBracketDelims(const MathArray & ar)
+{
+       return MathAtom(new MathDelimInset("[", "]", ar));
+}
+
+
+// replace '('...')' and '['...']' sequences by a real MathDelimInset
 void extractDelims(MathArray & ar)
 {
        //lyxerr << "\nDelims from: " << ar << endl;
-       replaceNested(ar, testOpenParen, testCloseParen, replaceDelims);
+       replaceNested(ar, testOpenParen, testCloseParen, replaceParenDelims);
+       replaceNested(ar, testOpenBracket, testCloseBracket, 
replaceBracketDelims);
        //lyxerr << "\nDelims to: " << ar << endl;
 }
 
@@ -441,10 +534,8 @@
 
                string name;
                // is it a function?
-               if ((*it)->asUnknownInset()) {
-                       // it certainly is if it is well known...
-                       name = (*it)->name();
-               } else {
+               // it certainly is if it is well known...
+               if (!extractFunctionName(*it, name)) {
                        // is this a user defined function?
                        // it it probably not, if it doesn't have a name.
                        if (!extractString(*it, name))
@@ -463,13 +554,13 @@
                // do we have an exponent like in
                // 'sin' '^2' 'x' -> 'sin(x)' '^2'
                MathArray exp;
-               extractScript(exp, jt, ar.end());
+               extractScript(exp, jt, ar.end(), true);
 
                // create a proper inset as replacement
                auto_ptr<MathExFuncInset> p(new MathExFuncInset(name));
 
                // jt points to the "argument". Get hold of this.
-               MathArray::iterator st = extractArgument(p->cell(0), jt, 
ar.end());
+               MathArray::iterator st = extractArgument(p->cell(0), jt, 
ar.end(), true);
 
                // replace the function name by a real function inset
                *it = MathAtom(p.release());
@@ -562,6 +653,25 @@
 }
 
 
+bool testTermDelimiter(MathAtom const & at)
+{
+       return testString(at, "+") || testString(at, "-");
+}
+
+
+// try to extract a "term", i.e., something delimited by '+' or '-'.
+// returns position behind the term
+MathArray::iterator extractTerm(MathArray & ar,
+       MathArray::iterator pos, MathArray::iterator last)
+{
+       while (pos != last && !testTermDelimiter(*pos)) {
+               ar.push_back(*pos);
+               ++pos;
+       }
+       return pos;
+}
+
+
 //
 // search sums
 //
@@ -631,7 +741,7 @@
                        p->cell(3) = sub->up();
 
                // use something  behind the script as core
-               MathArray::iterator tt = extractArgument(p->cell(0), it + 1, 
ar.end());
+               MathArray::iterator tt = extractTerm(p->cell(0), it + 1, 
ar.end());
 
                // cleanup
                ar.erase(it + 1, tt);
@@ -648,7 +758,16 @@
 // tests for 'd' or '\partial'
 bool testDiffItem(MathAtom const & at)
 {
-       return testString(at, "d");
+       if (testString(at, "d") || testSymbol(at, "partial"))
+               return true;
+
+       // we may have d^n .../d and splitScripts() has not yet seen it
+       MathScriptInset const * sup = at->asScriptInset();
+       if (sup && !sup->hasDown() && sup->hasUp() && sup->nuc().size() == 1) {
+               MathAtom const & ma = sup->nuc().front();
+               return testString(ma, "d") || testSymbol(ma, "partial");
+       }
+       return false;
 }
 
 
@@ -689,7 +808,8 @@
                // collect function, let jt point behind last used item
                MathArray::iterator jt = it + 1;
                //int n = 1;
-               MathArray const & numer = f->cell(0);
+               MathArray numer(f->cell(0));
+               splitScripts(numer);
                if (numer.size() > 1 && numer[1]->asScriptInset()) {
                        // this is something like  d^n f(x) / d... or  d^n / 
d...
                        // FIXME
@@ -697,24 +817,25 @@
                        if (numer.size() > 2)
                                diff->cell(0) = MathArray(numer.begin() + 2, 
numer.end());
                        else
-                               jt = extractArgument(diff->cell(0), jt, 
ar.end());
+                               jt = extractTerm(diff->cell(0), jt, ar.end());
                } else {
                        // simply d f(x) / d... or  d/d...
                        if (numer.size() > 1)
                                diff->cell(0) = MathArray(numer.begin() + 1, 
numer.end());
                        else
-                               jt = extractArgument(diff->cell(0), jt, 
ar.end());
+                               jt = extractTerm(diff->cell(0), jt, ar.end());
                }
 
                // collect denominator parts
-               MathArray const & denom = f->cell(1);
-               for (MathArray::const_iterator dt = denom.begin(); dt != 
denom.end();) {
+               MathArray denom(f->cell(1));
+               splitScripts(denom);
+               for (MathArray::iterator dt = denom.begin(); dt != 
denom.end();) {
                        // find the next 'd'
-                       MathArray::const_iterator et
+                       MathArray::iterator et
                                = find_if(dt + 1, denom.end(), &testDiffItem);
 
                        // point before this
-                       MathArray::const_iterator st = et - 1;
+                       MathArray::iterator st = et - 1;
                        MathScriptInset const * script = (*st)->asScriptInset();
                        if (script && script->hasUp()) {
                                // things like   d.../dx^n
@@ -755,24 +876,20 @@
 // assume 'extractDelims' ran before
 void extractLims(MathArray & ar)
 {
-       // we need at least three items...
-       if (ar.size() < 3)
-               return;
-
        //lyxerr << "\nLimits from: " << ar << endl;
-       for (size_t i = 0; i + 2 < ar.size(); ++i) {
+       for (size_t i = 0; i < ar.size(); ++i) {
                MathArray::iterator it = ar.begin() + i;
 
-               // is this a limit function?
-               if (!testSymbol(*it, "lim"))
+               // must be a script inset with a subscript (without superscript)
+               MathScriptInset const * sub = (*it)->asScriptInset();
+               if (!sub || !sub->hasDown() || sub->hasUp() || 
sub->nuc().size() != 1)
                        continue;
 
-               // the next one must be a subscript (without superscript)
-               MathScriptInset const * sub = (*(it + 1))->asScriptInset();
-               if (!sub || !sub->hasDown() || sub->hasUp())
+               // is this a limit function?
+               if (!testSymbol(sub->nuc().front(), "lim"))
                        continue;
 
-               // and it must contain a -> symbol
+               // subscript must contain a -> symbol
                MathArray const & s = sub->down();
                MathArray::const_iterator st = find_if(s.begin(), s.end(), 
&testRightArrow);
                if (st == s.end())
@@ -784,7 +901,7 @@
 
                // use something behind the script as core
                MathArray f;
-               MathArray::iterator tt = extractArgument(f, it + 2, ar.end());
+               MathArray::iterator tt = extractTerm(f, it + 1, ar.end());
 
                // cleanup
                ar.erase(it + 1, tt);
@@ -803,12 +920,12 @@
 void extractStructure(MathArray & ar)
 {
        //lyxerr << "\nStructure from: " << ar << endl;
+       splitScripts(ar);
+       extractDelims(ar);
        extractIntegrals(ar);
        extractSums(ar);
-       splitScripts(ar);
        extractNumbers(ar);
        extractMatrices(ar);
-       extractDelims(ar);
        extractFunctions(ar);
        extractDets(ar);
        extractDiff(ar);
@@ -942,7 +1059,7 @@
                MaximaStream ms(os);
                ms << ar;
                string expr = os.str();
-               string const header = "SIMPSUM:true;";
+               string const header = "simpsum:true;";
 
                string out;
                for (int i = 0; i < 100; ++i) { // at most 100 attempts
@@ -1175,6 +1292,98 @@
                return res;
        }
 
+
+       string fromMathematicaName(string const & name)
+       {
+               if (name == "Sin")    return "sin";
+               if (name == "Sinh")   return "sinh";
+               if (name == "ArcSin") return "arcsin";
+               if (name == "Cos")    return "cos";
+               if (name == "Cosh")   return "cosh";
+               if (name == "ArcCos") return "arccos";
+               if (name == "Tan")    return "tan";
+               if (name == "Tanh")   return "tanh";
+               if (name == "ArcTan") return "arctan";
+               if (name == "Cot")    return "cot";
+               if (name == "Coth")   return "coth";
+               if (name == "Csc")    return "csc";
+               if (name == "Sec")    return "sec";
+               if (name == "Exp")    return "exp";
+               if (name == "Log")    return "log";
+               if (name == "Arg" )   return "arg";
+               if (name == "Det" )   return "det";
+               if (name == "GCD" )   return "gcd";
+               if (name == "Max" )   return "max";
+               if (name == "Min" )   return "min";
+               if (name == "Erf" )   return "erf";
+               if (name == "Erfc" )  return "erfc";
+               return name;
+       }
+
+       MathArray pipeThroughMathematica(string const &, MathArray const & ar)
+       {
+               ostringstream os;
+               MathematicaStream ms(os);
+               ms << ar;
+               string const expr = os.str();
+               string out;
+
+               lyxerr << "expr: '" << expr << "'" << endl;
+
+               string const full = "TeXForm[" + expr + "]";
+               out = captureOutput("math", full);
+               lyxerr << "out: '" << out << "'" << endl;
+
+               string::size_type pos1 = out.find("Out[1]//TeXForm= ");
+               string::size_type pos2 = out.find("In[2]:=");
+
+               if (pos1 == string::npos || pos2 == string::npos)
+                       return MathArray();
+
+               // get everything from pos1+17 to pos2
+               out = out.substr(pos1 + 17, pos2 - pos1 - 17);
+               out = subst(out, '\r', ' ');
+               out = subst(out, '\n', ' ');
+
+               // Ugly code that tries to make the result prettier
+
+               string::size_type i = out.find("\\Mfunction{");
+               while (i != string::npos) {
+                       string::size_type j = get_matching_brace(out, i + 11);
+                       string fname = out.substr(i + 11, j - i - 11);
+                       out = out.substr(0,i)
+                               + "\\mathrm{" + fromMathematicaName(fname)
+                               + out.substr(j);
+                       //lyxerr << "out: " << out << endl;
+                       i = out.find("\\Mfunction{", i);
+               }
+
+               i = out.find("\\Muserfunction{");
+               while (i != string::npos) {
+                       string::size_type j = get_matching_brace(out, i + 15);
+                       string fname = out.substr(i + 15, j - i - 15);
+                       out = out.substr(0,i)
+                               + "\\mathrm{" + fname
+                               + out.substr(j);
+                       //lyxerr << "out: " << out << endl;
+                       i = out.find("\\Muserfunction{", i);
+               }
+
+               i = out.find("\\Mvariable{");
+               while (i != string::npos) {
+                       string::size_type j = get_matching_brace(out, i + 11);
+                       string vname = out.substr(i + 11, j - i - 11);
+                       out = out.substr(0,i)
+                               + vname
+                               + out.substr(j + 1);
+                       //lyxerr << "out: " << out << endl;
+                       i = out.find("\\Mvariable{", i);
+               }
+               MathArray res;
+               mathed_parse_cell(res, out);
+               return res;
+       }
+
 }
 
 
@@ -1190,6 +1399,9 @@
        if (lang == "maple")
                return pipeThroughMaple(extra, ar);
 
+       if (lang == "mathematica")
+               return pipeThroughMathematica(extra, ar);
+
        // create normalized expression
        ostringstream os;
        NormalStream ns(os);
Index: src/mathed/math_numberinset.C
===================================================================
--- src/mathed/math_numberinset.C       (revision 14586)
+++ src/mathed/math_numberinset.C       (working copy)
@@ -54,6 +54,12 @@
 }
 
 
+void MathNumberInset::mathematica(MathematicaStream & os) const
+{
+       os << str_;
+}
+
+
 void MathNumberInset::octave(OctaveStream & os) const
 {
        os << str_;
Index: src/mathed/math_matrixinset.C
===================================================================
--- src/mathed/math_matrixinset.C       (revision 14586)
+++ src/mathed/math_matrixinset.C       (working copy)
@@ -70,6 +70,24 @@
 }
 
 
+void MathMatrixInset::mathematica(MathematicaStream & os) const
+{
+       os << '{';
+       for (row_type row = 0; row < nrows(); ++row) {
+               if (row)
+                       os << ',';
+               os << '{';
+               for (col_type col = 0; col < ncols(); ++col) {
+                       if (col)
+                               os << ',';
+                       os << cell(index(row, col));
+               }
+               os << '}';
+       }
+       os << '}';
+}
+
+
 void MathMatrixInset::mathmlize(MathMLStream & os) const
 {
        MathGridInset::mathmlize(os);
Index: src/mathed/math_diffinset.C
===================================================================
--- src/mathed/math_diffinset.C (revision 14586)
+++ src/mathed/math_diffinset.C (working copy)
@@ -69,9 +69,23 @@
 }
 
 
+void MathDiffInset::maxima(MaximaStream & os) const
+{
+       os << "diff(";
+       for (idx_type idx = 0; idx < nargs(); ++idx) {
+               if (idx != 0)
+                       os << ',';
+               os << cell(idx);
+               if (idx != 0)
+                       os << ",1";
+       }
+       os << ')';
+}
+
+
 void MathDiffInset::mathematica(MathematicaStream & os) const
 {
-       os << "Dt[";
+       os << "D[";
        for (idx_type idx = 0; idx < nargs(); ++idx) {
                if (idx != 0)
                        os << ',';
Index: src/mathed/math_liminset.C
===================================================================
--- src/mathed/math_liminset.C  (revision 14586)
+++ src/mathed/math_liminset.C  (working copy)
@@ -59,9 +59,15 @@
 }
 
 
+void MathLimInset::maxima(MaximaStream & os) const
+{
+       os << "limit(" << cell(0) << ',' << cell(1) << ',' << cell(2) << ')';
+}
+
+
 void MathLimInset::mathematica(MathematicaStream & os) const
 {
-       os << "Lim[" << cell(0) << ',' << cell(1) << ',' << cell(2) << ']';
+       os << "Limit[" << cell(0) << ',' << cell(1) << "-> " << cell(2) << ']';
 }
 
 
Index: src/mathed/math_exfuncinset.C
===================================================================
--- src/mathed/math_exfuncinset.C       (revision 14586)
+++ src/mathed/math_exfuncinset.C       (working copy)
@@ -80,12 +80,15 @@
        if (name == "sin")    return "Sin";
        if (name == "sinh")   return "Sinh";
        if (name == "arcsin") return "ArcSin";
+       if (name == "asin")   return "ArcSin";
        if (name == "cos")    return "Cos";
        if (name == "cosh")   return "Cosh";
-       if (name == "arcos")  return "ArcCos";
+       if (name == "arccos") return "ArcCos";
+       if (name == "acos")   return "ArcCos";
        if (name == "tan")    return "Tan";
        if (name == "tanh")   return "Tanh";
        if (name == "arctan") return "ArcTan";
+       if (name == "atan")   return "ArcTan";
        if (name == "cot")    return "Cot";
        if (name == "coth")   return "Coth";
        if (name == "csc")    return "Csc";
@@ -93,6 +96,13 @@
        if (name == "exp")    return "Exp";
        if (name == "log")    return "Log";
        if (name == "ln" )    return "Log";
+       if (name == "arg" )   return "Arg";
+       if (name == "det" )   return "Det";
+       if (name == "gcd" )   return "GCD";
+       if (name == "max" )   return "Max";
+       if (name == "min" )   return "Min";
+       if (name == "erf" )   return "Erf";
+       if (name == "erfc" )  return "Erfc";
        return name;
 }
 
Index: src/mathed/math_numberinset.h
===================================================================
--- src/mathed/math_numberinset.h       (revision 14586)
+++ src/mathed/math_numberinset.h       (working copy)
@@ -38,6 +38,8 @@
        ///
        void maple(MapleStream &) const;
        ///
+       void mathematica(MathematicaStream &) const;
+       ///
        void mathmlize(MathMLStream &) const;
        ///
        void write(WriteStream & os) const;
Index: src/mathed/math_matrixinset.h
===================================================================
--- src/mathed/math_matrixinset.h       (revision 14586)
+++ src/mathed/math_matrixinset.h       (working copy)
@@ -35,6 +35,8 @@
        ///
        void maxima(MaximaStream &) const;
        ///
+       void mathematica(MathematicaStream &) const;
+       ///
        void mathmlize(MathMLStream &) const;
        ///
        void octave(OctaveStream &) const;
Index: src/mathed/math_diffinset.h
===================================================================
--- src/mathed/math_diffinset.h (revision 14586)
+++ src/mathed/math_diffinset.h (working copy)
@@ -38,6 +38,8 @@
        ///
        void mathmlize(MathMLStream &) const;
        ///
+       void maxima(MaximaStream &) const;
+       ///
        void write(WriteStream & os) const;
 private:
        virtual std::auto_ptr<InsetBase> doClone() const;
Index: src/mathed/math_liminset.h
===================================================================
--- src/mathed/math_liminset.h  (revision 14586)
+++ src/mathed/math_liminset.h  (working copy)
@@ -32,6 +32,8 @@
        ///
        void maple(MapleStream &) const;
        ///
+       void maxima(MaximaStream &) const;
+       ///
        void mathematica(MathematicaStream &) const;
        ///
        void mathmlize(MathMLStream &) const;

Reply via email to