SabrinaJewson / cmarker.typ

Transpile CommonMark Markdown to Typst, from within Typst!
MIT License
17 stars 0 forks source link

Note on the use of images #5

Open Doublonmousse opened 5 months ago

Doublonmousse commented 5 months ago

This is an unfortunate consequence of how eval is used in typst.

When markdown is parsed with the pakage and contains images, the path to find the eval is evaluated relative to the package file, NOT the main file.

When this package is used locally, this might not create any problem as the two files cmarker.typ and main.typ may well be in the same folder.

But for using the package using the package manager, this makes the code fails as the images are searched relative to whichever folder the package is stored. This issue extends to the web app as well.

To circumvent this, you need to defer the eval step and evaluate the converted typst string in the main.typ file.

For example,

#import "@preview/cmarker:0.1.0":* 

#let out = (render(show-source: true,read("simple.md")))
#eval(out.text,mode:"markup")

Will work for a simple markdown file that loads a single image but only calling the render function will not.