← Back to Archives

RefTex, I never knew I missed thee

hacks

Recently, Eric Rescorla told me about RefTex, a tool that makes writing documents in LaTeX with emacs just a tad bit easier.

Specifically, RefTex:

  • Can display a table of contents of your document in another sub-window, making the navigation of .tex files almost effortless. (using C-c =)
  • Allows for the insertion of \labels and \refs (etc.) and keeps an internal list of these things for easy insertion. (using C-c ( for labels and C-c ) for refs)
  • Allows for simple but powerful insertion of \cites by parsing the associated BibTeX file and displaying a list that you can select from. (using C-c [)

It does a bunch of other cool stuff like being able to jump to a label and renaming of labels and refs. Anyway, 'nuff said... it's very cool.

If you're using emacs greater than version 20.2, it's probably already installed... just open a .tex file in emacs and look at the status bar at the bottom of the window. If it says something like LaTeX Ref than RefTex is already on and you can try out the commands above. If you don't see that Ref in the status bar to indicate RefTex is on as a minor mode, type M-x reftex-mode and it should toggle on. (In this case, you'll want to put a hook in your .emacs file to trigger the RefTex mode when you open .tex files.)

I found one quirk that's a bit more trouble than I'd like: when I update a .bib file using tools external to emacs (like JabRef), somehow RefTex doesn't know about any changes I make in the .bib file. For example, if I add a cite using JabRef and save the .bib file, typing RefTex' C-c [ to add that new cite doesn't work; it doesn't know the .bib file has changed and spits back Sorry, no matches found.

Here's one way around this: keep the .bib file open in emacs. When you change the .bib file using an external tool, go back to the .bib file that's open in emacs and type any key; emacs will complain because the file has changed on disk. If you then type r, emacs will revert the copy it has of the file to the one on disk. After this, RefTex seems to know that the .bib file has changed, reparses that file and then C-c [ does work as expected.

Bless your heart if you've read this far! For that, you get one last treat: using all these tools together with BibLaTeX is a writer's dream. These are very powerful writing tools.

UPDATE [2009-04-12T06:49:17]: It turns out that the problem with updating .bib files was due to not having auto-revert-mode enabled. That mode makes sure that any changes on disk are noticed immediately by emacs. You can enable this mode in your .emacs by:

(global-auto-revert-mode t)

Thanks to Leo on the AucTeX list.