-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support typst with manim #3339
Comments
I would guess the problem is not so much for Manim to be able to accept typst-formatted input, since it is only a string. But is there any similar interface for external rendering of typst-formatted text which results in a graphical representation as there is for LaTeX? To give you the basics on how LaTeX in Manim works: you enter your string in a As far as I can see, typst only exists as an online cloud-service with a web-interface, without any standalone, downloadable version or even web-api... Ok, I was mistaken, since I see that there actually seems to be a standalone application in the github repo which you linked... |
@uwezi The linked source code https://github.com/typst/typst has some installation instructions and terminal compilation to pdf. |
As I pointed out at the end I finally figured it out. And the PDF can be converted to SVG (or even PNG) using (I will not argue here that I don't see why
|
I personally find LaTeX to be quite annoying to install. Having a light-weight alternative to LaTeX that succeeds to do most things that LaTeX can also do is why I really like the typst project. Having typst support in manim would make it easier for people who don't have a properly configured LaTeX setup on their machine to use mathematical expressions and also make automated CI setup for manim way easier since installing LaTeX also takes quite some time in CI. Another reason could be performance; but I'm not sure how much LaTeX rendering actually contributes to manim compilation times. |
typst actually has native support for png output and svg output (svg since typst/typst#1729, not released yet) so you don't even need third-party tools to do this. This is my output with your typst file: $ typst compile manim.typ
$ typst compile --ppi 600 manim.typ manim.png
$ typst compile manim.typ manim.svg |
There also seem to be python bindings for typst: |
I don't think that python bindings would be necessary. Running the command line tool on a temporary file just like in the LaTeX case should work perfectly fine. Typst then creates a PDF output which can be read and converted into an SVG stream using pymupdf . from manim import *
import fitz
class test(Scene):
def construct(self):
doc = fitz.open(r"bilder/test.pdf")
page = doc.load_page(0)
svg = page.get_svg_image()
file = open(r"media/20230822_test.svg", "w")
file.write(svg)
file.close()
svgmobj = SVGMobject(r"media/20230822_test.svg").set_color(WHITE).scale_to_fit_width(14)
self.add(svgmobj)
self.add(index_labels(svgmobj).set_color(RED).shift(UR)) The index labels indicate that there is nothing special going on with the conversion of the glyphs, so that later animations should be straightforward. It feels a bit weird that the SVG data has to be written and then read back - but currently there is no Manim object which interprets SVG data which already is in memory and I did not succeed to fake a file input using |
well, I didn't know that - it would make the whole process even simpler and not much of an implementation would be needed. All the pre-processing of LaTeX strings for splitting which does not work reliably could be skipped in my opinion... |
When the Python bindings support direct compilation from a string instead of a file (messense/typst-py#4) I think the Manim implementation could be a bit nicer without the need to write the typst code directly to disk and compiling it afterwards but doing everything in memory. |
🤔 so it's probably possible to do that. One thing i would ask for this is how would you decide on which one to use, because by default we expect Latex to be present on the system for things like the |
I think something like a I would make it somewhat similar to the |
This idea is great. LaTeX is just a bit too complicated and annoying for amateur math lovers... |
Maybe we should consider this, especially since #3523 showed up independently. |
One aspect I didn't see mentioned before is that Typst is easier to (automatically) parse and interface with. With a sufficiently deep integration, this could help (as an example) with those cases where you want to animate a part of a formula, which with TeX requires juggling with substrings and is generally a cumbersome thing to build upon.
|
Are you thinking of some particular Typst functionality that allows this sort of grouping? Working on this is somewhat high on my list of prioirities, and I'd really like to have a robust and well-working implementation for substring mapping. My current intention is to mimic (more or less) the functionality implemented here, which would mean that individual parts of a Typst string would be identified by wrapping them with Typst functions that set different fill colors, then importing the compiled SVG back to Manim and using the fill-colors to group together the parsed objects. I am not sure yet whether we should go the |
Unfortunately, I can't confidently say more about that, having little knowledge of Typst's internals. |
There is a thread on the Discord server related to this. There hasn't been a lot of discussion there yet, but the idea of exposing some primitives to more easily identify particular groups of the SVG output has been floated. |
Thanks, @laurmaedje! I'm following the post; we'll do our homework and come up with a more concrete design for the interface of Typst-rendererd objects on our end. In case we stumble over something that would be useful to have in SVGs generated by Typst I'll chime in there (I don't really see anything like that apart from grouped elements though). ((I've been using Typst somewhat excessively this semester in teaching and I enjoy it quite a bit -- so I'm definitely motivated to implement a nice interface for it within for Manim as well. 😄)) |
Typst integration would be a really nice add-on; as I am moving away from tex towards typst; and currently, using manim would reintroduce tex... |
I've been playing around and managed to write a prototype, if you will, of Typst class. The code is rather ugly, but the idea of how I made the "groups"(can be nested) is that I hid (via #hide in Typst) the desired part and then subtracted it from the whole scene. Here's an example: class Test(Scene):
def construct(self):
frame_ = _Typst(r"""
#{title}[== Introduction]
$ {int}(integral)_0^({u}(1)) x d x = lr(x^2/2|)_0^1 $
""")
frame_['title'].set_color(RED)
frame_['int'].set_color(YELLOW)
frame_['u'].set_color(GREEN)
self.add(frame_) I'm new here, and I'm not sure how good this design is and if it is how to proceed. |
Description of proposed feature
It would be nice to have support for the typst typesetting language next to LaTeX.
https://github.com/typst/typst
How can the new feature be used?
See https://typst.app/docs/reference/math/ for the typst math introduction.
The text was updated successfully, but these errors were encountered: