[Tex/LaTex] Modifying a bst file to allow for an arxiv field

bibliographiesbibtex

I am trying to add an arxiv reference to my bibentries and I would like to control how it shows up in the citation.

I would like to have the field only contain the informative part:

arxiv = 0809.0726

but for the result to be more informative and perhaps contain a link:

\href{https://arxiv.org/abs/0809.0726}{arXiv:0809.0726}

which, of course can be done with a macro:

\newcommand{\arxiv}[1]{{ \href{https://arxiv.org/abs/#1}{arXiv:#1}}}
\arxiv{0809.0726}

S far so good.

I've taken unsrt.bst and started modifying it.

  1. I've added arxiv to the ENTRY list

  2. I've added a format.arxiv function that is a model for what I want:

    FUNCTION {format.arxiv}
    { arxiv empty$
         { "" }
         {" {\url{arXiv:" * arxiv * "}}" * }
      if$
    }
    
  3. I modify the relevant output functions to call arxiv.output (for example, unpublished):

     FUNCTION {unpublished}
     { output.bibitem
      format.authors "author" output.check
      new.block
      format.title "title" output.check
      new.block
      note "note" output.check
      new.block
      format.arxiv output
      format.date output
      fin.entry
     }
    

However, when I try to compile a file I get the error:

Running `BibTeX' on `ResearchStatement' with ``bibtex ResearchStatement''
This is BibTeX, Version 0.99c (Web2C 7.5.6)
The top-level auxiliary file: ResearchStatement.aux
The style file: myunsrt.bst
Database file #1: general.bib
You can't pop an empty literal stack for entry FarjounSchaeffer2010
while executing---line 963 of file myunsrt.bst
(There was 1 error message)

BibTeX exited abnormally with code 2 at Thu Nov 10 16:39:09

I tried playing with the *'s in the format.arxiv function, but I kept getting the wrong results

I'm sure this is easy for those who can access the force…but I am still a grasshopper here…

Best Answer

Try placing the following in the .bst file. (The upper function may already be present).

FUNCTION {format.primaryClass}
{
  primaryClass empty$
      { "" }
      { " [" primaryClass * "]" *}
  if$            
}

FUNCTION {format.archive}
{
  archivePrefix empty$
      { "" }
      { archivePrefix ":" *}
  if$            
}

FUNCTION {format.eprint}
{ eprint empty$
     { ""}
     { archive empty$
          {"\textit{Preprint:}\href{http://arxiv.org/abs/" eprint * "}" * 
             "{{ " * format.archive * eprint *
              format.primaryClass * "}}" *}
          {"\href{" archive *  "/" * eprint * "}" * 
             "{{ " * format.archive * eprint *
              format.primaryClass * "}}" *}
     if$
     }
     if$
}

FUNCTION {unpublished}
{ output.bibitem
  format.authors "author" output.check
  new.block
  format.title "title" output.check
  format.date output
  new.block
  format.note "note" output.check
  format.eprint output
  fin.entry
}