Skip to content

Instantly share code, notes, and snippets.

@JackMorganNZ
Created June 1, 2016 21:06
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JackMorganNZ/6aeb18c74be3765d3d00de0d8c894e32 to your computer and use it in GitHub Desktop.
Save JackMorganNZ/6aeb18c74be3765d3d00de0d8c894e32 to your computer and use it in GitHub Desktop.
Example Python script for creating .png files for LaTeX math equations
import os, requests
def formula_as_file( formula, file):
formula = formula.replace('\n', ' ')
r = requests.get( 'http://latex.codecogs.com/png.latex?\dpi{{300}} {formula}'.format(formula=formula))
print('http://latex.codecogs.com/gif.latex?%5Cdpi%7B300%7D%20%5Cbegin%7Bbmatrix%7D%202%20%26%200%20%5C%5C%200%20%26%202%20%5C%5C%20%5Cend%7Bbmatrix%7D')
print(r.url)
f = open(file, 'wb')
f.write(r.content)
f.close()
formula = """\\begin{bmatrix}
2 & 0 \\\\
0 & 2 \\\\
\\end{bmatrix}"""
formula_as_file(formula, 'example_equation.png')
@JackMorganNZ
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment