5

I fail to suppress the warning

Package natbib Warning: Citation `Entry' multiply defined.

using the silence package when using natbib and multibib. This is my MWE:

% arara: pdflatex
% arara: bibtex
% arara: bibtex: {files: [Other]}
% arara: pdflatex
% arara: pdflatex

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @article{Entry, Title="Title"}
\end{filecontents}

\usepackage{natbib}

\usepackage{multibib}
\newcites{Other}{Other}

\usepackage{silence}
% does not compile:
%\WarningFilter*{natbib}{Citation `#1
% works, but unwanted:
%\WarningFilter*{natbib}{Citation `}
% does not work:
\WarningFilter*{natbib}{Citation `\#1' multiply defined}

\begin{document}
    \let\myjobname\jobname

    \cite{Entry}
    \citeOther{Entry}

    \bibliographystyle{plainnat}
    \bibliographystyleOther{plainnat}

    \bibliography{\myjobname}
    \bibliographyOther{\myjobname}
\end{document}

Note that you have to run bibtex on Other.aux manually if you do not use arara.

Am I perhaps doing something wrong with the escaping of #1?

Edit: I should have been a little more specific. I would like to use the starred version of the the WarningFilter so I can suppress this message for different bibtex entries. I just need to know how to teach silence to work with #1.

bers
  • 5,404

2 Answers2

4

You can say

\WarningFilter*{natbib}{Citation}

and this will suppress all warnings beginning with "Citation"; in particular, it will suppress the

Citation `#1' multiply defined 

from natbib. This, however, might not be what you want since natbib has other warning messages beginning with the string "Citation"; in this case, you could use

\WarningFilter{natbib}{Citation `Entry' multiply defined}

instead; notice the un-starred version, so you are targeting the warning message as it appears in the .log file.

Your example:

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
    @article{Entry, Title="Title"}
\end{filecontents}

\usepackage{natbib}
\usepackage{multibib}

\newcites{Other}{Other}

\usepackage{silence}
\WarningFilter*{natbib}{Citation}

\begin{document}
    \let\myjobname\jobname

    \cite{Entry}
    \citeOther{Entry}

    \bibliographystyle{plainnat}
    \bibliographystyleOther{plainnat}

    \bibliography{\myjobname}
    \bibliographyOther{\myjobname}
\end{document}
Gonzalo Medina
  • 505,128
  • Thanks for the try. I edited the question to make more clear that I look for an answer which
    1. works for many bibtex entries at a time,
    2. without removing all warnings starting with "Citation"

    Note, in particular, this part of my MWE:

    % works, but unwanted:
    %\WarningFilter*{natbib}{Citation `}
    
    – bers Aug 03 '14 at 09:20
2

I think what I need cannot be done. Here is some evidence:

First, it seems that #1 is never seen by silence, as this MWE shows:

% arara: pdflatex
\documentclass{article}
\usepackage{silence}
% works, but too unflexible:
% \WarningFilter{mypackage}{Suppress me}

% does not compile:
% \WarningFilter*{mypackage}{#1}

% this does nothing:
\WarningFilter*{mypackage}{\#1}

% in fact, this at least works for the first one:
\WarningFilter*{mypackage}{\TheWarning}

\begin{document}
    \newcommand{\IssueWarning}[1]{\PackageWarning{mypackage}{#1}}

    \newcommand{\TheWarning}{Suppress me!}
    \IssueWarning{\TheWarning}

    \IssueWarning{Suppress me, this may even be more difficult!}
\end{document}

In fact, I my original MWE, this works:

% works:
\WarningFilter*{natbib}{Citation `Entry' multiply defined}

Note that this is the starred version of WarningFilter!

From the silence doc, I assume that only one unique starred version of WarningFilter can match a (complete) given warning, so this must be it.

Why is that?

natbib issues the warning like this:

\renewcommand\bibcite[2]{\@ifundefined{b@#1\@extra@binfo}\relax
     {\NAT@citemultiple
      \PackageWarningNoLine{natbib}{Citation `#1' multiply defined}}%

So looking for the culprit call to \bibcite, I found:

       \write\@auxout{\string\bibcite{#5}{{#1}{#2}{{#3}}{{#4}}}}}\fi

Removing this \bibcite, the error message is indeed removed, and indeed, in both aux files I usually find this:

\bibcite{Entry}{{Ent}{}{{}}{{}}}

So the \bibcite call issuing the warning does not contain anything which would make a usable difference between \WarningFilter and \WarningFilter*, it seems.

What can in any way be learnt is that, for the purpose of silence, #1 needs to be tracked down recursively to find what it ultimately was. If it was plain text (such as in my second \IssueWarning example), \WarningFilter* does not offer any advantage.

Edit: A very simple patch of natbib would involve something along the lines

\newcommand{\HashOne}{#1}

before and replacing #1 by \HashOne in the warning line.

bers
  • 5,404
  • There is a similar issue with the graphics package. I guess that the #1 is resolved before it gets to silence. Interesting patch though, but I guess it'll be unlikely to get it implemented unfortunately. – zelanix Jan 16 '15 at 01:01