Friday, June 29, 2007

SEEing LaTeX 1: Citations

As a first step towards turning SubEthaEdit into a capable LaTeX editing machine, let's address citations. Citations are a challenge to keep consistent and accurate, so mechanized assistance is quite useful. For LaTeX, that means BibTeX. BibTeX separates content from presentation in much the way that TeX does. Considering the many different formatting styles for bibliographies and citations that are required by different journals, this is something that I won't give up on -- I'll type the citation keys by hand if needed.

Fortunately, getting citation support in SubEthaEdit is trivial! Just install BibDesk, if you're not already using it, and set up autocompletion for SubEthaEdit. Inside a \cite, hit F5 or command-escape, and you get a list of completions for a partial citation key. This works really well. I hadn't used BibDesk for that for a while, since TextMate had its own method (not that it has worked in recent versions), so I'd forgotten how slick this is.

Completions in general, not just for citations, can be made a little bit easier. In your user Library folder, there may be a KeyBindings folder; if not, create it. Create a file DefaultKeyBinding.dict in the KeyBindings folder. The file is an XML file with a list of key-action pairs; bind the escape key to a string "complete:" (with the colon, without the quotes). The Property List Editor works nicely for doing this. The end result is that you just press escape instead of command-escape to get a completion. It doesn't cause any problems for using escape to, say, select cancel in dialogs, so there's no down side, just completions that are easier to activate.

Thursday, June 28, 2007

Mac OS X editors for writing LaTeX

Well, it's taken a bit longer for me to get back to writing than I'd expected. I do intend to follow up on the one million answers post, but for now I'll take a look at something else.

In short, I am fed up with the LaTeX mode for TextMate, and maybe TextMate in general. Writing text, instead of programming, really seems to highlight the worst aspects of TextMate. Besides the well known failings of its undo, TextMate has two other serious annoyances that are relevant here.

First, you can only use monospace fonts. I accept it as the reality for a lot of programming, even if I don't like it. For writing LaTeX, it's terrible. Literally headache inducing.

The second flaw is how words are selected using the mouse. Standard behavior for Mac OS X is that when you double-click on a word, it is selected. Extending this, if you "click and a half," (double click, but keep the mouse button held down on the second click) you can then drag and select text by words instead of characters. In most applications, this works very well, and is often simpler than character-based selection. However, in TextMate, this works poorly, because you can't select a sentence including the period at the end. You can get to the last word, and then the selection jumps to include the first word of the next sentence.

All three of these problems make writing text a little bit harder, but aren't that big of a deal for programming. Taken all together, they make writing LaTeX into a stressful experience, and formal writing is hard enough. These troubles all come from the use of a custom text view instead of the standard Cocoa NSTextView. The author of TextMate, Allan Odgaard, has written that it would be easier to write a replacement for NSTextView than to get NSTextView to do what he wanted. I'm not sure I believe him; for me, at least, behaving like the rest of the Mac OS X text system is pretty important. In this sense, he hasn't written a replacement for NSTextView.

TextMate does have a LaTeX mode, though. It has a lot of nice features, like integrating with PDF viewers through pdfsync, text completion for citations and cross references, assorted functions for project management, and various snippets for simplifying typing. Unfortunately, not all of that works very well -- I've never got citation completion to work reliably, and not for lack of trying. Text completions have some funny behavior. Showing an outline of the document fails if it includes a file that started with the letter 'x' (no, I'm not kidding).

Because of all this, I've downloaded the current version of SubEthaEdit and will give that a try for the next month. So far, I'm finding the basic editing to be much more pleasant. I'm using a proportional font, undos work sanely, and I can select by words using the mouse. The basic task of writing seems a lot more pleasant. I haven't used SubEthaEdit much since getting TextMate, and the last version I'd used was version 2.2. It's still the same elegant, minimalist editor, but things have changed a bit. There are now language modes with mode-dependent scripting, not just syntax highlighting. There are now tabs, and a quite elegant implementation at that (no projects, yet, though).

That said, the LaTeX mode just has syntax highlighting. No pdfsync support. No keystroke to compile the file into a PDF and send it to a viewer. No completion of citations. However, SubEthaEdit is extendable by scripting and, thanks to its reliance on Mac OS X standards, the editing features can be extended by input managers. Over the thirty-day trial period, I'll see what I can do to extend SubEthaEdit's LaTeX mode into something a little more capable.