Script for Math drawing — April 29, 2013

Script for Math drawing

Here is a quick and dirty script for drawing math pictures I use when solving problems. An example picture:

Usually I use this script attached to a hotkey in conjunction with pinta (basically MS paint) on linux. It gives a prompt where you can enter latex. Then it puts the latex into your clipboard as a png file so you can paste it into paint. The end result? paint with latex. The reason I wrote this is because the inkscape / latex plugin I used to use was too resource heavy and slow for when solving problems.

Script:
#!/usr/bin/lua
a = io.popen(“zenity –entry”):read(“*a”)
b = string.gsub(a, “\n”, “”)
os.execute(“/home/andrew/mathtex.cgi \””..b..”\” -o textmp”)
os.execute(“python /home/andrew/imgclipLatex.py”)

Also you will need imgclipLatex.py (I found the bulk of this script somewhere else on the web a long time ago and have forgotten the source):
#! /usr/bin/python

import pygtk
pygtk.require(‘2.0’)
import gtk
import os
import sys

def copy_image(f):
assert os.path.exists(f), “file does not exist”
image = gtk.gdk.pixbuf_new_from_file(f)

clipboard = gtk.clipboard_get()
clipboard.set_image(image)
clipboard.store()

copy_image(“/home/andrew/textmp.png”);