>>>>> David Kastrup <[email protected]> writes:
>>> The test would be something like
>>
>>> /GS_PDF_ProcSet where { pop [put old code here] } if
>>
>> Do you mean that the patch listed below should work?
> No. The brackets in [put old code here] were part of the description,
> not of the code.
Thanks, but the code without those brackets as listed below still gives
the same error for me.
I'm now working on a slightly different approach attached with this
message. The option `preview-pdf-color-adjust-method' determines the
way how preview-latex works:
(1) New method using DELAYBIND
Good for gs > 9.27
Fail with gs <= 9.27
(2) Traditional method
Good for gs < 9.27
Fail with gs >= 9.27 if foreground color isn't trivial
(3) Fixed "black on white" appearance
Fallback for gs 9.27 with non-trivial foreground color
Regards,
Ikumi Keita
----- failed patch --------------------------------------------------
diff --git a/preview.el.in b/preview.el.in
index 30bf45bf..cbfeaf11 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -750,10 +750,12 @@ to Ghostscript floats."
(let ((fg (aref colors 1)))
(if fg
(concat
+ "/GS_PDF_ProcSet where { pop "
"/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 "))))
+ " 3 copy rg RG}bind store end readonly store "
+ "} if "))))
(defun preview-gs-color-string (colors)
"Return a string setting up colors"
----------------------------------------------------------------------
diff --git a/preview.el.in b/preview.el.in
index 30bf45bf..7d043d1e 100644
--- a/preview.el.in
+++ b/preview.el.in
@@ -602,6 +602,34 @@ tag in the mode line."
(setq preview-error-condition nil
compilation-in-progress (delq process compilation-in-progress)))))
+(defcustom preview-pdf-color-adjust-method 'compatible
+ "Method to adjust colors of images generated from PDF.
+It is not consulted when the latex command produces DVI files.
+
+The valid values are:
+t: preview-latex transfers FG and BG colors of Emacs to the
+generated image. This option requires that Ghostscript has
+working DELAYBIND feature, thus is invalid with gs 9.27 (and
+possibly < 9.27).
+
+compatible: preview-latex uses another mothod to transfer colors.
+This option is provided for compatibility with gs =< 9.27, but
+fail with gs 9.27 if `preview-reference-face' or the `default'
+face has non-trivial foreground color, including cases of
+customized themes.
+
+nil: no adjustment is done and \"black on white\" image is
+generated regardless of Emacs color. This is for gs 9.27 users
+with customized foreground color.
+
+The default value will be changed to t after Ghostscript 9.28 is
+released."
+ :group 'preview-appearance
+ :type '(choice :tag "Method"
+ (const :tag "Adjust to Emacs color (gs > 9.27)" t)
+ (const :tag "Compatibility for gs =< 9.27" compatible)
+ (const :tag "No adjustment (B/W, for gs 9.27)" nil)))
+
(defun preview-gs-sentinel (process string)
"Sentinel function for rendering process.
Gets the default PROCESS and STRING arguments
@@ -732,7 +760,19 @@ null eq{pop{pop}bind}if def\
{pop}{setpagedevice}{ifelse exec}\
stopped{handleerror quit}if \
.preview-ST aload pop restore}bind def "
- (preview-gs-color-string preview-colors)))
+ (preview-gs-color-string
+ preview-colors
+ ;; Compatibility for gs 9.27 with non-trivial
+ ;; foreground color.
+ ;; Suppress color adjustment with PDF backend
+ ;; when `preview-pdf-color-adjust-method' is nil.
+ (and (not preview-pdf-color-adjust-method)
+ ;; The switch `preview-parsed-pdfoutput' isn't
+ ;; set before parsing the latex output, so use
+ ;; heuristic here.
+ (with-current-buffer TeX-command-buffer
+ (and TeX-PDF-mode
+ (not TeX-PDF-from-DVI)))))))
(preview-gs-queue-empty)
(preview-parse-messages (or setup #'preview-gs-dvips-process-setup))))
@@ -744,21 +784,43 @@ to Ghostscript floats."
(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\
+ (cond (;; New code for gs > 9.27.
+ ;; This assumes DELAYBIND feature, which is known to be
+ ;; broken in gs 9.27 (and possibly, < 9.27).
+ ;; <URL:https://lists.gnu.org/archive/html/auctex-devel/2019-07/msg00000.html>
+ (eq preview-pdf-color-adjust-method t)
+ (concat
+ "/initgraphics {
+ //initgraphics
+ /RG where {
+ pop "
+ (mapconcat #'preview-gs-color-value fg " ")
+ " 3 copy rg RG
+ } if
+} bind def "))
+ (;; Traditional code for gs < 9.27.
+ ;; Works with gs 9.27 as well if the foreground color
+ ;; is trivial.
+ (eq preview-pdf-color-adjust-method 'compatible)
+ (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))
- (fg (aref colors 1))
+ (mapconcat #'preview-gs-color-value fg " ")
+ " 3 copy rg RG}bind store end readonly store "))
+ (;; Do nothing otherwise.
+ t
+ "")))))
+
+(defun preview-gs-color-string (colors &optional suppress-fgbg)
+ "Return a string setting up COLORS.
+If optional argument SUPPRESS-FGBG is non-nil, behave as if FG/BG
+colors were just the default value."
+ (let ((bg (and (not suppress-fgbg)
+ (aref colors 0)))
+ (fg (and (not suppress-fgbg)
+ (aref colors 1)))
(mask (aref colors 2))
(border (aref colors 3)))
(concat
@@ -910,9 +972,15 @@ The usual PROCESS and COMMAND arguments for
(cond ((eq status 'exit)
(delete-process process)
(setq TeX-sentinel-function nil)
+ (if (eq preview-pdf-color-adjust-method t)
+ (setq preview-gs-command-line (append
+ preview-gs-command-line
+ '("-dDELAYBIND"))))
(setq preview-gs-init-string
(concat preview-gs-init-string
- (preview-pdf-color-string preview-colors)))
+ (preview-pdf-color-string preview-colors)
+ (if (eq preview-pdf-color-adjust-method t)
+ ".bindnow")))
(preview-prepare-fast-conversion)
(when gsstart
(if preview-gs-queue
_______________________________________________
auctex-devel mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/auctex-devel