Ask Your Question
0

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 tex.sx here https://tex[dot]stackexchange[dot]com/q/557131/2288 (https://tex[dot]stackexchange[dot]com...).


When using the following sagetex.yaml arara rule

!config
# SageTeX-Rule for arara.
identifier: sagetex
name: SageTeX
authors:
- TeXnician (Author)
- cis (Idea)
arguments: []
commands:
- 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

\documentclass{article}
\usepackage{sagetex}

\begin{document}

    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:
    \begin{sageblock}
        f(x) = exp(x) * sin(2*x)
    \end{sageblock}

    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)}
\end{document}

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

Comments

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

I've found the solution. you have to edit thewinndowsCommand and add an rjust after "os.chdir(

Then, that part should be like "os.chdir(r'" and that's all. Sagetex rule works.

The full code is in the next answer.

Arensoft gravatar imageArensoft ( 2021-05-20 17:40:29 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
0

answered 2021-05-20 17:41:12 +0200

The full code for the arara rule is:

!config
# SageTeX-Rule for arara.
#
# Dear Windows-users, please check the paths
# pathToBashExecutive    and    pathToSageStartfile
# due to your Sage-installation!
#
identifier: sagetex
name: SageTeX
authors:
- TeXnician (Author)
- cis (Idea)
- Pedro J (final fix)
arguments: []
commands:
- 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(r'" + pathOfCurrentWorkingFolder + "'); load('" + getBasename(currentFile()) + ".sagetex.sage')");
        return isWindows(theWindowsCommand, getCommand("sage", getBasename(reference) + ".sagetex.sage"));
       }
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

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

Seen: 210 times

Last updated: Aug 03 '20