I'm trying to tweak a biblatex
bibliography. One problem is the rendering of entries with eprint
fields. Sometimes, I have something like
eprint = "hep-ph/0207124",
sometimes its
eprint = "0207124",
primaryClass = "hep-ph",
but sometimes the class is given in both:
eprint = "hep-ph/0207124",
primaryClass = "hep-ph",
I'd like to render all consistently in a format like "arXiv:hep-ph/0207124" for example. For this, I tried to customize \DeclareFieldFormat{eprint:arxiv}
. My problem is that I can't properly use xstring
commands like \IfSubStr
or \StrDel
in \DeclareFieldFormat
. If I try to find primaryClass
in eprint
, it just doesn't work.
I've traced it down a bit. If #1
is hep-ph/0207124
, then
\StrDel{#1}{\thefield{eprintclass}}
doesnt work. It doesn't find the string. I guess I need to make \thefield
expand somehow. Even then, directly substituting the string doesn't work either:
\StrDel{#1}{hep-ph}
But it works partially if I use 0
or \string h
(but not h
) as an argument. I believe it has to do with the catcodes of the arguments. I tried a bunch of \detokenize
, \expandafter
, \expandarg
, but without a systematic approach I can't get it to work.
So how do I use the string manipulation commands properly from within biblatex's field formats?
(Not-quite) minimal (not-quite) working example follows:
\documentclass{article}
\usepackage{filecontents}
\begin{filecontents}{\jobname.bib}
@article{Witten:2002ei,
author = "Witten, Edward",
title = "{Quest for unification}",
pages = "604-610",
year = "2002",
eprint = "hep-ph/0207124",
archivePrefix = "arXiv",
primaryClass = "hep-ph",
SLACcitation = "%%CITATION = HEP-PH/0207124;%%",
}
\end{filecontents}
\usepackage[style=numeric,sorting=none]{biblatex}
\addbibresource{\jobname.bib}
\usepackage{xstring}
\makeatletter
\DeclareFieldFormat{eprint:arxiv}{%
arXiv\addcolon\space%
\iffieldundef{eprintclass}%
{#1}%
{%
eprint = #1 \par
class = \thefield{eprintclass} \par
number = \StrDel{#1}{\thefield{eprintclass}} \par
removing `0' = \StrDel{#1}{0} \par%
removing `h' = \StrDel{#1}{h} \par%
removing `\textbackslash string h' = \StrDel{#1}{\string h} \par%
}%
}
\makeatother
\begin{document}
\cite{Witten:2002ei}
\printbibliography
\end{document}
DeclareSourceMap
and modify all fields global.