LaTeX related pages.


Endfloat is a LaTeX package for shifting your figures and tables onto seperate pages at the end of your article, a format requested by some journals. For example, adding


This includes endfloat, which adds to the end of your article

  • a list of figures and their captions followed by
  • the figures themselves on separate pages.

The bit setting the caption color to white hides the captions on the figure pages, since some journals don't like to have them. If you're using hyperref, and you have references from your captions (e.g. to equations, citations, etc.), those may get colored automatically, so they won't be "erased" by the CaptionFont redefinition. You can turn off hyperref's coloring with

\hypersetup{pdfborder=0 0 0}

which turns of the coloring of the link text, and disables the annoying boxes that hyperref likes to draw around links. Note that this will make links hard to find throughout your entire article, but just for the preprint with captionless figure pages, which isn't really a big deal. You can still find them by mousing around in places where you expect them to be.


Available in a git repository.
Repository: thesis
Browsable repository: thesis
Author: W. Trevor King

The source for my Ph.D. thesis (in progress). A draft is compiled after each commit. I use the drexel-thesis class, which I also maintain.

Exciting features: SCons build; Asymptote/asyfig, PGF, and PyMOL figures.


Available in a git repository.
Repository: drexel-thesis
Browsable repository: drexel-thesis
Author: W. Trevor King

Drexel, like every other academic institution, has very particular standards for the format of a Masters or Ph.D. Thesis. The library publishes a requirements manual. The LaTeX wisdom of generations of grad students has been assembled into the drexel-thesis class which you, dear reader, can use to easily format your thesis.

I'm the current maintainer, so besides the post in the department wiki, I'm including a page in this blog.

Your compiled thesis will look something like example.pdf (or, in draft mode, example-draft.pdf). Take a look at the manual to get started. You might also want to look at how I've used the class in my own thesis.


Available in a bzr repository.
Repository: pybtex
Author: W. Trevor King

I keep my BibTeX databases neat and tidy with my own branch of Pybtex. The actual command used to re-format the files is

$ python -c 'from pybtex.database.input.bibtex import Parser; from pybtex.database.output.clean_bibtex import Writer; p = Parser(); d = p.parse_file("path/to/db.bib"); w = Writer(); w.write_file(d, "path/to/db.bib", p.get_raw_macros())' 2> pybtex.log

Be sure to look over pybtex.log and git diff path/to/db.bib for anything suspicious before committing the new file (you are versioning it with Git right? ;). You may have to do some find-and-replacing to handle changed keys and consolidate or rename automatically generated macros.

You might also be interested in bibtool, but I'm more comfortable tweaking things in Python.


BibTex is system (tools and file format) for managing references in LaTeX documents. Forget about formatting your bibliography (is it “publisher (year)” or “publisher: year”?), just add entries for the works you're referencing, and drop in a \cite{key}. I also use my entrez script to pull nicely detailed citations off PubMed and its related databases. Once you've added the citation to your database the first citation, you can reuse that data in any future paper just by reusing your BibTeX database. It's wonderful.

Basic usage

At some point in your LaTeX document:

\bibliographystyle{prsty} % Phys. Rev. style

other syles include abbrv, alpha, plain, unsrt, ... In your LaTeX document where you want the bibliography:

\bibliography{wtk} % wtk.bib is the name of the database

compile (using latex for example) with:

$ latex example
$ bibtex example
$ latex example
$ latex example

Formatting names

There are many possible author name formats, but the least ambiguous is von Last, Jr., First Middle. If the von is capitalized (e.g. "Emanuela Di Cola"), use \uppercase:

@String{EDCola = "{\uppercase{d}}i Cola, Emanuela"}

See Tame the BeaST for details.


I don't actually use LaTeX's \cite{key} command as I claimed above. That works, but the Natbib package adds support for other citation styles & link formats. I actually use \citep{key} (parenthetical citations), \citet{key} (textual citations), and other more specialized Natbib commands. That way I don't have to worry about misspelling author names or remembering “et al.” when I cite a source in the text.


Customize bibliography with Makebst (latex makebst, from custom-bib), makes .bst (bib-style) format files according to your specifications.

Cross-references (more like sub-references)

Don't repeat yourself! BibTeX lets you piggyback low level references (@inbook, @inproceedings) underneath higher level references (@book, @proceedings) without duplicationg information from the parent entry (via crossref). However, this can be a bit tricky.

