chiark / gitweb /
latex2svg: more robust handling of libgs not being found.
authorVladimír Vondruš <mosra@centrum.cz>
Thu, 2 Mar 2023 12:34:20 +0000 (13:34 +0100)
committerVladimír Vondruš <mosra@centrum.cz>
Thu, 2 Mar 2023 12:34:20 +0000 (13:34 +0100)
Instead of just looking it up upfront and then hoping for the best,
verify also that dvisvgm actually detected and used it. Because it not
always does, in particular with versions < 3.0 and ghostscript 10.

plugins/latex2svg.py

index ea6d3ab5538aa086e969979c6b2657b44016cf99..95a5612206658e594822692e96e907f47020e0a3 100755 (executable)
@@ -143,6 +143,13 @@ def latex2svg(code, params=default_params, working_directory=None):
             return None
 
     output = ret.stderr.decode('utf-8')
+
+    # Since we rely on Ghostscript to give us a "depth" (= vertical alignment)
+    # value, dvisvgm not using it means the output would be broken and it makes
+    # no sense to continue.
+    if 'Ghostscript not found' in output:
+        raise RuntimeError('libgs not detected by dvisvgm, point the LIBGS environment variable to its location')
+
     width, height = get_size(output)
     depth = get_measure(output, 'depth')
     return {'svg': svg, 'depth': depth, 'width': width, 'height': height}