mitex-rs / mitex

LaTeX support for Typst, powered by Rust and WASM. https://mitex-rs.github.io/mitex/
https://mitex-rs.github.io/mitex/tools/underleaf.html
Apache License 2.0
240 stars 8 forks source link

Load resources from inside mitex #123

Closed Tweoss closed 5 months ago

Tweoss commented 5 months ago

Is it possible to load an image in a iftypst block?

I've been able to use typst.ts with mapShadow in the browser to render images. However, when I try to put this image in a iftypst block, I get a "failed to load file (access denied)", trace: [Call(Some("mimath"))], hints: ["cannot read file outside of project root" error.

It seems to me that the web demo is able to import both a bibliography and another template file. However, I cannot figure out where inpackages/mitex-web/src this virtual file system is handled. It appears that there is a VFS for the sidebar directory view, but I cannot tell how this integrates with mitex. Is there some documentation on this?

Myriad-Dreamin commented 5 months ago

How does your typst-side template look like?

There is a long-term issue (feature) in typst, that typst will resolve the path inside of a eval relative to the "eval site".

If you use mimath/mitext, whose the "eval site" is inside of the mitex package, then iftypst block can only read files inside of the mitex package.

See https://github.com/mitex-rs/mitex/blob/ae6e2c04cca8f66e2da9b49f1900287380a8794e/packages/mitex/mitex.typ#L28

If you uses mitex-convert, and evaluate the converted code in your typst files, then you can load images.

#import "/packages/mitex/lib.typ": *

#let res = mitex-convert(mode: "text", read("main.tex"))
#eval(res, mode: "markup", scope: mitex-scope)
Myriad-Dreamin commented 5 months ago

It seems to me that the web demo is able to import both a bibliography and another template file.

The web demo is exactly using the trick here:

https://github.com/mitex-rs/underleaf/blob/main/fixtures/underleaf/ieee/main.typ

Tweoss commented 5 months ago

Ah, lovely! Thank you so much, importing the image and displaying works perfectly now! (as well as json data files)