我想将该glossaries
包用于首字母缩略词和符号,显示首字母缩略词的页面引用和符号的公式引用。
我知道counter
可以将包选项设置equation
为
\usepackage[counter=equation]{glossaries}
,但是,缩写词词汇表会显示许多方程式是死链接。
我修改了 CTAN()中的示例文件sampleSort.tex
以提供一个最小的工作示例。
% This file is public domain
% If you want to use arara, you need the following directives:
% arara: pdflatex: { synctex: on }
% arara: makeglossaries
% arara: pdflatex: { synctex: on }
% arara: pdflatex: { synctex: on }
\documentclass{report}
% If you want to add babel to this document, you may have to
% replace the : character in the labels if you are using a
% language setting (e.g. french) that makes : active.
\usepackage[plainpages=false,colorlinks]{hyperref}
\usepackage[toc,acronym,counter=equation]{glossaries}
% Define a new glossary type called notation
\newglossary[nlg]{notation}{not}{ntn}{Notation}
\makeglossaries
\newcounter{sortcount}
\renewcommand{\glsprestandardsort}[3]{%
\ifdefstring{#2}{notation}%
{%
\stepcounter{sortcount}%
\edef#1{\glssortnumberfmt{\arabic{sortcount}}}%
}%
{%
\glsdosanitizesort
}%
}
% Notation definitions
\newglossaryentry{not:set}{type=notation, % glossary type
name={$\mathcal{S}$},
text={\mathcal{S}},
description={A set}}
\newglossaryentry{not:emptyset}{type=notation,
name={$\emptyset$},
text={\emptyset},
description={The empty set}}
\newglossaryentry{not:card}{type=notation,
name={$|\mathcal{S}|$},
vtext={|\mathcal{S}|},
description={cardinality of $\mathcal{S}$}}
% Added variables
\newglossaryentry{not:a}{type=notation,
name={\ensuremath{a}},
text={a},
description={a variable}}
\newglossaryentry{not:b}{type=notation,
name={\ensuremath{b}},
text={b},
description={another variable}}
% Main glossary definitions
\newglossaryentry{gls:set}{name=set,description={A collection of distinct objects}}
\newglossaryentry{gls:card}{name=cardinality,description={The number of elements in the specified set}}
% Acronym definitions
\newacronym{zfc}{ZFC}{Zermelo-Fraenkel set theory}
\newacronym{ad}{AD}{axiom of determinacy}
\newacronym{nf}{NF}{new foundations}
\begin{document}
\title{Sample Document using the glossaries Package}
\author{Nicola Talbot}
\pagenumbering{alph}
\maketitle
\begin{abstract}
%stop hyperref complaining about duplicate page identifiers:
\pagenumbering{Alph}
This is a sample document illustrating the use of the
\textsf{glossaries} package. In this example, a new glossary type
called \texttt{notation} is defined, so that the document can have a
separate glossary of terms, list of acronyms and index of notation.
\end{abstract}
\pagenumbering{roman}
\tableofcontents
\printglossaries
\chapter{Introduction}
\pagenumbering{arabic}
\Glspl{gls:set} are denoted by a calligraphic font
e.g.\ $\gls{not:set}$.
The \gls{gls:card} of a set $\mathcal{S}$ is denoted
$\gls{not:card}$. The empty set is denoted
$\gls{not:emptyset}$.
Here are some acronyms: \gls{nf}, \gls{zfc} and \gls{ad}.
\chapter{Another Chapter}
Another mention of the empty set $\gls{not:emptyset}$.
Here are the acronyms again: \gls{nf}, \gls{zfc} and \gls{ad}.
\begin{equation}
\gls{not:a} = \gls{not:b}
\end{equation}
\end{document}
答案1
如果某个词汇表的所有术语始终在编号数学环境中使用,那么您可以在最后的可选参数中设置计数器\newglossary
:
\newglossary[nlg]{notation}{not}{ntn}{Notation}[equation]
其他词汇表中的所有术语都将使用默认计数器(page
或包选项的值counter
)。
如果您的符号在编号和非编号数学环境中混合使用(例如,\begin{equation}\gls{not:a}\end{equation}
和$\gls{not:a}$
),那么您需要counter=equation
在编号数学环境中使用该选项:
\begin{equation}
\gls[counter=equation]{not:a} = \gls[counter=equation]{not:b}
\end{equation}
如果您尝试使用问题中的 MWE 进行此修改,您会发现类似以下警告:
Package glossaries Warning: Hyper target `2.0.1' can't be formed by prefixing
location `2.1'. You need to modify the definition of \theHequation
otherwise you will get the warning: "`name{equation.2.1}' has been
referenced but does not exist"
这意味着你需要重新定义\theHequation
,使其形式为字首.\theequation
或者只是使其与 相同。这是程序包尝试根据计数器名称、前缀和索引值重建数字列表中的超链接的\theequation
方式所施加的限制。glossaries
在这个例子中,\theequation
由章节编号和计数器的值组成equation
,它们通常应该形成唯一的目标名称,因此\theHequation
可以简单地重新定义为\theequation
。
完整示例:
\documentclass{report}
\usepackage[plainpages=false,colorlinks]{hyperref}
\usepackage[toc,acronym]{glossaries}
% Define a new glossary type called notation
\newglossary[nlg]{notation}{not}{ntn}{Notation}
\renewcommand\theHequation{\theequation}
\makeglossaries
\newcounter{sortcount}
\renewcommand{\glsprestandardsort}[3]{%
\ifdefstring{#2}{notation}%
{%
\stepcounter{sortcount}%
\edef#1{\glssortnumberfmt{\arabic{sortcount}}}%
}%
{%
\glsdosanitizesort
}%
}
% Notation definitions
\newglossaryentry{not:set}{type=notation, % glossary type
name={$\mathcal{S}$},
text={\mathcal{S}},
description={A set}}
\newglossaryentry{not:emptyset}{type=notation,
name={$\emptyset$},
text={\emptyset},
description={The empty set}}
\newglossaryentry{not:card}{type=notation,
name={$|\mathcal{S}|$},
text={|\mathcal{S}|},
description={cardinality of $\mathcal{S}$}}
% Added variables
\newglossaryentry{not:a}{type=notation,
name={\ensuremath{a}},
text={a},
description={a variable}}
\newglossaryentry{not:b}{type=notation,
name={\ensuremath{b}},
text={b},
description={another variable}}
% Main glossary definitions
\newglossaryentry{gls:set}{name=set,description={A collection of distinct objects}}
\newglossaryentry{gls:card}{name=cardinality,description={The number of elements in the specified set}}
% Acronym definitions
\newacronym{zfc}{ZFC}{Zermelo-Fraenkel set theory}
\newacronym{ad}{AD}{axiom of determinacy}
\newacronym{nf}{NF}{new foundations}
\begin{document}
\title{Sample Document using the glossaries Package}
\author{Nicola Talbot}
\pagenumbering{alph}
\maketitle
\begin{abstract}
%stop hyperref complaining about duplicate page identifiers:
\pagenumbering{Alph}
This is a sample document illustrating the use of the
\textsf{glossaries} package. In this example, a new glossary type
called \texttt{notation} is defined, so that the document can have a
separate glossary of terms, list of acronyms and index of notation.
\end{abstract}
\pagenumbering{roman}
\tableofcontents
\printglossaries
\chapter{Introduction}
\pagenumbering{arabic}
\Glspl{gls:set} are denoted by a calligraphic font
e.g.\ $\gls{not:set}$.
The \gls{gls:card} of a set $\mathcal{S}$ is denoted
$\gls{not:card}$. The empty set is denoted
$\gls{not:emptyset}$.
Here are some acronyms: \gls{nf}, \gls{zfc} and \gls{ad}.
\chapter{Another Chapter}
Another mention of the empty set $\gls{not:emptyset}$.
Here are the acronyms again: \gls{nf}, \gls{zfc} and \gls{ad}.
\begin{equation}
\gls[counter=equation]{not:a} = \gls[counter=equation]{not:b}
\end{equation}
\end{document}