我想在文中引用词汇表。解决方案在我网站上回答这个问题时,这个方法有效。但添加\usepackage{hyperref}
before 后,\usepackage{glossaries}
它就不再起作用了(输出为“词汇表从第 ??” 页开始)。如何在使用该hyperref
包的同时引用词汇表所在的页面?
\documentclass{book}
\usepackage{hyperref}
\usepackage{glossaries}
\makeglossaries
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@glossarysection}{%
\@@glossaryseclabel%
}{%
\@@glossaryseclabel%
\label{\glsautoprefix\@glo@type}% "main" for main glossary, "acronym" for list of acronyms
}{}{}
\makeatother
\newglossaryentry{electrolyte}{name=electrolyte,%
description={solution able to conduct electric current}}
\begin{document}
Some text about \gls{electrolyte}.
The glossary starts on page~\pageref{main}.
\printglossaries
\end{document}
答案1
我建议基于重新定义的以下简单解决方案\glossarypreamble
:
\documentclass{book}
\usepackage{hyperref}
\usepackage{glossaries}
\makeglossaries
\newglossaryentry{electrolyte}{name=electrolyte,
description={solution able to conduct electric current}}
\renewcommand*{\glossarypreamble}{%
\label{\currentglossary}%
}
\begin{document}
Some text about \gls{electrolyte}.
The glossary starts on \autopageref{main}.
\printglossaries
\end{document}
或者,你可以glossaries
使用以下方式加载包
\usepackage[numberedsection=autolabel]{glossaries}
但在这种情况下,词汇表部分是编号的。
答案2
您必须创建一个参考标记,这可以通过以下方式完成\phantomsection
\documentclass{book}
\usepackage{hyperref}
\usepackage{glossaries}
\makeglossaries
%-------------------------------------------------------
\newglossaryentry{electrolyte}{name=electrolyte,%
description={solution able to conduct electric current}}
%-------------------------------------------------------
\begin{document}
Some text about \gls{electrolyte}.
The glossary starts on page~\pageref{glossaries}.
\cleardoublepage
\phantomsection <------------------- here
\label{glossaries}<-----------------and here
\printglossaries
%-------------------------------------------------------
\end{document}
词汇表页面如下所示:
答案3
对于可以使用 和 的解决方案hyperref
(就像我的原始解决方案一样)而无需对文档主体进行修改,您必须使用 patch\@p@glossarysection
而不是\@glossarysection
。
\documentclass{book}
\usepackage{hyperref}
\usepackage{glossaries}
\makeglossaries
\usepackage{etoolbox}
\makeatletter
\patchcmd{\@p@glossarysection}{%
\@@glossaryseclabel%
}{%
\@@glossaryseclabel%
\label{\glsautoprefix\@glo@type}% "main" for main glossary, "acronym" for list of acronyms
}{}{}
\makeatother
\newglossaryentry{electrolyte}{name=electrolyte,%
description={solution able to conduct electric current}}
\begin{document}
Some text about \gls{electrolyte}.
The glossary starts on page~\pageref{main}.
\printglossaries
\end{document}