问题描述
观察到的行为
我正在使用 SCons 制作 Latex 实验书。我注意到,如果我为构建使用一个变体目录,这对于构建 Latex 项目非常有用,那么 SCons 将不会在第一次构建时执行 makeindex
命令。如果我不使用变体目录,它将在第二次调用时使用变体目录。我选择哪个选项来复制变体目录中的文件并不重要。
预期行为
无论是否使用变体目录,文档都会以相同的方式构建,并且在第一次构建后会在输出中显示索引。
最小工作示例 (MWE)
我在安装了系统 texlive 和 scons 包的 Fedora 33 机器上运行以下命令。
项目布局:
>> tree
.
├── SConstruct
└── src
├── document.tex
└── sconscript
文件
SConstruct
sconscript('src/sconscript',variant_dir='build')
sconscript('src/sconscript')
src/sconscript
PDF('document.tex')
src/document.tex
\UseRawInputEncoding
\documentclass[index=totoc,openany]{labbook}
\title{Journal}
\author{John Smith}
\begin{document}
\maketitle
\printindex
\tableofcontents
\labday{20210131}
\experiment[Experiment 1]{0800 Experiment I}
A cool experiment.
\end{document}
运行 MWE
当项目构建时,src/document.pdf
将在不使用变体目录的情况下构建,而 build/document.pdf
将使用变体目录构建。
SCons 版本
>> scons --version
SCons by Steven Knight et al.:
SCons: v4.1.0.post1.dc58c175da659d6c0bb3e049ba56fb42e77546cd,2021-01-20 04:32:28,by bdbaddog on Prodog2020
SCons path: ['/local/bellockk/Development/AS.430.800.81.SP21/contrib/makotemplate/local/lib/python3.9/site-packages/SCons']
copyright (c) 2001 - 2021 The SCons Foundation
不使用变体目录构建
>> scons src
scons: Reading sconscript files ...
scons: done reading sconscript files.
scons: Building targets ...
scons: building associated VariantDir targets: build
cd build && pdflatex -interaction=nonstopmode -recorder document.tex
...
cd build && pdflatex -interaction=nonstopmode -recorder document.tex
...
cd src && pdflatex -interaction=nonstopmode -recorder document.tex
...
cd src && makeindex document.idx
...
cd src && pdflatex -interaction=nonstopmode -recorder document.tex
...
cd src && makeindex document.idx
...
cd src && pdflatex -interaction=nonstopmode -recorder document.tex
...
Output written on document.pdf (4 pages,35444 bytes).
Transcript written on document.log.
scons: done building targets.
如您所见,我们得到了四个页面,因为它包含一个索引,并且执行了 makeindex
命令。
使用变体目录构建
>> scons build
scons: Reading sconscript files ...
scons: done reading sconscript files.
scons: Building targets ...
cd build && pdflatex -interaction=nonstopmode -recorder document.tex
...
cd build && pdflatex -interaction=nonstopmode -recorder document.tex
...
Output written on document.pdf (3 pages,34621 bytes).
Transcript written on document.log.
scons: done building targets.
在这个调用中,没有调用 makeindex
,我们只得到了三个页面。
如果我们修改源码,重新构建,就会得到索引。
>> echo " " >> src/document.tex
>> scons build
scons: Reading sconscript files ...
scons: done reading sconscript files.
scons: Building targets ...
cd build && pdflatex -interaction=nonstopmode -recorder document.tex
...
cd build && makeindex document.idx
...
cd build && pdflatex -interaction=nonstopmode -recorder document.tex
...
cd build && makeindex document.idx
...
cd build && pdflatex -interaction=nonstopmode -recorder document.tex
...
Output written on document.pdf (4 pages,35444 bytes).
Transcript written on document.log.
scons: done building targets.
问题
在使用变体目录时,有没有办法让 SCons 在第一次调用 SCons 时使用索引构建文档?
我目前的解决方法是构建一次,修改文档源,然后再构建一次。在 CI/CD 系统中自动构建时,这有点烦人,并且容易发生事故,因为文档最终会在没有包含索引的情况下分发。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)