Skip to content

Instantly share code, notes, and snippets.

@farleyknight
Created November 21, 2008 23:39
Show Gist options
  • Save farleyknight/27696 to your computer and use it in GitHub Desktop.
Save farleyknight/27696 to your computer and use it in GitHub Desktop.
require 'mechanize'
module MathUrl
def mathurl_agent
@agent ||= WWW::Mechanize.new
end
def mathurl_img_for(latex)
page = math_url_agent.get("http://mathurl.com")
form = page.forms.first
# You'll probably want to cache this..
form.set_field(:latex => latex || %q{ \sin \frac{\pi}{4} = \frac{\sqrt{2}}{2} })
form.add_field!("make", "make mathURL")
result = form.submit
image_url = result.uri.to_s.gsub("/\?", "/\?img=")
image_tag(image_url)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment