# Biblatex gobbles punctuation after undefined references

I am trying to use biblatex with the authoryear style, but when I have undefined references it "gobbles" the next punctuation point.

\documentclass{article}

\usepackage[style = authoryear]{biblatex}

\begin{document}

\textcite{UNDEFINED}A

\textcite{UNDEFINED}:

\textcite{aksin}:

\end{document}


How can I patch \textcite (or the bib drivers) so that it does not gobble the punctuation?

• Why the bounty? What is the problem with your own patch? Oct 4, 2017 at 9:38
• @UlrikeFischer Not sure, but the solution has problems with multiple citations: \textcite{UNDEFINED,aksin}: and \textcite{UNDEFINED,FLUNDEF}: give unwanted colons. Oct 4, 2017 at 9:49

Fixed in version 3.8 of biblatex (#630)

I had a bit of time on my hands to investigate this.

In a \cite-like command the first time the citation list is processed with \blx@citeadd, this happens in \blx@citeloop. That command distinguishes citations that were found in the .bib file and those that weren't (i.e. are undefined). The citations that were found are saved in a macro for further processing, the keys of those that weren't found are written out immediately in bold. Then the defined citations are passed on to \blx@citeprint. The command \blx@postcode that does the postpunct stuff - and a little bit more if required - is only called in \blx@citeprint when the last item has been processed.

If we have only undefined citations in our cite command, we never call \blx@postcode since the chain of macros is only executed with the list of defined citations, and not at all if this list is empty.

So we need to make \blx@citeloop call \blx@postcode directly in case there are no defined citations. It turns out that due to the nature of the additional code that \blx@postcode might contain it is not safe to execute there. We need to save the postpunct in a new command and use that instead.

My solution is to split the postpunct part from \blx@postcode into a new \blx@postpunct@saved (sadly the name \blx@postpunct was already taken, but suggestions for a better name are gladly accepted). This new macro can then be called in \blx@citeloop if there are no defined citations and otherwise together with \blx@postcode in \blx@citeprint.

The necessary modifications are not very copious, but the nature of the changed macros does not allow for a short MWE. The necessary changes can be found in the pull request https://github.com/plk/biblatex/pull/630; it has been merged and the fix is included in biblatex v3.8.

Now

\listfiles
\documentclass[american]{article}
\usepackage{babel}
\usepackage[style = authortitle]{biblatex}

\begin{document}

\textcite{UNDEFINED}A

\textcite{fghgvjh}:

\textcite{UNDEFINED}:

\textcite{aksin}:

\textcite{UNDEFINED,aksin}:

\cite{UNDEFINED,aksin}.

\textcite{aksin,UNDEFINED,gundf}:

\textcite{UNDEFINED,FLUNDF}A

\textcite{UNDEFINED,FLUNDF}:

\textcite{aksin,sigfridsson}:

\cite[14]{UNDEFINED,aksin}:

\cite[14]{UNDEFINED,aksin}A

\end{document}


gives

• Wow, nice hunting. I never would have been able to rip it apart and get it back together without have a few broken pieces and a few things left over. I need a bit of time to pull your file and test it out, but your results look promising. Oct 4, 2017 at 17:11
• @StrongBad Note that you can't simply download the biblatex.sty from my github and use it as a drop-in replacement of biblatex.sty. You will have to use the development version of Biber (3.8, from sourceforge) and you will have to use the install script. Oct 4, 2017 at 17:42
• @StrongBad gist.github.com/moewew/373b55c9b1ca2676d1ecf2f6f7c81268/… is a drop-in replacement for biblatex 3.7's biblatex.sty. Oct 4, 2017 at 17:48
• You rock. Was just locking at how to make a diff that I could use on my version. Oct 4, 2017 at 17:51
• @StrongBad I see you have awarded the bounty, thank you. Does that mean that you could test the solution and are happy with it? If so -- and even more so if not -- I'd really appreciate a short heads up because I'm thinking of opening a pull request to get this into the next release of biblatex. Real-life testing/feedback would be appreciated before merging. Oct 10, 2017 at 16:31

What I decided on in the end is to patch \blx@citeadd. I am not sure if this is the best macro to patch. It seems the "gobbled" punctuation is kept in \abx@field@postpunct.

\documentclass{article}
\usepackage{xpatch}
\usepackage[style = authoryear]{biblatex}

\makeatletter
\expandafter\abx@missing\expandafter{\blx@realkey}%
}{%
\expandafter\abx@missing\expandafter{\blx@realkey}%
\ifundef{\abx@field@postpunct}{}{\abx@field@postpunct}%
}{}{}%
\makeatother

\begin{document}

\textcite{UNDEFINED}A

\textcite{UNDEFINED}:

\textcite{aksin}:

\end{document}