From 62524279e8a4e69b17f775079764d04151ec6378 Mon Sep 17 00:00:00 2001 From: Vincenzo Mantova Date: Tue, 23 Aug 2022 15:57:57 +0100 Subject: [PATCH] find ghostscript executable on Windows --- lib/LaTeXML/Post/LaTeXImages.pm | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/lib/LaTeXML/Post/LaTeXImages.pm b/lib/LaTeXML/Post/LaTeXImages.pm index 08290bd51..379f09d3a 100644 --- a/lib/LaTeXML/Post/LaTeXImages.pm +++ b/lib/LaTeXML/Post/LaTeXImages.pm @@ -102,15 +102,17 @@ sub new { $$self{dvicmd_output_name} = 'imgx-%03d.png'; $$self{dvicmd_output_type} = 'png32'; } else { + # will run dvips before $$self{dvicmd} $$self{use_dvips} = 1; # GS options: # -q : quiet - # -sDEVICE=png16malpha : set output to 32-bit RGBA PNG + # -sDEVICE=pngalpha : set output to 32-bit RGBA PNG # -r : resolution # -dGraphicAlphaBits=4 : subsample antialiasing # -dTextAlphaBits=4 : subsample antialiasing # -dSAFER -dBATCH ... : suppress interactivity and enable security checks - $$self{dvicmd} = "gs -q -sDEVICE=pngalpha -r$$self{DPI}" . + # dvicmd will be filled by canProcess with the available ghostscript executable + $$self{dvicmd_opts} = "-q -sDEVICE=pngalpha -r$$self{DPI}" . " -dGraphicsAlphaBits=4 -dTextAlphaBits=4 -dSAFER -dBATCH -dNOPAUSE" . " -sOutputFile=imgx-%03d.png"; $$self{dvicmd_output_name} = 'imgx-%03d.png'; @@ -125,9 +127,13 @@ sub new { # is even needed. # This test is called once we know that, from within # +# NOTE: the test MUST be called if using ghostscript in order to find the +# correct executable on Windows. +# # At any rate: To process LaTeX snippets into images, we will need # * latex (or related) from a TeX installation # * Image::Magick (or similar) [see LaTeXML::Util::Image] +# * dvips and ghostscript if not using dvipng, dvisvgm sub canProcess { my ($self) = @_; # Check if we have Image::Magick (or similar) @@ -142,6 +148,23 @@ sub canProcess { "No latex command ($LATEXCMD) found; Skipping.", "Please install TeX to generate images from LaTeX"); return; } + # likewise for dvips and gs, if necessary + if ($$self{use_dvips}) { + if (!which('dvips')) { + Error('expected', 'dvips', undef, + "No dvips command found; Skipping.", + "Please install dvisvgm, dvipng, or dvips and ghostscript to generate images from LaTeX"); + return; } + else { + # find ghostscript executable + my @gscmd = grep { which $_ } ($^O eq 'MSWin32' ? ('gswin64c', 'gswin64', 'gswin32c', 'gswin32', 'mgs') : ('gs')); + if (@gscmd) { + $$self{dvicmd} = $gscmd[0] . ' ' . $$self{dvicmd_opts}; } + else { + Error('expected', 'gs', undef, "No ghostscript executable (" + . ($^O eq 'MSWin32' ? 'gswin64c, gswin64, gswin32c, gswin32, mgs' : 'gs') + . ") found; Skipping.", "Please install ghostscript to generate images from LaTeX"); + return; } } } return 1; } #**********************************************************************