Created
June 1, 2016 21:06
-
-
Save JackMorganNZ/6aeb18c74be3765d3d00de0d8c894e32 to your computer and use it in GitHub Desktop.
Example Python script for creating .png files for LaTeX math equations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adapted from http://jamesgregson.blogspot.co.nz/2013/06/latex-formulas-as-images-using-python.html