9

I am fairly happy with the way I can customize eprint references with Biblatex/biber, see below. I would like to know whether there is a way to achieve a similar result by solely relying on the possibly adapted but conventional bibtex styles (unsrt, plain...). I am aware of the various arXiv-compliant bibtex styles but it seems to me that managing distinct eprint styles in the same document is not straightforward if not impossible with bibtex.

\documentclass[10pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage[margin=1cm]{geometry}
\usepackage{xcolor}
\colorlet{doic}{green!50!black}
\colorlet{arkc}{blue!50!black}
\colorlet{oaic}{red!50!black}
\colorlet{hdlc}{yellow!50!black}
\colorlet{arxivc}{pink!50!black}
\usepackage[hyperref=true,backend=biber,style=numeric]{biblatex}
\addbibresource{ref.bib}

\usepackage[hidelinks]{hyperref}
\urlstyle{sf}

\title{Various eprint styles with Biblatex}

% DOI links
\def\doitourl#1{http://dx.doi.org/#1}
\DeclareFieldFormat{doi}{%
    \ifhyperref
      {\color{doic}\href{\doitourl#1}{[doi:\nolinkurl{#1}]}}
      {\nolinkurl{#1}}}

% ARK links
\def\arktourl#1{http://gallica.bnf.fr/#1}
\DeclareFieldFormat{eprint:ark}{%
    \ifhyperref
        {\color{arkc}\href{\arktourl#1}{[\nolinkurl{#1}]}}
        {\nolinkurl{#1}}}

% OAI links
\def\oaitourl#1{http://hal.archives-ouvertes.fr/#1}
\DeclareFieldFormat{eprint:oai}{%
    \ifhyperref
        {\color{oaic}\href{\oaitourl#1}{[oai:\nolinkurl{#1}]}}
        {\nolinkurl{#1}}}

% Orbi.lu links
\def\hdltourl#1{http://hdl.handle.net/#1}
\DeclareFieldFormat{eprint:hdl}{%
    \ifhyperref
        {\color{hdlc}\href{\hdltourl#1}{[hdl:\nolinkurl{#1}]}}
        {\nolinkurl{#1}}}

% ARXIV links       
\def\arxivtourl#1{http://arxiv.org/abs/#1}      
\DeclareFieldFormat{eprint:arxiv}{%
    \ifhyperref
        {\color{arxivc}\href{\arxivtourl#1}{[arxiv:\nolinkurl{#1}]}}
        {\nolinkurl{#1}}}

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

together with the ref.bib file (I've truncated the titles for compactness)

@article{Ba,
 year={2000},
 journal={Archive for Rational Mechanics and Analysis},
 volume={154},
 number={3},
 doi={10.1007/s002050000105},
 title={The Dynamics of Discrete Mechanical Systems},
 publisher={Springer-Verlag},
 author={Patrick Ballard},
 pages={199-274},
 eprinttype = {oai},
 eprint = {hal-00111308}}

@ARTICLE{Beylkin92,
  author = {Nguyen, Vinh-Phu},
  title = {Nitsche's method for two and three dimensional NURBS},
  journal = {Computational Mechanics},
  year = {2015},
  volume = {29},
  pages = {1716-1740},
  number = {6},
  eprint = {10993/13771},
  eprinttype = {hdl}}

@ARTICLE{Williams94,
  author = {C. Pfrommer},
  title = {Simulating cosmic ray physics on a moving mesh},
  journal = {International Journal for Numerical Methods in Engineering},
  eprint = {1604.07399},
  eprinttype = {arxiv}}

@book{Lame,
  title={Le\c{c}ons sur la théorie mathématique de l'élasticité des corps solides},
  author={Lamé, Gabriel},
  eprint= {ark:/12148/bpt6k5747708p},
  eprinttype = {ark},
  year={1852},
  publisher={Bachelier},
  address={Paris}}

enter image description here

8
+500

It's entirely possible to set this up by editing a standard .bst file, it's just somewhat tedious. There are three things needed. First, you need to tell BibTeX to make entries doi, eprint and eprinttype available by modifying the ENTRY list:

ENTRY {
  ...
  doi
  eprint
  eprinttype
  ...
}

Second, you need a function that is going to do the formatting. Exactly how you set this up will depend on whether you want all the bells and whistles. For example, adding a switch to detect hyperref makes life a bit more complex. In the following, I'll assume that hyperref will always be loaded. I'm also assuming in the following that we can take the types of eprinttype from the above and that it's all reliable (all entries will be of known types, \<eprinttype>tourl and <eprinttype>c colours will be defined in the document, etc.). That leads to something like the following

FUNCTION {format.doi.eprint}
{
  doi empty$
    'skip$
    {
      "\textcolor{doic}{\href{\doitourl{" doi * "}}{[doi:\nolinkurl{" * doi * "}]}}" *
      eprint empty$
        'skip$
        { output }
      if$
    }
  if$
  eprint empty$
  eprinttype empty$
  and not
    {
      "\textcolor{" eprinttype * "c}{\href{\" * eprinttype * "tourl{" *
         eprint * "}}{[" * eprinttype * ":\nolinkurl{" * eprint * "}]}}" *
    }
    'skip$
  if$
}

Finally, the function has to be added into the output of entry types. You could do that by adding it on to an existing general function such as that for the note field, but I'd do it manually:

FUNCTION {article}
{ output.bibitem
  format.authors "author" output.check
  new.block
  format.title "title" output.check
  new.block
  crossref missing$
    { journal emphasize "journal" output.check
      format.vol.num.pages output
      format.date "year" output.check
    }
    { format.article.crossref output.nonnull
      format.pages output
    }
  if$
  format.doi.eprint output
  new.block
  note output
  fin.entry
}

Depending on the sophistication required, one could add sanity tests, pass data concerning known types to BibTeX, etc.


Editing the above into plain.bst, renamed as eplain.bst, and using the example source

\RequirePackage{filecontents}
\begin{filecontents*}{\jobname.bib}
@article{Ba,
 year={2000},
 journal={Archive for Rational Mechanics and Analysis},
 volume={154},
 number={3},
 doi={10.1007/s002050000105},
 title={The Dynamics of Discrete Mechanical Systems},
 publisher={Springer-Verlag},
 author={Patrick Ballard},
 pages={199-274},
 eprinttype = {oai},
 eprint = {hal-00111308}}

@ARTICLE{Beylkin92,
  author = {Nguyen, Vinh-Phu},
  title = {Nitsche's method for two and three dimensional NURBS},
  journal = {Computational Mechanics},
  year = {2015},
  volume = {29},
  pages = {1716-1740},
  number = {6},
  eprint = {10993/13771},
  eprinttype = {hdl}}

@ARTICLE{Williams94,
  author = {C. Pfrommer},
  title = {Simulating cosmic ray physics on a moving mesh},
  journal = {International Journal for Numerical Methods in Engineering},
  eprint = {1604.07399},
  eprinttype = {arxiv}}

@book{Lame,
  title={Le\c{c}ons sur la théorie mathématique de l'élasticité des corps solides},
  author={Lamé, Gabriel},
  eprint= {ark:/12148/bpt6k5747708p},
  eprinttype = {ark},
  year={1852},
  publisher={Bachelier},
  address={Paris}}
\end{filecontents*}
\documentclass{article}
\usepackage{xcolor}
\colorlet{doic}{green!50!black}
\colorlet{arkc}{blue!50!black}
\colorlet{oaic}{red!50!black}
\colorlet{hdlc}{yellow!50!black}
\colorlet{arxivc}{pink!50!black}
\usepackage[hidelinks]{hyperref}
\urlstyle{sf}

\def\doitourl#1{http://dx.doi.org/#1}
\def\arktourl#1{http://gallica.bnf.fr/#1}
\def\oaitourl#1{http://hal.archives-ouvertes.fr/#1}
\def\hdltourl#1{http://hdl.handle.net/#1}
\def\arxivtourl#1{http://arxiv.org/abs/#1}   
\begin{document}
\nocite{*}
\bibliographystyle{eplain}
\bibliography{\jobname}
\end{document}

generates essentially the same output as in the question.

  • 1
    Whilst BibTeX is limited in some ways (non-ASCII input, fixed data model, etc.), the stack language is perfectly capable of managing this type of programming problem. The issue comes in that it has to be set up in every .bst file you want to use. – Joseph Wright May 9 '16 at 6:50
  • @pluton I've fixed various errors in the example: it now works if I add the three lines to ENTRY, add the one line to FUNCTION {article} and insert FUNCTION {format.doi.eprint} just before FUNCTION {article}. – Joseph Wright May 10 '16 at 12:37
  • Superb! Does the FUNCTION {format.doi.eprint} has to be necessarily placed right before FUNCTION {article} or anywhere else before would be fine? – pluton May 10 '16 at 12:47
  • 1
    @pluton Anywhere before the first use (unlike TeX, BibTeX does care about this). So somewhere in the set of format.<thing> functions seems sensible. – Joseph Wright May 10 '16 at 12:51

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.