Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using custom labelprefixes and \printbibtabular return [0] for all citations in text #21

Closed
yosata opened this issue Apr 22, 2021 · 4 comments
Labels
bug Something isn't working
Milestone

Comments

@yosata
Copy link

yosata commented Apr 22, 2021

Describe the bug
Using \printbibtabular with custom label prefixes return [0] when cited in the text. Replacing \printbibtabular by \printbibliography solves the citation issue, but obviously removes the reference table.

To Reproduce
Below a minimal example that reproduces the behavior:

\documentclass{article}
\usepackage[style=numeric, backend=biber, date=short, defernumbers=true]{biblatex}
\usepackage{biblatex-ext-tabular}
\usepackage{longtable}

\addbibresource{biblatex-examples.bib}

% Defines the function that prints references in a table
\defbibtabular{bibtabular}{%
    \begin{center}
        \setlength\LTleft{0pt}
        \setlength\LTright{0pt}
        \begin{longtable}{@{\extracolsep{\fill}}|c|p{0.7\linewidth}|c|@{}}
            \hline \textbf{RD Nr} & \textbf{Document Title} & \textbf{Date}\endhead 
            \hline
            }
            {
            \hline
        \end{longtable}
    \end{center}}
    {
    \anchorlang{%
      \printtext[labelnumberwidth]{%
      \printfield{labelprefix}%
      \printfield{labelnumber}}}
  & \plainlang{\usebibmacro{title}} \plainlang{\usebibmacro{author}}
  & \plainlang{\printdate}\\ \hline}

\begin{document}
\cite{worman,geer,nussbaum,companion}

\newrefcontext[labelprefix=RD]
\printbibtabular

\end{document}

Expected behaviour
I would expect that the reference labels follow the prefixes that I defined. For example, \cite{worman} should print "[RD4]".

Output
PDF output using \printbibtabular:
Screenshot 2021-04-22 at 16 56 02

Replacing \printbibtabular by \printbibliography gives the proper citation labels, but removes the tabular bibliography:
Screenshot 2021-04-22 at 16 56 41

Additional context
I'm trying to create a template for some technical documentation. In this template is a requirement for two types of bibliographies (Applicable Documents and Reference Documents), both in tabular format. I'm using \printbibtabular to print these in a tabular format, both with different label prefixes. The tables look fine. However, when citing in the document text, instead of returning the proper label (e.g. [RD1], [AD3], etc.) it returns [0] each time.
I'm not sure that it matters, but I'm using Overleaf to write my LaTeX documentation.

Things I've tried

  • Replacing \printbibtabular by \printbibliography solves the citation issue, but removes the reference table and replaces it with the normal reference list.
  • Setting defernumbers=false in the biblatex arguments removes the custom prefixes when citing in the text. The label prefixes are still added in the table. This is not ideal. The numeric citations work fine in this case, except that they do not reset when defining a second type of references.
@yosata yosata added the bug Something isn't working label Apr 22, 2021
@moewew
Copy link
Owner

moewew commented Apr 22, 2021

Thank you very much for reporting this issue.

I'm not quite sure yet how to fix this at the biblatex-ext end, but I think I know why it happens and I can offer you a workaround for your document.

The problem here is that we need to set the 'default refcontext' for the entries that appear in the tabular bibliography. In \printbibliography that happens directly when the items are printed. In \printbibtabular different bits of the entry can be printed with different commands. Only \driver sets the default refcontext. Since your example does not have a \driver call, the default refcontext is never set. biblatex-ext-tabular needs to be changed to make sure that the refcontext is always set no matter which printing commands are used. But I'm not quite sure how exactly we should do this.

For now a workaround for your document is to manually initiate setting the default refcontext.

\documentclass{article}
\usepackage[style=numeric, backend=biber, date=short, defernumbers=true]{biblatex}
\usepackage{biblatex-ext-tabular}
\usepackage{longtable}

\addbibresource{biblatex-examples.bib}

\makeatletter
\def\fixextblx@setrefcontext{%
  \expandafter\blx@setdefaultrefcontext\expandafter{\abx@field@entrykey}}

\defbibtabular{bibtabular}
  {\begin{center}
     \setlength\LTleft{0pt}
     \setlength\LTright{0pt}
     \begin{longtable}{@{\extracolsep{\fill}}|c|p{0.7\linewidth}|c|@{}}
       \hline \textbf{RD Nr} & \textbf{Document Title} & \textbf{Date}\endhead 
       \hline}
  {    \hline
     \end{longtable}
   \end{center}}
  {  \anchorlang{%
       \fixextblx@setrefcontext
       \printtext[labelnumberwidth]{%
         \printfield{labelprefix}%
         \printfield{labelnumber}}}
   & \plainlang{%
       \usebibmacro{title}%
       \newunit
       \usebibmacro{author}}
   & \plainlang{\printdate}\\ \hline}
\makeatother

\begin{document}
\cite{worman,geer,nussbaum,companion}

\newrefcontext[labelprefix=RD]
\printbibtabular

\end{document}

@moewew
Copy link
Owner

moewew commented Apr 22, 2021

This bug should be fixed with 06dd359, where we make sure to always set the default refcontext independent of the tabular wrappers you use. v0.12b was sent off to CTAN a few minutes ago and should land in TeX Live and MikTeX in the next days.

@yosata
Copy link
Author

yosata commented Apr 23, 2021

Thanks for the quick response! Your workaround did indeed fix the problem.

@yosata yosata closed this as completed Apr 23, 2021
@moewew
Copy link
Owner

moewew commented Apr 24, 2021

Version 0.12b with the fix is available in both MikTeX and TeX Live now. The MWE from the first post now produces the expected output.

Overleaf don't update their systems continuously, so you will need the workaround proposed on Overleaf until they offer TeX Live 2021 or later with updates from today or later (and you switch your document to that new system).

moewew added a commit that referenced this issue Apr 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants