Skip to content

[ENH]: Support Latex-like math rendering with Typst instead of pdflatex #26098

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

Closed
SeerLite opened this issue Jun 9, 2023 · 4 comments
Closed

Comments

@SeerLite
Copy link

SeerLite commented Jun 9, 2023

Problem

Latex compilers are very slow.

Proposed solution

Typst is orders of magnitude faster than any latex compiler (runs in milliseconds) and has a much easier to use syntax than latex (subjective but I think most agree). I'd like to request support for it as a rendering engine for math in figures.

I'm not sure how rendering is currently done, but here's an example of a 0-margin document with math using typst:

#set page(width: auto, height: auto, margin: 0pt)
$ y = integral_(x_0)^x f(s) d s $

Live preview on typst.app

@oscargus
Copy link
Member

oscargus commented Jun 9, 2023

I doubt that "instead" will ever be the case (too many people rely on and know LaTeX already), but not impossible to add it as an alternative rendering engine. It may want to start as a third-party package though(?).

@ksunden
Copy link
Member

ksunden commented Jun 9, 2023

Typst is still very new and changing rapidly.

I'm not opposed to including it in some way, but think it may not be quite ready for it yet.

Typst currently will only output in pdf or png format (and even the latter just made it into the released version today).

png is not a general solution as preferably text/equations are rendered as vector graphics where possible.

pdf is a complicated enough format that extracting vectors out of it is rather challenging, I believe, making that likely a poor candidate for the intermediate form. perhaps in the narrow case of a single page, single equation as it would be here, it is not too bad, but I don't know.

Much of the internals for Matplotlib TeX rendering is done via DVI currently, so a DVI output from Typst would probably be the easiest to slot in, but perhaps svg or some other (simpler) vector format could work well too.

The other implementation detail that I think may be hard to deal with is background color. We want transparent background, but I was unable (in quick testing) to get Typst to do that. PDF doesn't support a transparent background at all, but PNG should be able to (it still had a white background if I set the fill=rgb("#0000") in the page command. This further precludes PNG from being a usable format, though I think a vector format would be able to extract only the actual content and ignore the background, so probably not actually any more of a blocker than having an extractable vector format.

The ability to have auto sized pages is cool, and may help any Typst implementation avoid some pitfalls of TeX such as #24166 if the bounding box given to us by Typst can be trusted more than the page size of TeX.

@anntzer
Copy link
Contributor

anntzer commented Jun 10, 2023

See also #22715 re: alternate TeX-like engines and #4880 (comment) (and the rest of that issue's thread) re: speed.
I am somewhat tempted to close this issue as a semi-duplicate of #22715 and also as "we'll consider a PR implementing this or moving towards it, but it'll have to come from interested users."

@jklymak jklymak closed this as not planned Won't fix, can't repro, duplicate, stale Jun 10, 2023
@jklymak
Copy link
Member

jklymak commented Jun 10, 2023

Agreed this is basically #22715 and given the state of typst getting something to work that has a parsable dvi-like output seems more likely.

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

No branches or pull requests

5 participants