Skip to content

Instantly share code, notes, and snippets.

@vaiorabbit
Created April 7, 2012 15:53
Show Gist options
  • Save vaiorabbit/2329890 to your computer and use it in GitHub Desktop.
Save vaiorabbit/2329890 to your computer and use it in GitHub Desktop.
Converts math formula (written in TeX language) into PNG file via Google Chart API.
<html>
<head>
<script type="text/javascript">
function reload_formula(tex_math)
{
// Ref.: Comparing escape(), encodeURI(), and encodeURIComponent()
// http://xkr.us/articles/javascript/encode-compare/
document.getElementById("formula_image").src = "https://chart.googleapis.com/chart?cht=tx&chl=" + encodeURIComponent(tex_math);
}
</script>
</head>
<body onload="reload_formula(this.form.formula.value)">
<form id="form">
TeX Formula: <input type="text" name="formula" size="80" onkeyup="reload_formula(this.value)" value="x = \frac{-b\pm\sqrt{b^2-4ac}}{2a}"/>
</form>
<p>
Result: <br />
<img src="" id="formula_image"/>
</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment