我希望我的首字母缩略词第一次出现时会以强调的样式出现。因此,我按照常见问题解答的建议重新定义CustomAcronymFields
并使用SetCustomStyle
。这种方法一直有效,直到我需要对首字母缩略词进行特殊处理。我想这个例子是不言自明的?(尝试使用 和不使用SetCustomStyle
。)
\documentclass{scrreprt}
\usepackage[%
acronym, shortcuts,
xindy={language=german-duden,codepage=utf8}
]{glossaries}
%see: http://www.dickimaw-books.com/faqs/glossariesfaq.html#longformat
\renewcommand*{\CustomAcronymFields}{%
name={\the\glsshorttok},% name is abbreviated form
description={\the\glslongtok},% description is long form
first={\noexpand\emph{\the\glslongtok\space(\the\glsshorttok)}},%
firstplural={\noexpand\emph{\the\glslongtok\noexpand\acrpluralsuffix}\space(\the\glsshorttok)},%
text={\the\glsshorttok},%
plural={\the\glsshorttok\noexpand\acrpluralsuffix}%
}
\SetCustomStyle
\newacronym[
longplural={A long Test},
shortplural={AlT},
plural={TSTn}]{tst}{TST}{A Test}
\makeglossaries
\begin{document}
This is aspecial long form of \acp{tst}. An the singular of \ac{tst} and it's
plural \acp{tst}.
\printglossary[style=listdotted,type=\acronymtype]{}
\end{document}
我必须做哪些改变才能使长复数和短复数正常工作?
答案1
我认为在这种情况下最好升级到glossaries
4.0 版本(我最近将其上传到 CTAN)。它有更灵活的方式更改显示格式。示例:
\documentclass{scrreprt}
\usepackage[%
acronym, shortcuts,
xindy={language=german-duden,codepage=utf8}
]{glossaries}
\renewcommand*{\CustomAcronymFields}{%
name={\the\glsshorttok},% name is abbreviated form
description={\the\glslongtok},% description is long form
}
\renewcommand*{\SetCustomDisplayStyle}[1]{%
\defglsentryfmt[#1]{%
\ifdefempty\glscustomtext
{% no custom text supplied
\ifglsused{\glslabel}%
{% Subsequent use
\glsifplural
{% plural subsequent use
\glscapscase
{% no case change
\glsentryshortpl{\glslabel}\glsinsert
}%
{% first letter upper case
\Glsentryshortpl{\glslabel}\glsinsert
}%
{% all caps
\MakeTextUppercase{\glsentryshortpl{\glslabel}\glsinsert}%
}%
}%
{% singular subsequent use
\glscapscase
{% no case change
\glsentryshort{\glslabel}\glsinsert
}%
{% first letter upper case
\Glsentryshort{\glslabel}\glsinsert
}%
{% all caps
\MakeTextUppercase{\glsentryshort{\glslabel}\glsinsert}%
}%
}%
}%
{% First use
\glsifplural
{% plural first use
\glscapscase
{% no case change
\emph{\glsentrylongpl{\glslabel}\glsinsert\space
(\glsentryshortpl{\glslabel})}%
}%
{% first letter upper case
\emph{\Glsentrylongpl{\glslabel}\glsinsert\space
(\glsentryshortpl{\glslabel})}%
}%
{% All caps
\emph{\MakeTextUppercase{%
\glsentrylongpl{\glslabel}\glsinsert\space
(\glsentryshortpl{\glslabel})}}%
}%
}%
{% singular first use
\glscapscase
{% no case change
\emph{\glsentrylong{\glslabel}\glsinsert\space
(\glsentryshort{\glslabel})}%
}%
{% first letter upper case
\emph{\Glsentrylong{\glslabel}\glsinsert\space
(\glsentryshort{\glslabel})}%
}%
{% All caps
\emph{\MakeTextUppercase{%
\glsentrylong{\glslabel}\glsinsert\space
(\glsentryshort{\glslabel})}}%
}%
}%
}%
}%
{% custom text provided by \glsdisp
\ifglsused{\glslabel}%
{% subsequent use
\glscustomtext
}%
{% first use
\emph{\glscustomtext}%
}%
}%
}%
}
\SetCustomStyle
\newacronym[
longplural={A long Test},
shortplural={AlT}]{tst}{TST}{A Test}
\makeglossaries
\begin{document}
\chapter{Test}
\section{No Case Change}
First use plural: \acp{tst}. Next use plural: \acp{tst}.
\glsresetall
First use singular: \ac{tst}. Next use singular: \ac{tst}.
\glsresetall
\section{First Letter Uppercase}
First use plural: \Acp{tst}. Next use plural: \Acp{tst}.
\glsresetall
First use singular: \Ac{tst}. Next use singular: \Ac{tst}.
\glsresetall
\section{All Caps}
First use plural: \GLSpl{tst}. Next use plural: \GLSpl{tst}.
\glsresetall
First use singular: \GLS{tst}. Next use singular: \GLS{tst}.
\glsresetall
\section{Custom text}
First use: \glsdisp{tst}{sample text}. Next use: \glsdisp{tst}{sample text}.
\printglossary[style=listdotted,type=\acronymtype]{}
\end{document}
得出的结果为:
编辑:
从 4.02 版本开始,有一种更简单的方法:
\documentclass{scrreprt}
\usepackage[%
acronym, shortcuts,
xindy={language=german-duden,codepage=utf8}
]{glossaries}
% Define a new acronym style
\newacronymstyle{emfirst-long-short}
{%
\GlsUseAcrEntryDispStyle{long-short}%
}
{%
\GlsUseAcrStyleDefs{long-short}%
\renewcommand*{\genacrfullformat}[2]{%
\emph{\glsentryshort{##1}##2\space
(\glsentrylong{##1})}%
}%
\renewcommand*{\Genacrfullformat}[2]{%
\emph{\Glsentryshort{##1}##2\space
(\glsentrylong{##1})}%
}%
\renewcommand*{\genplacrfullformat}[2]{%
\emph{\glsentryshortpl{##1}##2\space
(\glsentrylongpl{##1})}%
}%
\renewcommand*{\Genplacrfullformat}[2]{%
\emph{\Glsentryshortpl{##1}##2\space
(\glsentrylongpl{##1})}%
}%
}
% Switch to the new acronym style
\setacronymstyle{emfirst-long-short}
\newacronym[
longplural={A long Test},
shortplural={AlT}]{tst}{TST}{A Test}
\makeglossaries
\begin{document}
\chapter{Test}
\section{No Case Change}
First use plural: \acp{tst}. Next use plural: \acp{tst}.
\glsresetall
First use singular: \ac{tst}. Next use singular: \ac{tst}.
\glsresetall
\section{First Letter Uppercase}
First use plural: \Acp{tst}. Next use plural: \Acp{tst}.
\glsresetall
First use singular: \Ac{tst}. Next use singular: \Ac{tst}.
\glsresetall
\section{All Caps}
First use plural: \GLSpl{tst}. Next use plural: \GLSpl{tst}.
\glsresetall
First use singular: \GLS{tst}. Next use singular: \GLS{tst}.
\glsresetall
\section{Custom text}
First use: \glsdisp{tst}{sample text}. Next use:
\glsdisp{tst}{sample text}.
\printglossary[style=listdotted,type=\acronymtype]{}
\end{document}
得出的结果为:
唯一的区别在于何时\glsdisp
使用。如果您也希望在第一次使用时使用它\emph
,您可以修改上述示例,如下所示:
\documentclass{scrreprt}
\usepackage[%
acronym, shortcuts,
xindy={language=german-duden,codepage=utf8}
]{glossaries}
% Define a new acronym style
\newacronymstyle{emfirst-long-short}
{%
\ifglshaslong{\glslabel}%
{%
\ifglsused{\glslabel}{\glsgenacfmt}{\emph{\glsgenacfmt}}%
}%
{\glsgenentryfmt}% not an acronym
}
{%
\GlsUseAcrStyleDefs{long-short}%
}
% Switch to the new acronym style
\setacronymstyle{emfirst-long-short}
\newacronym[
longplural={A long Test},
shortplural={AlT}]{tst}{TST}{A Test}
\makeglossaries
\begin{document}
\chapter{Test}
\section{No Case Change}
First use plural: \acp{tst}. Next use plural: \acp{tst}.
\glsresetall
First use singular: \ac{tst}. Next use singular: \ac{tst}.
\glsresetall
\section{First Letter Uppercase}
First use plural: \Acp{tst}. Next use plural: \Acp{tst}.
\glsresetall
First use singular: \Ac{tst}. Next use singular: \Ac{tst}.
\glsresetall
\section{All Caps}
First use plural: \GLSpl{tst}. Next use plural: \GLSpl{tst}.
\glsresetall
First use singular: \GLS{tst}. Next use singular: \GLS{tst}.
\glsresetall
\section{Custom text}
First use: \glsdisp{tst}{sample text}. Next use:
\glsdisp{tst}{sample text}.
\printglossary[style=listdotted,type=\acronymtype]{}
\end{document}
得出的结果为: