7

Completely edited!



The normal run of a tex-file which contains sagetex, say

\documentclass{report} 
\usepackage{sagetex} 
\begin{document} 
\sage{2^1234} 
\end{document}

is

pfdlatex example.tex
sage example.sagetex.sage
pfdlatex example.tex

For Linux this should run in exactly this form.

For Windows you have to compile the sage-part (2nd line) via

C:\Programme\SageMath8.9\runtime\bin\bash 
        -l C:/Programme/SageMath8.9/runtime/opt/sagemath-8.9/sage 
           -c "os.chdir('<My current working folder>');      
                    load('<my filename>.sagetex.sage')"

(without linebreaks), see here for details.

How to make a shortcut (for Windows and Linux) of this with arara?

My own try sagetex.yaml does not work :(

!config
identifier: sagetex
name: SageTeX
# Authors: 
# Version: 
# ===============================
# Info:  The Windows cmd-command is
# C:\Programme\SageMath8.9\runtime\bin\bash 
#    -l C:/Programme/SageMath8.9/runtime/opt/sagemath-8.9/sage 
#       -c "os.chdir('<My current working folder>');      
#                load('<my filename>.sagetex.sage')"
#For Windows =========================
arguments:
- identifier: PathToBashExecutive
  flag: >
     @{
        return C:\Programme\SageMath8.9\runtime\bin\bash
        }
- identifier: PathToSageStartfile
  flag: >
     @{
        return C:/Programme/SageMath8.9/runtime/opt/sagemath-8.9/sage
        }
- identifier: PathOfCurrentWorkingFolder
  flag: >
     @{
        return getBasename(toFile('getBasename(file).tex'));
        }
- identifier: TheWindowsCommand
  flag: >
     @{
        return 'PathToBashExecutive' -l 'PathToSageStartfile' -c "os.chdir('PathOfCurrentWorkingFolder'); load('getBasename(file).sagetex.sage')"
        }
# ===============================
commands:
- name: The application
  command: >
    @{
        return isWindows(TheWindowsCommand, sage getBasename(file).sagetex.sage);
       }
7
  • The rules are OS independent. As the commands do not differ across operating systems just write it as if you would for any other OS ;)
    – TeXnician
    Dec 16 '19 at 17:48
  • @TeXnician I am shure you are a Linux-guy, so I have to tell you, that I do not have a command 'sage' in the Windows cmd yet and I am not shure, that it is possible to get it. But I think here are some Pros, they can solve that.
    – cis
    Dec 16 '19 at 17:54
  • I don't know about arara but you can find on this site ways to reduce the 3 step compilation process to pressing one button. For example, with IDE Kile and TeXWorks/TeXStudio. I found Cocalc is the easiest way since internet access is not a problem. This also gives compilation by pressing one button.
    – DJP
    Dec 16 '19 at 19:13
  • @DJP Cocalc --> "1sec. / character"... arara would be the king and decentral. ;)
    – cis
    Dec 16 '19 at 19:36
  • Completely edited!
    – cis
    Dec 20 '19 at 16:13
7

In cooperation with the OP I did come up with the following:

!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:\\Programme\\SageMath8.9\\runtime\\bin\\bash";
        pathToSageStartfile = "C:/Programme/SageMath8.9/runtime/opt/sagemath-8.9/sage";
        pathOfCurrentWorkingFolder = currentFile().getParent();
        theWindowsCommand = getCommand(pathToBashExecutive, "-l", pathToSageStartfile, "-c", "os.chdir('" + pathOfCurrentWorkingFolder + "'); load('" + getBasename(currentFile()) + ".sagetex.sage')");
        return isWindows(theWindowsCommand, getCommand("sage", getBasename(file) + ".sagetex.sage"));
       }

arara 5.0

!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:\\Programme\\SageMath8.9\\runtime\\bin\\bash";
        pathToSageStartfile = "C:/Programme/SageMath8.9/runtime/opt/sagemath-8.9/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"));
       }

If you get an error SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes then as explained by Pedro (sagetex/arara: SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position 2-3: truncated \UXXXXXXXX escape) changing

"os.chdir('"

to

"os.chdir(r'"

can solve this problem (verified with Sage 9.2 and arara 6.1.0).

4
  • 1
    Please note that from version 5.0 on you should use reference instead of file (which works in version 4 as well).
    – TeXnician
    Apr 11 '20 at 17:13
  • @ TeXnician Did you edit your code according?
    – cis
    Aug 3 '20 at 4:21
  • @cis It's left as an exercise for the reader. And as the answer is community wiki, everyone can edit.
    – TeXnician
    Aug 3 '20 at 6:02
  • @TeXnician Do you have any idea where the error in my question comes from?
    – Diaa
    Aug 3 '20 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.