latex3 / tagging-project

Issues related to the tagging project
https://latex3.github.io/tagging-project/
LaTeX Project Public License v1.3c
31 stars 13 forks source link

empty `thebibliography` errors #641

Open mbertucci47 opened 1 month ago

mbertucci47 commented 1 month ago

An empty thebibliography environment, either in the main tex file or the bbl file, produces the error

! Package tagpdf Error: there is no open structure on the stack

Without tagging code loading you just get the usual warning

LaTeX Warning: Empty `thebibliography' environment on input line 12.

I'd say an error is not desirable since an author often starts writing a paper with \bibliography given but no \cite commands.

Example:

\DocumentMetadata
  {
    lang=en-US,
    pdfversion=2.0,
    pdfstandard=ua-2,
    testphase={phase-III,math,title,table,firstaid}
  }
\documentclass{article}

\begin{document}

text%\cite{inbook-full}

\bibliographystyle{amsalpha}
\bibliography{xampl}
%\begin{thebibliography}{9} % or this
%\end{thebibliography}

\end{document}
u-fischer commented 4 weeks ago

The problem is that the \endlist code tries to close structures that never have been opened as there is no \item in the bibliography. One could fake an empty structure with

\DocumentMetadata
  {
    lang=en-US,
    pdfversion=2.0,
    pdfstandard=ua-2,
    testphase={phase-III,math,title,table,firstaid},
  }
\documentclass{article}
\makeatletter
\renewenvironment{thebibliography}[1]
     {\section*{\refname}%
      \@mkboth{\MakeUppercase\refname}{\MakeUppercase\refname}%
      \list{\@biblabel{\@arabic\c@enumiv}}%
           {\settowidth\labelwidth{\@biblabel{#1}}%
            \leftmargin\labelwidth
            \advance\leftmargin\labelsep
            \@openbib@code
            \usecounter{enumiv}%
            \let\p@enumiv\@empty
            \renewcommand\theenumiv{\@arabic\c@enumiv}}%
      \sloppy
      \clubpenalty4000
      \@clubpenalty \clubpenalty
      \widowpenalty4000%
      \sfcode`\.\@m}
     {\def\@noitemerr
       {\@latex@warning{Empty `thebibliography' environment}%
       \tagstructbegin{tag=LI}\tagstructbegin{tag=LBody}% start empty structure
       }%
      \endlist}
\begin{document}

\begin{thebibliography}{9} % or this
\end{thebibliography}

\end{document}

The (probably better) alternative would be to test in \__block_list_end: if there is an open body/item to close.

FrankMittelbach commented 3 weeks ago

Not clear to me, whether an empty list without items should be treated as a list (with, say, vertical spacing being added before and after) or whether it should be treated as an error. In some sense it seems to me "error" is the right answer, but not low-level error.