我想用这解决方案在 BibLaTeX 中具有所有格引用,但将其扩展以正确解释以 's' 结尾的名称(至少在英文中)。该问题中发布的解决方案才不是考虑到这些,但是做在我的计算机上编译成功。
我认为我可以通过仅使用xstring
来检查名称是否以“s”结尾,从而轻松地扩展它,如果以“s”结尾,则仅添加'
到末尾,而不是's
。我尝试了下面的 mwe,但出现编译错误:
错误
ERROR: Illegal parameter number in definition of \xs_arg_i.
--- TeX said ---
<to be read again>
=
l.51 \posscite{crane22_plural}
is the easy case.
平均能量损失
\documentclass{article}
\author{ModallyFragile}
\title{Foo}
\usepackage{xstring}
\usepackage{filecontents}
\usepackage[style=authoryear]{biblatex}
\addbibresource{\jobname.bib}
% Support possessive citation
\DeclareNameWrapperFormat{labelname:poss}{\IfEndWith{#1}{s}{#1'}{#1's}}
\DeclareFieldFormat{shorthand:poss}{\ifnameundef{labelname}{\IfEndWith{#1}{s}{#1'}{#1's}}{#1}}
\DeclareFieldFormat{citetitle:poss}{\mkbibemph{\IfEndWith{#1}{s}{#1'}{#1's}}}
\DeclareFieldFormat{label:poss}{\IfEndWith{#1}{s}{#1'}{#1's}}
\newrobustcmd*{\posscitealias}{%
\AtNextCite{%
\DeclareNameWrapperAlias{labelname}{labelname:poss}%
\DeclareFieldAlias{shorthand}{shorthand:poss}%
\DeclareFieldAlias{citetitle}{citetitle:poss}%
\DeclareFieldAlias{label}{label:poss}}}
\newrobustcmd*{\posscite}{%
\posscitealias%
\textcite}
\newrobustcmd*{\Posscite}{\bibsentence\posscite}
\newrobustcmd*{\posscites}{%
\posscitealias%
\textcites}
\begin{filecontents}{\jobname.bib}
@Article{crane22_plural,
date = {2022},
title = {Plurals are easy!},
author = {Crane, Tim},
timestamp = {2023-07-23 20:44:43 (BST)}
}
@Article{mills23_plural,
date = {2023},
title = {Plurals are hard},
author = {Mills, Charles W.},
timestamp = {2023-07-23 20:44:18 (BST)}
}
\end{filecontents}
\begin{document}
\posscite{crane22_plural} is the easy case.
But \posscite{mills23_plural} is the hard case.
\end{document}
我已将错误归咎于我对IfEndWith
内部的使用DeclareNameWrapperFormat
。
是什么原因造成的(以及我该如何阻止它发生)?