When was the last time Microsoft Office gave you a holiday treat? TextMate gets all dressed up for Halloween.

More photos at flickr.
When was the last time Microsoft Office gave you a holiday treat? TextMate gets all dressed up for Halloween.

More photos at flickr.
A thread on R-Help recently discussed using Sweave/LaTeX for complicated projects. Two really useful tips were highlighted in that conversation—I use the first of them regularly: In the beginning of a Rnw/Snw file, use the prefix.string option to set the location of an includes directory: \SweaveOpts{prefix.string=/Path/to/directory}
This is really useful for organizing all the files that built by your project. (Mine are all directed to an includes directory that lives beneath my main manuscript directory.)
The second tip is to use a makefile to build a project that consists of multiple Sweave files. I like makefiles as much as the next guy, but here is my TextMate-specific solution for the same dilemma: Within the TM project, use the TM_SWEAVE_MASTER variable to name a master file, and in this file, simply plug in a single Sweave section that invokes source (for R-only files) or Sweave for your project’s various files. When you want to build the whole project (for example when you begin work for the day and need to load up all your data) all you do is open up the project and invoke the Sweave -> Sweave Project in R command.
For example, my dissertation project sets TM_SWEAVE_MASTER to “diss-master.Snw,” and that file looks like this:
<<echo=false,results=hide>>=
source(file="˜/data/diss/R/clean-summary.R")
source(file="˜/data/diss/R/tables.R")
source(file="˜/data/diss/R/figures.R")
source(file="˜/data/diss/R/citystats.R")
Sweave(file="˜/docs/diss/manuscript/data-collection.Snw")
Sweave(file="˜/docs/diss/manuscript/longevity.Snw")
@
The several R files do a little bit of data tweaking and build some tables/figures. Once all that data is loaded up, the two Sweave files can be built. I do this once per work session, using the Sweave Project in R command, which makes sure everything in the project is up to date. Subsequently, I can simply Sweave any individual Snw file (using the corresponding TextMate command), without having to recompile the entire project. (This all of course integrates well with using TM_LATEX_MASTER, also set at the project level, to order LaTeX to typeset the overall document.) I have found it to be a really nice and functional workflow.
A neat new bit of functionality for TextMate came through the svn pipe today, thanks to Haris:
Log for r5298
Added Console functionality to R. To use it, you need to have R.app up and running. Open a new document and set its language to “R Console”. Start by typing ”> ”. From now on, pretend you are in the R.app’s console.
Cool.
Note (mostly) to self: I made a few small updates to the Sweave Bundle for TextMate. Interested parties, you know what to do.
Haris Skiadas, who has made massive contributions to writing in LaTeX with TextMate (see for example his screencasts of good use of the LaTeX bundle), has put together a super TextMate GTD bundle. Haris has been hacking on it nearly-continously for several days—I confess to having harassed him significantly throughout development so far—and the bundle is a fully-capable GTD system: You can work with a single document, or as many as you want, can easily move projects around, add tasks, and add and modify contexts. The bundle has a number of commands to generate Next Actions lists, and it will archive completed tasks/projects to a separate log file.
Up until now, I’ve been using the Kinkless GTD system. Lately, however, that software began to feel a little cumbersome, a little too cognitively heavy and opaque. Since it lives in TextMate, Haris’s GTD bundle works with pure text, making highly extensible, and it works great (it even knows how to convert your Kinkless document to its own format). Today Haris capped it off with a script that filters an inbox (fed via Quicksilver) into your GTD documents. Seriously cool. I highly recommend giving it a try if you’re using either TextMate or GTD (or need an excuse to give either one a test drive).
I’ve been using BSAG’s Journal bundle (itself a markdown extension) for a little while now, to keep a sort of snippet log, and I’ve put together a quick command to search entries by keywords (I hacked up the “Find in Document” command of the TM bundle). Keywords are marked by brackets: [key1,key2,etc]. The command just finds given text and shows the first line or so of the actual snippet entry, to give it some context. It’s very simple, but I’ve found it useful to quickly find entries by keyword, so I thought I’d share it. Here’s a screenshot:
You can download the command here. To install it, just click on the .tmCommand file, and TextMate should take care of the rest. (You’ll also, of course, need to be using TextMate and BSAG’s Journal bundle.)
Update: The Sweave bundle is updated as of Oct 5 2006. Thanks to Haris for the contributions and improvements.
Yesterday I linked to a screencast that shows off some the neat things that one can do with the math bundle in TextMate. TextMate continues to get better, and it has become my primary editor on OSX. Kieran posted a comment about TextMate’s relative lack of functionality with regard to LaTeX and R:
I was looking into TextMate but its latex and R support is still fairly basic— there’s no real equivalent to auctex/reftex’s functionality, and the R bundle is rudimentary. This is a pity, as it seems like a really powerful environment, and for some time I’ve been looking for a way to escape from Emacs and use an OS X native, modern editor/IDE. Maybe soon.
Kieran is right in part: Auctex and Reftex are excellent additions to emacs and TextMate can’t yet match them. But it does offer some nice advantages over emacs, so I thought I’d write up a few thoughts on my transition to TextMate and the ways I’ve found to compensate for no longer having access to my beloved C-c C-c RET.
OS X is a pleasant working environment, and even builds of emacs that are meant to fit nicely in that environment still don’t feel native. Aquamacs is one such attempt. For brand new users of emacs, Aquamacs may be a good tool, but for those of us with pre-existing byzantine .emacs files, Aquamcs adds a whole additional level of confusion by changing keybindings and introducing a whole new set of configuration options. Despite all the attempts to make it more modern, setting one’s typeface in the editor remains a frustrating exercise. My machine is relatively modern and speedy, and emacs still takes a good long time to load fully, even after pruning unnecessary cruft from my config file. And once loaded, there are just enough interface differences to be jarring: scroll bars, for example, are something that most emacs builds have never really sorted out. It’s 2006; can I please get a scroll bar that works the same way as every other scroll bar on my machine?
It’s not about bling, however. As projects such as my dissertation grew in size — multiple data, LaTeX, R, and Sweave files spread around the place — the organization of all that material started to occupy an increasing chunk of my cognitive space. “Where’s file goober, and how is it related to file data?” Although emacs handles lots of files just brilliantly, and switching between them is a snap if you’ve loaded the right iswitch-b package, it doesn’t help much with the organization end of things. That was my real original incentive to switch: I wanted my software to take a little of the load off of my brain, and perhaps to do it a little more quickly.
Finally, switching is a nice opportunity to review the way I get work done and think conscientiously about how to improve. On the flip side, it’s also a nice way to structurally procrastinate.
Emacs is powerful. It can read email, browse the web, make a fully-functional wiki right on your desktop, and, on those occasions when appropriate, it can edit text files with championship ability. It is a mature working environment with brilliant integration with LaTeX, BibTeX, and R. Just using it can make one feel like a ninja, albeit a meek, deskbound one with rapidly deteriorating vision and nascent repetetive stress disorder in the wrists. As Kieran commented, nothing quite approaches the combination of AucTeX and RefTeX. I’m still reaching for those key-bindings that, alas, don’t work in TextMate no matter how many times I C-c [ them.
TextMate immediately addressed my core reason to switch with its handling of projects. It has a project drawer into which you can simply drag files and folders, create separators, and arbitrarily organize them all. It seems like a small thing, but the ability to see all the files that comprise a project, and then navigate them easily, is something that’s a) really important in order to have a clear sense of what I’m working on, and b) remarkably difficult in emacs.
Navigating those files is easy, as well: You can find and click in the project list, switch tabs with the keyboard, or hit cmd-T to bring up a file browser that finds files as you type: “cmt-T cl” narrows the list to those files that match the pattern “cl.” It pretty nicely approximates the autocompletion of switching buffers in emacs.

TextMate is, like emacs, extensible almost to the point of absurdity. The architect of this extensibility built TextMate to hook into virtually any programming language, shell command, and external application. TextMate comes with built-in support for LaTeX and BibTeX compilation, as well as completing citations and labels within LaTeX documents. The latter function isn’t nearly as slick as using RefTeX, but it works fairly well. There are a few useful screencast demonstrations of those features. Haris, the author of those screencasts, has contributed tremendously to cite key and label completion — they work pretty well, thanks much to him.
I’ve made what I think are a few improvements to existing bundles in order to faciliate my own work: I’ve modified the LaTeX compile command to switch to xelatex if necessary, for example.
More in depth, but still fairly simple, is my rudimentary Sweave bundle for TextMate.1 TextMate allows one to set environment variables at the global or project level, so, for instance, I can assign a “master document” variable to my dissertation. This allows me to generate LaTeX output from a single in-process Sweave file, or, with an alternate command, to re-run the entire Sweave project through R and then begin LaTeX compilation. With the bundle TextMate (mostly; it’s still a work in progress) correctly parses Sweave files, allowing for context-sensitive actions depending on the position of the caret in a file: Within a Sweave document, I can generate LaTeX, compile that associated LaTeX file, send selected code to R, or build the entire master document. It works pretty slick now that it’s set up. Whereas in Emacs, the ties between various files was frequently opaque, I’ve found that keeping track of those relationships and compiling documents is more transparent and much easier.
For me, it has been worth it. The tinker to work ratio starts out pretty high, but that’s not unusual. Breaking emacs habits is tougher, even after four months, and I’d love a citation mode that works more akin to that found in RefTeX — the ability to invoke the command and then choose citation types, for example — and I still miss some of the enhancements from AucTeX; it trained me too well to C-c C-s to insert a section, for example. The ease with which one can build bundles and interface with external applications suggests that it won’t be long before someone may start building equivalent tools, and that will be a happy day.
In the meantime, TextMate is fast, allows me to visualize my projects, and works well enough with the other applications I use, as well as within my workflow, to justify the switch. It’s a good app, and it has improved my work.
I forgot to mention another issue about switching. Up until now, my tools have been almost entirely cross-platform for the past five or six years. TextMate is OS X-specific, so I can’t smoothly use the same set of tools on the Windows laptop like I could with emacs. This gives me some pause: It’s nice to have a mostly universal workflow, in which I could sit down at a PC, Mac, or linux machine, sync some files, and work. But over the past year with the iMac, I’ve picked up a few other non cross-platform tools: BibDesk is a great BibTeX manager, and I’ve been doing a ton of stuff using OmniOutliner Pro in the past handful of months, so switching away from emacs on one platform isn’t as much of a transition on that front as it might have been a year ago. Besides, the Mac is a nice platform to work on. And, hey, one of these days I’ll be able to trade up the Toshiba for a shiny new *Book of some kind.
1 Download the sweave bundle here. To install it, unpack the archive in ~/Library/Application Support/TextMate/Bundles (you may have to create this directory), and then access the bundle’s commands from the Automation -> Run Command -> Sweave menu, or via the “gear” menu at the bottom of the TextMate window. return to text
Is there anything TextMate can't do? Here's a screencast (.mov) of the math bundle and a bunch of other tricks.
I’m a sociologist. This site is powered by Textpattern, TextDrive and the sociological imagination. For more about me and this site, see the long version.
Syndicate me with any of the following: Atom, RSS, sociology and linklog feeds are available.