TransWikia.com

Making broken references extra visible, redux: interacting with BibTeX (or BibLaTeX)

TeX - LaTeX Asked by jdc on May 3, 2021

In Making broken references extra-visible, I asked how to make LaTex’s normal ?? and [?] markers for broken references instead render as some super-annoying, colored text, so that in skimming a long book-class document, I can know instantly what needs fixing.

I have been instructed now how to do this for broken refs, but the MWE I provided was too minimal: I’d also like to know how to similarly mark broken cites.

Here is an MWE in case there is any doubt what I mean by this.

 documentclass{article}
 usepackage{amsthm,hyperref}
 bibliographystyle{amsalpha}
 newtheorem{theorem}{Theorem}
 begin{document}
 begin{theorem}label{catfish}
 end{theorem}
 Theorem ref{catfish} implies the truth of Theorem ref{god}, 
 as explained in cite{what}.
 bibliography{bibshort}{}
 end{document}.

I was encouraged to use BibLaTeX, but in creating this MWE found that don’t seem to be able to use BibLaTeX on my computer, so for the moment I am asking about BibTex. (I would have asked the other question first, but because I started this one first, it seems the site’s software requires me to either post it or delete it before I can ask a different question.)

One Answer

Update

With newer biblatex versions we can simply redefine the macro abx@missing@entry to change what is shown when a citation is not found.

documentclass{article}
usepackage[utf8]{inputenc}
usepackage[backend=biber, style=numeric]{biblatex}
usepackage{xcolor}
addbibresource{biblatex-examples.bib}

makeatletter
defabx@missing@entry#1{%
  {bfseriescolor{red} undefined Label: #1}}
makeatother

begin{document}
cite{cicero}

cite{lorem}
end{document}


Old answer

With biblatex, we have to modify blx@citation@entry, a command called for each citation item:

makeatletter
defblx@citation@entry#1#2{%
  blx@bibreq{#1}%
  ifinlist{#1}{blx@cites}
    {}
    {listgadd{blx@cites}{#1}%
     blx@auxwrite@mainaux{}{stringabx@aux@cite{#1}}}%
  ifinlistcs{#1}{blx@segm@thec@refsection @thec@refsegment}
    {}
    {listcsgadd{blx@segm@thec@refsection @thec@refsegment}{#1}}%
  blx@ifdata{#1}
    {}
    {ifcsdef{blx@miss@thec@refsection}
       {ifinlistcs{#1}{blx@miss@thec@refsection}
          {{bfseriescolor{red} undefined Label:} }
          {blx@logreq@active{#2{#1}}}}
       {blx@logreq@active{#2{#1}}}}}
makeatother

To get rid of a spurious space, we can also redefine (this has to be placed within a makeatletter ... makeatother group)

defblx@citeadd#1{%
  ifcsdef{blx@keyalias@thec@refsection @#1}
    {edefblx@realkey{csuse{blx@keyalias@thec@refsection @#1}}}
    {defblx@realkey{#1}}%
  expandafterblx@citationexpandafter{blx@realkey}blx@msg@cundefon
  expandafterblx@ifdataexpandafter{blx@realkey}
    {advanceblx@tempcnta@ne
     listeaddblx@tempa{blx@realkey}}
    {ifnumblx@tempcntb>z@multicitedelimfi
     expandafterabx@missingexpandafter{blx@realkey}%
     advanceblx@tempcntb@ne}}

Where we added a % at the end of the second-to-last line.

MWE

documentclass{article}
usepackage[utf8]{inputenc}
usepackage[backend=biber, style=numeric]{biblatex}
usepackage{xcolor}
addbibresource{biblatex-examples.bib}

makeatletter
defblx@citation@entry#1#2{%
  blx@bibreq{#1}%
  ifinlist{#1}{blx@cites}
    {}
    {listgadd{blx@cites}{#1}%
     blx@auxwrite@mainaux{}{stringabx@aux@cite{#1}}}%
  ifinlistcs{#1}{blx@segm@thec@refsection @thec@refsegment}
    {}
    {listcsgadd{blx@segm@thec@refsection @thec@refsegment}{#1}}%
  blx@ifdata{#1}
    {}
    {ifcsdef{blx@miss@thec@refsection}
       {ifinlistcs{#1}{blx@miss@thec@refsection}
          {{bfseriescolor{red} undefined Label:} }
          {blx@logreq@active{#2{#1}}}}
       {blx@logreq@active{#2{#1}}}}}

defblx@citeadd#1{%
  ifcsdef{blx@keyalias@thec@refsection @#1}
    {edefblx@realkey{csuse{blx@keyalias@thec@refsection @#1}}}
    {defblx@realkey{#1}}%
  expandafterblx@citationexpandafter{blx@realkey}blx@msg@cundefon
  expandafterblx@ifdataexpandafter{blx@realkey}
    {advanceblx@tempcnta@ne
     listeaddblx@tempa{blx@realkey}}
    {ifnumblx@tempcntb>z@multicitedelimfi
     expandafterabx@missingexpandafter{blx@realkey}%
     advanceblx@tempcntb@ne}}
makeatother

begin{document}
cite{cicero}

cite{lorem}
end{document}

enter image description here

Correct answer by moewe on May 3, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP