A Sublime Text plugin for the careless

So after close to a year of procrastinating, I finally made the code that I had written about back in June last year into a plugin for sublime text 2. The plugin basically checks for a couple of mistakes that are commonly made in latex by me and hopefully other people who forget to title case titles and put spaces after punctuations. On running the command, the plugin highlights each mistake and suggests a replacement which can be accepted or rejected by the user with a single key press. IF you’re actually reading this post, do feel free to check it out at https://github.com/vaisaghvt/CheckTypos .

The process of making it into a plugin was quite straightforward since my original script was in python. After some help from the excellent NetTuts tutorial and some help from some of the existing plugins and obviously the API I had the plugin working. About 10 lines of JSON later, I had an option in the tools menu, a key mapping for mac, linux and windows and a command in the command palette.  Seriously, I’ve no idea why I waited for so long.


p.s. It’s now available in package control as CheckTypos plugin. Love how that things works.

Regex + Python to clean up my writing

After shifting to using latex (with sublime text) for writing, one of the things I’ve found rather irritating is correcting the silly mistakes I keep making. These are things like accidentally putting two spaces adjacent to each other, repeating phrases and forgetting to capitalize letters in the right places. Word used to make things easier with it’s spell check. There is a dictionary in sublime text but it works only for spelling mistakes and those aren’t always the problem. Checking the PDF and going through them looking for mistakes was obviously quite irritating.

Initial Solution

It was around this time I made a list of standard regexes that I could search for and replace using sublime text’s in built search. I put these in my sublime text latex cheatsheet for easy access. I’d just copy these from the cheat sheet and paste into the search bar and fix each error as I saw it. Obviously quite time consuming. I intended on automating this with some sort of script but just never got around to doing it. With all the other checks I had to do like whether the text appeared in a comment or an equation block or something. I had no clue how to do this in a simple bash script.

Python To the Rescue

It was at this time I was reading about someone using regexes in Python and I realised this would be an interesting way to improve my limited python skills and do something useful. And I set about making a python script that checks for the common mistakes I make (the regexes in my cheatsheet) and makes the appropriate suggestions for replacements and updates the file.

Adding new regex patterns and ways in which it has to be replaced is as simple as writing a simple function and adding a line to the list of patterns to be tested. I still need to do some basic testing on it and add more patterns but I’ve put the code up on GitHub already (link) and would be extremely grateful to anyone who checks it and gives any suggestions. I will update the Readme file and comment my code very soon (seriously.. i will ).

Finally, using the idea of functions being first class members in python for the first time was super interesting and super useful. Gives a hint of some of the biggest limitations of java; and a brilliant rant by Steve Yegge on java and functional programming: http://steve-yegge.blogspot.sg/2006/03/execution-in-kingdom-of-nouns.html.

Sublime Text Latex Cheat Sheet

(Scroll to bottom for the pdf cheat sheets) 

The quest for efficiency

I’ve been looking around a good editor for latex ever since I started using latex.

When I had this problem when I initially started using Latex during my FYP, I settled for WinEdt which seemed to be the most popular one out there. Since I had to finish my FYP report quickly (I had about a week to setup and learn latex and write my report in it), I didn’t bother experimenting with different editors. The problem for me with latex on windows was that it took me a really long time to set everything up. And for some reason, I couldn’t typeset my tex files into pdf within winedt. I’ve heard this is possible now. I’m not sure if I just never figured it out or the feature wasn’t available in earlier versions.

In any case, once I started PhD and more specifically when I was about to start my confirmation report, there were whole new complications. I had a mac at home and a pc in the lab. I would need to work on my report at both places. I could use Winedt or some such on Windows and TexShop or TexWorks on OSX. But I really didn’t like either of these apps and I wanted to learn to properly use one powerful text editor so that I could work better. So I did a check online and the most fanatical text editor ppl were ppl who used Vim or Emacs. I started using Emacs . Not entirely sure why, but I guess it’s because I found a windows version of emacs and because I heard of Aquamacs for the mac. Within a day or two, I realised that this would be pointless for me. For one, I like using my trackpad and mouse and I like having a proper GUI regardless of how powerful the app can be without it. Moving the cursor in the app was itself a pain, so I didn’t really want to do much more. I was sure there must be some modern text editor that I can use to do all the stuff I need without having to waste so much of my time trying to learn Emacs. I mean, there had to be something better than notepad++ and Textwrangler that was also free.

Sublime Text 2

That’s about when I came across Sublime Text (http://www.sublimetext.com/). It’s powerful, beautiful, has a lot of customizable key bindings, plugin development opportunities (using Python) and most usefully at that point of time it was cross platform. And yep, it was completely free. You could choose to donate to the developer (Jon Skinner) to a licensed version. However, the unlicensed version did all that the licensed version did but with an annoying pop up that comes up at every 10th save or something.

I use it generally for C/C++, python, xml, html and latex. You can use it for all sorts of things. The app also has a console which can be used for doing all sorts of things. For one, when working with python you can actually compile your files and run them from Sublime Text itself. Please take a look at the website for their features. There seems to be a lot of activity on the plugin and package development front over the last few months.

To start installing and discovering packages. First install Sublime Text 2  (http://www.sublimetext.com/2) and then install package control (http://wbond.net/sublime_packages/package_control). And voila! Installing and discovering packages becomes as easy as taking candy from a baby.

Now to start using latex on sublime, you’ll want to install the latexTools package (http://tekonomist.wordpress.com/about/). It provides all sorts of features to you including forward and inverse search, wrapping text in environments and commands, auto completion of references, etc. Combined with the shortcut keys provided by Sublime Text and Papers2’s Manuscripts I have now an Amazing setup for writing my papers. Things have never been easier.

But to actually make full use of these, a cheat sheet is absolutely essential. So I’ve created a pdf of key bindings in sublime and latex tools that’ll be most useful for anyone using sublime for latex.

Cheat sheet:

Windows:  sublimelatexsheet – Windows (p.s. any and all suggestions are welcome)

Mac : sublimelatexsheet -Mac

Tex files for cheat sheet: Tex source files for cheat sheet

*Edit : added some regular expressions that I use for checking to the cheatsheet.

*Edit: Changed for new plugin settings
Update: Installing and updating latextools is a lot easier now. And the plugin is a lot more awesome now. I don’t even need Paper’s manuscripts (which is available now in windows also). Most of this article is old but the latex tools plugin is still updated as of Oct. 24 2012.

*Edit: For updated regexes and a plugin to use these in sublime text please refer to my newer post : https://vaisaghvt.wordpress.com/2013/04/17/a-sublime-text-plugin-for-the-careless/