我想获得词汇表的修改后的页码列表(反向引用)、首字母缩略词和符号列表。在\glsaddallunused
文档末尾,我将所有条目添加到列表中。因此,看起来有些条目没有页码引用,而有些条目有(这正是我想要的)。页码列表应该是:
- 如果没有页码,则不应出现附加文字和括号。
- 如果仅引用一页:“(页码)”
- 如果引用了多个页面:“(第 #、#-#、…、# 和 # 页)”
我通过执行以下操作在我的参考书目中实现了类似的行为(我完全不明白):
\renewcommand*{\backref}[1]{}
\renewcommand*{\backrefalt}[4]{%
{\footnotesize\mbox{
\ifcase #1%
(Not directly cited)%
\or
(Cited on page #2)%
\else
(#1 cites on pages #2)%
\fi}
}
}
如果词汇表绝对不可能做到这一点,我很乐意拥有:
- 如果没有页码,则不应出现任何附加文字。
- 如果引用一个或多个页面:“(#)”
MWE 确实不是根据参考文献有不同的页面列表:
\documentclass{scrreprt}
\usepackage[backref=page,plainpages=false,pdfpagelabels,colorlinks]{hyperref}
\usepackage[footnote,acronym,toc,hyperfirst]{glossaries}
% acronym style (Nicola Talbot)
\newacronymstyle{ex-footnote}%
{%
\GlsUseAcrEntryDispStyle{footnote}%
}%
{%
\GlsUseAcrStyleDefs{hyperfirst, footnote}%
\renewcommand*{\genacrfullformat}[2]{%
\firstacronymfont{\glsentryshort{##1}}##2%
\expandafter\footnote\expandafter{\expandafter\glsentrylong\expandafter{##1}}%
}%
\renewcommand*{\Genacrfullformat}[2]{%
\firstacronymfont{\Glsentryshort{##1}}##2%
\expandafter\footnote\expandafter{\expandafter\glsentrylong\expandafter{##1}}%
}%
\renewcommand*{\genplacrfullformat}[2]{%
\firstacronymfont{\glsentryshortpl{##1}}##2%
\expandafter\footnote\expandafter{\expandafter\glsentrylongpl\expandafter{##1}}%
}%
\renewcommand*{\Genplacrfullformat}[2]{%
\firstacronymfont{\Glsentryshortpl{##1}}##2%
\expandafter\footnote\expandafter{\expandafter\glsentrylongpl\expandafter{##1}}%
}%
}
\setacronymstyle{ex-footnote}
% glossary stile
\makeatletter
\newglossarystyle{MyGlossaryStyle}{%
% Use longtable with two columns:
\renewenvironment{theglossary}%
{\begin{longtable}[l]{p{.2\textwidth}p{.755\textwidth}}}%
{\end{longtable}}%
% start of the environment:
\renewcommand*{\glossaryheader}{}%
% Main (level 0) entries displayed in a row:
\renewcommand*{\glossaryentryfield}[5]{\hspace{-6pt}%
\glstarget{##1}{##2}%
& ##3\glspostdescription%
\space\footnotesize\mbox{(##5)}\tabularnewline%
}%
% Blank row between groups:
\renewcommand*{\glsgroupskip}{\\}%
}
\glossarystyle{MyGlossaryStyle}
\makeatother
\makeglossaries
% arconyms
\newacronym{D}{D}{Is not used}
\newacronym{DD}{DD}{\glslink{displacement damage}{Displacement Damage}}
\newacronym{DDD}{DDD}{Displacement Damage Dose}
\newacronym{FPGA}{FPGA}{Field-Programmable Gate Array}
% Gloassaries
\newglossaryentry{displacement damage}{
name = {Displacement Damage},
description = {Displacement damage description}
}
\newglossaryentry{displacement damage dose}{
name = {Displacement Damage Dose},
description = {\Gls{DD} dose description}
}
\newglossaryentry{interconnect}{
name = {Interconnect},
description = {The wiring resources in an \gls{FPGA}}
}
\begin{document}
page 1\\
What does \gls{interconnect} mean?
\clearpage
\newpage
page 2\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}, \gls{displacement damage dose} and again \gls{DDD}.\\
\clearpage
\newpage
page 3\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}
\clearpage
\newpage
page 4
\clearpage
\newpage
page 5\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}
\printglossary[type=\acronymtype, title=Abbreviations]
\printglossary[type=main, title=Glossary]
\glsaddallunused
\end{document}
注1:由于 MWE 中有交叉引用,您必须使用 makeglossaries 进行两次编译,例如:
- pdflatex
- makeglossaries
- pdflatex
- makeglossaries
- pdflatex
笔记2:页面列表出现问题,错误地添加了一个逗号和空格,如下所示:
注3:第 5 个参数\glossaryentryfield
是页面列表。使用
\ifx##5\relax
也不
\if\relax\detokenize{##5}\relax
也不
\ifthenelse{\isempty{##5}}
注4:我不介意清理我的词汇表风格的代码=)
答案1
我终于解决了这个问题。
我查看了\detokenize{##2}
(##2
页面列表在哪里\glossentry
)的输出,发现glsignore
如果没有页码,它有一个子字符串。此外,页码之间至少有一个子字符串delimR
或delimN
(仅当此处引用了多个页面时)。
由于\glossaryentryfield
已被弃用,您应改用\glossentry
。
欢迎您发布更优雅的解决方案......
\documentclass{scrreprt}
\usepackage{xstring}
\usepackage[backref=page,plainpages=false,pdfpagelabels,colorlinks]{hyperref}
\usepackage[footnote,acronym,toc,hyperfirst]{glossaries}
% acronym style (Nicola Talbot)
\newacronymstyle{ex-footnote}%
{%
\GlsUseAcrEntryDispStyle{footnote}%
}%
{%
\GlsUseAcrStyleDefs{hyperfirst, footnote}%
\renewcommand*{\genacrfullformat}[2]{%
\firstacronymfont{\glsentryshort{##1}}##2%
\expandafter\footnote\expandafter{\expandafter\glsentrylong\expandafter{##1}}%
}%
\renewcommand*{\Genacrfullformat}[2]{%
\firstacronymfont{\Glsentryshort{##1}}##2%
\expandafter\footnote\expandafter{\expandafter\glsentrylong\expandafter{##1}}%
}%
\renewcommand*{\genplacrfullformat}[2]{%
\firstacronymfont{\glsentryshortpl{##1}}##2%
\expandafter\footnote\expandafter{\expandafter\glsentrylongpl\expandafter{##1}}%
}%
\renewcommand*{\Genplacrfullformat}[2]{%
\firstacronymfont{\Glsentryshortpl{##1}}##2%
\expandafter\footnote\expandafter{\expandafter\glsentrylongpl\expandafter{##1}}%
}%
}
\setacronymstyle{ex-footnote}
% glossary style
\makeatletter
\newglossarystyle{MyGlossaryStyle}{%
% Use longtable with two columns:
\renewenvironment{theglossary}%
{\begin{longtable}[l]{p{.2\textwidth}p{.755\textwidth}}}%
{\end{longtable}}%
% start of the environment:
\renewcommand*{\glossaryheader}{}%
% Main (level 0) entries displayed in a row:
\renewcommand*{\glossentry}[2]{%
\glstarget{##1}{\glossentryname{##1}}% Name
& \glossentrydesc{##1}% Description
\IfSubStr*{\detokenize{##2}}{glsignore}{%
\footnotesize\space (Not used)%
}{%
\IfSubStr*{\detokenize{##2}}{delim}{%
\footnotesize\space (Pages ##2)%
}{%
\footnotesize\space (Page ##2)%
}%
}%
\tabularnewline% end of row
}%
% Similarly for sub-entries
\renewcommand*{\subglossentry}[3]{%
\glstarget{##2}{\glossentryname{##2}}% Name
& \glossentrydesc{##2}% Description
\IfSubStr*{\detokenize{##3}}{glsignore}{%
\footnotesize\space (Not used)%
}{%
\IfSubStr*{\detokenize{##3}}{delim}{%
\footnotesize\space (Pages ##3)%
}{%
\footnotesize\space (Page ##3)%
}%
}%
\tabularnewline% end of row
}%
% Blank row between groups:
\renewcommand*{\glsgroupskip}{\\}%
}
\setglossarystyle{MyGlossaryStyle}
\makeatother
\makeglossaries
% arconyms
\newacronym{D}{D}{Is not used}
\newacronym{DD}{DD}{\glslink{displacement damage}{Displacement Damage}}
\newacronym{DDD}{DDD}{Displacement Damage Dose}
\newacronym{FPGA}{FPGA}{Field-Programmable Gate Array}
% Gloassaries
\newglossaryentry{displacement damage}{
name = {Displacement Damage},
description = {Displacement damage description}
}
\newglossaryentry{displacement damage dose}{
name = {Displacement Damage Dose},
description = {\Gls{DD} dose description}
}
\newglossaryentry{interconnect}{
name = {Interconnect},
description = {The wiring resources in an \gls{FPGA}}
}
\begin{document}
page 1\\
What does \gls{interconnect} mean?
\clearpage
\newpage
page 2\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}, \gls{displacement damage dose} and again \gls{DDD}.\\
\clearpage
\newpage
page 3\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}, \gls{displacement damage dose}
\clearpage
\newpage
page 4
\clearpage
\newpage
page 5\\
What does \gls{interconnect} mean again?\\
\Gls{DDD}
\printglossary[type=\acronymtype, title=Abbreviations]
\printglossary[type=main, title=Glossary]
\glsaddallunused
\end{document}
编辑1
我\gls{displacement damage dose}
在第 3 页添加了内容。这就是为什么与问题中的原始 MWE 相比,第 3 页也被添加到词汇表中。