0

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,
    hyperref=true]{biblatex} % citation hyperlinks
    
    \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}{%
        \setunit{\adddot\addspace}%
             \printfield{volume}%
             \printfield{number}%
         \setunit{\addcomma\space}%
             \printfield{eid}} % changed volume-number-pages layout
    
      \renewcommand*{\bibpagespunct}{\ifentrytype{article}{\addcolon}{\addcomma\space}}% colon between volume numbers and pages
    \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
    \renewcommand*{\nameyeardelim}{\addcomma\space} % adds comma between cited author and year
    \renewcommand*{\compcitedelim}{\addsemicolon\space} % semicolons instead of commas between same author citations
    \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}}%
        {}%
    }

\addbibresource{Bib/Mendeley/library.bib}

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.

3

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}

\renewcommand*{\compcitedelim}{\addsemicolon\space}

\DeclareNameAlias{sortname}{family-given}
\DeclareDelimFormat{finalnamedelim}{\addspace\&\space}
\DeclareDelimFormat{nameyeardelim}{\addcomma\space}

\DeclareDelimFormat{translatortypedelim}{\addspace}

\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}{%
  \setunit{\adddot\addspace}%
  \printfield{volume}%
  \printfield{number}%
  \setunit{\addcomma\space}%
  \printfield{eid}}

\renewcommand*{\bibpagespunct}{%
  \ifentrytype{article}{\addcolon}{\addcomma\space}}

\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}
\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

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

\printbibliography
\end{document}

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.

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.

3
  • 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
    – Wolfe79
    Oct 20 '20 at 23:37
  • 1
    @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.
    – moewe
    Oct 21 '20 at 5:35
  • Double checked, works fine. Turns out my TeXStudio 'view' command froze. Thanks!
    – Wolfe79
    Oct 21 '20 at 12:47
1

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

1
  • 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.
    – moewe
    Oct 20 '20 at 20:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.