我遇到了 latexmk 和词汇表包的问题。我有一个大型的 `scrbook' 文档,其中包含一个主文件和几个章节文件。在我的序言中,我定义了大量的首字母缩略词(我相信大约有 30 个)。问题是,当我向文档添加 \gls{} 条目,然后使用 latexmk 排版时(我在 Mac OSX 上使用 TexShop),它会达到最大运行次数并返回错误。不幸的是,我无法用一个最小的文档来重现错误并发布在这里,但我希望有人至少可以给我提示一下在哪里查看,例如已知的包冲突或类似的东西。这是错误日志的最后一部分:
Rule 'bibtex thesis': File changes, etc:
Changed files, or newly in use since previous run(s):
'thesis.aux'
------------
Run number 2 of rule 'bibtex thesis'
------------
------------
Running 'bibtex "thesis"'
------------
Latexmk: applying rule 'bibtex thesis'...
For rule 'bibtex thesis', running '&run_bibtex( )' ...
This is BibTeX, Version 0.99d (TeX Live 2015)
The top-level auxiliary file: thesis.aux
The style file: ieeetr.bst
Database file #1: thesis_references.bib
Warning--entry type for "goalwebsite" isn't style-file defined
--line 324 of file thesis_references.bib
(There was 1 warning)
Rule 'cusdep acr acn thesis': File changes, etc:
Changed files, or newly in use since previous run(s):
'thesis.acr'
------------
Run number 3 of rule 'cusdep acr acn thesis'
------------
Latexmk: applying rule 'cusdep acr acn thesis'...
For rule 'cusdep acr acn thesis', running '&do_cusdep( makeacr2acn )' ...
This is makeindex, version 2.15 [TeX Live 2015] (kpathsea + Thai support).
Scanning style file ./thesis.ist.............................done (29 attributes redefined, 0 ignored).
Scanning input file thesis.acr...done (0 entries accepted, 72 rejected).
Nothing written in thesis.acn.
Transcript written in thesis.alg.
Rule 'cusdep acn acr thesis': File changes, etc:
Changed files, or newly in use since previous run(s):
'thesis.acn'
------------
Run number 4 of rule 'cusdep acn acr thesis'
------------
Latexmk: applying rule 'cusdep acn acr thesis'...
For rule 'cusdep acn acr thesis', running '&do_cusdep( makeacn2acr )' ...
This is makeindex, version 2.15 [TeX Live 2015] (kpathsea + Thai support).
Scanning style file ./thesis.ist.............................done (29 attributes redefined, 0 ignored).
Scanning input file thesis.acn...done (0 entries accepted, 0 rejected).
Nothing written in thesis.acr.
Transcript written in thesis.alg.
Rule 'pdflatex': File changes, etc:
Changed files, or newly in use since previous run(s):
'thesis.acr'
'thesis.aux'
'thesis.toc'
Latexmk: Maximum runs of pdflatex reached without getting stable files
Latexmk: Did not finish processing file 'thesis.tex':
'pdflatex' needed too many passes
Latexmk: Use the -f option to force complete processing,
unless error was exceeding maximum runs of latex/pdflatex.
Latexmk: applying rule 'pdflatex'...
Latexmk: Errors, so I did not complete making targets
我确信问题出在词汇表上,因为 `thesis.acr' 文件在每次运行时都会不断更新,而且如果我注释掉打印词汇表的命令,它也能顺利编译。奇怪的是,如果我删除辅助文件,它也能顺利编译。
这是我的“latexmkrcedit”文件的样子,我看到它确实承认词汇表存在问题,但我不知道该怎么办:
# Don't edit this file IF it is named latexmkrcDONTedit directly since
# TeXShop may replace it on update.
# If you wish to edit or add to this file, copy it to ~/Library/TeXShop/bin
# and rename it latexmkrcedit if that file doesn't already exist.
# Edit this File to add/change dependencies and rules
# The following is used by ALL the latexmk engine files
# change the empty string ,'', to '--shell-escape' to add the shell-escape default
$TSUserCompileOptions = '';
#$TSUserCompileOptions = '--shell-escape';
# turn recorder option off (no .fls file generated)
#$recorder=0;
# turn off duplicated missing references
$silence_logfile_warnings = 1;
# Custom dependency for glossary/glossaries package
# if you make custom glossaries you may have to add items to the @cus_dep_list and corresponding sub-routines
add_cus_dep('glo', 'gls', 0, 'makeglo2gls');
sub makeglo2gls {
system("makeindex -s '$_[0]'.ist -t '$_[0]'.glg -o '$_[0]'.gls '$_[0]'.glo");
}
# The glossaries package, with the [acronym] option, produces a .acn file when processed with (xe/pdf)latex and
# then makeindex to process the .acn into .acr and finally runs of (xe/pdf)latex to read in the .acr file. Unfortunately
# the glossary package does just the reverse; i.e. (xe/pdf)latex processing produces a .acr files and makeindex then
# is used to convert the .acr file to a .acn file which is then ... . This dependency assumes the glossaries package.
add_cus_dep('acn', 'acr', 0, 'makeacn2acr');
sub makeacn2acr {
system("makeindex -s '$_[0]'.ist -t '$_[0]'.alg -o '$_[0]'.acr '$_[0]'.acn");
}
# for glossary package (Sigh...) --- they can co-exist!
add_cus_dep('acr', 'acn', 0, 'makeacr2acn');
sub makeacr2acn {
system("makeindex -s '$_[0]'.ist -t '$_[0]'.alg -o '$_[0]'.acn '$_[0]'.acr");
}
# example of an added custom glossary type that is used in some of the glossary/glossaries example files:
# this is for the new glossary type command \newglossary[nlg]{notation}{not}{ntn}{Notation} from the glossaries package
# NOTE: the glossary package uses a very different command: the <in-ext> and <out-ext>
# are reversed in the calling sequence :-(
add_cus_dep('ntn', 'not', 0, 'makentn2not');
sub makentn2not {
system("makeindex -s '$_[0]'.ist -t '$_[0]'.nlg -o '$_[0]'.not '$_[0]'.ntn");
}
# for the glossary package (Sigh...) --- they can co-exist!
add_cus_dep('not', 'ntn', 0, 'makenot2ntn');
sub makenot2ntn {
system("makeindex -s '$_[0]'.ist -t '$_[0]'.nlg -o '$_[0]'.ntn '$_[0]'.not");
}
# dependencies for custom indexes using the index package
# examples for sample.tex for index package:
add_cus_dep('adx', 'and', 0, 'makeadx2and');
sub makeadx2and {
system("makeindex -o '$_[0]'.and '$_[0]'.adx");
}
add_cus_dep('ndx', 'nnd', 0, 'makendx2nnd');
sub makendx2nnd {
system("makeindex -o '$_[0]'.nnd '$_[0]'.ndx");
}
add_cus_dep('ldx', 'lnd', 0, 'makeldx2lnd');
sub makeldx2lnd {
system("makeindex -o '$_[0]'.lnd '$_[0]'.ldx");
}
# Custom dependency and function for nomencl package
add_cus_dep('nlo', 'nls', 0, 'makenlo2nls');
sub makenlo2nls {
system("makeindex -s nomencl.ist -o '$_[0]'.nls '$_[0]'.nlo");
}
我会非常感激您的帮助,因为随机出现的问题导致您无法集中精力学习内容,这很令人沮丧。谢谢。
答案1
这在一定程度上是我的错,因为我在替换时混淆了文件扩展名glossary
和glossaries
。 这输入从 LaTeX 的角度来看,文件是输出从索引应用程序的角度来看,输出从 LaTeX 的角度来看,文件是输入从索引应用程序的角度看文件。我搞混了,因为我从错误的角度看它。
如果你使用glossaries
文件依赖链,则“如果有文件.glo
,则运行makeindex
以创建.gls
文件”。这意味着你需要
add_cus_dep('glo', 'gls', 0, 'makeglo2gls');
sub makeglo2gls {
system("makeindex -s '$_[0]'.ist -t '$_[0]'.glg -o '$_[0]'.gls '$_[0]'.glo");
}
在您的latexmkrcedit
文件中。
makegls2glo
旧包的反向过程有效。如果您同时拥有和glossary
,则会出现问题。如果您使用,则需要从文件中删除代码。这是导致您特定问题的原因。makeglo2gls
makegls2glo
glossaries
makegls2glo
latexmkrcedit
然而,这里存在更大的问题,不仅仅是对于latexmk
其他构建过程,对于其他构建过程,假设你必须运行
makeindex -s basename -t basename.glg -o basename.gls basename.glo
其中 LaTeX 文件名为basename.tex
。这包括后处理器配置文件和用户创建的批处理文件。
该glossaries
包的灵活性使其可以用于各种各样的文档,但是这种灵活性阻碍了简单的文件依赖关系的构建。
让我们考虑一个简单的例子:
\documentclass{article}
\usepackage{glossaries}
\makeglossaries
\newglossaryentry{sample}{name={sample},
description={an example}}
\begin{document}
\gls{sample}.
\printglossaries
\end{document}
这符合基本的文件依赖模型。如果文件名为test.tex
,则需要运行:
makeindex -s test.ist -t test.glg -o test.gls test.glo
现在假设我们有一个小小的修改:
\documentclass{article}
\usepackage{glossaries}
\setStyleFile{mygloss}
\makeglossaries
\newglossaryentry{sample}{name={sample},
description={an example}}
\begin{document}
\gls{sample}.
\printglossaries
\end{document}
现在的调用makeindex
是:
makeindex -s mygloss.ist -t test.glg -o test.gls test.glo
这不符合基本模型。
现在假设我们有:
\documentclass{article}
\usepackage[nomain]{glossaries}
\newglossary[glg]{main}{glo}{gls}{Glossary}%
\makeglossaries
\newglossaryentry{sample}{name={sample},
description={an example}}
\begin{document}
\gls{sample}.
\printglossaries
\end{document}
这会将文件扩展名恢复到原始包中的样子glossary
,所以现在调用的makeindex
是:
makeindex -s test.ist -t test.glg -o test.glo test.gls
现在假设我们有:
\documentclass{article}
\usepackage[nomain]{glossaries}
\newglossary*{unit}{Units}
\newglossary*{sym}{Symbols}
\makeglossaries
\newglossaryentry{mm}{type={unit},
name={millimetre},
description={length unit}}
\newglossaryentry{alpha}{type={sym},
name={\ensuremath{\alpha}},
sort={alpha},
description={alpha}}
\begin{document}
\gls{mm}, \gls{alpha}.
\printglossaries
\end{document}
这需要:
makeindex -s test.ist -t test.unit-glg -o test.unit-gls test.unit-glo
makeindex -s test.ist -t test.sym-glg -o test.sym-gls test.sym-glo
这glossary-lipsum-examples.tex
软件包附带的示例文件glossaries
包含 10 个词汇表。每个词汇表都需要单独makeindex
调用。
也许我想将makeindex
特定文档的默认词序切换为字母序:
\documentclass{article}
\usepackage[order=letter]{glossaries}
\makeglossaries
\newglossaryentry{seal}{name={seal},
description={aquatic mammal}}
\newglossaryentry{sealion}{name={sealion},
description={a type of \gls{seal} with ears}}
\begin{document}
\gls{seal}, \gls{sealion}.
\printglossaries
\end{document}
这需要-l
切换:
makeindex -l -s test.ist -t test.glg -o test.gls test.glo
但仅限于该文件。
也许我想用xindy
:makeindex
\documentclass{article}
\usepackage[british]{babel}
\usepackage[order=letter,xindy]{glossaries}
\makeglossaries
\newglossaryentry{seal}{name={seal},
description={aquatic mammal}}
\newglossaryentry{sealion}{name={sealion},
description={a type of \gls{seal} with ears}}
\begin{document}
\gls{seal}, \gls{sealion}.
\printglossaries
\end{document}
现在需要:
xindy -M ord/letorder -L english -I xindy -M test -t test.glg -o test.gls test.glo
因此,通过测试中常见文件扩展名的存在latexmk
或在后处理器中的简单硬编码调用所使用的这些硬编码规则makeindex
无法应对可能使用的各种选项glossaries
。
这就是为什么glossaries
提供makeglossaries
Perl 脚本。它会解析.aux
文件以确定要做什么。
对于最后一个例子,该.aux
文件包含以下行:
\@xdylanguage{main}{british}
\@gls@codepage{main}{}
\@newglossary{main}{glg}{gls}{glo}
\@istfilename{test.xdy}
\@glsorder{letter}
这提供了makeglossaries
它需要的所有信息,所以如果我这样做
makeglossaries test
它知道使用xindy
而不是makeindex
(来自 中的文件扩展名\@istfilename
),它知道字母顺序是必需的(\@glsorder
),它知道输入/输出/成绩单文件扩展名(来自\@newglossary
)。如果xindy
需要 ,它还知道每个词汇表使用的语言(来自\@xdylanguage
)和输入编码,如果inputenc
已经使用了该包(来自\@gls@codepage
,在这种情况下为空,因为文档不会加载inputenc
)。
有一个轻量级的 Lua 替代方案,makeglossaries
它也能解析.aux
文件,但比 更严格makeglossaries
。例如,makeglossaries
知道 的babel
语言british
选项需要xindy
通过开关传递给-L english
。Lua 版本没有这些语言映射,因此如果您使用makeglossaries-lite.lua
,则需要:
\usepackage[order=letter,xindy={language=english,codepage=utf8}]{glossaries}
makeglossaries
下面是另一个比直接调用更好的例子makeindex
:
\documentclass{article}
\usepackage{glossaries}
\makeglossaries
\newglossaryentry{seal}{name={seal},
description={aquatic mammal}}
\newglossaryentry{sealion}{name={sealion},
description={a type of \gls{seal} with ears}}
\begin{document}
\gls[format=textbf]{seal}, \gls{sealion} and \gls{seal} again.
\printglossaries
\end{document}
如果我明确地这样做:
makeindex -s test.ist -t test.glg -o test.gls test.glo
我收到来自以下来源的警告makeindex
:
## Warning (input = test.glo, line = 1; output = test.gls, line = 5):
-- Conflicting entries: multiple encaps for the same page under same key.
该条目的位置列表seal
重复了第 1 页,首先以正常字体,然后以粗体显示:
海豹水生哺乳动物。1、1
makeglossaries
这是需要检查并尝试修复的问题,所以如果我这样做
makeglossaries test
相反,这些信息包括以下内容:
Multiple encaps detected. Attempting to remedy.
现在,生成的test.pdf
文件在条目的位置列表中只包含粗体的第 1 页seal
。(Lua 版本makeglossaries-lite.lua
不会这样做。)这种情况不会发生,xindy
因为xindy
会丢弃该textbf
位置而不进行注释。
有些xindy
消息可能有点难以理解,但makeglossaries
会检查它们并尝试提供更具参考性的错误消息。请考虑以下示例:
\documentclass{article}
\usepackage[xindy]{glossaries}
\makeglossaries
\newglossaryentry{P}{
name={\P},
description={paragraph symbol}}
\begin{document}
\gls{P}
\printglossaries
\end{document}
这将产生以下错误消息xindy
:
WARNING: Would replace complete index key by empty string,
ignoring
#<ordrule-regexp: '\\[a-zA-Z@]+ *' => '' :again NIL :only-at-start NIL>
这是什么意思?如果我使用makeglossaries
,我会收到一条更具信息量的消息:
Sort key required for entries only containing command names
Attempting to determine which entries have problem sort keys
Parsing 'test.glo'
1 problematic entry found:
Label: 'P'. Sort value : '\\P '
(Try adding sort={P} to the definition.)
这里的问题是该P
条目需要排序键,所以我需要更正我的 LaTeX 代码:
\newglossaryentry{P}{
name={\P},
sort=P,
description={paragraph symbol}}
这就是为什么我认为后处理器配置文件和其他构建工具应该真正使用makeglossaries
而不是尝试明确调用makeindex
。
我个人更喜欢使用arara
尽管我习惯将其用作make
通用编译工具,但这允许我根据每个文档自定义构建过程,因此我可以这样做:
% arara: pdflatex
% arara: makeglossaries
% arara: pdflatex
\documentclass{article}
\usepackage{glossaries}
\makeglossaries
\newglossaryentry{seal}{name={seal},
description={aquatic mammal}}
\newglossaryentry{sealion}{name={sealion},
description={a type of \gls{seal} with ears}}
\begin{document}
\gls[format=textbf]{seal}, \gls{sealion} and \gls{seal} again.
\printglossaries
\end{document}
或者使用 4.0 版本:
% arara: pdflatex
% arara: makeglossaries if found("aux", "@istfilename")
% arara: pdflatex
\documentclass{article}
\usepackage{glossaries}
\makeglossaries
\newglossaryentry{seal}{name={seal},
description={aquatic mammal}}
\newglossaryentry{sealion}{name={sealion},
description={a type of \gls{seal} with ears}}
\begin{document}
\gls[format=textbf]{seal}, \gls{sealion} and \gls{seal} again.
\printglossaries
\end{document}
如果我无法决定选择\makeglossaries
或哪个更方便\makenoidxglossaries
。