Like a number of TeX tools, BibTeX tries to accomplish as much as possible with a single pass through your data. This makes things more memory efficient (if you really can't spare that extra MB ;), but it also makes for some odd errors. While working on my thesis, I ran into:

$ bibtex root
Database file #9: root.bib
Warning--string name "nist:esh" is undefined
--line 1175 of file root.bib
A bad cross reference---entry "NIST:gumbel"

The problem is due to the @inbook entries occuring after the @book they reference:

@book{ NIST:ESH,

@inbook{ NIST:gumbel,
  crossref = {NIST:ESH},

When it's reading your bibliography, BibTeX hits the @book entry (NIST:ESH), and says to itself, “Hmm, it doesn't look like anyone's referencing NIST:ESH. I'll save some memory by forgetting I've seen it.” Then when BibTeX hits the @inbook entry (NIST:gumbel), it says, “Ahh, this references NIST:ESH. I'd better keep an eye out for that.” Unfortunately, this is too late, because it's already past that entry. BibTeX hits the end of the database without finding a (second) NIST:ESH definition, and complains about the missing reference.

The solution is just to order your @inbooks (and other crossref consumers) so they occur before the entry they reference:

@inbook{ NIST:gumbel,
  crossref = {NIST:ESH},

@book{ NIST:ESH,

Embarassingly, this information is spelled out on Wikipedia's BibTeX page:

The referred entry must stand below the referring one.

That's the kind of thing you'll only remember after you've been bitten by it ;). Hopefully putting the bad cross reference error message in the surrounding text will help the rest of you searching for solutions.

It looks like Matěj Cepl (who has also contributed to rss2email) ran into the same issue back in 2000. It's a small world ;).


There are a number of good resources to get you going:


Available in a git repository.
Repository: problempack
Browsable repository: problempack
Author: W. Trevor King

I've put together a LaTeX package problempack to make it easier to write up problem sets with solutions for the classes I TA.


The package takes care of a few details:

  • Make it easy to compile one pdf with only the problems and another pdf with problems and solutions.
  • Define nicely typeset environments for automatically or manually numbered problems.
  • Save retyping a few of the parameters (course title, class title, etc), that show up in the note title and also need to go out to pdftitle and pdfsubject.
  • Change the page layout to minimize margins (saves paper on printing).
  • Set the spacing between problems (e.g. to tweak output to a single page, versions >= 0.2).
  • Add section level entries to the table-of-contents and hyperref bookmarks (versions >= 0.3).

The basic idea is to make it easy to write up notes. Just install problempack.sty in your texmf tree, and then use it like I do in the example included in the package. The example produces a simple problem set (probs.pdf) and solution notes (sols.pdf).

For a real world example, look at my Phys 102 notes with and without solutions (source). Other notes produced in this fashion: Phys201 winter 2009, Phys201 spring 2009, and Phys102 summer 2009.


A related package that defines some useful physics macros (\U, \E, \dg, \vect, \ihat, ...) is my wtk_cmmds.sty. This used to be a part of problempack.sty, but the commands are less general, so I split them out into their own package.


The final package in the problempack repository is wtk_format.sty, which adjusts the default LaTeX margins to pack more content into a single page.


PGF (Portable Graphic Format) provides LaTeX-style graphics for LaTeX. Take a look at these examples. The manual is pretty readable (and pretty pretty ;), but sometimes lacking in detail. There's only so much you can fit into 500 odd pages ;). Don't get intimidated, the size is due to the quantity and quality of useful macros.


Hate repeating yourself? Love macros? LaTeX lets you write `beautiful documents' (PDF, DVI, HTML, ...) with macros. It can be a bit tricky to get things just right, but once you figure it out, it's easy to reuse the code.

Take a look at my packages, the Drexel Liki page, the source for most of my papers (if you scroll to the bottom of a paper's HTML, there is a source files link), and my thesis.

If you're interested in LaTeX and graphics, you'll probably be interested in Asymptote and PGF.


Asymptote is a C++ style graphics drawing package for LaTeX. I've written a few libraries to make it easier to draw pictures for physics problem sets (as part of my course website package). Here are a few teasers (rendered as SVGs).




To see the Circ library in full form, check out this writeup of a recent recitation problem.


Elsevier and LaTeX

Recently I've been writing up an article for one of the Elsevier journals using their elsarticle LaTeX package. Unfortunately, their BibTeX style file, elsarticle-num.bst (version 1.1, 2008-10-13), is a bit broken. With the help of Nicolas Markey's excellent Tame the BeaST, I've fixed it up so it runs without errors (!), works with natbib's \citet{}, and conforms with the examples posted in the International Journal of Biological Macromolecules' author guide.

Update: Oct. 6. Turns out the code linked from Elsevier is out of date. Rishi over at River-Valley (writers of the elsarticle package) pointed me to some more up to date documentation and source. Version 1.2 fixes most of my problems (with elsarticle-num-names.bst), but I'm still not sure why it doesn't replace elsarticle-num.bst entirely...