Subject: bug#35696: preview-latex does not work under any Emacs themes and bug#35571: 12.1; Changing foreground breaks previews

From: Ikumi Keita <[email-masked]>
Date: Tue, 28 May 2019 15:55:51 +0900

>>>>> David Kastrup <[email-masked]> writes:
> The current code is already a sledgehammer that looks like a "not again"
> approach of evading yet another changed API.  Looking at the history of
> the recommended replacements, I see that the Ghostscript developers
> state that some of those were removed in some Ghostscript versions but
> reinstated.

> So it's conceivable that reverting the last change to these code lines
> is all that it would take to work with current Ghostscript (at the price
> of breaking _some_ older version).

> Might be worth a try.

Thanks for your advice, the attached patch works well.  The foreground
color of the generated image matches with the default face of emacs
without `preview-pdf-color-string', at least for gs 9.27 on my machine.

> (at the price of breaking _some_ older version).

I don't know which version of gs needs `preview-pdf-color-string'.
Maybe we should not delete it and instead introduce a user option as a
flag whether to disable the function or not.  What do others think?

Regards,
Ikumi Keita

>From 1523e06d83996aa020d842328bff4ad91a894c41 Mon Sep 17 00:00:00 2001
From: Ikumi Keita <[email-masked]>
Date: Tue, 28 May 2019 15:21:31 +0900
Subject: [PATCH] Remove walk around for older Ghostscript (bug#35696 and
 bug#35571)

The codes once introduced as walk around for obsolete API now became
incompatible with the current Ghostscript.  So just remove it.

* preview.el.in (preview-pdf-color-string): Remove.
(preview-pdf2dsc-sentinel): Don't use the removed function.
---
 preview.el.in | 16 ----------------
 1 file changed, 16 deletions(-)

diff --git a/preview.el.in b/preview.el.in
index 30bf45bf..594e6e6b 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -742,19 +742,6 @@ Conversion from Emacs color numbers (0 to 65535) in VALUE
 to Ghostscript floats."
   (format "%g" (/ value 65535.0)))
 
-(defun preview-pdf-color-string (colors)
-  "Return a string that patches PDF foreground color to work properly."
-  ;; Actually, this is rather brutal.  It will only be invoked in
-  ;; cases, however, where previously it was not expected that
-  ;; anything readable turned up, anyway.
-  (let ((fg (aref colors 1)))
-    (if fg
-	(concat
-	 "/GS_PDF_ProcSet GS_PDF_ProcSet dup maxlength dict copy dup begin\
-/graphicsbeginpage{//graphicsbeginpage exec "
-	 (mapconcat #'preview-gs-color-value fg " ")
-	 " 3 copy rg RG}bind store end readonly store "))))
-
 (defun preview-gs-color-string (colors)
   "Return a string setting up colors"
   (let ((bg (aref colors 0))
@@ -910,9 +897,6 @@ The usual PROCESS and COMMAND arguments for
 	(cond ((eq status 'exit)
 	       (delete-process process)
 	       (setq TeX-sentinel-function nil)
-	       (setq preview-gs-init-string
-		     (concat preview-gs-init-string
-			     (preview-pdf-color-string preview-colors)))
 	       (preview-prepare-fast-conversion)
 	       (when gsstart
 		 (if preview-gs-queue
-- 
2.21.0