# Bib conditionally render fields

How can I get biblatex/biber to only render the URL field if the type of the bib latex citation is misc, i.e. not article?

• Mendele is used. And: \usepackage[backend=biber,maxbibnames=6,firstinits=true,arxiv=false,doi=false,citestyle=authoryear-icomp,uniquename=false]{biblatex} – Georg Heiler Nov 7 '17 at 19:46
• You could search for the formatting code in the style file you use and alter what you see there for every other key than misc to exclude the URL. – Skillmon likes topanswers.xyz Nov 7 '17 at 19:48
• I am based on gitlab.cg.tuwien.ac.at/auzinger/vutinfth which is using vutinfth but have no idea where to fine a stile file to configure this. – Georg Heiler Nov 7 '17 at 19:51
• The 'best' online entry type is @online and not @misc. If you use @online, you can use the preamble option url=false that turns off displaying URLs, but makes an exception for @online so that the URL there is always printed. – moewe Nov 8 '17 at 8:20

biblatex supports source maps that let you edit your library on the fly.

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\pernottype{misc} % only if type is not misc
\step[fieldset=url, null] % delete field
}
}
}


The style takes some getting used to, but the "language" is surprisingly powerful. You basically define lists of steps that are executed for each entry. You can add restrictions like the \pernottype above and there is the final step option that breaks processing if a condition is fulfilled (or not fulfilled, depending on the condition). The following snippet removes eprint and arXiv entries from the database when a DOI is present

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=doi, final] % stop if doi doesn't exist
\step[fieldset=archiveprefix, null] % delete field
\step[fieldset=arxivid, null] % delete field
\step[fieldset=eprint, null] % delete field
}
}
}


The whole language is documented in section 4.5.3 of the manual

Another way to do this is to redefine the url+urldate macro so that it only does something for @misc entry types. Try putting this in your preamble:

\renewbibmacro*{url+urldate}{%
\ifentrytype{misc}
{\usebibmacro{url}%
\iffieldundef{urlyear}
{}
\usebibmacro{urldate}}}
{}}

• Since you supplied the patch that solved tex.stackexchange.com/q/342236/35864 would you like to write up a short answer there that the problem is fixed in biblatex 3.8? – moewe Nov 15 '17 at 16:51

The files are located in your texmf.

If you don't use a bibliography style, search for a file named standard.bbx else for a file named <your-bib-style>.bbx.

In it you'll find lines like \DeclareBibliographyDriver{article} or \RequireBibliographyStyle{<another-style>} (in which case you should search for those files and do the following with them), inside of those blocks you'll find lines like \usebibmacro{doi+eprint+url}.

You'll notice that most of the types use this macro (including article and misc). So you could change the definition of this particular bibmacro to don't print an URL (or to do nothing if you don't want doi or eprint either).

Then you can copy the definition of \DeclareBibliographyDrive{misc} and change it to use another macro instead of \usebibmacro{doi+eprint+url} which matches the original definition of this.

Applying all of this for standard.bbx results in:

\documentclass[]{article}

\usepackage[backend=biber,maxbibnames=6,firstinits=true,arxiv=false,doi=false,citestyle=authoryear-icomp,uniquename=false]{biblatex}
\usepackage{filecontents}

\begin{filecontents*}{\jobname.bib}
@article{article,
author = {foo},
title = {bar},
journal = {baz},
year = {2017},
URL = {www.foo.bar}
}
@misc{misc,
author = {foo},
title = {bar},
year = {2017},
URL = {www.foo.bar}
}
\end{filecontents*}

\DeclareBibliographyDriver{misc}{%
\usebibmacro{bibindex}%
\usebibmacro{begentry}%
\usebibmacro{author/editor+others/translator+others}%
\setunit{\printdelim{nametitledelim}}\newblock
\usebibmacro{title}%
\newunit
\printlist{language}%
\newunit\newblock
\usebibmacro{byauthor}%
\newunit\newblock
\usebibmacro{byeditor+others}%
\newunit\newblock
\printfield{howpublished}%
\newunit\newblock
\printfield{type}%
\newunit
\printfield{version}%
\newunit
\printfield{note}%
\newunit\newblock
\usebibmacro{organization+location+date}%
\newunit\newblock
\usebibmacro{doi+eprint+url2}%
\newunit\newblock
\setunit{\bibpagerefpunct}\newblock
\usebibmacro{pageref}%
\newunit\newblock
\iftoggle{bbx:related}
{\usebibmacro{related:init}%
\usebibmacro{related}}
{}%
\usebibmacro{finentry}}

\newbibmacro*{doi+eprint+url2}{% original definition of doi+eprint+url
\iftoggle{bbx:doi}
{\printfield{doi}}
{}%
\newunit\newblock
\iftoggle{bbx:eprint}
{\usebibmacro{eprint}}
{}%
\newunit\newblock
\iftoggle{bbx:url}
{\usebibmacro{url+urldate}}
{}}

\renewbibmacro*{doi+eprint+url}{%
\iftoggle{bbx:doi}
{\printfield{doi}}
{}%
\newunit\newblock
\iftoggle{bbx:eprint}
{\usebibmacro{eprint}}
{}%
\newunit\newblock% I don't know whether this should be removed, too, or not
}


• This is a bit overkill. You only have to modify the url+urldate macro. – David Purton Nov 7 '17 at 23:56