Subject: Re: bug#28811: 11.90.2.2017-07-25; preview-at-point

From: Arash Esbati <[email-masked]>
Date: Fri, 03 Nov 2017 23:34:19 +0100

Florian Stecker <[email-masked]> writes:

> I am having the same problem. Since Ghostscript upgraded to 9.22,
> preview-latex stopped working altogether, independent of the
> document. Sometimes I get "Error: /undefined in .runandhide" and
> sometimes "Error: /typecheck in --setfileposition--".
>
> I submitted a bug report to Ghostscript:
>
> https://bugs.ghostscript.com/show_bug.cgi?id=698680
>
> Apparently they removed the .runandhide operator in version 9.22, so
> it is likely that this causes the problem.

Hi Florian,

thanks for the report.  I can confirm that preview-latex does not work
with GS 9.22.  I have the following observation when doing `C-c C-p C-d'
on circ.tex packaged with AUCTeX (on Win10):

a)  When preview-latex invokes the latest `rungs' from texlive2017, I
get no errors, just no snippets to be inserted in Emacs.

b) When preview-latex invokes the latest `gswin64c (set via
`preview-gs-command'), it fails to write a file preview.dsc and gives me
this error:

--8<---------------cut here---------------start------------->8---
Running `Preview-PDF2DSC' with ``pdf2dsc circ.pdf circ.prv/tmp8548-eJ/preview.dsc''
Error: /undefinedfilename in --file--
Operand stack:
   PDFfile   (circ.pdf)   (r)
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--   --nostringval--   --nostringval--   false   1   %stopped_push   2047   1   3   %oparray_pop   2046   1   3   %oparray_pop   2030   1   3   %oparray_pop   1916   1   3   %oparray_pop   --nostringval--   %errorexec_pop   .runexec2   --nostringval--   --nostringval--   --nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:993/1684(ro)(G)--   --dict:0/20(G)--   --dict:80/200(L)--
Current allocation mode is local
Last OS error: No such file or directory
Current file position is 1822
GPL Ghostscript 9.22: Unrecoverable error, exit code 1
--8<---------------cut here---------------end--------------->8---

> It would be great if someone who actually understands what
> preview-latex does could supply them with a sample input file and try
> to work out what to use instead of ".runandhide". Thank you!

Well, the requirement above does not apply to me, but preview-latex uses
`.runandhide' in two places:

--8<---------------cut here---------------start------------->8---
(defun preview-gs-open (&optional setup)
  "Start a Ghostscript conversion pass.
SETUP may contain a parser setup function."
  (let ((image-info (assq preview-image-type preview-gs-image-type-alist)))
    (setq preview-gs-image-type (nth 1 image-info))
    (setq preview-gs-sequence nil)
    (setq preview-gs-command-line (append
				   preview-gs-options
				   (nthcdr 2 image-info))
	  preview-gs-init-string
	  (format "{DELAYSAFER{.setsafe}if}stopped pop\
/.preview-BP currentpagedevice/BeginPage get dup \
null eq{pop{pop}bind}if def\
<</BeginPage{currentpagedevice/PageSize get dup 0 get 1 ne exch 1 get 1 ne or\
{.preview-BP %s}{pop}ifelse}bind/PageSize[1 1]>>setpagedevice\
/preview-do{[count 3 roll save]3 1 roll dup length 0 eq\
{pop}{setpagedevice}{ifelse .runandhide}\
stopped{handleerror quit}if \
aload pop restore}bind def "
		  (preview-gs-color-string preview-colors)))
    (preview-gs-queue-empty)
    (preview-parse-messages (or setup #'preview-gs-dvips-process-setup))))
--8<---------------cut here---------------end--------------->8---

and

--8<---------------cut here---------------start------------->8---
(defun preview-prepare-fast-conversion ()
  "This fixes up all parameters for fast conversion."
  (let* ((file (if (consp (car preview-ps-file))
		   (if (consp (caar preview-ps-file))
		       (car (last (caar preview-ps-file)))
		     (caar preview-ps-file))
		 (car preview-ps-file)))
	 (all-files (if (and (consp (car preview-ps-file))
			     (consp (caar preview-ps-file)))
			(caar preview-ps-file)
		      (list file))))
    (setq preview-gs-dsc (preview-dsc-parse file))
    (setq preview-gs-init-string
	  (concat (format "{<</PermitFileReading[%s]>> setuserparams \
.locksafe} stopped pop "
			  (mapconcat 'preview-ps-quote-filename all-files ""))
		  preview-gs-init-string
		  (format "[%s(r)file]aload exch %s .runandhide aload pop "
			  (preview-ps-quote-filename file)
			  (preview-gs-dsc-cvx 0 preview-gs-dsc))))))
--8<---------------cut here---------------end--------------->8---

@Ken: Sorry for the late response from AUCTeX side, and many thanks for
your offer to resolve this issue.  I'm not familiar enough with PS to
come up with an alternative code.  Do you have a suggestion?  TIA.

Best, Arash