我正在学习 latexindent。我想跟进这个问题:如何使用 arara 和 latexindent 自动缩进子文件?并要求澄清:
是否需要对 arara 规则 indent.yaml 或 latexindent 的配置进行修改?如果我查看 Windows 10 上 TeXlive 2019 附带的 arara.yaml,我看不到对选项“文件”的支持。
链接问题中发布的代码对我来说不起作用,错误退出代码为 1;indent.log 说它找不到“文件”选项中所述的文件……
由于 MWE 可用于回答链接问题或此代码:
Main.tex
% arara: indent: { overwrite: yes, files: [ main.tex, chapter/chapter.tex ] }
% arara: lualatex: { shell: yes }
\documentclass [a4paper, 12pt, twoside, openright] {book}
\usepackage{fontspec}
\usepackage{import}
\begin{document}
Main document test itemization.
\begin{itemize}
\item first item
\item second item
\item another item
\end{itemize}
\chapter{Imported chapter}
\import{chapter/}{chapter.tex}
\end{document}
/chapter/chapter.tex
Imported chapter itemization:
\begin{itemize}
\item first item
\item second item
\item another item
\end{itemize}
编辑:如果我将文件“chapter.tex”放入与“Main.tex”相同的文件夹中并相应地更改 arara 缩进规则,则一切正常。我如何指定 latexindent 的搜索路径以在与“Main.tex”不同的文件夹中查找“chapter.tex”?
编辑2:修改 MWE 以进行一次运行(文件 Main.tex 上的第一次运行,即带有 arara 指令的运行)并发布创建的 indent.log 的内容:
INFO: latexindent.exe version 3.7, 2019-07-13, a script to indent .tex files
latexindent.exe lives here: C:/texlive/2019/bin/win32/
Sat Sep 14 17:05:07 2019
Filename: chapter.tex
INFO: Processing switches:
-w|--overwrite: Overwrite mode active, will make a back up of chapter.tex first
INFO: Directory for backup files and indent.log: .
INFO: YAML settings read: defaultSettings.yaml
Reading defaultSettings.yaml from C:/texlive/2019/bin/win32/defaultSettings.yaml
Reading defaultSettings.yaml (2nd attempt, TeXLive, Windows) from C:/texlive/2019/bin/win32/../../texmf-dist/scripts/latexindent/defaultSettings.yaml
INFO: YAML settings read: indentconfig.yaml or .indentconfig.yaml
Home directory is C:/Users/user (didn't find either indentconfig.yaml or .indentconfig.yaml)
To specify user settings you would put indentconfig.yaml here: C:/Users/user/indentconfig.yaml
Alternatively, you can use the hidden file .indentconfig.yaml as: C:/Users/user/.indentconfig.yaml
FATAL: I couldn't find chapter.tex, are you sure it exists?.
No indentation done.
Exiting.
编辑:休斯先生要求的 arara.log 文件内容:啊,日期是我的本地设置。希望它不介意 :)
15 Zář 2019 21:31:39.958 INFO - Welcome to arara 4.0 (revision 1)!
15 Zář 2019 21:31:39.959 INFO - -----------------------------------------------------------------
15 Zář 2019 21:31:39.961 INFO - ::: arara @ C:\texlive\2019\texmf-dist\scripts\arara
15 Zář 2019 21:31:39.961 INFO - ::: Java 1.8.0_221, Oracle Corporation
15 Zář 2019 21:31:39.961 INFO - ::: C:\Program Files (x86)\Java\jre1.8.0_221
15 Zář 2019 21:31:39.961 INFO - ::: Windows 10, x86, 10.0
15 Zář 2019 21:31:39.961 INFO - ::: user.home @ C:\Users\Tomáš Kruliš
15 Zář 2019 21:31:39.961 INFO - ::: user.dir @ D:\Dokumenty\Prace SUJB\Sujb migrace\Compilation arara speed test\TestLatexindent\MWE
15 Zář 2019 21:31:39.961 INFO - ::: CF @ [none]
15 Zář 2019 21:31:39.962 INFO - -----------------------------------------------------------------
15 Zář 2019 21:31:39.962 INFO - Processing 'main.tex' (size: 451 bytes, last modified: 09/15/2019 21:29:57), please wait.
15 Zář 2019 21:31:39.968 INFO - I found a potential pattern in line 1: indent: { overwrite: yes, files: [ main.tex, chapters/chapter.tex ] }
15 Zář 2019 21:31:39.968 INFO - I found a potential pattern in line 2: lualatex: { shell: yes }
15 Zář 2019 21:31:40.004 INFO - I found a potential directive: Directive: { identifier: indent, parameters: {overwrite=yes, files=[main.tex, chapters/chapter.tex]}, conditional: { NONE }, lines: [1] }
15 Zář 2019 21:31:40.005 INFO - I found a potential directive: Directive: { identifier: lualatex, parameters: {shell=yes}, conditional: { NONE }, lines: [2] }
15 Zář 2019 21:31:40.006 INFO - All directives were validated. We are good to go.
15 Zář 2019 21:31:40.006 INFO - -------------------------- DIRECTIVES ---------------------------
15 Zář 2019 21:31:40.006 INFO - Directive: { identifier: indent, parameters: {reference=D:\Dokumenty\Prace SUJB\Sujb migrace\Compilation arara speed test\TestLatexindent\MWE\Main.tex, file=Main.tex, overwrite=yes}, conditional: { NONE }, lines: [1] }
15 Zář 2019 21:31:40.006 INFO - Directive: { identifier: indent, parameters: {reference=D:\Dokumenty\Prace SUJB\Sujb migrace\Compilation arara speed test\TestLatexindent\MWE\chapters\chapter.tex, file=chapter.tex, overwrite=yes}, conditional: { NONE }, lines: [1] }
15 Zář 2019 21:31:40.006 INFO - Directive: { identifier: lualatex, parameters: {shell=yes, file=main.tex, reference=D:\Dokumenty\Prace SUJB\Sujb migrace\Compilation arara speed test\TestLatexindent\MWE\main.tex}, conditional: { NONE }, lines: [2] }
15 Zář 2019 21:31:40.006 INFO - -----------------------------------------------------------------
15 Zář 2019 21:31:40.007 INFO - I am ready to interpret rule 'indent'.
15 Zář 2019 21:31:40.008 INFO - Rule location: 'C:\texlive\2019\texmf-dist\scripts\arara\rules'
15 Zář 2019 21:31:40.131 INFO - I am ready to interpret task 'The latexindent.pl script' from rule 'Indent'.
15 Zář 2019 21:31:40.131 INFO - System command: [ latexindent, -w, Main.tex ]
15 Zář 2019 21:31:40.851 INFO - ---------------------- BEGIN OUTPUT BUFFER ----------------------
15 Zář 2019 21:31:40.851 INFO - % arara: indent: { overwrite: yes, files: [ main.tex, chapters/chapter.tex ] }
% arara: lualatex: { shell: yes }
\documentclass [a4paper, 12pt, twoside, openright] {book}
\usepackage{fontspec}
\usepackage{import}
\begin{document}
Main document test itemization.
\begin{itemize}
\item first item
\item second item
\item another item
\end{itemize}
\chapter{Imported chapter}
\import{chapter/}{chapter.tex}
\end{document}
15 Zář 2019 21:31:40.851 INFO - ----------------------- END OUTPUT BUFFER -----------------------
15 Zář 2019 21:31:40.854 INFO - Task result: SUCCESS
15 Zář 2019 21:31:40.855 INFO - I am ready to interpret rule 'indent'.
15 Zář 2019 21:31:40.855 INFO - Rule location: 'C:\texlive\2019\texmf-dist\scripts\arara\rules'
15 Zář 2019 21:31:40.860 INFO - I am ready to interpret task 'The latexindent.pl script' from rule 'Indent'.
15 Zář 2019 21:31:40.861 INFO - System command: [ latexindent, -w, chapter.tex ]
15 Zář 2019 21:31:41.548 INFO - ---------------------- BEGIN OUTPUT BUFFER ----------------------
15 Zář 2019 21:31:41.548 INFO - I couldn't find chapter.tex, are you sure it exists?.
No indentation done.
Exiting. at C:\Users\TOMKRU~1\AppData\Local\Temp\par-546f6de19a204b72756c699a\cache-e5261462a856ca06b13fe24504351eecc6e6a781\inc\lib/LatexIndent/FileExtension.pm line 88.
15 Zář 2019 21:31:41.548 INFO - ----------------------- END OUTPUT BUFFER -----------------------
15 Zář 2019 21:31:41.549 INFO - Task result: FAILURE
15 Zář 2019 21:31:41.551 INFO - Total: 1.54 seconds
根据 Cereda 先生的要求,我在使用变体 1 后添加了 arara.log 文件,并使用“参考”arara 键:
17 Zář 2019 14:26:38.494 INFO - Welcome to arara 4.0 (revision 1)!
17 Zář 2019 14:26:38.494 INFO - -----------------------------------------------------------------
17 Zář 2019 14:26:38.494 INFO - ::: arara @ C:\Users\tomas.krulis\AppData\Local\Programs\MiKTeX 2.9\scripts\arara
17 Zář 2019 14:26:38.494 INFO - ::: Java 1.8.0_221, Oracle Corporation
17 Zář 2019 14:26:38.494 INFO - ::: C:\Program Files\Java\jre1.8.0_221
17 Zář 2019 14:26:38.494 INFO - ::: Windows 7, x86, 6.1
17 Zář 2019 14:26:38.494 INFO - ::: user.home @ C:\Users\tomas.krulis
17 Zář 2019 14:26:38.510 INFO - ::: user.dir @ Z:\TestLatexindent\MWE
17 Zář 2019 14:26:38.510 INFO - ::: CF @ [none]
17 Zář 2019 14:26:38.510 INFO - -----------------------------------------------------------------
17 Zář 2019 14:26:38.510 INFO - Processing 'Main.tex' (size: 501 bytes, last modified: 09/17/2019 14:26:25), please wait.
17 Zář 2019 14:26:38.510 INFO - I found a potential pattern in line 1: indent: { overwrite: yes, reference: [ Z:\TestLatexindent\MWE\main.tex, Z:\TestLatexindent\MWE\chapters\chapter.tex ] }
17 Zář 2019 14:26:38.510 INFO - I found a potential pattern in line 2: lualatex: { shell: yes }
17 Zář 2019 14:26:38.572 ERROR - There was a problem with the provided YAML map in a directive (1). This part is quite tricky, since it involves aspects of the underlying data serialization format. There are more details available on this exception:
17 Zář 2019 14:26:38.572 ERROR - while scanning a plain scalar
in 'string', line 1, column 32:
{ overwrite: yes, reference: [ Z:\TestLatexindent\MWE\main.tex, ...
^
found unexpected ':'
in 'string', line 1, column 33:
{ overwrite: yes, reference: [ Z:\TestLatexindent\MWE\main.tex, ...
^
Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details.
17 Zář 2019 14:26:38.572 INFO - Total: 0.00 seconds
它在装有 MikTeX 发行版的机器上进行了测试(我可以访问的其他机器装有 TeXlive 2019)。
看上去很简单。
但是如果我用“。”删除“Z:”;我会收到不同的错误:
17 Zář 2019 14:32:45.364 INFO - Welcome to arara 4.0 (revision 1)!
17 Zář 2019 14:32:45.364 INFO - -----------------------------------------------------------------
17 Zář 2019 14:32:45.364 INFO - ::: arara @ C:\Users\tomas.krulis\AppData\Local\Programs\MiKTeX 2.9\scripts\arara
17 Zář 2019 14:32:45.364 INFO - ::: Java 1.8.0_221, Oracle Corporation
17 Zář 2019 14:32:45.364 INFO - ::: C:\Program Files\Java\jre1.8.0_221
17 Zář 2019 14:32:45.364 INFO - ::: Windows 7, x86, 6.1
17 Zář 2019 14:32:45.364 INFO - ::: user.home @ C:\Users\tomas.krulis
17 Zář 2019 14:32:45.364 INFO - ::: user.dir @ Z:\TestLatexindent\MWE
17 Zář 2019 14:32:45.364 INFO - ::: CF @ [none]
17 Zář 2019 14:32:45.364 INFO - -----------------------------------------------------------------
17 Zář 2019 14:32:45.379 INFO - Processing 'Main.tex' (size: 499 bytes, last modified: 09/17/2019 14:32:31), please wait.
17 Zář 2019 14:32:45.379 INFO - I found a potential pattern in line 1: indent: { overwrite: yes, reference: [ .\TestLatexindent\MWE\main.tex, .\TestLatexindent\MWE\chapters\chapter.tex ] }
17 Zář 2019 14:32:45.379 INFO - I found a potential pattern in line 2: lualatex: { shell: yes }
17 Zář 2019 14:32:45.442 INFO - I found a potential directive: Directive: { identifier: indent, parameters: {overwrite=yes, reference=[.\TestLatexindent\MWE\main.tex, .\TestLatexindent\MWE\chapters\chapter.tex]}, conditional: { NONE }, lines: [1] }
17 Zář 2019 14:32:45.442 INFO - I found a potential directive: Directive: { identifier: lualatex, parameters: {shell=yes}, conditional: { NONE }, lines: [2] }
17 Zář 2019 14:32:45.442 ERROR - I read a directive (1) and found out that the key 'reference' was used. This key is reserved, so you cannot use it. But do not worry, this should be an easy fix. Just replace it by another name.
17 Zář 2019 14:32:45.442 INFO - Total: 0.00 seconds
这可能是语法问题?据我所知,如何在“引用”字段中正确写入绝对路径?我完全确定所有脚本和规则路径都是正确的,因为我将所有规则和 TeX 二进制文件都放在一个地方,并且我已经用您建议的规则替换了当前规则。
EDIT2:使用 Cereda 先生提供的答案中的解决方案 #1,同时在“主”项目目录中还存在 arararc.yaml。我已重新定义了 arara 指令,如下所示:
% arara: indent: { overwrite: yes, reference: [ Z:\TestLatexindent\MWE\main.tex, Z:\TestLatexindent\MWE\chapter\chapter.tex ] }
% arara: lualatex: { shell: yes }
结果是编译失败,arara.log 内容如下:
18 Zář 2019 08:51:06.724 INFO - Welcome to arara 4.0 (revision 2)!
18 Zář 2019 08:51:06.724 INFO - -----------------------------------------------------------------
18 Zář 2019 08:51:06.724 INFO - ::: arara @ C:\Users\tomas.krulis\AppData\Local\Programs\MiKTeX 2.9\scripts\arara
18 Zář 2019 08:51:06.724 INFO - ::: Java 1.8.0_221, Oracle Corporation
18 Zář 2019 08:51:06.724 INFO - ::: C:\Program Files\Java\jre1.8.0_221
18 Zář 2019 08:51:06.724 INFO - ::: Windows 7, x86, 6.1
18 Zář 2019 08:51:06.740 INFO - ::: user.home @ C:\Users\tomas.krulis
18 Zář 2019 08:51:06.740 INFO - ::: user.dir @ Z:\TestLatexindent\MWE
18 Zář 2019 08:51:06.740 INFO - ::: CF @ Z:\TestLatexindent\MWE\arararc.yaml
18 Zář 2019 08:51:06.740 INFO - -----------------------------------------------------------------
18 Zář 2019 08:51:06.740 INFO - Processing 'main.tex' (size: 549 bytes, last modified: 09/18/2019 08:28:43), please wait.
18 Zář 2019 08:51:06.740 INFO - I found a potential pattern in line 1: indent: { overwrite: yes, reference: [ Z:\TestLatexindent\MWE\main.tex, Z:\TestLatexindent\MWE\chapter\chapter.tex ] }
18 Zář 2019 08:51:06.740 INFO - I found a potential pattern in line 2: lualatex: { shell: yes }
18 Zář 2019 08:51:06.756 ERROR - There was a problem with the provided YAML map in a directive (1). This part is quite tricky, since it involves aspects of the underlying data serialization format. There are more details available on this exception:
18 Zář 2019 08:51:06.756 ERROR - while scanning a plain scalar
in 'string', line 1, column 32:
{ overwrite: yes, reference: [ Z:\TestLatexindent\MWE\main.tex, ...
^
found unexpected ':'
in 'string', line 1, column 33:
{ overwrite: yes, reference: [ Z:\TestLatexindent\MWE\main.tex, ...
^
Please check http://pyyaml.org/wiki/YAMLColonInFlowContext for details.
18 Zář 2019 08:51:06.756 INFO - Total: 0.00 seconds
我猜这可能是因为我用错误的语法编写了引用值。如果我在两个引用“值”中省略“Z:”,则会创建如下指令:
% arara: indent: { overwrite: yes, reference: [ \TestLatexindent\MWE\main.tex, \TestLatexindent\MWE\chapter\chapter.tex ] }
% arara: lualatex: { shell: yes }
我使用此 arara.log 编译失败:
18 Zář 2019 09:24:21.417 INFO - Welcome to arara 4.0 (revision 2)!
18 Zář 2019 09:24:21.433 INFO - -----------------------------------------------------------------
18 Zář 2019 09:24:21.433 INFO - ::: arara @ C:\Users\tomas.krulis\AppData\Local\Programs\MiKTeX 2.9\scripts\arara
18 Zář 2019 09:24:21.433 INFO - ::: Java 1.8.0_221, Oracle Corporation
18 Zář 2019 09:24:21.433 INFO - ::: C:\Program Files\Java\jre1.8.0_221
18 Zář 2019 09:24:21.433 INFO - ::: Windows 7, x86, 6.1
18 Zář 2019 09:24:21.433 INFO - ::: user.home @ C:\Users\tomas.krulis
18 Zář 2019 09:24:21.433 INFO - ::: user.dir @ Z:\TestLatexindent\MWE
18 Zář 2019 09:24:21.433 INFO - ::: CF @ Z:\TestLatexindent\MWE\arararc.yaml
18 Zář 2019 09:24:21.433 INFO - -----------------------------------------------------------------
18 Zář 2019 09:24:21.433 INFO - Processing 'Main.tex' (size: 545 bytes, last modified: 09/18/2019 09:23:57), please wait.
18 Zář 2019 09:24:21.448 INFO - I found a potential pattern in line 1: indent: { overwrite: yes, reference: [ \TestLatexindent\MWE\main.tex, \TestLatexindent\MWE\chapter\chapter.tex ] }
18 Zář 2019 09:24:21.448 INFO - I found a potential pattern in line 2: lualatex: { shell: yes }
18 Zář 2019 09:24:21.448 INFO - I found a potential directive: Directive: { identifier: indent, parameters: {overwrite=yes, reference=[\TestLatexindent\MWE\main.tex, \TestLatexindent\MWE\chapter\chapter.tex]}, conditional: { NONE }, lines: [1] }
18 Zář 2019 09:24:21.448 INFO - I found a potential directive: Directive: { identifier: lualatex, parameters: {shell=yes}, conditional: { NONE }, lines: [2] }
18 Zář 2019 09:24:21.448 ERROR - I read a directive (1) and found out that the key 'reference' was used. This key is reserved, so you cannot use it. But do not worry, this should be an easy fix. Just replace it by another name.
18 Zář 2019 09:24:21.448 INFO - Total: 0.00 seconds
我正在测试用于解决我的问题的建议规则,通过直接在 arara 脚本目录中替换原始规则 indent.yaml,因此更新的 indent.yaml 应该以与所有其他 arara 规则相同的方式被选择。
对于解决方案#2,使用新的“目录”选项,如果我正确理解了 GitHub 对话,我正在使用这样的 arara 指令:
% arara: indent: { overwrite: yes }
% arara: indent: { overwrite: yes, directory: 'chapter', files: [ chapter.tex ] }
% arara: lualatex: { shell: yes }
我也遇到了这个 arara.log 编译失败的情况:
18 Zář 2019 10:31:23.040 INFO - Welcome to arara 4.0 (revision 2)!
18 Zář 2019 10:31:23.040 INFO - -----------------------------------------------------------------
18 Zář 2019 10:31:23.040 INFO - ::: arara @ C:\Users\tomas.krulis\AppData\Local\Programs\MiKTeX 2.9\scripts\arara
18 Zář 2019 10:31:23.040 INFO - ::: Java 1.8.0_221, Oracle Corporation
18 Zář 2019 10:31:23.040 INFO - ::: C:\Program Files\Java\jre1.8.0_221
18 Zář 2019 10:31:23.040 INFO - ::: Windows 7, x86, 6.1
18 Zář 2019 10:31:23.055 INFO - ::: user.home @ C:\Users\tomas.krulis
18 Zář 2019 10:31:23.055 INFO - ::: user.dir @ Z:\TestLatexindent\MWE
18 Zář 2019 10:31:23.055 INFO - ::: CF @ Z:\TestLatexindent\MWE\arararc.yaml
18 Zář 2019 10:31:23.055 INFO - -----------------------------------------------------------------
18 Zář 2019 10:31:23.055 INFO - Processing 'Main.tex' (size: 491 bytes, last modified: 09/18/2019 10:31:10), please wait.
18 Zář 2019 10:31:23.055 INFO - I found a potential pattern in line 1: indent: { overwrite: yes }
18 Zář 2019 10:31:23.055 INFO - I found a potential pattern in line 2: indent: { overwrite: yes, directory: 'chapter', files: [ chapter.tex ] }
18 Zář 2019 10:31:23.055 INFO - I found a potential pattern in line 3: lualatex: { shell: yes }
18 Zář 2019 10:31:23.071 INFO - I found a potential directive: Directive: { identifier: indent, parameters: {overwrite=yes}, conditional: { NONE }, lines: [1] }
18 Zář 2019 10:31:23.071 INFO - I found a potential directive: Directive: { identifier: indent, parameters: {overwrite=yes, directory=chapter, files=[chapter.tex]}, conditional: { NONE }, lines: [2] }
18 Zář 2019 10:31:23.071 INFO - I found a potential directive: Directive: { identifier: lualatex, parameters: {shell=yes}, conditional: { NONE }, lines: [3] }
18 Zář 2019 10:31:23.071 INFO - All directives were validated. We are good to go.
18 Zář 2019 10:31:23.071 INFO - -------------------------- DIRECTIVES ---------------------------
18 Zář 2019 10:31:23.071 INFO - Directive: { identifier: indent, parameters: {overwrite=yes, file=Main.tex, reference=Z:\TestLatexindent\MWE\Main.tex}, conditional: { NONE }, lines: [1] }
18 Zář 2019 10:31:23.071 INFO - Directive: { identifier: indent, parameters: {reference=Z:\TestLatexindent\MWE\chapter.tex, file=chapter.tex, overwrite=yes, directory=chapter}, conditional: { NONE }, lines: [2] }
18 Zář 2019 10:31:23.071 INFO - Directive: { identifier: lualatex, parameters: {shell=yes, file=Main.tex, reference=Z:\TestLatexindent\MWE\Main.tex}, conditional: { NONE }, lines: [3] }
18 Zář 2019 10:31:23.071 INFO - -----------------------------------------------------------------
18 Zář 2019 10:31:23.071 INFO - I am ready to interpret rule 'indent'.
18 Zář 2019 10:31:23.071 INFO - Rule location: 'C:\Users\tomas.krulis\AppData\Local\Programs\MiKTeX 2.9\scripts\arara\rules'
18 Zář 2019 10:31:23.211 INFO - I am ready to interpret task 'The latexindent.pl script' from rule 'Indent'.
18 Zář 2019 10:31:23.211 INFO - System command: [ latexindent, -w, Main.tex ]
18 Zář 2019 10:31:24.085 INFO - ---------------------- BEGIN OUTPUT BUFFER ----------------------
18 Zář 2019 10:31:24.085 INFO - % arara: indent: { overwrite: yes }
% arara: indent: { overwrite: yes, directory: 'chapter', files: [ chapter.tex ] }
% arara: lualatex: { shell: yes }
\documentclass [a4paper, 12pt, twoside, openright] {book}
\usepackage{fontspec}
\usepackage{import}
\begin{document}
Main document test itemization.
\begin{itemize}
\item first item
\item second item
\item another item
\end{itemize}
\chapter{Imported chapter}
\import{chapter/}{chapter.tex}
\end{document}
18 Zář 2019 10:31:24.085 INFO - ----------------------- END OUTPUT BUFFER -----------------------
18 Zář 2019 10:31:24.085 INFO - Task result: SUCCESS
18 Zář 2019 10:31:24.085 INFO - I am ready to interpret rule 'indent'.
18 Zář 2019 10:31:24.101 INFO - Rule location: 'C:\Users\tomas.krulis\AppData\Local\Programs\MiKTeX 2.9\scripts\arara\rules'
18 Zář 2019 10:31:24.116 INFO - I am ready to interpret task 'The latexindent.pl script' from rule 'Indent'.
18 Zář 2019 10:31:24.116 INFO - System command: [ latexindent, -w, Z:\TestLatexindent\MWE\chapter.tex ] @ chapter
18 Zář 2019 10:31:24.927 INFO - ---------------------- BEGIN OUTPUT BUFFER ----------------------
18 Zář 2019 10:31:24.927 INFO - I couldn't find Z:\TestLatexindent\MWE\chapter.tex, are you sure it exists?.
No indentation done.
Exiting. at C:/Users/tomas.krulis/AppData/Local/Programs/MiKTeX 2.9/scripts/latexindent/LatexIndent/FileExtension.pm line 83.
18 Zář 2019 10:31:24.927 INFO - ----------------------- END OUTPUT BUFFER -----------------------
18 Zář 2019 10:31:24.927 INFO - Task result: FAILURE
18 Zář 2019 10:31:24.927 INFO - Total: 1.85 seconds
我之前已经将 arara 更新到修订版 2,还更新了解决方案 #2 中建议的新规则。据我了解,arara 不是在目录“chapter”中搜索“chapter.tex”,而是在主目录中搜索。
编辑3:根据要求,“indent.yaml”的位置是:
C:\Users\tomas.krulis\AppData\Local\Programs\MiKTeX 2.9\scripts\arara\rules
解决方案 #2(新目录字段)的“indent.yaml”内容如下:
!config
identifier: indent
name: Indent
authors:
- Chris Hughes
- Paulo Cereda
commands:
- name: The latexindent.pl script
command: >
@{
if (isEmpty(directory)) {
return getCommand('latexindent', silent, trace, screenlog,
settings, cruft, overwrite, output, file,
modifylinebreaks, replacement, options, logfile);
}
else {
return getCommandWithWorkingDirectory(directory,
'latexindent', silent, trace, screenlog,
settings, cruft, overwrite, output, reference,
modifylinebreaks, replacement, options, logfile);
}
}
arguments:
- identifier: silent
flag: >
@{
isTrue(parameters.silent, '-s')
}
- identifier: overwrite
flag: >
@{
isTrue(parameters.overwrite, '-w')
}
- identifier: trace
flag: >
@{
if ([ 'default', 'complete' ].contains(parameters.trace)) {
return isTrue(parameters.trace == 'default', '-t', '-tt');
}
else {
throwError('You provided an invalid value for trace.');
}
}
- identifier: screenlog
flag: >
@{
isTrue(parameters.screenlog, '-sl')
}
- identifier: modifylinebreaks
flag: >
@{
isTrue(parameters.modifylinebreaks, '-m')
}
- identifier: settings
flag: >
@{
check = parameters.containsKey('where');
location = check ? parameters.where : '';
if ([ 'local', 'onlydefault' ].contains(parameters.settings)) {
return isTrue(parameters.settings == 'local', isTrue(check,
'-l='.concat(location), '-l'), '-d');
}
else {
throwError('You provided an invalid value for settings.');
}
}
- identifier: cruft
flag: >
@{
'-c='.concat(parameters.cruft)
}
- identifier: logfile
flag: >
@{
[ '-g', parameters.logfile ]
}
- identifier: output
flag: >
@{
[ '-o', parameters.output ]
}
- identifier: where
flag: >
@{
check = parameters.containsKey('settings');
setting = check ? parameters.settings : '';
if (setting != 'local') {
throwError('This key requires a local setting.');
}
}
- identifier: replacement
flag: >
@{
opts = [ 'full' : '-r', 'noverb' : '-rv', 'noindent' : '-rr' ];
if (opts.keySet().contains(parameters.replacement)) {
return opts[parameters.replacement];
}
else {
throwError('You provided an invalid value for replacement.');
}
}
- identifier: options
flag: >
@{
if (isList(parameters.options)) {
return parameters.options;
}
else {
throwError('I was expecting a list of options.');
}
}
- identifier: directory
flag: >
@{
entry = toFile(parameters.directory);
if (entry.isFile()) {
throwError('I was expecting a directory.');
}
else {
if (!isSubdirectory(entry)) {
throwError('Only subdirectories are allowed.');
}
else {
return entry;
}
}
}
对于主文件夹中的配置文件(您的意思是 arararc.yaml,是吗?),我已经使用了已经提到的设置:
!config
paths:
- '.'
我认为这可能是错误的原因,因此我已将 arararc.yaml 更改为精确指向文件夹,其中放置了之前提到的“indent.yaml”,如下所示:
!config
paths:
- 'C:\Users\tomas.krulis\AppData\Local\Programs\MiKTeX 2.9\scripts\arara\rules'
答案1
这种行为可能看起来像是一个错误,但实际上是预料之中的。file
变量被标准化为仅保存文件名,并且任何现有路径都被删除。做出这一决定是因为一些与 TeX 相关的工具在不在所提供文件的同一级别调用时会出现问题。为了解决这个问题,版本 4.0 提供了另一个名为 的变量reference
,它保存了所提供文件的完整规范路径,从根文件系统到端点。
从这个意义上来说,有两种方法可以使规则发挥作用:
第一种方法是最明显的,即在规则上下文
file
中用替换reference
。对于latexindent
,新规则将如下所示:!config identifier: indent name: Indent authors: - Chris Hughes - Paulo Cereda commands: - name: The latexindent.pl script command: > @{ return getCommand('latexindent', silent, trace, screenlog, settings, cruft, overwrite, output, reference, modifylinebreaks, replacement, options, logfile); } arguments: - identifier: silent flag: > @{ isTrue(parameters.silent, '-s') } - identifier: overwrite flag: > @{ isTrue(parameters.overwrite, '-w') } - identifier: trace flag: > @{ if ([ 'default', 'complete' ].contains(parameters.trace)) { return isTrue(parameters.trace == 'default', '-t', '-tt'); } else { throwError('You provided an invalid value for trace.'); } } - identifier: screenlog flag: > @{ isTrue(parameters.screenlog, '-sl') } - identifier: modifylinebreaks flag: > @{ isTrue(parameters.modifylinebreaks, '-m') } - identifier: settings flag: > @{ check = parameters.containsKey('where'); location = check ? parameters.where : ''; if ([ 'local', 'onlydefault' ].contains(parameters.settings)) { return isTrue(parameters.settings == 'local', isTrue(check, '-l='.concat(location), '-l'), '-d'); } else { throwError('You provided an invalid value for settings.'); } } - identifier: cruft flag: > @{ '-c='.concat(parameters.cruft) } - identifier: logfile flag: > @{ [ '-g', parameters.logfile ] } - identifier: output flag: > @{ [ '-o', parameters.output ] } - identifier: where flag: > @{ check = parameters.containsKey('settings'); setting = check ? parameters.settings : ''; if (setting != 'local') { throwError('This key requires a local setting.'); } } - identifier: replacement flag: > @{ opts = [ 'full' : '-r', 'noverb' : '-rv', 'noindent' : '-rr' ]; if (opts.keySet().contains(parameters.replacement)) { return opts[parameters.replacement]; } else { throwError('You provided an invalid value for replacement.'); } } - identifier: options flag: > @{ if (isList(parameters.options)) { return parameters.options; } else { throwError('I was expecting a list of options.'); } }
第二种方法涉及添加一个额外的
directory
选项以涵盖此类情况。这有点复杂,但我们(团队)实际上正在考虑这种方法,以便为所有引擎和其他 TeX 相关工具提供此类支持。这样做的原因是我们希望施加一定的限制,使其arara
只能处理主文件层次结构下的文件,以此来减轻文件系统中的滥用。在修订版 2 中,我们添加了一个新的辅助方法以实现此支持。新规则将是:!config identifier: indent name: Indent authors: - Chris Hughes - Paulo Cereda commands: - name: The latexindent.pl script command: > @{ if (isEmpty(directory)) { return getCommand('latexindent', silent, trace, screenlog, settings, cruft, overwrite, output, file, modifylinebreaks, replacement, options, logfile); } else { return getCommandWithWorkingDirectory(directory, 'latexindent', silent, trace, screenlog, settings, cruft, overwrite, output, file, modifylinebreaks, replacement, options, logfile); } } arguments: - identifier: silent flag: > @{ isTrue(parameters.silent, '-s') } - identifier: overwrite flag: > @{ isTrue(parameters.overwrite, '-w') } - identifier: trace flag: > @{ if ([ 'default', 'complete' ].contains(parameters.trace)) { return isTrue(parameters.trace == 'default', '-t', '-tt'); } else { throwError('You provided an invalid value for trace.'); } } - identifier: screenlog flag: > @{ isTrue(parameters.screenlog, '-sl') } - identifier: modifylinebreaks flag: > @{ isTrue(parameters.modifylinebreaks, '-m') } - identifier: settings flag: > @{ check = parameters.containsKey('where'); location = check ? parameters.where : ''; if ([ 'local', 'onlydefault' ].contains(parameters.settings)) { return isTrue(parameters.settings == 'local', isTrue(check, '-l='.concat(location), '-l'), '-d'); } else { throwError('You provided an invalid value for settings.'); } } - identifier: cruft flag: > @{ '-c='.concat(parameters.cruft) } - identifier: logfile flag: > @{ [ '-g', parameters.logfile ] } - identifier: output flag: > @{ [ '-o', parameters.output ] } - identifier: where flag: > @{ check = parameters.containsKey('settings'); setting = check ? parameters.settings : ''; if (setting != 'local') { throwError('This key requires a local setting.'); } } - identifier: replacement flag: > @{ opts = [ 'full' : '-r', 'noverb' : '-rv', 'noindent' : '-rr' ]; if (opts.keySet().contains(parameters.replacement)) { return opts[parameters.replacement]; } else { throwError('You provided an invalid value for replacement.'); } } - identifier: options flag: > @{ if (isList(parameters.options)) { return parameters.options; } else { throwError('I was expecting a list of options.'); } } - identifier: directory flag: > @{ entry = toFile(parameters.directory); if (entry.isFile()) { throwError('I was expecting a directory.'); } else { if (!isSubdirectory(entry)) { throwError('Only subdirectories are allowed.'); } else { return entry; } } }
这是我们正在讨论目录支持的未决问题。对我们来说,这个问题已经基本解决了,现在我们需要更新规则包(以及相应的用户手册条目)以反映这一点。
顺便说一句,如上所述,新的辅助方法仅从修订版 2 开始可用,因此在旧版本中运行它(即使是 4.0 系列)也会报告错误。确保arara
使用 TeX 发行版管理器至少更新到修订版 2,这样方法 #2 中的上述规则将具有预期的行为。您可以在运行该工具时通过查看标题来检查修订版:arara 4.0 (revision 2)
。
笔记:截至 2019 年 9 月 16 日,arara
4.0 的修订版 2 已成功提交给 CTAN 并由其处理,因此它将在几个小时后在 CTAN 镜像中可用。