No really — there's a church and background processing.

OK, so maybe some of you are still thinking "Remote file access? Surely you don't still think that's worth blogging about, do you?." And I'll be the first to agree — what really got me going was this:

Properly typeset formula in an Emacs window

There are lots of other nice things (as you're about to see), but if it hadn't been for the ability to do that, you probably wouldn't be reading this.

So what's it like, then? Well, I'm no LaTeX heavyweight — I've never written a document that spreads across multiple files, unlike several of my friends — but I've done enough here and there to be able to see that this is a very well thought-out package.

First though, install AUCTeX. I use Ubuntu (as you might have gathered by now), so I just type:

aptitude install auctex

The README gives three lines which you should add to your .emacs file, but I'm feeling exuberant, so instead I let dpkg configure things so that everyone on my machine (that is, me) gets AUCTeX.

Then we install the preview-latex package, which we'll see more of later.

aptitude install preview-latex

And now the fun starts!

  • First, there's a key binding (C-c C-e) to insert any kind of environment you might want (and you can tab-complete them if you're not sure). For example, starting a new report using the 11pt font is as simple as typing C-c C-e document RET ...
    Specifying the environment type
  • ... report RET 11pt RET.
    Specifying document options
  • Inserting section headings (C-c C-s) is just as simple: decide whether you want a section, subsection, chapter, or whatever, then give it a title. I find this interactive approach makes life much easier. You'll also find the cursor automatically positioned somewhere useful; starting a document leaves it just after the \begin{document} line.
    Entering the section title
  • You're prompted to supply a label for the section (with a helpful prefix filled in automatically), and headings are (configurably) displayed in a suitable font.
    A section heading with its label
  • You also get font highlighting available for footnotes, math mode, etc., plus a couple of subtle things, like subscript characters being slightly smaller (look at the B, D, and E characters in the formula).
    Font highlighting on various elements
  • The fun really begins when you fire up the preview-latex package. First we type C-c C-p C-f to turn on some caching, and then we type C-c C-p C-b to run the preview-buffer command. (There's a menu you can access all of this from, too, of course.) After a couple of seconds and some processor activity, bits of the document vanish, and are mysteriously replaced by tiny "men at work" signs:
    Men-at-work signs where elements will be rendered
  • After another couple of seconds, the roadworks signs vanish too, and you see the fully-rendered TeX output, right there in the buffer! There are a few things to notice here. First, the section heading has the appropriate number attached; it's 0.1 here because we're in a report and there isn't a chapter yet. Second, the math-mode formula has been rendered, and properly shows the superscript and subscript characters. Finally, the footnote has been rendered down to a superscript '1'.
    Buffer with LaTeX elements rendered
  • All of the rendered sections are genuine parts of the buffer, not some kind of temporary overlay — they scroll off-screen with the rest of the text, and you can move the cursor around and over them. The only difference is that they will expand into the original source whenever you try to move 'into' them. You can then edit that source normally, and recompile the affected part using C-c C-p C-p to run the preview-at-point command.
    Rendered footnote expanded to source
  • Even better, it's compatible with a 'greenscreen' mode I put together a while ago. You need to re-render things to pick up the new colours, but that's it. Green-tastic!
    Same buffer in 'greenscreen' mode

There are, of course, lots of things which I haven't covered here: toggling whether a preview section is rendered or not; marking sections of the document to be rendered as a single block; re-rendering only part of a buffer, or the whole document; do-the-right-thing LaTeX compiling and viewing commands; handling multi-file compilation; block-(un)commenting commands; LaTeX environment folding; and lots of customisable options through M-x customize-group RET AUCTeX RET.

One thing which I came across myself and might be of use if you notice the same problem was that some of the rendered text had green fringing. (If you weren't sharp-eyed enough earlier, have a look at the bottom of the '0.1' section header.) This is caused by preview-mode antialiasing to the wrong color. By default it uses the pale green used for mouse highlighting, and it does look exactly right when you move the mouse over it (for example, if you're asking preview-mode to render the section again via a pop-up). Normally I don't use the mouse, though, so I customised this by changing the value of "Preview Transparent Color" using M-x customize-group RET preview-appearance RET (or, for a slightly quicker way, via C-h v preview-transparent-color RET and the 'customize' link).

Something to be aware of if you do this: setting the transparency colour to exactly the same colour as the default text background makes the cursor shape used for rendered sections change from a box around the outside of them to a solid rectangle, which can make previews hard to see. There might be more informed ways to solve this problem, but I found that setting the transparency colour to almost exactly the same as the background looked fine.

After all these features, I can start to see where sites such as this one might be coming from …