当引用未定义时,LaTeX 仅显示[??]
它没有提供太多信息。我希望它显示标签。当更多合作者在同一预印本上工作并且参考文献尚未完成时,这很有用。
我既不使用biblatex
也不使用natbib
。我确实使用,bibtex
但它与这个问题无关。
梅威瑟:
\documentclass{article}
\begin{document}
This: \cite{undef}
should look like: [{\bfseries ?? undef}]
\end{document}
答案1
的定义\cite
调用一个内部函数\@citex
来检查引用,并\hbox{\reset@font\bfseries ?}
为未定义的引用添加一个。将其改为调用参数而\cite
不是问号就可以了。
\makeatletter
% latex.ltx, line 6121:
\def\@citex[#1]#2{\leavevmode
\let\@citea\@empty
\@cite{\@for\@citeb:=#2\do
{\@citea\def\@citea{,\penalty\@m\ }%
\edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
\if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
\@ifundefined{b@\@citeb}{\hbox{\reset@font\bfseries
\expandafter\strip@prefix\meaning\@citeb}%
\G@refundefinedtrue
\@latex@warning
{Citation `\@citeb' on page \thepage \space undefined}}%
{\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
\makeatother
一个更简洁的重新定义方法\@citex
是用xpatch
:
\usepackage{xpatch}
\makeatletter
\xpatchcmd{\@citex}{\bfseries ?}{\bfseries\expandafter\strip@prefix\meaning\@citeb}{}{}
\makeatother
梅威瑟:
\documentclass{article}
% \usepackage{lmodern}
\usepackage[T1]{fontenc}
\makeatletter
% latex.ltx, line 6121:
\def\@citex[#1]#2{\leavevmode
\let\@citea\@empty
\@cite{\@for\@citeb:=#2\do
{\@citea\def\@citea{,\penalty\@m\ }%
\edef\@citeb{\expandafter\@firstofone\@citeb\@empty}%
\if@filesw\immediate\write\@auxout{\string\citation{\@citeb}}\fi
\@ifundefined{b@\@citeb}{\hbox{\reset@font\bfseries
\expandafter\strip@prefix\meaning\@citeb}%
\G@refundefinedtrue
\@latex@warning
{Citation `\@citeb' on page \thepage \space undefined}}%
{\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
\makeatother
\begin{document}
\null\vfill\thispagestyle{empty}
This: \cite{undef} should look like: [{\bfseries ?? undef}]
This one \cite{article-minimal} shouldn't.
Ugly citation keys with special chars like \cite{_$^/:&!@*(-=+)}
also should be printed.
\bibliography{xampl.bib}
\bibliographystyle{plain}
\end{document}
本回答由以下机构赞助texdef
以及 tohecz 和 Gonzalo Medina 的(非常!)特别评论:)
答案2
biblatex
默认提供此功能:
\documentclass{article}
\usepackage{biblatex}% http://ctan.org/pkg/biblatex
\begin{document}
See~\cite{author}.
\end{document}