# Appending Data to Bibliography with Biblatex

I am trying to add a custom 'field' to my bibtex data, and then call that. However, I am getting a very strange scenario: when I call the field mr, then it works; when I call it mrnumber, then it doesn't work. Below is a MWE.

\documentclass[]{article}

\usepackage{filecontents}
\begin{filecontents*}{ext-eprint.dbx}
\ProvidesFile{ext-eprint.dbx}[2016/09/11 extended stand-alone eprint fields]
\DeclareDatamodelFields[type=field,datatype=verbatim]{arxiv,mr}
\DeclareDatamodelEntryfields{arxiv,mr}
\end{filecontents*}

\begin{filecontents*}{\jobname.bib}
@article{AGHH:dynamic-cm,
archivePrefix = {arXiv},
eprinttype = {arxiv},
eprint = {1606.07639},
title = {Mixing Times of Random Walks on Dynamic Configuration Models},
date = {2016-06-24},
author = {Avena, Luca and G{\"u}lda{\c s}, Hakan and van der Hofstad, Remco and den Hollander, Frank},
options = {useprefix=true}
}
@article{FR:giant-mixing,
title = {The Evolution of the Mixing Rate of a Simple Random Walk on the Giant Component of a Random Graph},
volume = {33},
number = {1},
journaltitle = {Random Structures \& Algorithms},
urldate = {2018-03-22},
date = {2008-05-12},
pages = {68-86},
author = {Fountoulakis, Nikolaos and Reed, Bruce A.},
mr = {12}
}
@book{LPW:markov-mixing,
location = {{Providence, RI, USA}},
title = {Markov {{Chains}} and {{Mixing Times}}},
isbn = {978-1-4704-2962-1},
pagetotal = {xvi+447},
publisher = {{American Mathematical Society}},
date = {2017},
author = {Levin, David A. and Peres, Yuval and Wilmer, Elizabeth L.},
mr = {3726904},
}
\end{filecontents*}

\usepackage{csquotes}
\usepackage[doi=false,isbn=false,url=false,
backend=biber,
style=numeric,
datamodel=ext-eprint]{biblatex}
\usepackage{hyperref}

\makeatletter
\DeclareFieldFormat{arxiv}{%
---HOW DO I CUSTOMISE THIS??---}%\href{https://arxiv.org/abs/#1}}
\makeatother
\DeclareFieldFormat{mr}{%
{\href{http://www.ams.org/mathscinet-getitem?mr=MR#1}{MR#1}}}

\renewbibmacro*{eprint}{%
\printfield{arxiv}%
\newunit\newblock
\printfield{mr}%
\newunit\newblock
\iffieldundef{eprinttype}
{\printfield{eprint}}
{thisdoesappear\printfield[eprint:\strfield{eprinttype}]{eprint}}
}

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


This prints out the following.

However, if I replace all five references to mr with mrnumber, then I get the same output just without the MR3726904 appended. I got the majority of the structure from moewe's answer to BibTeX fields for DOI, MR, Zbl and arxiv?.

As you may have noticed in the MWE, I do \DeclareFieldFormat{arxiv}{..., but whatever I put in here does not affect the output, only the thisdoesappear appears, and this is in an \iffieldundef statement. I do want to just use eprint for both arXiv and MR, because each item will have precisely one of these. I'd like to be able to customise the appearance of the arxiv part, as I have done with the MR part.

Remark. I know some of the other formatting isn't very nice, but don't worry about that: I've looked at that separately, and have just tried to put the minimal amount in for the example here.

• arxiv is an eprinttype, so DeclareFieldFormat will not really work as you are trying to do it. I'm not sure I get what you want to achieve. As far as I understood, you want mr to function as an eprinttype the same way as arxiv does. Is that it? – gusbrs May 9 '18 at 18:48
• I'd like to make "arXiv: 1606.07639" customisable, eg maybe write "available at arxiv.org/abs/1606.07369". I'd also like to be able to change the mr variable to mrnumber -- MathSciNet automatically outputs mrnumber, not mr, and so I don't want to have to go through all my references changing them from mrnumber to mr. Is that clearer? :) – Sam T May 9 '18 at 20:00
• One more thing to clear up. That answer you link to creates extra fields because the requirement was that a single paper belonged to more than one eprinttype. In your case, is it sufficient that each paper is either arXiv or MR (that is, not both)? – gusbrs May 9 '18 at 20:18

There are several things going on here. The most important thing is that biblatex distinguishes the explicitly defined arxiv and mrnumber field from the eprint field. The eprint field is special and its contents get special treatment.

1. In the MWE below mrnumber works for me. The code is just a result of replacing all mrs in your code with mrnumber.
2. If you want to change the output of arXiv-eprints, you don't modify the field format arxiv, you need to modify eprint:arxiv. You can see that eprint:arxiv is used by examining the false branch of iffieldundef{eprinttype}: \printfield[eprint:\strfield{eprinttype}]{eprint}. This calls the field format eprint:<eprinttype>, so eprint:arxiv in our case. \DeclareFieldFormat{arxiv} works only if you use the arxiv field directly.
3. You could also use eprint for both arXiv and mrnumber, but then you would have to transform mrnumber to eprints. This could be done automatically with a sourcemap. The advantage of that approach is that you don't need a new .dbx file. The disadvantage is that the mrnumber occupies the eprint slot.

The code below shows three ways to deal with MR numbers and arXiv links

1. Write the identifier into the eprint field and the type (arxiv, mrnumber) into eprinttype manually. See entries AGHH:dynamic-cm and FR:giant-mixing.
2. Use a dedicated arxiv and mrnumber field in the source. This is what baez/online and LPW:markov-mixing do. The implementation on the biblatex side can be done in two ways here.
1. Internally re-map arxiv = {foo} to eprint = {foo} with eprinttype = {arxiv} and mrnumber = {bar} to eprint = {bar} with eprinttype = {mrnumber}. This is done with the out-\iffalsed source map below, the data model is not needed in that case. This results in the fields being treated just like eprint, which means DeclareFieldFormat{eprint:arxiv} and DeclareFieldFormat{eprint:mrnumber} are the formats responsible, the fields are printed with \printfield[eprint:\strfield{eprinttype}]{eprint}. The advantage of this approach is that you don't need a data model, the disadvantage is that the one eprint slot you have is occupied. On the biblatex side (i.e. for writing a biblatex style) this is equivalent to the first method.
2. Declare the arxiv and mrnumber fields as native fields in a special data model and load the data model. The fields can be used independently and are controlled with DeclareFieldFormat{arxiv} and DeclareFieldFormat{mrnumber} and printed with \printfield{arxiv} and \printfield{mrnumber}.

\documentclass{article}

\usepackage{filecontents}
\begin{filecontents*}{ext-eprint.dbx}
\ProvidesFile{ext-eprint.dbx}[2018/05/09 extended stand-alone eprint fields]
\DeclareDatamodelFields[type=field,datatype=verbatim]{arxiv,mrnumber}
\DeclareDatamodelEntryfields{arxiv,mrnumber}
\end{filecontents*}

\begin{filecontents*}{\jobname.bib}
@online{AGHH:dynamic-cm,
eprinttype    = {arxiv},
eprint        = {1606.07639},
title         = {Mixing Times of Random Walks on Dynamic Configuration Models},
date          = {2016-06-24},
author        = {Avena, Luca and G{\"u}lda{\c s}, Hakan and van der Hofstad, Remco and den Hollander, Frank},
options       = {useprefix=true}
}
@online{baez/online,
author  = {Baez, John C. and Lauda, Aaron D.},
title   = {Higher-Dimensional Algebra {V}: 2-Groups},
date    = {2004-10-27},
version = 3,
arxiv   = {math/0307200v3},
}
@article{FR:giant-mixing,
title        = {The Evolution of the Mixing Rate of a Simple Random Walk on the Giant Component of a Random Graph},
volume       = {33},
number       = {1},
journaltitle = {Random Structures \& Algorithms},
urldate      = {2018-03-22},
date         = {2008-05-12},
pages        = {68-86},
author       = {Fountoulakis, Nikolaos and Reed, Bruce A.},
eprinttype   = {mrnumber},
eprint       = {12},
}
@book{LPW:markov-mixing,
location  = {Providence, RI, USA},
title     = {Markov Chains and Mixing Times},
isbn      = {978-1-4704-2962-1},
pagetotal = {xvi+447},
publisher = {American Mathematical Societ},
date      = {2017},
author    = {Levin, David A. and Peres, Yuval and Wilmer, Elizabeth L.},
mrnumber  = {3726904},
}
\end{filecontents*}

\usepackage{csquotes}
\usepackage[doi=false,isbn=false,url=false,
backend=biber,
style=numeric,
datamodel=ext-eprint, % comment this out to see what the data model does
]{biblatex}
\usepackage{hyperref}

\DeclareFieldFormat{arxiv}{%
\ifhyperref
as field}
\DeclareFieldFormat{eprint:arxiv}{%
\ifhyperref
via eprint}

\DeclareFieldFormat{mrnumber}{%
\ifhyperref
{\href{http://www.ams.org/mathscinet-getitem?mr=MR#1}{MR#1}}
{MR#1}%
real field}
\DeclareFieldFormat{eprint:mrnumber}{%
\ifhyperref
{\href{http://www.ams.org/mathscinet-getitem?mr=MR#1}{MR#1}}
{MR#1}%
eprint}

% This map maps all mrnumber fields to eprints with eprinttype mrnumber
% and all arxiv fields to eprint with eprinttype arxiv
% If you remove the \iffalse and \fi, this becomes active,
% in that case the datamodel is not needed any more.
\iffalse
\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=mrnumber, fieldtarget=eprint, final]
\step[fieldset=eprinttype, fieldvalue=mrnumber]
}
\map{
\step[fieldsource=arxiv, fieldtarget=eprint, final]
\step[fieldset=eprinttype, fieldvalue=arxiv]
}
}
}
\fi

\renewbibmacro*{eprint}{%
\printfield{arxiv}%
\newunit\newblock
\printfield{mrnumber}%
\newunit\newblock
\iffieldundef{eprinttype}
{\printfield{eprint}}
{\printfield[eprint:\strfield{eprinttype}]{eprint}}}

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


• Thank you. Did you have to manually edit the bibdata to put in eprinttype = {mrnumber} and eprint = {12}? I'm trying to avoid that. I see though that if I comment out the datamodel part, and remove the \iffalse ... \fi, then it works exactly as desired with the mrnumber field. You're a TeX genius! – Sam T May 10 '18 at 8:28
• @SamT Yes and no. The answer shows essentially three possible ways to deal with these identifiers. I have updated the answer to clarify this. If you want to keep arxiv and mrnumber fields from wherever you get your data from, only the way 2.1 or 2.2 are interesting for you. Way 1 indeed requires manual adjustments. – moewe May 10 '18 at 8:42
• Thank you very much. I've implemented Method 2.1 -- at least, I'm pretty sure that's what I've done! [See i.stack.imgur.com/xYe1P.png for a snapshot] – Sam T May 10 '18 at 8:52
• @SamT In that case the \printfield{arxiv} and \printfield{mrnumber} lines do nothing. In fact you can simply delete the entire \renewbibmacro*{eprint} block, the default definition \newbibmacro*{eprint}{% \iffieldundef{eprinttype} {\printfield{eprint}} {\printfield[eprint:\strfield{eprinttype}]{eprint}}} should be good enough for you. If we ignore the thisdoesappear and a possibly unwanted space created by forgetting to add a % in the last line of the definition. I have also edited the field formats to work even if hyperref is not loaded. – moewe May 10 '18 at 8:58
• Thank you so much, I'm so grateful :) -- I've literally spent 7hrs+ on this, and I'd still have so far to go if it weren't for you :) – Sam T May 10 '18 at 9:19

This is a suggestion for you to use the easily extensible eprint facilities of biblatex (moewe's third suggestion).

For that, you have to create a field format for your desired new eprint in the format biblatex expects. In your case eprint:mr:

\DeclareFieldFormat{eprint:mr}{% based on eprint:jstor
\ifhyperref


You can keep mrnumber and remap it to eprint with:

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=mrnumber, fieldtarget=eprint, final]
\step[fieldset=eprinttype, fieldvalue=mr]
}
}
}


This also sets eprinttype to mr for all entries which contain a mrnumber.

As to customizing arXiv, you should use \DeclareFieldFormat{eprint:arxiv}, as explained by moewe.

Putting things together:

\documentclass[]{article}

\usepackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{AGHH:dynamic-cm,
eprinttype = {arxiv},
eprint = {1606.07639},
title = {Mixing Times of Random Walks on Dynamic Configuration Models},
date = {2016-06-24},
author = {Avena, Luca and G{\"u}lda{\c s}, Hakan and van der Hofstad, Remco and den Hollander, Frank},
options = {useprefix=true}
}
@article{FR:giant-mixing,
title = {The Evolution of the Mixing Rate of a Simple Random Walk on the Giant Component of a Random Graph},
volume = {33},
number = {1},
journaltitle = {Random Structures \& Algorithms},
urldate = {2018-03-22},
date = {2008-05-12},
pages = {68-86},
author = {Fountoulakis, Nikolaos and Reed, Bruce A.},
mrnumber = {12}
}
@book{LPW:markov-mixing,
location = {{Providence, RI, USA}},
title = {Markov {{Chains}} and {{Mixing Times}}},
isbn = {978-1-4704-2962-1},
pagetotal = {xvi+447},
publisher = {{American Mathematical Society}},
date = {2017},
author = {Levin, David A. and Peres, Yuval and Wilmer, Elizabeth L.},
mrnumber = {3726904},
}
\end{filecontents*}

\usepackage{csquotes}
\usepackage[doi=false,isbn=false,url=false,
backend=biber,
style=numeric]{biblatex}
\usepackage{hyperref}

\DeclareSourcemap{
\maps[datatype=bibtex]{
\map{
\step[fieldsource=mrnumber, fieldtarget=eprint, final]
\step[fieldset=eprinttype, fieldvalue=mr]
}
}
}

\makeatletter
\DeclareFieldFormat{eprint:arxiv}{%
\autocap{a}vailable\space at\space arXiv\addcolon\space% <- changed here, relative to the default definition
\ifhyperref
{\href{https://arxiv.org/\abx@arxivpath/#1}{%
\iffieldundef{eprintclass}
{}
\iffieldundef{eprintclass}
{}
\makeatother

\DeclareFieldFormat{eprint:mr}{% based on eprint:jstor
\ifhyperref

• Thank you very much. Did you have to manually type in eprinttype = {mr} into all your bibliography entries? I'm trying to avoid having do manually edit them – Sam T May 10 '18 at 8:21
• @SamT I've adapted the answer for the eprinttype to be automatically set to mr for all entries which contain a mrnumber. – gusbrs May 10 '18 at 10:40
• I see, thank you. I suppose this has the advantage over moewe's that it doesn't require \begin{filecontents*}{ext-eprint.dbx} ... -- in fact, it's almost exactly the same, just without this, but with \makeatletter ... \makeatother – Sam T May 10 '18 at 10:53
• @SamT moewe's answer includes different alternatives. As I mentioned, this just expands the third suggestion, for which he says himself "The advantage of that approach is that you don't need a new .dbx file." The .dbx is included in his code because it is needed for the other suggestions. Here \makeatletter ... \makeatother is only used to redefine the formating directive for eprint:arxiv because I took the original definition, which contains the macro \abx@arxivpath. But I suppose moewe's definition of it would also work here. – gusbrs May 10 '18 at 11:14