4

I use references that have an address in the url field. They use following template in my .bib file: ssrn.com/abstract=1234567.

However, the generated hyperlink is also ssrn.com/abstract=1234567. This makes pdf readers not want to open the link, since there is no http:// prefix. Adding the latter for each URL would (be tedious, and) take too much place in the list of references.

Question: How to make biblatex generate an hyperlink like \href{http://<url-field-content>}{<url-field-content>} in the references?
(where <url-field-content> is information given by the .bib file)


\documentclass{article}

    \usepackage[style=authoryear-comp]{biblatex}
        \addbibresource{\jobname.bib}
        \begin{filecontents}{\jobname.bib}
            @book{key,
                author = {Author, A.},
                year = {2001},
                title = {Title},
                publisher = {Publisher},
                url = {ssrn.com/abstract=1234567},
            }
        \end{filecontents}

    \usepackage{filecontents}
    \usepackage{hyperref}

\begin{document}
    \nocite{key}
    \printbibliography
\end{document}
8

You can do this by redefining the url field.

% arara: pdflatex
% arara: biber
% arara: pdflatex
% arara: pdflatex
\begin{filecontents}{\jobname.bib}
  @book{key,
    author = {Author, A.},
    year = {2001},
    title = {Title},
    publisher = {Publisher},
    url = {ssrn.com/abstract=1234567},
  }
\end{filecontents}

\documentclass{article}

\usepackage[style=authoryear-comp]{biblatex}
\DeclareFieldFormat{url}{%
  \mkbibacro{URL}\addcolon\space
  \href{http://#1}{\UrlFont#1}%
}
\addbibresource{\jobname.bib}

\usepackage{hyperref}

\begin{document}
\nocite{key}
\printbibliography
\end{document}

enter image description here

2

Use Biber's sourcemapping. This allows you to not modify URL fields that are already correct. The following adds http:// to url fields that do not start with ftp://, http:// or https://.

\documentclass{article}
\usepackage[style=authoryear-comp]{biblatex}

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

\usepackage{hyperref}

\DeclareSourcemap{
  \maps[datatype=bibtex]{
    \map{
      \step[fieldsource=url, notmatch=\regexp{\A(ftp|https?)://}, final]
      \step[fieldsource=url, match=\regexp{\A(.*)\Z}, replace=\regexp{http://$1}]
    }
  }
}

\begin{document}
    \nocite{*}
    \printbibliography
\end{document}

bibliography section of the example file

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.