我正在编写一份包含特定课程要求的教学大纲。活动都标有这些要求以展示对齐。我想使用标签或索引系统来标记对齐实例,然后引用发生对齐实例的所有页面。
是否有一个包可以引用所有包含相同标签的页面(如索引中),但允许我在文档中的任意位置打印该标签的页面?
这种需求似乎具有 \label - \ref 和 \index 的元素。
我没有最小的工作示例,但我想要的看起来像这样。
\documentclass{article}
\begin{document}
\begin{description}
\item[CR1] This is a description of a requirement. \\ See page <LIST OF PAGES LABELED WITH CR1>
\item[CR2] This is a description of another requirement. \\ See page <LIST OF PAGES LABELED WITH CR2>
\end{description}
\section{Section 1}
This is an activity aligned with CR1. (\label{CR1} or \index{CR1})
This is an activity aligned with CR2. (\label{CR2} or \index{CR2})
\section{Section 2}
This is another activity aligned with CR1. (\label{CR1} or \index{CR1})
\end{document}
答案1
我看到 Nicola 刚刚做了一个词汇表版本,但这是我的 makeindex 基本版本。
您只是想要一种索引样式,将每个页面列表保存在定义中而不是排版中,例如foo.ist
:
preamble
"\n\\makeatletter{"
postamble
"}\n\\makeatother\n"
item_0 "}\n\\@namedef{"
delim_0 "}{"
然后
pdflatex file
makeindex -s foo.ist file
pdflatex file
应该从类似以下文档生成上述输出
\documentclass{article}
\usepackage{makeidx}
\makeindex
\def\listfor#1{\csname #1\endcsname}
\begin{document}
\printindex
\begin{description}
\item[CR1] This is a description of a requirement. \\ See pages \listfor{CR1}
\item[CR2] This is a description of another requirement. \\ See pages \listfor{CR2}
\end{description}
\section{Section 1}
This is an activity aligned with CR1\index{CR1}.
aa
\clearpage
This is an activity aligned with CR2\index{CR2}.
\section{Section 2}
This is another activity aligned with CR1\index{CR1}.
\section{Section 3}
This is an activity aligned with CR1\index{CR1}.
aa
\clearpage
This is an activity aligned with CR2\index{CR2}.
\section{Section 4}
This is another activity aligned with CR1\index{CR1}.
aa
\clearpage
aa
\clearpage
This is an activity aligned with CR2\index{CR2}.
\section{Section 4}
This is another activity aligned with CR1\index{CR1}.
\end{document}
答案2
下面是一个使用glossaries
:
\documentclass{article}
\usepackage[colorlinks]{hyperref}% optional but if needed must come
% before glossaries.sty
\usepackage[nopostdot]{glossaries}
\makeglossaries
% syntax: \newglossaryentry{label}{options}
\newglossaryentry{CR1}{name={CR1},
description={This is a description of a requirement.}}
% Or
% syntax: \longnewglossaryentry{label}{options}{description}
\longnewglossaryentry{CR2}{name={CR2}}%
{This is a description of another requirement.
With a paragraph break.
}
\begin{document}
\printglossary[title={Requirements}]
\section{Section 1}
This is an activity aligned with CR1.\glsadd{CR1}% index only
This is an activity aligned with \gls{CR2}.% index and show name
\section{Section 2}
This is an activity aligned with \gls{CR1}.% index and show name
\end{document}
构建过程(假设文件名为myDoc.tex
):
pdflatex myDoc
makeglossaries myDoc
pdflatex myDoc
makeglossaries
makeindex
是一个调用所有必需开关设置的Perl 脚本。
或者如果你没有安装 Perl,有一个轻量级的 Lua 脚本:
pdflatex myDoc
makeglossaries-lite myDoc
pdflatex myDoc
任一构建过程都会产生:
红色文字表示超链接。1
描述后面是引用该条目的页码。
使用扩展包glossaries-extra
您可以使用此选项单独抑制自动索引noindex
。
\documentclass{article}
\usepackage[colorlinks]{hyperref}% optional but if needed must come
% before glossaries.sty
\usepackage{glossaries-extra}
\makeglossaries
% syntax: \newglossaryentry{label}{options}
\newglossaryentry{CR1}{name={CR1},
description={This is a description of a requirement.}}
% Or
% syntax: \longnewglossaryentry{label}{options}{description}
\longnewglossaryentry{CR2}{name={CR2}}%
{This is a description of another requirement.
With a paragraph break.
}
\begin{document}
\printglossary[title={Requirements}]
\section{Section 1}
This is an activity aligned with CR1.\glsadd{CR1}% index only
This is an activity aligned with \gls{CR2}.% index and show name
\newpage
\section{Section 2}
This is an activity aligned with \gls{CR1}.% index and show name
Some minor reference to \gls[noindex]{CR2} that doesn't need
indexing.
\end{document}
构建过程相同。
您可以更改样式。例如:
\printglossary[title={Requirements},style=index]
供将来参考,很快就会有另一种方法使用bib2gls
而不是makeglossaries
/ makeglossaries-lite
。我把它添加到这里是为了以防以后有人发现这个问题。
创建一个.bib
名为的文件,例如requirements.bib
:
@entry{CR1,
name={CR1},
description={This is a description of a requirement.}
}
@entry{CR2,
name={CR2},
description={This is a description of another requirement.
With a paragraph break.}
}
该文件myDoc.tex
现为:
\documentclass{article}
\usepackage[colorlinks]{hyperref}% optional but if needed must come
% before glossaries.sty
\usepackage[record]{glossaries-extra}
\GlsXtrLoadResources[src={requirements}]% data in requirements.bib
\begin{document}
\printunsrtglossary[title={Requirements}]
\section{Section 1}
This is an activity aligned with CR1.\glsadd{CR1}% index only
This is an activity aligned with \gls{CR2}.% index and show name
\newpage
\section{Section 2}
This is an activity aligned with \gls{CR1}.% index and show name
Some minor reference to \gls[noindex]{CR2} that doesn't need
indexing.
\end{document}
构建过程如下:
pdflatex myDoc
bib2gls myDoc
pdflatex myDoc
无需同时调用makeindex
从文件bib2gls
中提取和排序条目.bib
以及从文件收集位置.aux
。
此处的区别在于使用record
选项 和\GlsXtrLoadResources
。该命令\makeglossaries
不是必需的,并且现在使用\printunsrtglossary
而不是来打印词汇表\printglossary
。