2
  • Is there a "off-the-shelf" way to use the url of a bibliography entry in the \href{} command using the \citefield{}{} command, for example \href{\citefield{ctan}{url}}{link}?
  • The MWE below gives an error (TeX capacity exceeded, sorry [input stack size=10000].).
  • I found an 8-year old related question but I was hoping that now there is a easier way to do it.

\documentclass{article}

\usepackage{biblatex} \usepackage{hyperref}

\bibliography{biblatex-examples.bib}

\begin{document}

\begin{description} \item[cite] \cite{ctan} \item[citefield] \citefield{ctan}{url} \item[href] \href{http://www.ctan.org}{link} \item[href + citefield] %\href{\citefield{ctan}{url}}{link} % <-- Comment in/out to test. \end{description}

\printbibliography

\end{document}

enter image description here


Related

  • 1
    biblatex has no user-facing commands to extract fields expandably. All commands you could use to obtain entry data just print that data and are not expandable. So the best solution depends on your use case. There is something like https://tex.stackexchange.com/q/290611/35864 if the text you want to link is available in the biblatex entry itself (or can easily be generated there). And there are workarounds like https://tex.stackexchange.com/q/467262/35864 if you need to pass arbitrary text to the command. – moewe Dec 22 '22 at 06:28
  • @moewe Thanks. Could you provide an answer that allows me the same function as \href{\citefield{ctan}{url}}{link}? Meaning, that the URL is in the bib entry and that one only needs to have two arguments, bib key and link text? – Dr. Manuel Kuehner Dec 22 '22 at 15:44
  • If I understand correctly, that's pretty much what https://tex.stackexchange.com/q/467262/35864 does. – moewe Dec 22 '22 at 15:49
  • @moewe Oh, sorry that I did not get that (shouldn't look at the code on my phone and instead use a proper screen)! I will try your linked answer, thanks again for your time and effort. – Dr. Manuel Kuehner Dec 22 '22 at 16:48
  • @moewe Just FYI, I posted an "answer" that shows my actual use case. I use your code inside a \item[] as \item[{\myCiteBibURL[link text]{bib key}}]. – Dr. Manuel Kuehner Dec 22 '22 at 18:11

2 Answers2

1

The best approach here depends on your use case.

If you want to link arbitrary text that is provided on the fly in-document to the URL of an entry, the solution from create a hyperlink by using the url stored in the bibliography reference? is probably the way to go.

But if you actually want to link content that is part of the .bib entry or that can be generated programmatically by biblatex, then you should use the approach from What is the simplest way to extract a URL from a .bib entry for use in \href{}{} (probably using Biblatex)?.


In your answer you always only link the shorttitle. In that case you could go for

\documentclass{article}
\usepackage{biblatex}
\usepackage{csquotes}
\usepackage[
  hidelinks,
  colorlinks = true,
  linkcolor = blue,
  urlcolor = blue,
  citecolor = red,
]{hyperref}

\DeclareFieldFormat{urllink}{\href{\thefield{url}}{#1}} \DeclareCiteCommand{\titleurlcite} {\boolfalse{citetracker}% \boolfalse{pagetracker}% \usebibmacro{prenote}} {\ifciteindex {\indexfield{indextitle}} {}% \printfield[urllink]{labeltitle}} {\multicitedelim} {\usebibmacro{postnote}}

\begin{filecontents}{\jobname.bib} @techreport{ISO_TS_16951_2021, type = {Technical Specification (ISO/TS)}, title = {Road vehicles -- Ergonomic aspects of transport information and control systems (TICS) -- Procedures for determining priority of on-board messages presented to drivers}, shorttitle = {ISO/TS 16951:20216}, url = {https://www.iso.org/standard/81103.html}, number = {ISO/TS 16951:2021}, institution = {International Organization for Standardization (ISO)}, author = {ISO}, date = {2021-03}, } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document} \titleurlcite{ISO_TS_16951_2021}

\printbibliography \end{document}

Linked shorttitle


If you only need this for the description environment, you can make biblatex generate that with a \printbibliography. (Again, how exactly this should be implemented depends very much on your precise use case. This is just a straightforward way of implementing it. You may or may not need some tweaks to have this behave as you want.)

\documentclass{article}
\usepackage{biblatex}
\usepackage{csquotes}
\usepackage[
  hidelinks,
  colorlinks = true,
  linkcolor = blue,
  urlcolor = blue,
  citecolor = red,
]{hyperref}

\DeclareFieldFormat{urllink}{\href{\thefield{url}}{#1}}

\newrobustcmd*{\localbibliographyalias}[2]{% \csedef{blx@bbx@#1}{% \expandafter\noexpand\csname blx@bbx@#2\endcsname}}

\defbibenvironment{standardslist} {\localbibliographyalias{report}{standardslist}% \list {\printfield[urllink]{shorttitle}} {\setlength{\labelwidth}{\bibhang}% \setlength{\leftmargin}{\labelwidth}% \setlength{\labelsep}{\biblabelsep}% \addtolength{\leftmargin}{\labelsep}% \setlength{\itemsep}{\bibitemsep}% \setlength{\parsep}{\bibparsep}}} {\endlist} {\item}

\defbibcheck{standardslist}{% \ifentrytype{report} {} {\skipentry}% }

\DeclareBibliographyDriver{standardslist}{% \usebibmacro{bibindex}% \usebibmacro{begentry}% \printtext{The title of this document is}% \setunit{\addspace}% \usebibmacro{title}% \setunit{\addspace}% \printtext[brackets]{\usebibmacro{cite}}% \setunit{\bibpagerefpunct}\newblock \usebibmacro{pageref}% \newunit\newblock \iftoggle{bbx:related} {\usebibmacro{related:init}% \usebibmacro{related}} {}% \usebibmacro{finentry}}

\begin{filecontents}{\jobname.bib} @techreport{ISO_TS_16951_2021, type = {Technical Specification (ISO/TS)}, title = {Road vehicles -- Ergonomic aspects of transport information and control systems (TICS) -- Procedures for determining priority of on-board messages presented to drivers}, shorttitle = {ISO/TS 16951:20216}, url = {https://www.iso.org/standard/81103.html}, number = {ISO/TS 16951:2021}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2021-03}, } @techreport{ISO_15006_2011, type = {Standard}, title = {Road vehicles -- Ergonomic aspects of transport information and control systems -- Specifications for in-vehicle auditory presentation}, shorttitle = {ISO 15006:2011}, url = {https://www.iso.org/standard/55322.html}, number = {ISO 15006:2011}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2011-10}, } @techreport{ISO_TR_12204_2012, type = {Technical Report (ISO/TR)}, title = {Road vehicles — Ergonomic aspects of transport information and control systems — Introduction to integrating safety critical and time critical warning signals}, shorttitle = {ISO/TR 12204:2012}, url = {https://www.iso.org/standard/55322.html}, number = {ISO/TR 12204:2012}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2012-11}, } @techreport{ISO_TR_16352_2005, type = {Technical Report (ISO/TR)}, title = {Road vehicles -- Ergonomic aspects of in-vehicle presentation for transport information and control systems -- Warning systems}, shorttitle = {ISO/TR 16352:2005}, url = {https://www.iso.org/standard/37859.html}, number = {ISO/TR 16352:2005}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2005-12}, } @techreport{ISO_15005_2017, type = {Standard}, title = {Road vehicles -- Ergonomic aspects of transportation and control systems -- Dialogue management principles and compliance procedures}, shorttitle = {ISO 15005:2017}, url = {https://www.iso.org/standard/69238.html}, number = {ISO 15005:2017}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2017-02}, } @techreport{ISO_15007_2020, type = {Standard}, title = {Road vehicles -— Measurement and analysis of driver visual behaviour with respect to transport information and control systems}, shorttitle = {ISO 15007:2020}, url = {https://www.iso.org/standard/63220.html}, number = {ISO 15007:2020}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2011-10}, } @techreport{ISO_15008_2017, type = {Standard}, title = {Road vehicles -- Ergonomic aspects of transport information and control systems -- Specifications and test procedures for in-vehicle visual presentation}, shorttitle = {ISO 15005:2017}, url = {https://www.iso.org/standard/62784.html}, number = {ISO 15008:2017}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2017-09}, } @techreport{ISO_16673_2017, type = {Standard}, title = {Road vehicles -- Ergonomic aspects of transport information and control systems -- Occlusion method to assess visual demand due to the use of in-vehicle systems}, shorttitle = {ISO 16673:2017}, url = {https://www.iso.org/standard/71508.html}, number = {ISO 16673:2017}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2005-12}, } @techreport{ISO_17287_2003, type = {Standard}, title = {Road vehicles —- Ergonomic aspects of transport information and control systems —- Procedure for assessing suitability for use while driving}, shorttitle = {ISO 17287:2003}, url = {https://www.iso.org/standard/30597.html}, number = {ISO 17287:2003}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2003-04}, } \end{filecontents} \addbibresource{\jobname.bib} \addbibresource{biblatex-examples.bib}

\begin{document} \nocite{ISO_15006_2011,ISO_TR_16352_2005,ISO_TS_16951_2021,ISO_15005_2017, ISO_15006_2011,ISO_15007_2020,ISO_15008_2017,ISO_16673_2017, ISO_17287_2003,ISO_TR_12204_2012}

Lorem \autocite{sigfridsson,worman,geer,aksin,moraux}

\printbibliography[env=standardslist, check=standardslist, title=Lots of standards] \printbibliography

\end{document}

Standards biblist

moewe
  • 175,683
  • Very elegant, thank you. – Dr. Manuel Kuehner Dec 23 '22 at 14:59
  • In your \titleurlcite command, where does it say to use the shorttitle field? I just see indextitle and labeltitle. I assume the "secret sauce" is somewhere in {\ifciteindex {\indexfield{indextitle}} {}% \printfield[urllink]{labeltitle}}. – Dr. Manuel Kuehner Dec 23 '22 at 22:45
  • 1
    @Dr.ManuelKuehner labeltitle is created by Biber according to \DeclareLabeltitle. By default it is the first of shorttitle-title-maintitle that is nonempty. In our case we always get shorttitle, but the macro will also work in other cases, when there is only a title and no shorttitle. – moewe Dec 24 '22 at 06:49
  • Ah, thanks! Happy Xmas! – Dr. Manuel Kuehner Dec 24 '22 at 19:55
  • 1
    @Dr.ManuelKuehner Thank you. Merry Christmas to you, too! – moewe Dec 25 '22 at 15:22
0

Based on user's moewe great comment and already existing answer, this is how I now use his code. Maybe this is useful for future reference.

\documentclass{article}
\usepackage{biblatex}
\usepackage{csquotes} % for \enquote
\usepackage[
    hidelinks,
    colorlinks = true,
    linkcolor = blue,
    urlcolor = blue,
    citecolor = red,
    ]{hyperref}

% Based on % https://tex.stackexchange.com/questions/467262/ \DeclareCiteCommand{\myCiteBibURL} {\boolfalse{citetracker}% \boolfalse{pagetracker}} {\iffieldundef{url} {\PackageWarning{biblatex} {The entry \thefield{entrykey} has no URL.\MessageBreak No link will be created}% \printfield{postnote}} {\href{\thefield{url}} {\iffieldundef{postnote} {\PackageWarning{biblatex} {Text argument missing,\MessageBreak using the title for entry\MessageBreak \thefield{entrykey}}% \printfield[citetitle]{labeltitle}} {\printfield{postnote}}}}} {} {}

\begin{filecontents}{\jobname.bib} @techreport{ISO_TS_16951_2021, type = {Technical Specification (ISO/TS)}, title = {Road vehicles -- Ergonomic aspects of transport information and control systems (TICS) -- Procedures for determining priority of on-board messages presented to drivers}, shorttitle = {ISO/TS 16951:20216}, url = {https://www.iso.org/standard/81103.html}, number = {ISO/TS 16951:2021}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2021-03}, }

@techreport{ISO_15006_2011, type = {Standard}, title = {Road vehicles -- Ergonomic aspects of transport information and control systems -- Specifications for in-vehicle auditory presentation}, shorttitle = {ISO 15006:2011}, url = {https://www.iso.org/standard/55322.html}, number = {ISO 15006:2011}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2011-10}, }

@techreport{ISO_TR_12204_2012, type = {Technical Report (ISO/TR)}, title = {Road vehicles — Ergonomic aspects of transport information and control systems — Introduction to integrating safety critical and time critical warning signals}, shorttitle = {ISO/TR 12204:2012}, url = {https://www.iso.org/standard/55322.html}, number = {ISO/TR 12204:2012}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2012-11}, }

@techreport{ISO_TR_16352_2005, type = {Technical Report (ISO/TR)}, title = {Road vehicles -- Ergonomic aspects of in-vehicle presentation for transport information and control systems -- Warning systems}, shorttitle = {ISO/TR 16352:2005}, url = {https://www.iso.org/standard/37859.html}, number = {ISO/TR 16352:2005}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2005-12}, }

@techreport{ISO_15005_2017, type = {Standard}, title = {Road vehicles -- Ergonomic aspects of transportation and control systems -- Dialogue management principles and compliance procedures}, shorttitle = {ISO 15005:2017}, url = {https://www.iso.org/standard/69238.html}, number = {ISO 15005:2017}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2017-02}, }

@techreport{ISO_15007_2020, type = {Standard}, title = {Road vehicles -— Measurement and analysis of driver visual behaviour with respect to transport information and control systems}, shorttitle = {ISO 15007:2020}, url = {https://www.iso.org/standard/63220.html}, number = {ISO 15007:2020}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2011-10}, }

@techreport{ISO_15008_2017, type = {Standard}, title = {Road vehicles -- Ergonomic aspects of transport information and control systems -- Specifications and test procedures for in-vehicle visual presentation}, shorttitle = {ISO 15005:2017}, url = {https://www.iso.org/standard/62784.html}, number = {ISO 15008:2017}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2017-09}, }

@techreport{ISO_16673_2017, type = {Standard}, title = {Road vehicles -- Ergonomic aspects of transport information and control systems -- Occlusion method to assess visual demand due to the use of in-vehicle systems}, shorttitle = {ISO 16673:2017}, url = {https://www.iso.org/standard/71508.html}, number = {ISO 16673:2017}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2005-12}, }

@techreport{ISO_17287_2003, type = {Standard}, title = {Road vehicles —- Ergonomic aspects of transport information and control systems —- Procedure for assessing suitability for use while driving}, shorttitle = {ISO 17287:2003}, url = {https://www.iso.org/standard/30597.html}, number = {ISO 17287:2003}, institution = {International Organization for Standardization (ISO)}, author = {{ISO}}, date = {2003-04}, } \end{filecontents} \addbibresource{\jobname.bib}

\begin{document}

\begin{description} % \item[{\myCiteBibURL[]{}}] Text % <-- The additional "{}" inside the optional argumeny of the \item command is needed because of the "[]" of the \myCiteBibURL command. \item[{\myCiteBibURL[\citefield{ISO_15006_2011}{shorttitle}]{ISO_15006_2011}}] The title of the document is \enquote{\citefield{ISO_15006_2011}{title}} \parencite{ISO_15006_2011}. \item[{\myCiteBibURL[\citefield{ISO_TR_16352_2005}{shorttitle}]{ISO_TR_16352_2005}}] The title of the document is \enquote{\citefield{ISO_TR_16352_2005}{title}} \parencite{ISO_TR_16352_2005}. \item[{\myCiteBibURL[\citefield{ISO_TS_16951_2021}{shorttitle}]{ISO_TS_16951_2021}}] The title of the document is \enquote{\citefield{ISO_TS_16951_2021}{title}} \parencite{ISO_TS_16951_2021}. \item[{\myCiteBibURL[\citefield{ISO_15005_2017}{shorttitle}]{ISO_15005_2017}}] The title of the document is \enquote{\citefield{ISO_15005_2017}{title}} \parencite{ISO_15005_2017}. \item[{\myCiteBibURL[\citefield{ISO_15006_2011}{shorttitle}]{ISO_15006_2011}}] The title of the document is \enquote{\citefield{ISO_15006_2011}{title}} \parencite{ISO_15006_2011}. \item[{\myCiteBibURL[\citefield{ISO_15007_2020}{shorttitle}]{ISO_15007_2020}}] The title of the document is \enquote{\citefield{ISO_15007_2020}{title}} \parencite{ISO_15007_2020}. \item[{\myCiteBibURL[\citefield{ISO_15008_2017}{shorttitle}]{ISO_15008_2017}}] The title of the document is \enquote{\citefield{ISO_15008_2017}{title}} \parencite{ISO_15008_2017}. \item[{\myCiteBibURL[\citefield{ISO_16673_2017}{shorttitle}]{ISO_16673_2017}}] The title of the document is \enquote{\citefield{ISO_16673_2017}{title}} \parencite{ISO_16673_2017}. \item[{\myCiteBibURL[\citefield{ISO_17287_2003}{shorttitle}]{ISO_17287_2003}}] The title of the document is \enquote{\citefield{ISO_17287_2003}{title}} \parencite{ISO_17287_2003}. \item[{\myCiteBibURL[\citefield{ISO_TR_12204_2012}{shorttitle}]{ISO_TR_12204_2012}}] The title of the document is \enquote{\citefield{ISO_TR_12204_2012}{title}} \parencite{ISO_TR_12204_2012}. \end{description}

\printbibliography

\end{document}

enter image description here

enter image description here

  • 1
    If you always want to show the shorttitle and link that to the URL, the approach from https://tex.stackexchange.com/a/290681/35864 is more elegant. If your use case is always this formulaic, an even more elegant solution would be to pack all of this up into a biblatex macro directly. – moewe Dec 22 '22 at 20:14
  • @moewe If you have time and motivation, then please provide an answer for a biblatex macro solution and I will accept it. – Dr. Manuel Kuehner Dec 22 '22 at 21:23