sagetex/arara:语法错误:(unicode 错误)‘unicodeescape’编解码器无法解码位置 2-3 中的字节:截断的 \UXXXXXXXX 转义

sagetex/arara:语法错误:(unicode 错误)‘unicodeescape’编解码器无法解码位置 2-3 中的字节:截断的 \UXXXXXXXX 转义

后续行动这个答案,我在 arara 的日志文件中出现以下错误

SyntaxError:(unicode 错误)'unicodeescape' 编解码器无法解码位置 2-3 中的字节:截断的 \UXXXXXXXX 转义

使用此sagetex.yaml规则时

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

编译以下文档

% 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}

可以找到完整的 arara 日志文件这里

答案1

我想(我希望)我已经找到了解决这个问题的方法。

使用:“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 有效。我认为问题出在 里面os.chdir(),因为我们必须使用/而不是\。如果有任何方法可以将 arara 规则“PathOfWorkingFolder”中的分隔符更改为 ,\那么/规则可能最终会起作用。

这是我的测试图像:

在此处输入图片描述

编辑:\\在 sage 控制台上使用os.chdir('d:\\')可以,但在 cmd 的命令行中却不行。

最后,我找到了解决方案。你必须编辑windows命令并r在其后添加一个"os.chdir(

那么,那部分应该就是这样"os.chdir(r'"。Sagetex 规则有效。

完整代码如下:

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

相关内容