当使用以下期限discardperiod
的功能时glossaries-extra
,如果使用明确的长格式,则会被不适当地丢弃:
\documentclass{article}
\usepackage[
abbreviations,
shortcuts=abbr,
]{glossaries-extra}
\glssetcategoryattribute{abbreviation}{discardperiod}{true}
\glssetcategoryattribute{abbreviation}{retainfirstuseperiod}{true}
\newabbreviation{dr}{Dr.}{Doctor}
\begin{document}
% This is OK.
\ab{dr}. \ab{dr}.
% This is still OK.
\as{dr}.
% This period gets unduly discarded.
\al{dr}.
\end{document}
有人碰巧知道正确处理此案的方法吗?
答案1
我想我可以想出一些合理的办法,即使这个办法比我希望的要棘手。
\documentclass{article}
\usepackage[
abbreviations,
shortcuts=abbr,
]{glossaries-extra}
\glssetcategoryattribute{abbreviation}{discardperiod}{true}
\glssetcategoryattribute{abbreviation}{retainfirstuseperiod}{true}
\newtoggle{glsenddot}
\NewDocumentCommand{\glsdot}{}{\global\toggletrue{glsenddot}.\@}
\makeatletter
\renewcommand*{\glsxtrifperiod}[1]{%
\iftoggle{glsenddot}
{%
\global\togglefalse{glsenddot}%
\new@ifnextchar.{\@firstoftwo{#1}}%
}
{\@secondoftwo{#1}}%
}
\makeatother
\preto\glsxtrpostlink{\global\togglefalse{glsenddot}}
\newabbreviation{dr}{Dr\glsdot}{Doctor}
\newabbreviation{abc}{ABC}{Aaaa Bbbb Cccc}
\begin{document}
% This is OK.
\ab{dr}. \ab{abc}. \ab{abc}. \ab{dr}.
% This is still OK.
\as{dr}.
% This period is now in place.
\al{dr}.
\ab{abc}.
\end{document}