I use biblatex and would like my bibliography to only include a DOI field, whenever there is DOI information available. This involves two things:
Biblatex has to suppress the URL field whenever a DOI field is present. This can be done with the following code in the preamble. (This is a simplified version of Joseph Wright's answer here).
\renewbibmacro*{doi+eprint+url}{% \iftoggle{bbx:doi} {\printfield{doi}} {}% \newunit\newblock \iftoggle{bbx:eprint} {\usebibmacro{eprint}} {}% \newunit\newblock \iftoggle{bbx:url} {% \iffieldundef{doi} {\usebibmacro{url+urldate}} {% \clearfield{url}% }% } {}}
So everytime a DOI field is present in the bibtex file, the URL field is cleared.
My bibtex file is exported from Zotero. Unfortunately Zotero does not provide DOI fields for all entry types (yet), so I often enter the DOI information into the URL field like http://dx.doi.org/10.1145/1364782.1364794. So my question is: Is it possible to have biblatex take the DOI information from the URL field, store it into the DOI field and write only that into the bibliography?
I guess one would have to modify the
\usebibmacro{url+urldate}
conditional: First, check whether the URL field contains "dx.doi.org/" (ideally one should allow for http and https). If it does, take everything after "dx.doi.org/", copy it into the DOI field (with\restorefield
?) and\printfield{doi}
. If it does not, i.e. if it is not a DOI-URL,\usebibmacro{url+urldate}
.
Is that possible?
xstring
package in combination with test likeifthenelse
(biblatex manual section 4.6.3).