Wednesday, July 20, 2011

Splitting body and references in Latex for NSF proposals

For those of us who prepare grant proposals for the NSF, and use LaTeX for formatting, it can be a pain to separate the body of the proposal from the references, as the two have to be uploaded separately. A combination of pdftk (the PDF toolkit) and make handles this in a pretty straightforward fashion:

1. put the following in your LaTeX source, just before generating the bibliography, to mark the last page:

\label{page:last}

2. Use a makefile that looks like this (assuming you use pdflatex):

FILE = proposal
$(FILE).pdf: $(FILE).tex
    pdflatex $(FILE)
    bibtex $(FILE)
    pdflatex $(FILE)
    pdflatex $(FILE)

DESC_END = $(shell grep page:last $(FILE).aux | tr '{}' ' ' | awk '{print $$NF}')
REFS_START = $(shell expr $(DESC_END) + 1)

description.pdf: $(FILE).pdf
        pdftk $< cat 1-$(DESC_END) output $@

references.pdf: $(FILE).pdf
        pdftk $< cat $(REFS_START)-end output $@