«

»

Dec 04

LaTeX colorization in Google Docs with AppScript [w/code]

Screen Shot 2013-12-03 at 7.38.53 PMThere's a fantastic way to collaborate when writing an academic paper in LaTeX - using Google Docs. LaTeX is all text anyway, so collaborating over GDocs is straightforward, but alas there is no colorization to make it like a good LaTeX editor... Fortunately there's AppScript to help us!

There is another caveat though, downloading the paper to your computer and compiling it to PDF. Sure there's LatexTab, but ain't no way I'm giving them access to my Google account, let alone to my precious unpublished academic paper! I want a "local" solution (it is already in Google's hands, but... security-in-obscurity is the key to sleeping better), but all I can do is run a local script on the GDoc.
To generate a PDF I wrote a tiny script that downloads the document (needs the sharing URL from GDoc) using Rob Miller's excellent script to the disk and just runs pdflatex (R.Miller does it with make, here it's just bash)

#!/bin/sh
cd "${0%/*}"
python gdoc2latex.py https://docs.google.com/document/d/<<<GDOC_ID>>>/edit?usp=sharing > paper.tex
/usr/texbin/pdflatex paper.tex

exit 0

Colorizing in GDocs

So far I've not seen a way to get an "onEdit" event in G documents (it's available only in spreadsheets) so I'm constrained to running the colorized manually from a menu in the GDoc. But it's not so bad.

Get the GIST here.

Add it to your GDoc by Tools -> Script Manager... -> New.
Then run it to get the new menu to show up, where you can then run the colorization functions.

Enjoy
Roy

Share