On Wed, Aug 09, 2006 at 02:07:20AM +0200, Enrico Forestieri wrote:
> Looking at the sources I had the impression that CAS support was in
> an unfinished state (sort of),
Correct. It's just in a 'proof-of-concept' state.
> so I tried to improve it.
Good idea ;-)
> Please find attached a patch which monotonically improves such support.
> I tested it with octave, maxima, and mathematica.
Looks pretty good in general. A few comments nevertheless:
> +// is this a known function?
> +bool isKnownFunction(string & str)
Coould be const.
> +
> + 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;
> + }
Can't this just convert everything to lower case?
> + 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);
A few 'const' coould be added...
> + 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);
> + }
Refactor in a helper function?
> 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";
Probably my doing initially but it looks like the list is not big enough
to use a map or such...
Andre'