# Modifying a bst file to allow for an arxiv field

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


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


which, of course can be done with a macro:

\newcommand{arxiv}[1]{{ \href{arXiv:#1}{www.arxiv.org/abs/#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...

-
Have you looked into modifying the url field, supplied by, say, the plainnat.bst file? –  Mico Nov 10 '11 at 22:36
Have you checked out these styles: arxiv.org/hypertex/bibstyles ? Apropos of your approach, there is already a version of unsrt.bst modified to show eprint numbers. –  Lev Bishop Nov 11 '11 at 1:15

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
}

-
I generated my own bst file in the usual way when I wrote my thesis, but wanted something similar to what you want. I got my hack on and this was the result. Honestly, I'm not 100% certain of how it's working now, but looks fairly straight forward. –  qubyte Nov 10 '11 at 21:58

The answer by Mark, is a complete working example, but I had my way of doing things and I therefore wanted an answer on how to fix my code...not a different code...but looking at his code I managed to figure out that there was a spurious * in my definition, which then pulled too many items from the stack. The format.arxiv function that I ended up using is:

 FUNCTION {format.arxiv}
{ arxiv empty${ "" } {"\href{www.arxiv.org/abs/" arxiv * "}" * "{\tt arXiv:" * arxiv * "}" *} if$
}


Notice the lack of a * between the first two arguments of the false clause.

-

You can download the file unsrt-phys.bst in the link below: https://drive.google.com/open?id=0B8AqjYFfBKw0dEZXcFN0WEVIN0U&authuser=0 and put it in the folder of your article. Then change the style of bibliography to \bibliographystyle{unsrt-phys}. Run Bibtex, and enjoy it!

-

use

FUNCTION {format.arxiv}
{ arxiv empty${ "" } { "{\url{arXiv:" arxiv * "}}" * } if$
}


and, of course, an entry arxiv in the list ENTRY. Then I get:

\documentclass{article}
\usepackage{filecontents}
\usepackage{url}
\begin{filecontents*}{\jobname.bib}
@unpublished{demo,
author="foo",
title="bar",
arxiv="1234.5678"
}
\end{filecontents*}

\begin{document}
\nocite{*}
\bibliographystyle{unsrt}
\bibliography{\jobname}
\end{document}


-