4

My university referencing style defines two distinct styles for online resources. The first one is used when the exact link is known and in the public domain. This scenario is served well by the standard url entry in bib file.

The second type is used when the resource is available online, but the access is restricted. In this case the following is required, for example.

Available from: ebookcentral.com [restricted access]

It seems like I should define a new type, say url2, that would be positioned in the same place in the reference entry as url would be. The new type would have two arguments {web adress}{comment}.

Is there any way to do this from the document preamble, without going into biber configuration files?

I should also clarify that the string before the URL also needs to change. The default entries pring URL in front of the address string, but the ones with with the [restricted access] option should have 'Available from: ' in front.

1 Answer 1

10

There are several ways you can go about doing this.

In newer versions of biblatex and Biber you could use the data annotation feature. For restricted URLs you can add url+an = {restricted}, that annotation can be queried in the field format with \iffieldannotation{restricted}.

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

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

\NewBibliographyString{urlrestricted}
\DefineBibliographyStrings{english}{
  urlrestricted = {restricted access},
}

\DeclareFieldFormat{url}{%
  \mkbibacro{URL}\addcolon\space
  \url{#1}%
  \iffieldannotation{restricted}
    {\space
     \mkbibbrackets{\bibstring{urlrestricted}}}
    {}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@online{elk,
  author  = {Anne Elk},
  title   = {A Theory on Brontosauruses},
  date    = {1971},
  url     = {https://example.edu/~elk/bronto.pdf},
}
@online{elk:paid,
  author     = {Anne Elk},
  title      = {A Paid Theory on Brontosauruses},
  date       = {1972},
  url        = {https://example.com/~elk/paywall/bronto/},
  url+an     = {=restricted},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
\cite{sigfridsson,elk,elk:paid}
\printbibliography
\end{document}

A bibliography showing an entry "Elk, Anne (1971). A Theory on Brontosauruses. URL: https://example.edu/~elk/bronto.pdf." and "Elk, Anne  (1972). A Paid Theory on Brontosauruses. URL: https://example.com/~elk/paywall/bronto/ [restricted access]."


Another simple way would be to define an entry option that you can toggle on or off to say whether or not a URL is restricted. Unrestricted URLs need no special treatment but entries with restricted URLs would add options = {urlrestricted},.

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

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

\newtoggle{nzcbx@urlrestricted}
\DeclareEntryOption[boolean]{urlrestricted}[true]{%
  \settoggle{nzcbx@urlrestricted}{#1}%
}

\NewBibliographyString{urlrestricted}
\DefineBibliographyStrings{english}{
  urlrestricted = {restricted access},
}

\DeclareFieldFormat{url}{%
  \mkbibacro{URL}\addcolon\space
  \url{#1}%
  \iftoggle{nzcbx@urlrestricted}
    {\space
     \mkbibbrackets{\bibstring{urlrestricted}}}
    {}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@online{elk,
  author  = {Anne Elk},
  title   = {A Theory on Brontosauruses},
  date    = {1971},
  url     = {https://example.edu/~elk/bronto.pdf},
}
@online{elk:paid,
  author     = {Anne Elk},
  title      = {A Paid Theory on Brontosauruses},
  date       = {1972},
  url        = {https://example.com/~elk/paywall/bronto/},
  options    = {urlrestricted},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
\cite{sigfridsson,elk,elk:paid}
\printbibliography
\end{document}

The output is as above.


If you want more than just a toggle, you can turn the option into a string option. In the MWE below it is renamed to urlcomment and it can be fed with arbitrary text. If possible the text is interpreted as the name of a bibstring and that bibstring is printed. If there is no bibstring, the text is printed as is. In case no value is given, the default value restricted (which corresponds to a bibstring) is assumed.

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

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

\DeclareEntryOption[string]{urlcomment}[restricted]{%
  \csdef{nzcbx@urlcomment}{#1}%
}

\NewBibliographyString{restricted}
\DefineBibliographyStrings{english}{
  restricted = {restricted access},
}

\DeclareFieldFormat{url}{%
  \mkbibacro{URL}\addcolon\space
  \url{#1}%
  \ifcsundef{nzcbx@urlcomment}
    {}
    {\space
     \mkbibbrackets{%
     \ifbibxstring{\csuse{nzcbx@urlcomment}}
       {\bibstring{\csuse{nzcbx@urlcomment}}}
       {\csuse{nzcbx@urlcomment}}}}}

\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@online{elk,
  author  = {Anne Elk},
  title   = {A Theory on Brontosauruses},
  date    = {1971},
  url     = {https://example.edu/~elk/bronto.pdf},
}
@online{elk:paid,
  author     = {Anne Elk},
  title      = {A Paid Theory on Brontosauruses},
  date       = {1972},
  url        = {https://example.com/~elk/paywall/bronto/},
  options    = {urlcomment},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
\cite{sigfridsson,elk,elk:paid}
\printbibliography
\end{document}

The output is as above.

If you want to pass arbitrary text for the URL comment I would, however, prefer a new field urlcomment altogether. That seems to be more robust than an option. Again the content of the field is interpreted as bibstring if possible; it is printed as-is if no bibstring is available. In contrast to the string option there is no default field value. This solution requires a data model, technically speaking that would be/lead to a Biber configuration file.

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

\begin{filecontents}{url.dbx}
\DeclareDatamodelFields[type=field, datatype=key]{urlcomment}
\end{filecontents}

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

\NewBibliographyString{urlrestricted}
\DefineBibliographyStrings{english}{
  urlrestricted = {restricted access},
}

\DeclareFieldFormat{urlcomment}{\mkbibbrackets{\ifbibstring{#1}{\bibstring{#1}}{#1}}}

\renewbibmacro{url}{%
  \printfield{url}%
  \setunit*{\addspace}%
  \printfield{urlcomment}}

\begin{filecontents}{\jobname.bib}
@online{elk,
  author  = {Anne Elk},
  title   = {A Theory on Brontosauruses},
  date    = {1971},
  url     = {https://example.edu/~elk/bronto.pdf},
}
@online{elk:paid,
  author     = {Anne Elk},
  title      = {A Paid Theory on Brontosauruses},
  date       = {1972},
  url        = {https://example.com/~elk/paywall/bronto/},
  urlcomment = {urlrestricted},
}
\end{filecontents}

\addbibresource{\jobname.bib}
\addbibresource{biblatex-examples.bib}

\begin{document}
\cite{sigfridsson,elk,elk:paid}
\printbibliography
\end{document}

Again the output is as above.


In case you use the last method, you can add

\DeclareFieldFormat{url}{%
  \iffieldundef{urlcomment}
    {\mkbibacro{URL}}
    {\bibstring{urlfrom}}%
  \addcolon\space
  \url{#1}}

to switch the "URL" to "Available from" for entries with a urlcomment field.

4
  • The idea of being able to feed arbitrary text or a default option fits my needs perfectly. I was trying to pass arbitrary text to the second solution using options field but that does not seem to work on my laptop. The third solution using urlcomment works perfectly, with the caveat that if one wishes to change the comment, the .bbl file needs to be manually deleted for the change to show.
    – Niko Z.
    Jul 29, 2018 at 21:02
  • I would like to accept this answer as a solution, however, I still need to resolve the other half of my question. The reference entries with [restricted access] tag should begin with 'Available from:' string. Can this be added to the third solution?
    – Niko Z.
    Jul 29, 2018 at 21:07
  • @NikoZ. If the second solution (I added another solution, so it's the third now) does not work for you, maybe your version of biblatex/Biber is too old. I just double checked and it definitely works for me as posted. For all solutions changes in the .bib file should propagate after a Biber and additional LaTeX run. It should not be necessary to delete the .bbl file manually. See the edit for your last request.
    – moewe
    Jul 30, 2018 at 6:02
  • I can confirm that the combination of the third and fourth solution works well for me. Thank you!
    – Niko Z.
    Jul 30, 2018 at 15:00

You must log in to answer this question.

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