LyX, BiBTeX, ADS, astro-ph and hyperref for Astronomers

Quick Note If you just want to look at the files used to do this work, have a look in the directory: ads_lyx/

Other useful links:

Using BiBTeX entries generated by ADS

Introduction to AstroNat

Things to fix

Introduction

The goal is to include a bibtex generated from a private library exported from the ADS service into a LyX document as a bibliography, and then to export it as a PDF complete with clickable links to hit back on the astro-ph references and the ADS paper page.

This can be broken down into several parts:

The bibtex entries have an adsurl entry that contains the link to the ADS web page for a given reference. If you can make that linked in, you're golden.

Getting a latex file to recognise the abbreviations in an ADS Bibtex download

Normally, you can add the bibtex style fix as listed in the AstroNat link, so that the \apj gets replaced by ''ApJ'', but it turns out that the ADS generates Bibtex items with braces that 'protect' any string replacement that use @STRING see here

So, I've taken the list of journal names from (http://ads.harvard.edu/pubs/bibtex/astronat/mnras/mn-jour.bib) and changed them into a long list of \def statements. You can add this into your latex file as \input{mnras-replacements}. NOTE: I've removed a couple of the more obscure journal names whose \def seems to replace a latex command or two. They're fairly obscure journals, so here's to never reading ''Space'' journal.

Getting LyX to find and recognise the BiBTeX file

In Document... => Settings.... => Bibliography, under Citation Style, select the ''Natbib'' radio button, and Natbib-style of Author-year.

In Document... => Settings.... => LaTex Preample add:

\def\apjl{ApJL }
\def\aj{AJ }
\def\apj{ApJ }
\def\pasp{PASP }
\def\spie{SPIE }
\def\apjs{ApJS }
\def\araa{ARAA }
\def\aap{A\&A }
\def\nat{Nature }
\usepackage{hyperref}
\hypersetup{colorlinks=true,citecolor=blue,linkcolor=black,filecolor=black,runcolor=black}

Optionally addd urlcolor=blue into the \hypersetup line if you want blue external URL links instead of the rather fetching purple they are at the moment.

Setting up how the references and citations look in LyX

This is done with the Q and A section of latex makebst.tex....

Making LyX recognise the URLs in the BiBTeX file

Okay, so you should have a Bibtex style file that you can link to in youe latex file or in your added Biblio section in oyur lyx file. This file is called .bst

(deep breath) So, it turns out that *.bib are your biblio databases, with the name, publiction date, and so on. Latex spits out an .aux file which lists all the references it wants to find. Bibtex then taks this .aux file, reads in your bibtex .bib file, and processes the latex references according to the style file *.bst.

the bibtex style file is in fact a simple stack-based programming language, and so you need to hack the .bst file itself to get the proper behaviour!

I'm sure there is a better method to doing this, but I haven't found it yet, and anyway, this one works as it stands.

First, the astro-ph links. I've decided to keep these as just plain text with no URL link. ADS is now set up so that it links to the astro-ph for any paper that is in its system.

Look for a line in the bst file that looks like this:

"\providecommand{\eprint}[2][]{\texttt{#2}}"

...and change it to:

"\providecommand{\eprint}[2][]{\url{#2}}"

The bst file outputs latex commands for the bibliography section during processing, and in this section of the bst file, it is writing out a latex command that will deal with the formatting of any 'eprint' field in the bibliography. If you have loaded the hyperref package in the LyX preamble, it takes the astro-ph:0702.1234 reference and makes it a clickable link. This is wrong, and instead of hacking through the proper replacement, we force it to print it out in a typewriter font instead.

Now, the URL links to the ADS website for that given paper.

Change the url to adsurl in the first ENTRY, about 20-60 lines into the file.

Look for

FUNCTION {format.url}
{ url empty$

...and change to:

FUNCTION {format.adsurl}
{ adsurl empty$

and then about three/four lines below that, find:

{ "\urlprefix\url{" url * "}" * }

...and change it to...

{ "\href{" adsurl * "}{[ADS]}" * }

Finally, do a 'search and replace' for format.url and replace with format.adsurl

That's it! It's hacky, kludgy, and generally grungy, but for me, it works.

The style file I use that works with this is nsf.bst and you can see the successful results in example.pdf

Feel free to email me and ask questions, or even better, tell me how to do it properly!

Cheers,

Matt

Originally written: 2008 Apr 02

Last updated: Monday June 02, 2008

Valid HTML