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);
       }
cis
  • 8,073
  • 1
  • 16
  • 45
  • 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
  • What do you expect this rule to do? You did not quote strings and expect some kind of macro preprocessing to replace "variables". Why don't you put all which isn't an argument into command? – TeXnician Dec 20 '19 at 16:53
  • @TeXnician I did not say, I am an arara-expert.... – cis Dec 20 '19 at 17:05

1 Answers1

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).

PHPirate
  • 1,775
  • 1
  • 21
  • 37
TeXnician
  • 33,589