mgieseki / dvisvgm

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

Ghostscript sill not found (macOS) #267

Closed eposse closed 1 month ago

eposse commented 3 months ago

I've ran into the same problems reported in Issues #66, #143, and #157, and also looked at issue #197, but I still get the same error message stating that Ghostscript is not found (macOS) when trying to use dvisvgm with a small file generated from latex:

See attached file at the end.

$ dvisvgm hello.dvi
pre-processing DVI file (format version 2)
processing of PostScript specials is disabled (Ghostscript not found)
processing page 1
  WARNING: 82 PostScript specials ignored. The resulting SVG might look wrong.
  graphic size: 217.409988pt x 145.139999pt (76.410872mm x 51.010876mm)
  output written to hello.svg
1 of 1 page converted in 0.520588 seconds

This happens even after setting LIBGS:

$ export LIBGS=/usr/local/lib/libgs.dylib
$ dvisvgm hello.dvi

or using the --libgs command-line option.

$ dvisvgm --libgs=/usr/local/lib/libgs.dylib hello.dvi

But I get the same result.

Following the FAQ instructions, I can verify this:

$ dvisvgm --help |grep libgs
      --libgs=filename          set name of Ghostscript shared library

so Ghostscript is enabled, which according to the FAQ, means that the library should link at runtime. But

$ dvisvgm -V1 --libgs=/usr/local/lib/libgs.dylib
dvisvgm 3.2.2 (x86_64-apple-darwin18.7.0)
-----------------------------------------
brotli:   1.1.0
clipper:  6.2.1
freetype: 2.13.2
kpathsea: 6.4.0
mutool:   1.23.11
potrace:  1.16
xxhash:   0.8.2
zlib:     1.3.1

So no Ghostscript there.

$ dvisvgm -l
bgcolor    background color special
color      complete support of color specials
dvisvgm    special set for embedding raw SVG snippets
em         line drawing statements of the emTeX special set
html       hyperref specials
papersize  special to set the page size
pdf        PDF hyperlink, font map, and pagesize specials
tpic       TPIC specials

And no ps here either.

This is dvisvgm that was bundled with MacTeX 2024. When installing it I made sure to install Ghostscript and its libraries:

$ gs --version
10.03.0
$ ls -la /usr/local/lib/ |grep libgs
lrwxr-xr-x   1 root  wheel       58 19 Mar 18:36 libgs.10.00.dylib -> /usr/local/share/ghostscript/10.00.0/lib/libgs.dylib.10.00
lrwxr-xr-x   1 root  wheel       58 25 Mar 22:45 libgs.10.03.dylib -> /usr/local/share/ghostscript/10.03.0/lib/libgs.dylib.10.03
lrwxr-xr-x   1 root  wheel       58 25 Mar 22:45 libgs.10.dylib -> /usr/local/share/ghostscript/10.03.0/lib/libgs.dylib.10.03
lrwxr-xr-x   1 root  wheel       58 25 Mar 22:45 libgs.dylib -> /usr/local/share/ghostscript/10.03.0/lib/libgs.dylib.10.03

I even tried manually adding /usr/local/lib to LD_LIBRARY_PATH, DYLD_LIBRARY_PATH and DYLD_FALLBACK_LIBRARY_PATH without effect.

Why is dvisvgm not detecting the library?

I'm on macOS Sonoma 14.4.1.

The source LaTeX file is here: hello.txt. I changed the extension to .txt as it didn't allow me to upload a .tex file.

GitHub won't let me upload the .dvi file, but I generated it from the file above with

$ latex hello.tex

(after renaming hello.txt to hello.tex, of course).

I appreciate any help. Thanks.

muzimuzhi commented 3 months ago

Tested on macOS 13.6.5, dvisvgm v3.2.2 automatically detects ghostscript v10.03.0 installed by Homebrew. No LIBGS environment variable nor --libgs option is needed.

mgieseki commented 3 months ago

Thank you @muzimuzhi for testing this. I still don't have access to a Mac and can't provide much help.

Option --libgs and variable LIBGS probably don't work because of the more strict security measures introduced in recent macOS versions. That's why path /usr/local/lib is now hardcoded in dvisvgm to lookup the GS library on Mac. Maybe Sonoma introduced even more restrictions that prevent loading the library. That would have to be investigated by someone on a corresponding system, though.

eposse commented 3 months ago

Ok, I did a bit more experimenting, and I have now some success.

First, I tried installing dvisvgm with MacPorts (I don't have Homebrew, and it's a bad idea having both Homebrew and MacPorts installed at the same time). It looks like this version comes with the Ghostscript library statically linked:

dvisvgm -V1
dvisvgm 3.1.2 (x86_64-apple-darwin23.2.0)
-----------------------------------------
brotli:      1.1.0
clipper:     6.2.1
freetype:    2.13.2
Ghostscript: 10.03.0
kpathsea:    6.3.5
mutool:      1.23.11
potrace:     1.16
xxhash:      0.8.2
zlib:        1.3.1

Note that it is older than the version included by MacTeX, which is 3.2.2.

But when I ran dvisvgm, I got a lot of kpathsea errors:

dvisvgm hello.dvi
warning: kpathsea: /opt/local/share/texmf-local/ls-R: No usable entries in ls-R.
warning: kpathsea: See the manual for how to generate ls-R.
warning: kpathsea: /opt/local/etc/texmf/ls-R: No usable entries in ls-R.
warning: kpathsea: See the manual for how to generate ls-R.
warning: kpathsea: /opt/local/var/db/texmf/ls-R: No usable entries in ls-R.
warning: kpathsea: See the manual for how to generate ls-R.
warning: kpathsea: /opt/local/share/texmf/ls-R: No usable entries in ls-R.
warning: kpathsea: See the manual for how to generate ls-R.
warning: kpathsea: /opt/local/share/texmf-texlive/ls-R: No usable entries in ls-R.
warning: kpathsea: See the manual for how to generate ls-R.
WARNING: map file ps2pk.map not found
WARNING: map file pdftex.map not found
WARNING: map file dvipdfm.map not found
WARNING: map file psfonts.map not found
WARNING: none of the default map files could be found
pre-processing DVI file (format version 2)
WARNING: PostScript header file tex.pro not found
WARNING: PostScript header file texps.pro not found
WARNING: PostScript header file special.pro not found
WARNING: PostScript header file color.pro not found
PostScript error: undefined in TeXDict

Apparently that version of dvisvgm doesn't play well with the TeXlive version installed by MacTeX, as the tree structures are in different directories, usually under /usr/local/ whereas MacPorts installs on /opt/local.

I started to try to do symlinks from the expected /usr/local/ TeX folders to the ones in /opt/local/ but realized that the directory structure doesn't match, so that would be a bit of a mess.

Instead, I installed the minimal variant of texlive provided by MacPorts, and that works. Well, it performs the conversion without errors, and even produces the correct output for a TikZ picture, but the output is not exactly as I expected. Nevertheless, that's a separate issue.

So the workaround is not to use MacTeX, but use either the MacPorts or the HomeBrew versions of TeX and dvisvgm.

mgieseki commented 1 month ago

Since the issue seems to be solved with a workaround, I'm closing this ticket. Feel free to reopen it if necessary.