jupyter-book / mystmd

Command line tools for working with MyST Markdown.
https://mystmd.org/guide
MIT License
191 stars 62 forks source link

Change `convert` to `magick` to support Windows: SVG images cause PDF export to fail #290

Open riziles opened 1 year ago

riziles commented 1 year ago

What version of mystjs are you using?

0.1.17

How did you install myst?

npm

What operating system are you using?

Windows

Which area is this feature request for?

Export: LaTeX or PDF

Describe the Bug

Running myst build --pdf fails if MyST document contains SVG images. Following error message is displayed:

Could not convert from SVG to PNG: 
_build\temp\mystmqG4xb\images\aaecccbb623db43cfbe1b76430ef9e1b.svg 
- Error: Command failed: convert -density 600  -colorspace RGB 
- _build\temp\mystmqG4xb\images\aaecccbb623db43cfbe1b76430ef9e1b.svg 
- _build\temp\mystmqG4xb\images\aaecccbb623db43cfbe1b76430ef9e1b.png
Invalid Parameter - 600

Expected Behavior

An exported PDF document.

To Reproduce

sample-doc.md:

---
exports:
  - format: pdf
---

# SVG Export Test

```{figure} https://myst-parser.readthedocs.io/en/latest/_static/logo-wide.svg
---
name: svg-export-test
---
SVG MyST Logo

This is a test

rowanc1 commented 1 year ago

Thanks @riziles for the report! We will take a look and get back to you soon!

riziles commented 1 year ago

FYI, I signed up for a paid Curvenote account, and I'm able to export docs with SVGs beautifully from the Curvenote website. However if I use the Curvenote CLI and try to do it locally, I receive the same error message, so I'm guessing it must be either a Windows issue or something specifically wrong with my local setup.

rowanc1 commented 1 year ago

@fwkoch has been redoing all of the image exports in #317 based on thinking through some of this.

Can you run, to see if it is a version mismatch?

convert --version
riziles commented 1 year ago

Error message is Invalid drive specification. . FYI, my workaround of exporting the SVGs to PDF and just using those still works fine AND it keeps the images from getting rasterized.

riziles commented 1 year ago

convert --version

@rowanc1 , I am a little puzzled by this request. As far as I can tell, convert is a Windows system command to convert file systems on your hard drive. What does it have to do with rendering SVGs?

fwkoch commented 1 year ago

Hey @riziles - on unix systems, convert can be used for imagemagick - not so much for Windows! However, the recommended cross-platform command for imagemagick is magick - I'll update the CLI to use that.

Before getting too ahead of myself though, can you give it a try and make sure it works - ensure imagemagick is installed, then:

magick -density 600 -colorspace RGB input.svg output.png
riziles commented 1 year ago

Unfortunately it's not possible. ImageMagick requires admin rights to install, and I don't have 'em.

riziles commented 1 year ago

@fwkoch , quick update: there is a portable version on the ImageMagick website. I downloaded that, extracted it, added the folder to my user path list and was able to successfully run the command above. That said, if the proposed solution is just to convert the SVGs to PNGs please don't do that on my account. I'd rather stick with my current workaround of converting them to PDF instead.

riziles commented 1 year ago

WAIT @rowanc1 / @fwkoch ! I just added Inkscape's bin folder to my Windows path list and all my errors went away and the fully vectorized SVGs are showing up beautifully in my PDF.

rowanc1 commented 1 year ago

We are adding some better docs on this in #317 (see below). We still need to actually change convert to magick to ensure that it actually works on Windows. I have updated the issue title as we narrow this down!

Franklin also added support for wildcard extensions (#304) which can be used for explicit export targets for various different platforms (e.g. a gif for web, and a pdf for latex).

image

image-translation

riziles commented 1 year ago

convert to magick

@rowanc1 , why not stick with Inkscape instead of ImageMagick? They look so much better with Inkscape.

fwkoch commented 1 year ago

@riziles - Inkscape will still be the preferred conversion library for SVGs, if the user has it installed. (Inkscape handles vectors nicely, imagemagick always rasterizes images during conversion 😞 )

Updating convert -> magick will just allow a user without inkscape to convert their images (imagemagick is also used for non-vector images, e.g. gif/tiff/etc. - we don't want these to fail on windows).

I think along with changing convert -> magick we should:

rowanc1 commented 2 months ago

Note that the first part of this is going to be merged with #1388.