LaTeX - 更改失败的参考颜色

LaTeX - 更改失败的参考颜色

假设我有这个 MWE:

\documentclass[a4paper,10pt]{article}

\usepackage{todonotes}
\usepackage{caption}

\usepackage{filecontents}

\begin{filecontents}{\jobname.bib}
  @book{Knu86,
    author = {Knuth, Donald E.},
    year = {1986},
    title = {The \TeX book},
  }
\end{filecontents}

\begin{document}

Good cross-reference: Table \ref{tab:good}

Bad cross-reference: Table  \ref{tab:bad}

\begin{table}[h]
  \caption{table}
  \label{tab:good}
\end{table}



Good citation: \cite{Knu86}

Bad citation: \cite{Knu86q898}

\bibliographystyle{alpha}
\bibliography{\jobname}

\end{document}

两个问题:

1) 我可以更改失败引用的颜色/字体,以便它不显示 3 个灰色问号,而是显示 3 个粗体红色字体的 \大问号吗?

2)我可以对失败的引用做同样的事情吗?

我正在寻找论文中失败的参考/引用,这将有很大帮助。

谢谢

编辑

@campa 的补丁在使用 MWE 时运行完美,但在我的论文上运行时,出现如下错误:

line 374: LaTeX error: "xparse/command-already-defined" Command '\xshowcmd' already defined! For immediate help type H <return>. }

line 376: LaTeX error: "xparse/command-already-defined" Command '\xpretocmd' already defined! For immediate help type H <return>. ...\xpatch_pretocmd:Nnnn #1 {#2} {#3} {#4} }

line 378: LaTeX error: "xparse/command-already-defined" Command '\xapptocmd' already defined! For immediate help type H <return>. ...\xpatch_apptocmd:Nnnn #1 {#2} {#3} {#4} }

line 390: LaTeX error: "xparse/command-already-defined" Command '\xpatchcmd' already defined! For immediate help type H <return>. }

line 403: LaTeX error: "xparse/command-already-defined" Command '\xshowbibmacro' already defined! For immediate help type H <return>. }

line 408: LaTeX error: "xparse/command-already-defined" Command '\xpretobibmacro' already defined! For immediate help type H <return>. }

line 413: LaTeX error: "xparse/command-already-defined" Command '\xapptobibmacro' already defined! For immediate help type H <return>. }

知道是什么原因造成的吗?有可能导致这种情况的软件包吗?我使用比布拉特克斯用于图书馆管理。

编辑2

使用正则表达式补丁代替补丁解决了这个问题。

答案1

相关命令是

% latex.ltx lines 4046-
\def\@setref#1#2#3{%
  \ifx#1\relax
   \protect\G@refundefinedtrue
   \nfss@text{\reset@font\bfseries ??}%  <======= HERE THE TWO QUESTION MARKS
   \@latex@warning{Reference `#3' on page \thepage \space
             undefined}%
  \else
   \expandafter#2#1\null
  \fi}

以供参考,以及

%latex.ltx lines 6316-
\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 ?}% <= HERE THE QUESTION MARK
       \G@refundefinedtrue
       \@latex@warning
         {Citation `\@citeb' on page \thepage \space undefined}}%
       {\@cite@ofmt{\csname b@\@citeb\endcsname}}}}{#1}}

引用。您可以修补它们以替换问号

\documentclass[a4paper,10pt]{article}

\usepackage{color}
\usepackage{xpatch}

\makeatletter
%Usage: \xpatchcmd{command}{search}{replace}{success}{failure}
\xpatchcmd{\@setref}{??}{\Large\textcolor{red}{???}}{}{}
\xpatchcmd{\@citex}{?}{\Large\textcolor{red}{???}}{}{}
\makeatother

\begin{document}

Good cross-reference: Table \ref{tab:good}

Bad cross-reference: Table  \ref{tab:bad}

\begin{table}[h]
  \caption{table}
  \label{tab:good}
\end{table}



Good citation: \cite{Knu86}

Bad citation: \cite{Knu86q898}

\begin{thebibliography}{9}
\bibitem{Knu86} A book.
\end{thebibliography}

\end{document}

在此处输入图片描述

相关内容