5

I'm using biblatex and would like my DOIs to be printed (achieved thanks to doi=true) in a different color and font in the bibliography section.

Basically, they are formatted the same way as URL, which are quite large in my style. I would like both to reduce the font of DOIs, and display them in a lighter color.

Here is a minimal working example:

\documentclass[a4paper]{article}

\usepackage{libertine}

\usepackage[T1]{fontenc}

\usepackage[utf8]{inputenc}

\usepackage[backend=biber,doi=true]{biblatex}
\addbibresource{mybib.bib}


\begin{document}

Hello \cite{Smith12}

\printbibliography[title={References}]

\end{document}

With the following mybib.bib:

@article{Smith12,
    author    = {John Smith},
    title     = {A great article},
    journal   = {Journal of something},
    volume    = {1},
    number    = {1-3},
    pages     = {42--50},
    year      = {2012},
    doi       = {12.345/123456789},
}

Note 1: package libertine is not necessary, just it makes the URL font even larger.

Note 2: I do not want to change the URL font (which is easy), but just the DOI color and font.

  • 1
    Please show us a code example of what you have so far (MWE). The solution will depend on the current style. What about the font of the URLs? – moewe Aug 15 '18 at 14:08
6

You could adjust the doi+eprint+url macro:

\documentclass[a4paper]{article}

\usepackage{libertine}

\usepackage[T1]{fontenc}

\usepackage[utf8]{inputenc}


\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{Smith12,
    author    = {John Smith},
    title     = {A great article},
    journal   = {Journal of something},
    volume    = {1},
    number    = {1-3},
    pages     = {42--50},
    year      = {2012},
    doi       = {12.345/123456789},
}

\end{filecontents*}

\usepackage{xcolor}
\usepackage[backend=biber,doi=true]{biblatex}
\addbibresource{\jobname.bib}

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


\begin{document}

Hello \cite{Smith12}

\printbibliography[title={References}]

\end{document}

enter image description here


EDIT

Thanks to the great comment by @moewe it is easier to just change the field format of the doi:

\documentclass[a4paper]{article}

\usepackage{libertine}

\usepackage[T1]{fontenc}

\usepackage[utf8]{inputenc}


\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{Smith12,
    author    = {John Smith},
    title     = {A great article},
    journal   = {Journal of something},
    volume    = {1},
    number    = {1-3},
    pages     = {42--50},
    year      = {2012},
    doi       = {12.345/123456789},
}

\end{filecontents*}

\usepackage{xcolor}
\usepackage[backend=biber,doi=true]{biblatex}
\addbibresource{\jobname.bib}

\DeclareFieldFormat{doi}{%
    \color{red}\tiny%
  \mkbibacro{DOI}\addcolon\space
  \ifhyperref
    {\href{https://doi.org/#1}{\nolinkurl{#1}}}
    {\nolinkurl{#1}}}

\begin{document}

Hello \cite{Smith12}

\printbibliography[title={References}]

\end{document}
  • I guess normally you would redefine the field format for the DOI. The default is \DeclareFieldFormat{doi}{% \mkbibacro{DOI}\addcolon\space \ifhyperref {\href{https://doi.org/#1}{\nolinkurl{#1}}} {\nolinkurl{#1}}}. Depending on how other URL-like things should be handled it might be an option to redefine \nolinkurl instead. – moewe Aug 15 '18 at 19:14
  • @moewe Once more: Thanks a lot for your helpful comment! – user36296 Aug 15 '18 at 21:18

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.