如何makeindex
从文档类源中运行memoir
以创建词汇表?
对于词汇表,调用makeindex
(通过imakeidx
包)失败memoir
。
这是我的源代码,它makeindex
(通过imakeidx
包)调用,看似使用了第 17.3 节中描述的语法memman.pdf
。
当我在源上运行 pdflatex 制作文件(从 TeXShop 内部,通过 pdflatexmk 引擎)时,出现以下错误:
Rule 'cusdep goo gas book': File changes, etc:
Non-existent destination files:
'book.gls
来源:
% BOOK.TEX
\documentclass{memoir}
\usepackage{amsmath}
\usepackage[makeindex]{imakeidx}
\makeglossary
\makeindex[options=-s glossarystyle.gst,-o book.gls book.glo]
\begin{document}
The empty set is denoted by $\emptyset$.%
\glossary{$\emptyset$}{empty set}
The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\glossary{$\mathcal{P}(X)$}{power set of set}
\newpage
For sets $X$ and $Y$, the notation $f \colon X \to Y$ means that $f$ is a functions from $X$ to $Y$.%
\glossary{$f \colon X \to Y$}{functions from one set to another}.
\printglossary
\end{document}
引用的样式文件`glossarystyle.gst:
% GLOSSARYSTYLE.GST
%%% basic.gst basic makindex glossary style file
%%% Output style parameters
preamble "\\begin{theglossary}"
postamble "\n\\end{theglossary}\n"
item_0 "\n\\glossitem"
delim_0 "{\\memglonum{"
encap_suffix "}}}"
headings_flag 1
heading_prefix "\\doglobookmark{"
heading_suffix "}"
%%% Input style parameters
keyword "\\glossaryentry"
请注意,我只使用该类的内置词汇表功能memoir
,并且不是外包装glossaries
!
latexmkrc
TeXShop.app 内置的 pdflatexmk 引擎调用的文件是:
# latexmkrcedit
# 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;
# 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");
}
而 pdflatexmk 引擎又是脚本文件:
#!/bin/bash
# pdflatexmk.engine
#
export TSBIN="$HOME/Library/TeXShop/bin/tslatexmk"
export LTMKBIN="$HOME/Library/TeXShop/bin/tslatexmk"
export LTMKEDIT="$HOME/Library/TeXShop/bin"
# make sure latexmkrcedit exists in bin
if [ ! -e "${LTMKEDIT}/latexmkrcedit" ] ; then
cp "${TSBIN}/latexmkrcDONTedit" "${LTMKEDIT}/latexmkrcedit"
fi
# Use local rc file platexmkrc if it exists. p = project
export localrc=""
if [ -e ./platexmkrc ] ; then
export localrc="-r ./platexmkrc"
fi
"${LTMKBIN}"/latexmk -pdf -r "${LTMKEDIT}/latexmkrcedit" -r "${TSBIN}/pdflatexmkrc" ${localrc} "$1"
对于普通索引,调用makeindex
(通过imakeidx
包)做与...合作memoir
。
例如,以下做生成索引:
\documentclass{memoir}
\usepackage{amsmath}
\usepackage[makeindex]{imakeidx}
\makeindex[options=-s indexheaders]
%%\makeglossary
%%\makeindex[options=-s glossarystyle.gst -o book.gls book.glo]
\begin{document}
The empty set is denoted by $\emptyset$.%
\index{empty set!notation}
%%\glossary{$\emptyset$}{empty set}
The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\index{power set}
%%\glossary{$\mathcal{P}(X)$}{power set of set}
\newpage
For sets $X$ and $Y$, the notation $f \colon X \to Y$ means that $f$ is a functions from $X$ to $Y$.%
\index{function!notation}
%%\glossary{$f \colon X \to Y$}{functions from one set to another}.
\printindex
%%\printglossary
\end{document}
这里引用的索引样式文件indexheaders.ist
是:
headings_flag 1
heading_prefix "{\\medskip\\hfill\\large\\textsf{\\textbf{"
heading_suffix "}}\\hfill}\\medskip\\nopagebreak\n"
新的尝试:没有错误,但没有词汇表
我改变了源文件行
\makeindex[options=-s glossarystyle.gst,-o book.gls book.glo]
到
\makeindex[name=glossary,title=Index of notation,options=-s glossarystyle.gst -o book.gls book.glo]
并改变每个\glossary
命令以添加可选文件名(glossary
),例如:
glossary[glossary]{$\emptyset$}{empty set}
现在,当我运行 TeXShop 的 pdflatexmk 引擎时,它不会生成任何错误 - 但根本没有词汇表!它glossary.glo
使用几个\glossaryentry
命令生成预期的文件,但该glossary.gls
文件是空的。
解决方案!
感谢 macosx-tex 邮件列表和私人邮件中 Herb Schulz 的帮助,下面的方法解决了该问题,同时仍然只使用了 的内部词汇表功能memoir
,而没有使用glossaries
软件包。
修正后的来源:
\documentclass{memoir}
\usepackage{amsmath}
\newcommand{\from}{\mathpunct{:}}
%\newcommand{\from}{\protect\colon}
%\newcommand{\from}{:}
\makeglossary[glossary]
\renewcommand*{\glossaryname}{Index of Notation}
\makeindex
\begin{document}
The empty set is denoted by $\emptyset$.%
\index{empty set!notation}
\glossary[glossary]{$\emptyset$}{empty set}
The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\index{power set}
\glossary[glossary]{$\mathcal{P}(X)$}{power set of set}
\newpage
$f \from X \to Y$
For sets $X$ and $Y$, the notation $f \from X \to Y$ means that $f$ is a functions from $X$ to $Y$.%
\index{function!notation}
\glossary[glossary]{$f \from X \to Y$}{function from one set to another}
\printglossary[glossary]
\printindex
\end{document}
事实上,使用 TeXShop 就不需要了imakeidx
。源代码在 TeXShop 内部使用其pdflatexmk
引擎进行处理,并且以下附加文件platexmkrc
放置在源目录中:
add_cus_dep('glo', 'gls', 0, 'makeglo2gls');
sub makeglo2gls {
system("makeindex -s basic.gst -t '$_[0]'.glg -o '$_[0]'.gls '$_[0]'.glo");
};
(为了完整性:所示的三个版本是避免参数中的\newcommand{\from}...
数学关系错误的方法,而不必解决 中的错误,每个\colon
\glosary
\@@glossary
词汇表中带有回忆录类的条目中有额外的“@”。
答案1
错误消息
Rule 'cusdep goo gas book': File changes, etc:
看起来像是来自 (pdf) 的消息latexmk
(不是 TeX 消息)。这表明有一条latexmk
规则
add_cus_dep('goo', 'gas', 0, 'something');
这实际上没有任何意义,因为您的文档没有写入或读取任何具有这些扩展名的文件,因此似乎有些令人困惑latexmk
,但您发布的代码中没有任何内容可以解释这一点(据我所知)。错误消息的其余部分:
Non-existent destination files:
'book.gls
表明它期望文件book.gls
存在,但对于memoir
,文件.gls
是依赖于文件的文件。您可以从包含以下行的.glo
转录 ( ) 文件中看出这一点:book.log
Writing glossary file book.glo
这是包含要处理的词汇表信息的文件makeindex
。稍后的抄本中还有另一行:
No file book.gls.
这是读取的文件,也是需要创建的\printglossary
文件。makeindex
因此完整的构建顺序是:
pdflatex book
makeindex -s glossarystyle.gst -o book.gls book.glo
pdflatex book
pdflatexmk
如果依赖关系设置正确,就应该这样做,但是似乎有些东西把它们弄乱了。
您可以makeindex
使用 TeX 的 shell 转义来调用,这似乎是您尝试做的事情imakeidx
,但正如@egreg 在评论中指出的那样,在这种情况下无法做到这一点。
相反,你可以明确地使用 shell 转义符\write18
。像这样:
\documentclass{memoir}
\immediate\write18{makeindex -s glossarystyle.gst -o \jobname.gls \jobname.glo}
\usepackage{amsmath}
\makeglossary
\begin{document}
The empty set is denoted by $\emptyset$.%
\glossary{$\emptyset$}{empty set}
The set of all subsets of a set $X$ is denoted by $\mathcal{P}(X)$.%
\glossary{$\mathcal{P}(X)$}{power set of set}
\newpage
For sets $X$ and $Y$, the notation $f \colon X \to Y$ means that $f$
is a functions from $X$ to $Y$.%
\glossary{$f \colon X \to Y$}{functions from one set to another}.
\printglossary
\end{document}
请注意,\immediate
这里需要确保在覆盖文件makeindex
之前运行。现在您只需要:\makeglossary
.glo
pdflatex book
pdflatex book
这会导致您的测试文件出现几个错误:\doglobookmark
未定义(我假设您只是将其从测试文件中省略)并makeindex
报告错误(记录在book.ilg
):
!! Input index error (file = test.glo, line = 3):
-- Extra `@' at position 106 of first argument.
这是由于 的过早扩张造成的\colon
,这个问题已在另一个问题中处理过。