Skip to content

LaTeX writer: remote SVG images with non-.svg URI extensions are not treated as SVGs #10553

@max-heller

Description

@max-heller

Explain the problem.
The LaTeX writer relies on the path extension of an image to determine whether to use \includegraphics or \includesvg:

((if isSVG then "\\includesvg" else "\\includegraphics") <>

This breaks in instances where the URI of an image does not reference .svg. Consider, for instance, the following image:

![](https://img.shields.io/github/actions/workflow/status/jgm/pandoc/ci.yml)

(Rendered: )

Passing this to pandoc yields an error:

$ echo '![](https://img.shields.io/github/actions/workflow/status/jgm/pandoc/ci.yml)' | pandoc -o test.pdf
[WARNING] Could not convert image /private/var/folders/_n/dwfw0_316w554fyv3q9t7m1w0000gn/T/tex2pdf.-7a6e25991b71d6c9/6e49fa4c4ffe43659ba3f4187ea0145ff5768d7a.yml: Cannot load file
  Jpeg Invalid marker used
  PNG Invalid PNG file, signature broken
  Bitmap Invalid Bitmap magic identifier
  GIF Invalid Gif signature : <svg x
  HDR Invalid radiance file signature
  Tiff Invalid endian tag value
  TGA not enough bytes
Error producing PDF.
! LaTeX Error: Unknown graphics extension: .yml.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

l.69 ...fa4c4ffe43659ba3f4187ea0145ff5768d7a.yml}}

Relevant code and possible solutions:

  • When the image is added to the media bag, the .yml extension is preferred over the mimetype.
    ext = case takeExtension path of
    '.':e | '%' `notElem` e -> '.':e
    _ -> maybe "" (\x -> '.':T.unpack x) $ extensionFromMimeType mt

    For remote images, this could be changed to prefer mimetype over any extension contained in the URI, at least if the extension in the URI does not correspond to an image. Then, the image would be stored as ...8d7a.svg and the extension check would be sufficient.
  • The LaTeX writer could check the mimetype of the image in the mediabag instead of checking the extension of the URI:
    let isSVG = ".svg" `T.isSuffixOf` source || ".SVG" `T.isSuffixOf` source

Pandoc version?
pandoc 3.6.1 MacOS

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions