1

How to make LaTeX compilation abort if \bibitem is using? Below is a code snippet which I want the compilation to fail.

\documentclass{article}
\usepackage{amssymb,longtable,amsmath,booktabs,url,amstext,array,geometry}

\begin{document}
\cite{notes}
\cite{notes2}

\begin{thebibliography}{1}
\bibitem{notes} John W. Dower {\em Readings compiled for History 21.479.}  1991.
\end{thebibliography}
\end{document}
lockstep
  • 250,273
sherlock
  • 1,463
  • 2
  • 15
  • 21
  • Are you open to using BibLaTeX? – Sean Allred Oct 04 '14 at 13:24
  • Till now I have only used PdfLatex, but no harm in trying a different compiler. – sherlock Oct 04 '14 at 13:32
  • Heh, not quite :) http://tex.stackexchange.com/q/25701/17423 BibLaTeX/biber is the next generation of BibTeX. – Sean Allred Oct 04 '14 at 13:33
  • 3
    for a document of any size it is normal to not write the thebibliography but let a separate program (bibtex or more recently biber) generate that based on information from the first run, in which case getting the ? for all citations on the first run is normal. – David Carlisle Oct 04 '14 at 13:38
  • @SeanAllred - I guess the OP wants an error message to be issued if a \bibitem instruction is encountered in the tex file. This would seem to be independent of the issue of how the \bibitem instruction got there: somebody could have written it entirely by hand, or either bibtex or biblatex (with either bibtex or biber as the backend) were used to create the \bibitems... – Mico Oct 04 '14 at 18:24
  • 2
    If \bibitem is using what? – egreg Oct 04 '14 at 19:28

1 Answers1

2

As noted in comments it is better to use bibtex or biber to generate the bibliography however latex warns at the end of document for any undefined citations or references and you can easily make that an error rather than a warning if you wish:

\documentclass{article}
\usepackage{amssymb,longtable,amsmath,booktabs,url,amstext,array,geometry}

\makeatletter
\def\G@refundefinedtrue{%
  \gdef\@refundefined{%
    \GenericError{}{}{There were undefined references}{you wanted an error}}}
\makeatother
\begin{document}
\cite{notes}
\cite{notes2}

\begin{thebibliography}{1}
\bibitem{notes} John W. Dower {\em Readings compiled for History 21.479.}  1991.
\end{thebibliography}
\end{document}

with the above, the terminal output shows:

! .

There were undefined references
Type  H <return>  for immediate help.
 ...                                              

l.16 \end{document}

? h
you wanted an error
? 
David Carlisle
  • 757,742