arara:sage - arara 的 Sage(数学)规则

arara:sage - arara 的 Sage(数学)规则

完整編輯!



包含 sagetex 的 tex 文件正常运行,例如

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

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

对于 Linux,这应该以这种形式运行。

对于 Windows,你必须通过以下方式编译 sage-part(第二行)

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')"

无换行),详情请参阅此处

如何使用 arara 创建此快捷方式(适用于 Windows 和 Linux)?

我自己的尝试sagetex.yaml没有成功:(

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

答案1

在与 OP 的合作下,我确实想出了以下内容:

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

阿拉拉 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"));
       }

如果您收到错误SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes,则如 Pedro 所解释的那样(sagetex/arara:语法错误:(unicode 错误)‘unicodeescape’编解码器无法解码位置 2-3 中的字节:截断的 \UXXXXXXXX 转义)改变

"os.chdir('"

"os.chdir(r'"

可以解决这个问题(已通过Sage 9.2和arara 6.1.0验证)。

相关内容