Load resources from inside mitex
Tweoss opened this issue · comments
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?
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.
- relative to the
packages/mitex/mitex.typ
file. - or absolute to the package's root, the
packages/mitex/
directory.
See
mitex/packages/mitex/mitex.typ
Line 28 in ae6e2c0
If you uses mitex-convert
, and evaluate the converted code in your typst files, then you can load images.
- relative to your file,
/main.typ
. - or absolute to the root
/
.
#import "/packages/mitex/lib.typ": *
#let res = mitex-convert(mode: "text", read("main.tex"))
#eval(res, mode: "markup", scope: mitex-scope)
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
Ah, lovely! Thank you so much, importing the image and displaying works perfectly now! (as well as json data files)