commit 9665f6d39ad055b865f78764533d289ae32a22fb
Author: Pavel Sanda <[email protected]>
Date:   Sun Apr 27 21:25:57 2025 +0200

    CAS: Allow commands for maxima (part of #13178).
    
    Now constructs like:
      math-extern maxima factor
    should work.
---
 src/LyXAction.cpp         |  9 +++++++--
 src/mathed/MathExtern.cpp | 21 ++++++++++++++++-----
 2 files changed, 23 insertions(+), 7 deletions(-)

diff --git a/src/LyXAction.cpp b/src/LyXAction.cpp
index 7b52bd2ab4..ecc7b4f327 100644
--- a/src/LyXAction.cpp
+++ b/src/LyXAction.cpp
@@ -2825,9 +2825,14 @@ void LyXAction::init()
  * \li Syntax: math-extern <LANG> [<COMMAND>]
  * \li Params: <LANG>: octave|maxima|maple|mathematica|script \n
                        where "script" stands for the external script 
(normalized
-                       expression will be passed)
+                       expression will be passed)\n
+               <COMMAND>: Particular command can be entered here. The way it 
will
+                          be used is language specific. E.g. for maxima it will
+                          be rewritten to the form:\n
+                          simpsum:true;tex(<COMMAND>(MATHED_EXPRESSION))}}
  * \li Origin: Andre, 24 Apr 2001
- * \li Sample: math-extern maple simplify
+ * \li Sample: math-extern maple simplify \n
+               math-extern maxima factor
  * \endvar
  */
                { LFUN_MATH_EXTERN, "math-extern", Noop, Math },
diff --git a/src/mathed/MathExtern.cpp b/src/mathed/MathExtern.cpp
index 301c4b1a69..34c75af407 100644
--- a/src/mathed/MathExtern.cpp
+++ b/src/mathed/MathExtern.cpp
@@ -1102,7 +1102,7 @@ namespace {
                return string::npos;
        }
 
-       MathData pipeThroughMaxima(docstring const &, MathData const & ar)
+       MathData pipeThroughMaxima(docstring const &command, MathData const & 
ar)
        {
                odocstringstream os;
                MaximaStream ms(os);
@@ -1110,6 +1110,16 @@ namespace {
                docstring expr = os.str();
                docstring const header = from_ascii("simpsum:true;");
 
+               docstring comm_left = from_ascii("tex(");
+               docstring comm_right = from_ascii(");");
+               // "simpsum:true;tex(COMMAND(EXPR));" if command (e.g. 
"factor") is present
+               if (command != "noextra") {
+                       comm_left = comm_left + command + "(";
+                       comm_right = ")" + comm_right;
+               }
+               int preplen = comm_left.length();
+               int headlen = header.length();
+
                string out;
                for (int i = 0; i < 100; ++i) { // at most 100 attempts
                        // try to fix missing '*' the hard way
@@ -1120,8 +1130,8 @@ namespace {
                        // 2x;
                        //  ^
                        //
-                       lyxerr << "checking expr: '" << to_utf8(expr) << "'" << 
endl;
-                       docstring full = header + "tex(" + expr + ");";
+                       docstring full = header + comm_left + expr + comm_right;
+                       lyxerr << "checking input: '" << to_utf8(full) << "'" 
<< endl;
                        out = captureOutput("maxima", to_utf8(full));
 
                        // leave loop if expression syntax is probably ok
@@ -1141,10 +1151,11 @@ namespace {
                        getline(is, line);
                        getline(is, line);
                        size_t pos = line.find('^');
-                       lyxerr << "found caret at pos: '" << pos << "'" << endl;
+                       //we print with header at lyxerr, but maxima won't show 
it in its error
+                       lyxerr << "found caret at pos: '" << pos + headlen << 
"'" << endl;
                        if (pos == string::npos || pos < 4)
                                break; // caret position not found
-                       pos -= 4; // skip the "tex(" part
+                       pos -= preplen; // skip the "tex(command(" part (header 
is not printed by maxima)
                        if (expr[pos] == '*')
                                break; // two '*' in a row are definitely bad
                        expr.insert(pos, from_ascii("*"));
-- 
lyx-cvs mailing list
[email protected]
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to