biblatex icon indicating copy to clipboard operation
biblatex copied to clipboard

`\savename` and `\restorename` don't save and restore the number of names

Open dcpurton opened this issue 11 months ago • 2 comments

For background, see https://tex.stackexchange.com/q/738654/87678

I was trying to use \savename and \restorename to smuggle a translator from an xref entry to the parent entry and discovered that it only worked if I also copied the translator counter.

I realise that I might not be using the macros in the intended way. But it took me a while to figure out and it seems like something that should either work or be mentioned in the manual.

MWE

This MWE shows a working version. If you don't copy the translator counter the translator field is printed incorrectly in the parent entry after the \restorename operation.

\documentclass{article}
\begin{filecontents}[overwrite]{\jobname.bib}
@book{test,
  translator = {First and Second}
}
@book{test2,
  xref = {test}
}
\end{filecontents}
\usepackage[minxrefs=1]{biblatex}
\addbibresource{\jobname.bib}

\makeatletter

\newcounter{dcp@savedtranslator}

\DeclareCiteCommand{\cite}
  {}
  {\entrydata*{\thefield{xref}}{%
     \printnames{translator}%
     \savename{translator}{\savedtranslator}%
     \setcounter{dcp@savedtranslator}{\value{translator}}%
   }%
   \newunit
   \restorename{translator}{\savedtranslator}%
   \setcounter{translator}{\value{dcp@savedtranslator}}%
   \printnames{translator}}
  {}
  {}

\makeatother

\begin{document}
\cite{test2}
\end{document}

dcpurton avatar Mar 12 '25 12:03 dcpurton

Ah yes. This should definitely be fixed.

moewew avatar Apr 08 '25 19:04 moewew

I had hoped to address this before the next release, which should happen fairly soon, but if we want to do this properly, i.e. with just a single macro (holding both the list and the counter) and not with a hidden second macro that holds the counter separately, it requires changes to how the list and name list data structures are implemented internally. It seems very doable, but I'd want some more time for testing, so I'd like to defer it until after the imminent release.

moewew avatar Jul 03 '25 07:07 moewew