Skip to content
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

Typst Writer Wrongly Escapes Image Paths #9389

Closed
ljrk0 opened this issue Jan 30, 2024 · 0 comments
Closed

Typst Writer Wrongly Escapes Image Paths #9389

ljrk0 opened this issue Jan 30, 2024 · 0 comments
Labels

Comments

@ljrk0
Copy link

ljrk0 commented Jan 30, 2024

Explain the problem.
When a source file references an external file (in this case an image), Pandoc converts the path to an URI, escaping ' ' with '%20' and so on. Typst expects a "plain" path and thus chokes on the provided URIs.

Given the following mwe.md Markdown file next to a foo bar.png image:

![](foo bar.png)

Then rendering the file to PDF produces the following error, despite foo bar.png being available:

$ pandoc --pdf-engine=typst mwe.md -o mwe.pdf
error: file not found (searched at /private/tmp/mwe/foo%20bar.png)
   ┌─ toPdfViaTempFile37815-0.html:97:40
   │
97 │ #box(width: 3.8528428093645486pt, image("foo%20bar.png"))
   │                                         ^^^^^^^^^^^^^^^

Error producing PDF.

Unescaping the URI characters fixes the issue.

Pandoc version?

$ pandoc --version
pandoc 3.1.11
Features: +server +lua
Scripting engine: Lua 5.4
User data directory: /Users/janis.koenig/.local/share/pandoc
Copyright (C) 2006-2023 John MacFarlane. Web: https://pandoc.org
This is free software; see the source for copying conditions. There is no
warranty, not even for merchantability or fitness for a particular purpose.

Installed via Nix on macOS, but I verified with the main branch in the source code. Compare the following for the Typst Writer:

      let coreImage = "image" <> parens (doubleQuoted src)

with the version for LaTeX

      source' = if isURI source
                   then source
                   else T.pack $ unEscapeString $ T.unpack source

which uses Network.URI (unEscapeString) to remove the URI characters again.

Fix
I currently don't have a Haskell environment here, but I suspect something like this should fix the issue:

+       let src' = if isURI src
+                     then src
+                     else T.pack $ unEscapeString $ T.unpack src
        let coreImage = "image" <> parens (doubleQuoted src')
@ljrk0 ljrk0 added the bug label Jan 30, 2024
@jgm jgm closed this as completed in 9ab0ffb Jan 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant