Friday, December 23, 2011

Automated Mathematica language module BBEdit or TextWrangler

I realize that a few people will find this useful, however those will appreciate it.

If you're a frequent user of Wolfram Mathematica like me, you've probably found yourselves in situations where you could not simply edit your code stored in notebooks (files with.nb extensions) with Mathematica itself. This could be due to various reasons, for example when you don't have Mathematica installed on your current machine or operating system. Luckily, most, if not all, text editors can open and edit notebooks. However, if you use a text editor that supports advanced features like syntax coloring, you will be disappointed when the whole Mathematica code will be in the same default color.
My text editor of choice on OS X is TextWrangler, developed by Bare Bones Software, Inc. In my opinion it captures the perfect balance between the simplicity of use and its many powerful functions. It is also free, in comparison to its bigger brother, BBEdit, which comes with even more features.
Both TextWrangler and BBEdit support syntax coloring for a number of programming languages out of the box, but Mathematica is not one of them. This is not a problem though, as you can easily create a so called language module, a property list (file extension .plist) file with syntax coloring specifications for your language of choice that the text editor will recognize.
Of course, the first thing I did when I found out that TextWrangler does not recognize the Mathematica code was go to google to search for the language module. The only useful result was an old blog post with the property list file made long ago in 2004 for Mathematica 5.0. Now, seven years later, Mathematica has more than doubled the number of its built-in functions, so I was not really satisfied with it. Getting the list of all built-in functions in Mathematica is very easy, so I used parts of that deprecated code to create my automatic generator of the property list file that will always be up to date. It's written in Mathematica and it's only required to be run once every time you install a new version of Mathematica. It supports both TextWrangler and BBEdit. I'm releasing property list files for both TextWrangler and BBEdit (built with Mathematica 8.0.4, in case you don't have access to Mathematica or you have an older version) and the notebook with the generator code under the Creative Commons Attribution-ShareAlike License.

Download the files below: