2

I wish to print the url field using the authoryear style but only for @MISC entry types.

My hacky solution is to set style=authoryear, url=false in the package options, and set the title field equal to url for @MISC entries. This is OK for me in this particular case, because the title of the @MISC entries are not important, but I would like to know whether there is a better way to do this.

The url -> title is achieved through the following preamble code

\DeclareSourcemap{
    \maps[datatype=bibtex]{
        \map[overwrite]{
            \pertype{misc}
            \step[fieldsource=url]
            \step[fieldset=title, origfieldval]
        }
    }
}

1 Answer 1

1

0. Use @online instead of @misc

The @online entry type always shows the url field regardless of the global url option setting.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[backend=biber, style=authoryear, url=false]{biblatex}


\begin{filecontents}{\jobname.bib}
@online{bronto,
  author  = {Anne Elk},
  title   = {Towards a Unified Theory on Brontosauruses},
  date    = {1972-11-16},
  url     = {http://example.edu/~elk/bronto.pdf},
  urldate = {2015-09-07},
}
\end{filecontents}
\addbibresource{\jobname.bib}


\begin{document}
\autocite{bronto}
\printbibliography
\end{document}

1. Set the url option per type (biblatex 3.15 and above)

Since biblatex 3.15 you can set the url option per type in the standard styles (https://github.com/plk/biblatex/pull/1000), so you can disable url globally, but reenable it for @misc.

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[backend=biber, style=authoryear, url=false]{biblatex}
\ExecuteBibliographyOptions[misc]{url=true}

\begin{filecontents}{\jobname.bib}
@misc{bronto,
  author  = {Anne Elk},
  title   = {Towards a Unified Theory on Brontosauruses},
  date    = {1972-11-16},
  url     = {http://example.edu/~elk/bronto.pdf},
  urldate = {2015-09-07},
}
\end{filecontents}
\addbibresource{\jobname.bib}


\begin{document}
\autocite{bronto}
\printbibliography
\end{document}

2. Delete the url field with a sourcemap

This solution does not use the url option. Instead it deletes the url and urldate fields for all types except @misc with a sourcemap.

The advantage is that the field is really gone for good and is not used to generate label data (for example the label date).

\documentclass[british]{article}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}
\usepackage{babel}
\usepackage{csquotes}

\usepackage[backend=biber, style=authoryear]{biblatex}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \pernottype{misc}
      \step[fieldset=url, null]
      \step[fieldset=urldate, null]
    }
  }
}

\begin{filecontents}{\jobname.bib}
@misc{bronto,
  author  = {Anne Elk},
  title   = {Towards a Unified Theory on Brontosauruses},
  date    = {1972-11-16},
  url     = {http://example.edu/~elk/bronto.pdf},
  urldate = {2015-09-07},
}
\end{filecontents}
\addbibresource{\jobname.bib}


\begin{document}
\autocite{bronto}
\printbibliography
\end{document}

In all cases the output will be

Elk, Anne (16th Nov. 1972). Towards a Unified Theory on Brontosauruses. url: http://example.edu/~elk/bronto.pdf (visited on 07/09/2015).

2
  • Awesome, thanks! BTW, is your last solution equivalent to \AtEveryBibitem{\ifentrytype{misc}{}{\clearfield{url}\clearfield{urldate}}} ? Commented Oct 6, 2020 at 5:42
  • @Enredanrestos Not exactly. The sourcemap clears out the data before it even reaches biblatex. \AtEveryBibitem & \clearfield only clear the data at the last minute when the bibliography entry is printed. Often that results in the same output, but in case of urldate this has implications for labeldate generation. If urldate is cleared with a sourcemap it is definitely not seen, if \clearfield is used, it is still used. Generally I recommend getting rid of unwanted data as early as possible (so with a sourcemap rather than \clearfield) or suppress printing via options.
    – moewe
    Commented Oct 6, 2020 at 5:47

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .