A BibTeX style file for American Journal of Physics: Revised

The original version of this post tried to make a .bst file suitable for
American Journal of Physics, and found that the otherwise-excellent makebst.tex gave some odd output, and I tried to come up with a fix.

On communicating with the author of makebst, I received a reply saying that I had in fact done nothing wrong and had found a little bug. I am sure the new version of merlin.mbs will be up on the ctan page soon enough, and I don’t see that I have the right to post it here, but I have updated the .bst that is available at this page.

————————————————————-

I recently used the marvellous makebst.tex to make a bst for American Journal of Physics, who (as far as I can tell) ask for LaTeX but do not provide a .bst file, that is, a file to control the layout of the bibliography. The one I came up with can be downloaded here (chop off the .txt, it is just for the webserver’s convenience).

Running makebst.tex, I kept getting a small error. I have manually fixed it in the generated .bst file but I suspect I am doing something wrong and the error is mine and not in the package. And though I have a fix (see below) I am worried it will introduce more problems down the line with unforeseen combinations of inputs…

Anyway.

Referring to the AJP website, they want various bibliography entry formats as specified (http://ajp.dickinson.edu/Contributors/manFormat.html). When I asked makebst.tex to format the publisher as (Pub, Address, date) (by selecting option ‘d’ at one of the interactive prompts), I got a .bst file that threw an error when I ran bibtex.

I emphasise that I had at this stage not edited anything by hand and not done anything except run the program in a naive user space kind of way. (I copied it into my local space

cp /usr/share/texlive/texmf-dist/tex/latex/custom-bib/makebst.tex . 

then ran it, so there are no file permission problems or anything.)

So running latex on makebst.tex runs an interactive session that asks you lots of questions about how you want the bibliography entries to look (see the relevant sections in The LaTeX Companion). The result is a .dbj file that you then run through latex to make a .bst file. It works pretty well. But in this case I was getting an error when processing an “@inproceedings” bibtex entry:

$ bibtex myfile
This is BibTeX, Version 0.99d (TeX Live 2012/Debian)
The top-level auxiliary file:
myfile.aux
The style file: try.bst
Database file #1: myfileNotes.bib
Database file #2: kate.bib
You can't pop an empty literal stack for entry yasuda2013b
while executing---line 1303 of file try.bst
(There was 1 error message)

Now, the .dbj essentially consists of a bunch of options, and can be viewed directly. The problem menu is here:

%PUBLISHER IN PARENTHESES:
%   %: (def) Publisher as normal block
% pub-par,%: Publisher in parentheses
  pub-date,%: Publisher and date in parentheses
% pub-date,pub-xc,%: Publisher and date in parentheses, no comma
% pub-date,pub-xpar,%: Publisher and date without parentheses
% pub-date,pub-xpar,pub-xc,%: Publisher and date, no parentheses, no comma

If I comment out the selected entry (pub-date) and choose another one, everything functions fine but gives me the wrong format (of course, since it is not the entry I want). If I try to use pub-date, I get the error.

With some trial and error, I figured out that the problem was here, in the generated .bst file:

FUNCTION {format.org.or.pub}
{ 't :=
  ""
  year empty$
    { "empty year in " cite$ * warning$ }
    'skip$
  if$
  address empty$ t empty$ and
  year empty$ and
    'skip$
    {
      add.blank "(" *
      t empty$
        { address "address" bibinfo.check *
        }
        { t *
          address empty$
            'skip$
            { ", " * address "address" bibinfo.check * }
          if$
        }
      if$
      year empty$
        'skip$
        { t empty$ address empty$ and
            'skip$
            { ", " swap$ * * }
          if$
          year "year" bibinfo.check
          *
        }
      if$
      ")" *
    }
  if$
}

and in particular the line

{ ", " swap$ * * }

Some more trial and error and a bit of reading The LaTeX Companion, suggested this instead:

{ ", " swap$ * ", " * }

Now, I have a lot of trouble with the reverse Polish notation for bibtex styles, but I have tested this and it works, even if only one of the fields (Pub, Addr, year) is given. So it seems to have delivered me a successful .bst file for American Journal of Physics.

Amazing.

Advertisements

Tags: , , , , , , ,

About Darren

I'm a scientist by training, based in Australia.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: