4

I am aware of \clearfield, \clearlist etc (cf. Is it possible to suppress a specific field from bibtex .bbl in biblatex?) - but I'm really not sure how to apply it in this context:

Say you have a split bibliography (i.e. several calls to \printbibliography in one document). How can you filter a specific field in a bibliography item - but only in one bibliography (i.e. only in one call to \printbibliography)?

For instance, in the MWE below (compiles with pdflatex test.tex && biber test && pdflatex test.tex && pdflatex test.tex), let's say I'd like to filter urldate (i.e. urldate is not typeset) only in the first bibliography - but for the second one, the original/default behavior should be restored (i.e. urldate is typeset). How to I do that?

\documentclass{article}
\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@online{ctan,
  title        = {CTAN},
  date         = 2006,
  url          = {http://www.ctan.org},
  subtitle     = {The Comprehensive TeX Archive Network},
  urldate      = {2006-10-01},
  label        = {CTAN},
  langid       = {english},
  langidopts   = {variant=american},
}
@misc{google,
  title        = {Google},
  date         = 2007,
  url          = {http://www.google.com},
  urldate      = {2007-10-01},
}
@misc{hotmail,
  title        = {Hotmail},
  date         = 2008,
  url          = {http://www.hotmail.com},
  urldate      = {2008-10-01},
}
@misc{yahoo,
  title        = {Yahoo},
  date         = 2009,
  url          = {http://www.yahoo.com},
  urldate      = {2009-10-01},
}
@misc{aol,
  title        = {AOL},
  date         = 2010,
  url          = {http://www.aol.com},
  urldate      = {2010-10-01},
}
@misc{altavista,
  title        = {AltaVista},
  date         = 2011,
  url          = {http://www.altavista.com},
  urldate      = {2011-10-01},
}
\end{filecontents*}
\usepackage[utf8]{inputenc}
\usepackage[backend=biber,defernumbers=true,style=ieee]{biblatex}
\bibliography{\jobname}

\begin{document}

\section{Section 1}
\begin{refsection}

Citing some stuff here: first \cite{ctan}, then \cite{google}, and finally \cite{hotmail}.

\printbibliography[sorting=none,section=\therefsection,resetnumbers=true]

\end{refsection}

\section{Section 2}
\begin{refsection}

Citing some stuff here: first \cite{yahoo}, then \cite{aol}, and finally \cite{altavista}.

\printbibliography[sorting=none,section=\therefsection,resetnumbers=true]

\end{refsection}

\end{document}

Output:

test.png

sdaau
  • 17,079

2 Answers2

7
\documentclass{article}

\usepackage[utf8]{inputenc}
\usepackage[backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}

\newbool{clearurl}

\AtEveryBibitem{%
 \ifbool{clearurl}
  {%
   \clearfield{urlday}%
   \clearfield{urlmonth}%
   \clearfield{urlyear}%
  }{}%
  }

\begin{document}

Citing some stuff here: first \cite{ctan}

\booltrue{clearurl}
\printbibliography


\boolfalse{clearurl}
\printbibliography
\end{document}

Output:

test.png

sdaau
  • 17,079
Ulrike Fischer
  • 327,261
  • 1
    Many thanks for that, @UlrikeFischer - looks great; I also added an image to your example - cheers! – sdaau May 18 '15 at 17:20
3

We can define a new command for that: \AtEveryBibitemNextBibOnly (what a name), it combines the best of \AtEveryBibitem and \AtNextBibliography.

\makeatletter
\newrobustcmd*{\AtEveryBibitemNextBibOnly}{%
  \ifundef\blx@hook@bibitem@save
    {\global\let\blx@hook@bibitem@save\blx@hook@bibitem
     \preto\blx@endbibliography{\global\let\blx@hook@bibitem\blx@hook@bibitem@save
                                \global\undef\blx@hook@bibitem@save}}
    {}%
  \gappto\blx@hook@bibitem}
\makeatother

Essentially, it saves the current definition of what \AtEveryBibitem does and appends all the code you feed it to the \AtEveryBibitem, but the old definition of \AtEveryBibitem is restored after the next bibliography.

So all code you add via \AtEveryBibitemNextBibOnly is executed for every item in the next bibliography (and only in the next bibliography).

In our example we then only need

\AtEveryBibitemNextBibOnly{\clearfield{urlyear}}

right before the bibliography where we want to suppress the urldate.

MWE

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage[backend=biber,defernumbers=true,style=ieee]{biblatex}
\addbibresource{biblatex-examples.bib}

\makeatletter
\newrobustcmd*{\AtEveryBibitemNextBibOnly}{%
  \ifundef\blx@hook@bibitem@save
    {\global\let\blx@hook@bibitem@save\blx@hook@bibitem
     \preto\blx@endbibliography{\global\let\blx@hook@bibitem\blx@hook@bibitem@save
                                \global\undef\blx@hook@bibitem@save}}
    {}%
  \gappto\blx@hook@bibitem}
\makeatother

\begin{document}
\section{Section 1}
\begin{refsection}
Citing some stuff here: first \cite{ctan}, then \cite{markey}.
\AtEveryBibitemNextBibOnly{\clearfield{urlyear}}
\printbibliography[sorting=none,section=\therefsection,resetnumbers=true]
\end{refsection}

\section{Section 2}
\begin{refsection}
Citing some stuff here: first \cite{ctan}, then \cite{markey}.
\printbibliography[sorting=none,section=\therefsection,resetnumbers=true]
\end{refsection}
\end{document}

enter image description here

moewe
  • 175,683
  • Thanks for that @moewe - great to have this approach in mind, though I liked UlrikeFischer's approach a bit better; cheers! – sdaau May 18 '15 at 17:21