mgieseki / dvisvgm

A fast DVI, EPS, and PDF to SVG converter
https://dvisvgm.de
GNU General Public License v3.0
306 stars 33 forks source link

Broken TikZ output on macOS #157

Closed davidstraka2 closed 3 years ago

davidstraka2 commented 3 years ago

When an SVG image is generated from a DVI document containing TikZ output, the resulting SVG is missing any shapes but the text, and all the text is aligned to the top of the image with characters overlapping. This is happening specifically on macOS; on Windows and Linux everything seems to be working.

Software versions used: macOS 10.15.7, MacTeX 2021.0328 (comes with dvisvgm 2.11.1)

Commands used:

  1. latex image.tex
  2. dvisvgm --no-fonts image.dvi

The DVI file generated seems to not be the issue, since when the DVI file generated on macOS is copied over to Windows 10 and then the Windows version of dvisvgm (the one included in texlive) is used on that file, the resulting SVG is fine.

TeX source of a simple reproducible example:

\documentclass[tikz]{standalone}
\begin{document}
  \begin{tikzpicture}[]
    \draw (0,0) -- (1,1) node[pos=0.5]{x};
  \end{tikzpicture}
\end{document}

For a comparison of two versions (ok Windows version and broken macOS version) of a more complex SVG (not the one in the simple example above), see the image below.

comparison

A GitHub Actions workflow to generate outputs on macOS and upload job artifacts:

name: CI
on: [push, pull_request]
jobs:
  Test:
    name: Test macOS
    runs-on: macos-10.15
    steps:
      - uses: actions/checkout@v2
      - name: Install MacTex
        run: |
          export HOMEBREW_NO_INSTALL_CLEANUP=1
          brew install --cask mactex
          echo "/Library/TeX/texbin" >> $GITHUB_PATH
      - name: Process image
        run: |
          latex image.tex
          dvisvgm --no-fonts image.dvi
      - name: Archive artifacts
        uses: actions/upload-artifact@v2
        with:
          name: output
          path: |
            image.dvi
            image.log
            image.svg
mgieseki commented 3 years ago

I can't really help with Mac specific issues because I don't have access to one. However, as far as I can tell from the missing graphics elements and the positioning errors shown in the screenshots, it's a Ghostscript related issue. Do you get a warning message from dvisvgm during a conversion that Ghostscript can't be found? Does dvisvgm -V1 list Ghostscript in the output?

davidstraka2 commented 3 years ago

Thanks for the fast reply! You're right about the Ghostscript warning (processing of PostScript specials is disabled (Ghostscript not found), WARNING: 56 PostScript specials ignored. The resulting SVG might look wrong.). I ran both latex and dvisvgm commands at once in CI (as I too don't have a Mac myself) and only looked that the job step finished successfully and skimmed through the log file (where there's only latex output and no dvisvgm output, which I didn't realize), so I completely missed the warning, apologies for that.

The dvisvgm -V1 output confirms that:

dvisvgm 2.11.1
--------------
brotli:    1.0.9
clipper:   6.2.1
fontforge: 20160721
freetype:  2.10.4
kpathsea:  6.3.3
potrace:   1.16
xxhash:    0.8.0
zlib:      1.2.11

Weirdly enough, Ghostscript should be installed since MacTeX depends on it (https://formulae.brew.sh/cask/mactex) and the CI output includes

==> Installing ghostscript
==> Pouring ghostscript--9.54.0.catalina.bottle.tar.gz
🍺  /usr/local/Cellar/ghostscript/9.54.0: 683 files, 149MB

while installing MacTeX using Homebrew.

Perhaps it's not present in PATH and needs to be added? Though that's somewhat confusing to me, since on my Windows 10 there's no Ghostscript in PATH and dvisvgm works fine.

mgieseki commented 3 years ago

Ok, good to hear that it's "only" a Ghostscript issue. If Ghostscript is not linked to the dvisvgm binary, dvisvgm tries to dlopen the GS library when needed which makes the dynamic linker look for it in its search path. Maybe the GS package from Homebrew doesn't update the ld search path and therefore dvisvgm can't find the file. You can use environment variable LIBGS or command-line option --libgs to specify the absolute path of the library file.

davidstraka2 commented 3 years ago

Got it. I also just found the "Why is dvisvgm’s PostScript support disabled on my machine?" in the FAQ, which explains it nicely. Thanks for your help!