2

Consider the eprint:arxiv. It is originally defined in biblatex.def as:

\DeclareFieldFormat{eprint:arxiv}{%
  arXiv\addcolon\space
  \ifhyperref
    {\href{http://arxiv.org/\abx@arxivpath/#1}{%
       \nolinkurl{#1}%
       \iffieldundef{eprintclass}
         {}
         {\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}}}
    {\nolinkurl{#1}
     \iffieldundef{eprintclass}
       {}
       {\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}}}

but suppose I want all arXiv links to appear in red, then I need:

\DeclareFieldFormat*{eprint:arxiv}{{% Note the extra brace
  \color{red}%
  arXiv\addcolon\space
  \ifhyperref
    {\href{http://arxiv.org/\abx@arxivpath/#1}{%
       \nolinkurl{#1}%
       \iffieldundef{eprintclass}
         {}
         {\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}}}
    {\nolinkurl{#1}
     \iffieldundef{eprintclass}
       {}
       {\addspace\texttt{\mkbibbrackets{\thefield{eprintclass}}}}}}}

The problem, however, is that this will override any modification to the eprint:arxiv field format that may have been introduced by another style.

Is there a way to make modifications to a field format in a style-agnostic manner? Obviously, this will (and should) not modify the existing output of a style but just wrap around it (and as a result, I understand that if the style already has a {\color{blue}...} for their arXiv links, then wrapping it with {\color{red}...} won't do anything)

I thought that the \savefieldformat and \restorefieldformat commands may have been helpful, but it doesn't seem like it now and I can't find anything else within the documentation that might help.

As a little extra, it would be great if there was a function such as \AddToFieldFormat[<entrytype...>]{<field>}{<code>} so that modifying eprint:arxiv would be

\AddToField{eprint:arxiv}{{\color{red}#1}}

and where #1 is the by the previous bibliography style's output.

1 Answer 1

2

egreg's xpatch package seems the way to go. Amongst others it provides \xpretofieldformat to prepend code to the field definitions

You just need

\xpretofieldformat{eprint:arxiv}{\color{red}}{}{}

MWE

\documentclass{article}
\usepackage[style=verbose,backend=biber]{biblatex}
\addbibresource{biblatex-examples.bib}
\usepackage{xcolor}

\usepackage{xpatch}
\xpretofieldformat{eprint:arxiv}{\color{red}}{}{}

\begin{document}
\nocite{baez/article,itzhaki,wassenberg}
\printbibliography
\end{document}
1
  • Fantastic! I'm glad there was an easy solution out there already :)
    – JP-Ellis
    Commented Feb 22, 2016 at 2:57

You must log in to answer this question.

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