Last active
December 29, 2021 11:38
-
-
Save weskerfoot/0ea80a377e27276256a96f1d14307719 to your computer and use it in GitHub Desktop.
This file contains 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
#! /usr/bin/env python | |
import requests | |
import cairosvg | |
import click | |
from io import BytesIO | |
from PIL import Image as PILImage | |
from urllib.parse import quote | |
from pixcat import Image | |
def get_png(tex): | |
url = "https://render.githubusercontent.com/render/math?math={0}".format(quote(tex)) | |
textimage = PILImage.open(BytesIO(cairosvg.svg2png(bytestring=requests.get(url).content))) | |
background = PILImage.new('RGBA', textimage.size, (255,255,255)) | |
alpha_composite = PILImage.alpha_composite(background, textimage) | |
return alpha_composite | |
@click.command() | |
@click.option("--tex", help="The LaTeX stuff you want to render") | |
def write_text(tex): | |
png = get_png(tex) | |
Image(png).fit_screen(enlarge=True, h_margin=10, v_margin=10).show() | |
# write_text(r"""\[\begin{bmatrix}A_x \\A_y\end{bmatrix}.\begin{bmatrix}B_x \\B_y\end{bmatrix}=(A_x)(B_x)+(A_y)(B_y)\]""") | |
if __name__ == "__main__": | |
write_text() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment