# How to show URLs in bibliography as short hyperlinks - biblatex

I am trying to devise a way to show URL as just that - a hyperlinked "URL" stub instead of a full string. The prospect of wasted lines of paper in the final print version of the document isn't thrilling. I have read this answer but it seems to only apply to BibTeX default styles?

I am using a modified biblatex style backended with Biber where I've redefined various arguments to make the references look the way I'd like them to look ultimately in my thesis.

Would the workflow from the linked answer still somehow apply i.e. find the corresponding .bst file and modify accordingly?

Below is the current state of the referencing style parameters:

\usepackage
[backend=biber,
bibencoding=utf8,
style=authoryear-comp,
citestyle=authoryear-icomp,
maxcitenames=2, % sets limit for et al in citations
maxbibnames=99, % frees up limits to authors listed in references
giveninits=true, % initialise each author
sorting=nyt, % sort by name, author and publication title
uniquename=false,
uniquelist=false, % turns off author first names disambiguation
sortcites=true,

\defbibenvironment{bibliography}
{\enumerate{}
{\setlength{\leftmargin}{\bibhang}%
\setlength{\itemindent}{-\leftmargin}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}
{\endenumerate}
{\item}
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldset=issn, null]
}
}
}

%Corrections to referencing style

\DeclareFieldFormat*{title}{{#1}} % * clears formatting of publication titles
\DeclareFieldFormat*{journaltitle}{\mkbibemph{#1}\isdot} % italicised journal titles
\DeclareFieldFormat*[inbook]{volume}{\mkbibbold{#1}\isdot} % italicised journal titles

\renewbibmacro{volume+number+eid}{%
\printfield{volume}%
\printfield{number}%
\printfield{eid}} % changed volume-number-pages layout

\DeclareFieldFormat[article]{number}{\mkbibparens{#1}} % parentheses around volume number

\DeclareDelimFormat{translatortypedelim}{\addspace} % parentheses bracket around Ed.

\DeclareNameAlias{sortname}{family-given} % puts given names after surname
\DeclareFieldFormat{postnote}{#1}% no postnote prefix in "normal" citation commands
\DeclareFieldFormat{multipostnote}{#1}% no postnote prefix in "multicite" commands
\DeclareFieldFormat[article]{pages}{#1}% no prefix for the pages field in the articles within bibliography
\DeclareFieldFormat[article]{volume}{\mkbibbold{#1}}%emboldens volume #
\renewbibmacro{in:}{}

\newcommand{\biband}{\ifcurrentname{labelname}{\bibstring{and}}{\&}} % changes citation 'and' to ampersand
\renewcommand*\finalnamedelim{ \& } % references delimiter becomes ampersand
\AtEveryBibitem{\clearfield{month}} % remove month from year-published

% print url if no doi
\renewbibmacro*{doi+eprint+url}{%
\printfield{doi}%
\newunit\newblock%
\iftoggle{bbx:eprint}{%
\usebibmacro{eprint}%
}{}%
\newunit\newblock%
\iffieldundef{doi}{%
\usebibmacro{url+urldate}}%
{}%
}



At the moment bib entry:

@incollection{Zharikov2007,
abstract = {A Study Group was set up under the leadership of N. Pertsev to consider the nomenclature of metasomatism and metasomatic processes. This paper reports the conclusions of that group. The term metasomatism was introduced by Naumann (1826). Metasomatism, metasomatic process and metasomatose are synonyms although some authors use metasomatose as a name for specific varieties of metasomatism (e.g. Na-metasomatose, Mg-metasomatose, etc.).},
author = {Zharikov, V. A. and Pertsev, N. N. and Rusinov, V. L. and Callegari, E. and Fettes, D. J.},
booktitle = {Recommendations by the IUGS Subcommission on the Systematics of Metamorphic Rocks},
chapter = {9},
file = {:C$\backslash$:/Users/User/Mendeleyed Refs/Zharikov et al/Zharikov et al.. 2007. Metasomatism and metasomatic rocks.pdf:pdf},
keywords = {Metasomatism},
number = {July},
pages = {17},
title = {{Metasomatism and metasomatic rocks}},
url = {http://stuff.mit.edu/afs/athena/course/12/12.115/www/12.114 Papers/BGS/Metamorphic/DetailedMetamorphic/9 Metasomatism and metasomatic rocks.pdf{\%}5Cnwww.bgs.ac.uk/scmr/home.html},
year = {2007}
}


displays as

1. Zharikov, V. A., Pertsev, N. N., Rusinov, V. L., Callegari, E. & Fettes, D. J. (2007). Metasomatism and metasomatic rocks. Recommendations by the IUGS Subcommission on the Systematics of Metamorphic Rocks. July. Chap. 9, p. 17. URL: http://stuff.mit.edu/afs/athena/course/12/12.115/www/12.114%20Papers/BGS/Metamorphic/DetailedMetamorphic/9%20Metasomatism%20and%20metasomatic%20rocks.pdf%7B%5C%%7D5Cnwww.bgs.ac.uk/scmr/home.html.

where as I'd like it to be

1. Zharikov, V. A., Pertsev, N. N., Rusinov, V. L., Callegari, E. & Fettes, D. J. (2007). Metasomatism and metasomatic rocks. Recommendations by the IUGS Subcommission on the Systematics of Metamorphic Rocks. July. Chap. 9, p. 17. URL

I am using the latest version of TeXStudio and Mendeley auto-updated .bib source file to call each entry.

With biblatex that is as easy as changing the field format for url from the standard (l. 582 in biblatex.def, v3.15a)

\DeclareFieldFormat{url}{\mkbibacro{URL}\addcolon\space\url{#1}}


to

\DeclareFieldFormat{url}{\href{#1}{\mkbibacro{URL}}}


In the MWE I simplified and modernised some of your modifications (in particular I got rid of some superfluous load-time options)

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

\usepackage[backend=biber,
style=authoryear-icomp,
maxcitenames=2,
maxbibnames=99,
giveninits=true,
uniquename=false,
uniquelist=false,
]{biblatex}
\usepackage{hyperref}

\DeclareNameAlias{sortname}{family-given}

\DeclareFieldFormat*{title}{#1}
\DeclareFieldFormat*{journaltitle}{\mkbibemph{#1}\isdot}

\DeclareFieldFormat*[inbook]{volume}{\mkbibbold{#1}\isdot}

\renewbibmacro{in:}{}
\DeclareFieldFormat[article]{number}{\mkbibparens{#1}}
\DeclareFieldFormat[article]{volume}{\mkbibbold{#1}}

\renewbibmacro{volume+number+eid}{%
\printfield{volume}%
\printfield{number}%
\printfield{eid}}

\renewcommand*{\bibpagespunct}{%

\DeclareFieldFormat{postnote}{#1}
\DeclareFieldFormat{multipostnote}{#1}
\DeclareFieldFormat[article]{pages}{#1}

\DeclareFieldFormat{url}{\href{#1}{\mkbibacro{URL}}}

\renewbibmacro*{doi+eprint+url}{%
\printfield{doi}%
\newunit\newblock%
\iftoggle{bbx:eprint}
{\usebibmacro{eprint}}
{}%
\newunit\newblock%
\iffieldundef{doi}
{\usebibmacro{url+urldate}}%
{}}

\AtEveryBibitem{\clearfield{month}}

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldset=issn, null]
}
}
}

\defbibenvironment{bibliography}
{\enumerate{}
{\setlength{\leftmargin}{\bibhang}%
\setlength{\itemindent}{-\leftmargin}%
\setlength{\itemsep}{\bibitemsep}%
\setlength{\parsep}{\bibparsep}}}
{\endenumerate}
{\item}

\begin{filecontents}{\jobname.bib}
@incollection{Zharikov2007,
author    = {Zharikov, V. A. and Pertsev, N. N. and Rusinov, V. L.
and Callegari, E. and Fettes, D. J.},
title     = {Metasomatism and Metasomatic Rocks},
booktitle = {Recommendations by the {IUGS} Subcommission
on the Systematics of Metamorphic Rocks},
chapter   = {9},
keywords  = {Metasomatism},
number    = {July},
pages     = {17},
url       = {http://stuff.mit.edu/afs/athena/course/12/12.115/www/12.114 Papers/BGS/Metamorphic/DetailedMetamorphic/9 Metasomatism and metasomatic rocks.pdf},
year      = {2007},
}
\end{filecontents}

\begin{document}
Lorem \autocite{sigfridsson,Zharikov2007}

\printbibliography
\end{document}


Note that the URL in the entry Zharikov2007 looked a bit wrong. The {\%}5Cnwww.bgs.ac.uk/scmr/home.html at the end seemed to serve no purpose.

The number = {July}, also looks a bit odd.

• Nice, thanks for tidying up my mess. I am still however getting a full string in my reference list despite copying the MWE over. Would using hypersetup several times before the \printbibliography command make a difference? I've recolored links to black for TOC and LOF before setting it back to blue before the \begin{document} command. Other than that I can't see any argument that would interfere with the mkbibacro once it was called in the preamble Oct 20 '20 at 23:37
• @Wolfe79 Can you please compile the MWE without change to double-check that the code as posted produces the output shown in here? If that works, please try to cut down your non-working code to an MWE that shows how you included my code. Double check that you have no other \DeclareFieldFormat{url} or \DeclareFieldFormat[<type>]{url} in your file. Oct 21 '20 at 5:35
• Double checked, works fine. Turns out my TeXStudio 'view' command froze. Thanks! Oct 21 '20 at 12:47

add hyperref package and use url = {\href{http://stuff.mit.edu/afs/athena/course/12/12.115/www/12.114%20Papers/BGS/Metamorphic/DetailedMetamorphic/9%20Metasomatism%20and%20metasomatic%20rocks.pdf%7B%5C%%7D5Cnwww.bgs.ac.uk/scmr/home.html}{source}}, in biblio file

• With the standard settings of biblatex (and also with the settings shown in the question) this does not work as expected. That is because biblatex expects the url field to contain the raw URL and not code to print a URL. On a conceptual level this violates the idea of separating content (data) and formatting (presentation) and makes it harder to adjust the output to a different style. Oct 20 '20 at 20:16