chiark / gitweb /
latex2svg: work around dvisvgm < 3.0 not detecting ghostscript 10.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 2 Mar 2023 12:38:11 +0000 (13:38 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 2 Mar 2023 12:38:11 +0000 (13:38 +0100)
The latex stack and everything around it is ... interesting. A huge pile
of stuff that randomly breaks in very silent and non-obvious ways, and
it's all so huge and complicated that even distro package maintainers
have no way to know if the packages are mutually compatible.

Now that I figured this out, I still need to comment on that ArchLinux
bug.

plugins/latex2svg.py

index 95a5612206658e594822692e96e907f47020e0a3..f2f3e1e09b00d8452a73bb5c6ded7fe681dd0cff 100755 (executable)
@@ -48,8 +48,8 @@ default_params = {
     'libgs': None,
 }
 
-
-if not hasattr(os.environ, 'LIBGS') and not find_library('gs'):
+libgs = find_library('gs')
+if not hasattr(os.environ, 'LIBGS') and not libgs:
     if sys.platform == 'darwin':
         # Fallback to homebrew Ghostscript on macOS
         homebrew_libgs = '/usr/local/opt/ghostscript/lib/libgs.dylib'
@@ -57,7 +57,20 @@ if not hasattr(os.environ, 'LIBGS') and not find_library('gs'):
             default_params['libgs'] = homebrew_libgs
     if not default_params['libgs']:
         print('Warning: libgs not found')
-
+# dvisvgm < 3.0 only looks for ghostscript < 10 on its own, attempt to supply
+# it directly if version 10 is found. Fixed in
+# https://github.com/mgieseki/dvisvgm/commit/46b11c02a46883309a824e3fc798f8093041daec
+# TODO remove once https://bugs.archlinux.org/task/76083 is resolved and
+# there's no other similar case in other distros
+elif '.so.10' in str(libgs):
+    # Just winging it here, there doesn't seem to be an easy way to get the
+    # actual full path the library was found in -- ctypes/util.py does crazy
+    # stuff like invoking gcc (!!) to get the library filename.
+    libgs_absolute = os.path.join('/usr/lib', libgs)
+    if os.path.exists(libgs_absolute):
+        default_params['libgs'] = libgs_absolute
+    else:
+        raise RuntimeError('libgs found, but is not in ' +  libgs_absolute)
 
 def latex2svg(code, params=default_params, working_directory=None):
     """Convert LaTeX to SVG using dvisvgm.