如果 bibitem 正在使用,则终止 LaTeX 编译

如果 bibitem 正在使用,则终止 LaTeX 编译

如果使用 \bibitem,如何使 LaTeX 编译中止?下面是我希望编译失败的代码片段。

\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}

答案1

正如评论中所述,最好使用 bibtex 或 biber 来生成参考书目,但是 latex 会在文档末尾对任何未定义的引用或参考发出警告,如果您愿意,您可以轻松地将其设为错误而不是警告:

\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}

通过上述操作,终端输出显示:

! .

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

l.16 \end{document}

? h
you wanted an error
? 

相关内容