5

My document has an empty citation \cite{}. I'd expected to get some warning about it.

Is it a bug? (if not - why?) Is it possible to enable checking for such cases?

MWE:

\documentclass{article} \begin{document} \cite{Goodfellow2014a} \cite{} \bibliography{main} \bibliographystyle{plain} \end{document} 

and main.bib:

@misc{Goodfellow2014a, author = {Goodfellow, I J and Shlens, J and Szegedy, C}, title = {{Explaining and harnessing adversarial examples}}, year = {2014} } 

I'm using pdflatex and bibtex.

3
  • 2
    I'm almost tempted to say it is a bug: if you go \cite{Goodfellow2014a,somethingelse,} then you do get a warning about the empty entry from the trailing , but a completely empty list is silently accepted Commented Mar 8, 2022 at 11:44
  • 1
    I think it classifies as a bug and should be fixed because people may rely on fixing cites later and being warned that something is not resolved. Can you please open an issue at github.com/latex3/latex2e/issues ? Commented Mar 9, 2022 at 12:43
  • 1
    @FrankMittelbach I opened an issue - github.com/latex3/latex2e/issues/790 Commented Mar 10, 2022 at 9:36

2 Answers 2

3

We can't change \@for but given that it looks like wrong behavior perhaps we can fix it by checking for an empty argument before calling \@citex (we can't do in that macro because too many styles redefine that).

E.g., something like

\documentclass{article} \makeatletter \DeclareRobustCommand\cite{% \@ifnextchar [{\@tempswatrue\@citexfix}{\@tempswafalse\@citexfix[]}} \def\@citexfix[#1]#2{% \IfBlankTF {#2}% {\@citex[#1]{\space}}% {\@citex[#1]{#2}}% } \ExplSyntaxOn \cs_new_eq:NN \IfBlankTF \tl_if_blank:nTF \ExplSyntaxOff \makeatother \begin{document} \cite{Goodfellow2014a} \cite{} \cite{ } \cite{ } %tab \bibliography{main} \bibliographystyle{plain} \end{document} 
7

Hmmm \cite takes a comma separated list of cite keys, if you use \cite{aaa,bbb,} then you get a warning about an empty entry from the trailing comma, but if the list is completely empty then the whole thing is skipped.

This is actually a feature of LaTeX's \@for loop macro:

\documentclass{article} \makeatletter \begin{document} \@for \tmp:=aa,bb,\do{\typeout{1 [\tmp]}} \@for \tmp:=\do{\typeout{2 [\tmp]}} \end{document} 

produces terminal and log output

1 [aa] 1 [bb] 1 [] 

where the first loop includes an iteration with an empty value but the second loop has no iterations at all.

This might be a bit unexpected but \@for has been that way since the earliest latex releases, so almost 40 years now and it is used in multiple places in the latex format and in packages.

\@for is documented as accepting (and by implication skipping) lists of length 0

% \@for NAME := LIST \do {BODY} : Assumes that LIST expands to A1,A2, % ... ,An . % Executes BODY n times, with NAME = Ai on the i-th iteration. % Optimized for the normal case of n = 1. Works for n=0. 

so arguably the unexpected behaviour is that the trailing comma isn't ignored.

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.