Skip to content

Instantly share code, notes, and snippets.

@uwezi
Last active October 18, 2023 22:01
Show Gist options
  • Save uwezi/8144626910d97948f6ff7170cbb60ebf to your computer and use it in GitHub Desktop.
Save uwezi/8144626910d97948f6ff7170cbb60ebf to your computer and use it in GitHub Desktop.
[Download font] On-the-fly downloading a font for LaTeX. #manim #latex #tex #fontspec #font #download #requests #xetex
class smileyFont(Scene):
def construct(self):
import requests
import zipfile
import re
import io
from pathlib import Path
a=requests.get("https://github.com/atelier-anchor/smiley-sans/releases/download/v1.1.1/smiley-sans-v1.1.1.zip")
z = zipfile.ZipFile(io.BytesIO(a.content))
font_names = [name for name in z.namelist() if re.search('\.ttf$|\.otf$', name)]
print(font_names)
z.extractall(path="./fonts", members=font_names)
for i,font_name in enumerate(font_names):
MyTexTemplate = TexTemplate(
tex_compiler="xelatex",
output_format='.xdv',
)
MyTexTemplate.add_to_preamble(rf"\usepackage{{fontspec}}\setmainfont{{{font_names[1]}}}[Path=./fonts/]")
tex = Tex(
r"得意黑 abc",
tex_template=MyTexTemplate,
color = BLUE,
).scale(2).move_to([0,3-i,0], aligned_edge=LEFT)
self.add(tex)
fname = Text(font_name, font_size=36).move_to([0,3-i,0], aligned_edge=RIGHT)
self.add(fname)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment