突出显示未定义引用的标签?

突出显示未定义引用的标签?

我希望没有相应“bibitem”条目的“cite”条目以红色显示,以及缺失的参考标签的名称。我找到了一个论坛条目它提出了一个解决方案,但它只显示 [?citation?]。我更希望它显示 [?nameOfMissingKey?],但我对 LaTeX 还不太熟悉,所以不确定调整它的最佳方法是什么。

任何帮助,将不胜感激。

顺便说一下,建议的解决方案是:

\documentclass{article}
\usepackage{xcolor}
\newcommand*{\missingreference}{\colorbox{red}{?reference?}}
\newcommand*{\missingcitation}{\colorbox{red}{?citation?}}
\makeatletter
\def\@setref#1#2#3{%
  \ifx#1\relax
   \protect\G@refundefinedtrue
   \nfss@text{\reset@font\missingreference}%
   \@latex@warning{Reference `#3' on page \thepage \space
             undefined}%
  \else
   \expandafter#2#1\null
  \fi}
\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\missingcitation}%
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
\makeatother
\begin{document}

This is a missing reference: \ref{somefig}.

This is a mssing citation: \cite{somebib}.

\end{document}

答案1

评论太长:

您可以简单地重新定义一些代码。我用我的姓名首字母突出显示了更改的行。

\documentclass{article}
\usepackage{xcolor}
\newcommand*{\missingreference}[1]{\colorbox{red}{?#1?}}%JB
\newcommand*{\missingcitation}[1]{\colorbox{red}{?#1?}}%JB
\makeatletter
\def\@setref#1#2#3{%
  \ifx#1\relax
   \protect\G@refundefinedtrue
   \nfss@text{\reset@font\missingreference{#3}}%%JB
   \@latex@warning{Reference `#3' on page \thepage \space
             undefined}%
  \else
   \expandafter#2#1\null
  \fi}
\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\missingcitation{#2}}%%JB
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}
\makeatother
\begin{document}

This is a missing reference: \ref{somefig}.

This is a mssing citation: \cite{somebib}.

\end{document}

相关内容