Configuring an arara rule of sagetex on Windows 10

asked 2020-08-03 23:10:57 +0200

Diaa gravatar image

This question has been cross-posted on here https://tex[dot]stackexchange[dot]com/q/557131/2288 (https://tex[dot]stackexchange[dot]com...).

When using the following sagetex.yaml arara rule

# SageTeX-Rule for arara.
identifier: sagetex
name: SageTeX
- TeXnician (Author)
- cis (Idea)
arguments: []
- name: A SageTeX Rule for arara
  command: >
        pathToBashExecutive = "C:\\Program Files\\SageMath 9.1\\runtime\\bin\\bash";
        pathToSageStartfile = "C:/Program Files/SageMath 9.1/runtime/opt/sagemath-9.1/sage";
        pathOfCurrentWorkingFolder = currentFile().getParent();
        theWindowsCommand = getCommand(pathToBashExecutive, "-l", pathToSageStartfile, "-c", "os.chdir('" + pathOfCurrentWorkingFolder + "'); load('" + getBasename(currentFile()) + ".sagetex.sage')");
        return isWindows(theWindowsCommand, getCommand("sage", getBasename(reference) + ".sagetex.sage"));

to compile the following document

% arara: lualatex
% arara: sagetex
% arara: lualatex



    Using Sage\TeX, one can use Sage to compute things and put them into your \LaTeX{} document. For example, there are
    $\sage{number_of_partitions(1269)}$ integer partitions of $1269$.
    You don't need to compute the number yourself, or even cut and paste it from somewhere.

    Here's some Sage code:
        f(x) = exp(x) * sin(2*x)

    The second derivative of $f$ is
    \frac{\mathrm{d}^{2}}{\mathrm{d}x^{2}} \sage{f(x)} =
    \sage{diff(f, x, 2)(x)}.
    Here's a plot of $f$ from $-1$ to $1$:
    \sageplot{plot(f, -1, 1)}

I get this error

SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape

So, what should be changed in both the arara rule and, consequently, the following command to make everything work?

"C:\Program Files\SageMath 9.1\runtime\bin\bash" -l "C:/Program Files/SageMath 9.1/runtime/opt/sagemath-9.1/sage" -c "os.chdir('C:\Users\Diaa\Desktop\Test'); load('testsagetex.sagetex.sage')"
edit retag flag offensive close merge delete


A minimal text in the document block, that still produces the error, may better isolate its reason and lead to the (needed escape sequence for the) solution...

dan_fulea gravatar imagedan_fulea ( 2020-08-04 10:21:01 +0200 )edit

@dan_fulea The same document can be compiled successfully without errors from the sage shell. So, apparently, the command prompt syntax needs some fixes.

Diaa gravatar imageDiaa ( 2020-08-04 20:49:00 +0200 )edit

Yes, i understand, the problem is that the error may highly depend on a given installation and configuration of many pieces of stuff. So we possibly have no chance to detect the error, in such a situation it is best to try yourself to isolate as good as possible the error. Just cut the document block into pieces till the error is eliminated. Then give us that line producing the error.

dan_fulea gravatar imagedan_fulea ( 2020-08-05 21:49:43 +0200 )edit