# Show url only for one reference

I am using biblatex.

Like I use zotero to retrieve metadata of references, I have plenty of urls into my .bib file. In most cases, I don't want the url to be printed (because it is only the url of the publisher webpage presenting the book). So I use the following line with url=false :

\usepackage[style=authoryear-comp,
hyperref,
backend=biber,
isbn=false,
doi=false,
url=false,
date=year]{biblatex}


However, in some case, the url is important: for example if I cite an online article which has no physical publisher.

How can I tell to biblatex to print the url for some references (explicitly indicated) without removing all (useless) urls in my references to keep only the useful ones?

• How do you indicate the references? You can use DeclareSourceMap for this issue. – Marco Daniel Jan 7 '14 at 18:11
• @MarcoDaniel With \autocite{key} – ppr Jan 7 '14 at 19:07
• Maybe those articles should be of type @online, for example? Even with url=false, biblatex will include urls for reference types where that information is essential and it sounds as if that is the sort of entry you may be talking about here. See the user manual for details of which types will still pick up the url when url=false is passed to the package. – cfr Jan 7 '14 at 23:45
• The question really is: How would you like tot tell biblatex which URLs not to discard? There are several ways for biblatex to get rid of the URL but they all require you telling biblatex which to keep (or not to keep). The best way, obviously, is to remove superfluous URLs from the .bib file, there is no point in them being there, if they serve no purpose in the bibliography. But of course that is quite tiresome and tedious if your bibliography is compiled by an external programme. You could add a marker (a keyword via keywords) to entries whose URL is important. – moewe Jan 8 '14 at 7:20
• The url macro could then be extended to only print URLs if a particular keyword is set. But of course that also requires a tedious sift through your .bib file and might be equally time consuming as deleting unnecessary URL fields, so we probably don't win a lot here. The most on-the-fly way would probably be to define a \DeclareBibliographyCategory{needsurl}, use a macro \newcommand{\dispurlinbib}[#1]{\addtocategory{needsurl}{#1}}, and redefine the url macro to only print URLs of entries that are in needsurl. If you are interested in this, I might write up an answer. – moewe Jan 8 '14 at 7:28

To tell biblatex on the fly whose URL to print, try the following.

For this to work, you must not pass url=false to biblatex.

We define a new category (these can be very easily dealt with on the fly and via input in the .tex, not the .bib file): needsurl.

\DeclareBibliographyCategory{needsurl}


We also redefine the URL macro to print the URL only if the entry is in the category needsurl.

% this is basically the standard macro from biblatex.def,
% augmented with the logic for needsurl
\renewbibmacro*{url+urldate}{%
\ifcategory{needsurl}
{\printfield{url}%
\iffieldundef{urlyear}
{}
\printurldate}}
{}}


Then there is a short command to indicate to biblatex that a certain entry needs its URL displayed.

\newcommand{\entryneedsurl}[1]{\addtocategory{needsurl}{#1}}


You can use it anywhere you like in the document, but keep in mind that \entryneedsurl does not print anything, it just tells biblatex to print the URL, if the entry appears in the bibliography.

It is used as you would expect, if you want the entry markey to have its URL displayed, just issue \entryneedsurl{markey} anywhere in the document.

The \entryneedsurl could also be incorporated into certain \cite macros, so you could have a \citebiburl macro that does everything \cite does, but adds the entry to the category needsurl.

The MWE

\documentclass[UKenglish]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{babel}
\usepackage{lmodern}
\usepackage[style=authoryear-comp, hyperref, backend=biber, isbn=false, doi=false, date=year]{biblatex}

\DeclareBibliographyCategory{needsurl}
\renewbibmacro*{url+urldate}{%
\ifcategory{needsurl}
{\printfield{url}%
\iffieldundef{urlyear}
{}
\printurldate}}
{}}

\begin{document}
A\entryneedsurl{markey}B
\cite{markey,ctan}
\printbibliography
\end{document}


yields

• This seem more complicated than I would expect. The bib file has the information regarding what type each citation is, e.g., article, book, online, or misc. It seems there should be a way to automate this so that biber recognizes if the citation is the specified type and include the url. – Steven C. Howell Dec 3 '15 at 5:45
• @stvn66 Showing the URL per type is much easier. If you use url=false it will only be shown for @online, in Biblatex: Suppressing urldate does not work (\clearfield) you can see how this can be extended for other types. – moewe Dec 3 '15 at 7:17