Subject: Re: bug#36357: Wrong Ghostscript program name on MS Win

From: Tassilo Horn <[email-masked]>
Date: Wed, 22 Apr 2020 11:05:24 +0200

Arash Esbati <[email-masked]> writes:

Hi again,

> I tend not to agree here as I've seen people who only have
> TeXlive/MikTeX installed on Windows which cater for a minimal
> Ghostscript.  Those people could benefit from the code above.

I think that's a valid argument.  So that's what I would go for.

--8<---------------cut here---------------start------------->8---
@@ -153,14 +153,27 @@ doc-view
   :prefix "doc-view-")
 
 (defcustom doc-view-ghostscript-program
-  (cond
-   ((memq system-type '(windows-nt ms-dos))
-    "gswin32c")
-   (t
-    "gs"))
+  (or
+   ;; Standard Ghostscript
+   (executable-find "gs")
+   ;; Windows Ghostscript
+   (executable-find "gswin64c")
+   (executable-find "gswin32c")
+   ;; The GS wrapper coming with TeX Live
+   (executable-find "rungs")
+   ;; The MikTeX builtin GS Check if mgs is functional for external
+   ;; non-MikTeX apps.  Was available under:
+   ;; http://blog.miktex.org/post/2005/04/07/Starting-mgsexe-at-the-DOS-Prompt.aspx
+   (when-let ((mgs (executable-find "mgs")))
+     (when (= 0 (shell-command
+                 (concat (shell-quote-argument mgs)
+                         " -q -dNODISPLAY -c quit")))
+       mgs))
+   ;; Standard Ghostscript as fallback
+   "gs")
   "Program to convert PS and PDF files to PNG."
   :type 'file
-  :version "27.1")
+  :version "28.1")
--8<---------------cut here---------------end--------------->8---

We should ask ourselves if the order is ok, i.e., if on systems where
multiple gs installs are available, the "best" one gets selected.  So is
it correct to prefer gswin64c over gswin32c and that over rungs and mgs?

Another question: You both used executable-find with exe file extension.
Was that intended?  I mean, it makes sure we don't falsely set some
"gs.bat" or "gs.cmd" which might have nothing to do with GhostScript.
Is that a real danger?  If so, we need the OS distinction again.

Bye,
Tassilo