1

Following up this answer, I have the following error in the arara's log file

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

when using this sagetex.yaml rule

!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)
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}

Full arara's log file can be found here.

8
  • This error seems to come from Sage. Have you tried running the programs on the same file one after the other?
    – TeXnician
    Aug 3, 2020 at 18:17
  • @TeXnician yes I tested the document with sage externally, and it worked fine.
    – Diaa
    Aug 3, 2020 at 18:57
  • With tested you mean the same system call, i.e. 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')"?
    – TeXnician
    Aug 3, 2020 at 19:43
  • @TeXnician No, I mean that I first ran lualatex on it. Then, opened sagetex shell to run it on the *.sage file. Finally, I ran lualatex on the tex file without problems. I will give your suggestion a try from the windows command prompt then let you know.
    – Diaa
    Aug 3, 2020 at 19:49
  • Well, arara executes exactly that (as seen in the log) because it has been told to (in the rule). This rule is rather suboptimal as well because it is very much tailored towards what cis needed. If your sage is in your PATH you could probably omit all those path handling (not sure on that).
    – TeXnician
    Aug 3, 2020 at 20:39

1 Answer 1

3

I think (I hope) I've found the solution to the problem.

using: "C:\Users\Pedro Jose\AppData\Local\SageMath 9.1\runtime\bin\bash" -l "C:/Users/Pedro Jose/AppData/Local/SageMath 9.1/runtime/opt/sagemath-9.1/sage" -c "os.chdir('D:/'); load('prueba.sagetex.sage')"

sage works. I think the problem is inside os.chdir(), because we have to use / instead of \. If there is any way to change inside the arara rule "PathOfWorkingFolder" the delimiter \ to / it's probably the rule finaly works.

Here is my test image:

enter image description here

Edit: Using \\ on the sage console os.chdir('d:\\') works, but in the command line on cmd it doesn't work.

and finaly, 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:

!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"));
       }
1
  • I can confirm that without the extra r I get @Diaa's problem, and with it everything works fine. Good find, great!
    – PHPirate
    May 19, 2021 at 13:30

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .