chiark / gitweb /
latex2svg: restrict the libgs workaround to dvisvgm < 3.0.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 22 Feb 2024 15:09:20 +0000 (16:09 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 22 Feb 2024 15:09:20 +0000 (16:09 +0100)
On newer versions this isn't needed, and the hardcoded paths aren't
always enough. So better to just not try at all.

plugins/latex2svg.py

index 2df47865496d80cceae903292385667fc1a73138..e4a5c520435c24f8f5eb5438cfc46f7edcd0dc88 100755 (executable)
@@ -64,21 +64,34 @@ if not hasattr(os.environ, 'LIBGS') and not libgs:
 # 2023, remove after enough time passes if no similar case happens in other
 # distros
 elif '.so.10' in str(libgs):
+    # If dvisvgm seems to be at least 3.0, don't even attempt to find libgs and
+    # just assume it works
+    dvisvgm_is_new_enough = False
+    try:
+        ret = subprocess.run(['dvisvgm', '--version'], stdout=subprocess.PIPE)
+        if b'dvisvgm 3' in ret.stdout:
+            dvisvgm_is_new_enough = True
+    except:
+        pass
+
     # 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.
     #
     # On Arch /usr/lib64 is a symlink to /usr/lib, so only the former is
     # needed; on Fedora it's two distinct directories and libgs is in the
-    # latter (ugh).
-    prefixes = ['/usr/lib', '/usr/lib64']
-    for prefix in prefixes:
-        libgs_absolute = os.path.join(prefix, libgs)
-        if os.path.exists(libgs_absolute):
-            default_params['libgs'] = libgs_absolute
-            break
-    else:
-        raise RuntimeError('libgs found by linker magic, but is not in {}'.format(' or '.join(prefixes)))
+    # latter (ugh). Elsewhere it might be /usr/lib/x86_64-linux-gnu or just
+    # anything else, so let's just bet that dvisvgm is 3.0+ in most cases and
+    # this gets hit only very rarely.
+    if not dvisvgm_is_new_enough:
+        prefixes = ['/usr/lib', '/usr/lib64']
+        for prefix in prefixes:
+            libgs_absolute = os.path.join(prefix, libgs)
+            if os.path.exists(libgs_absolute):
+                default_params['libgs'] = libgs_absolute
+                break
+        else:
+            raise RuntimeError('libgs found by linker magic, but is not in {}'.format(' or '.join(prefixes)))
 
 def latex2svg(code, params=default_params, working_directory=None):
     """Convert LaTeX to SVG using dvisvgm.