[Tex/LaTex] Can not generate Preview by AUCTeX

auctexemacsghostscriptpreview

I try to generate preview by AUCTeX (on Emacs GUI), but it displays

enter image description here

I click on the red sign, choose View error and get

/usr/bin/rungs -dOutputFile\=\(_region_.prv/tmp5971SJc/pr1-5.png\) -q 
-dDELAYSAFER -dNOPAUSE -DNOPLATFONTS -dPrinted -dTextAlphaBits\=4 -
dGraphicsAlphaBits\=4 -sDEVICE\=png16m -r118.561x117.723
GS>{<</PermitFileReading[(_region_.pdf)
(_region_.prv/tmp5971SJc/preview.dsc)]>> setuserparams .locksafe} 
stopped pop {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 0.98439 0.98439 0.98439 setrgbcolor clippath 
fill 0.191409 0.210941 0.230472 setrgbcolor}
{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 
/GS_PDF_ProcSet GS_PDF_ProcSet dup maxlength dict copy dup 
begin/graphicsbeginpage{//graphicsbeginpage exec 0.191409 0.210941 
0.230472 3 copy rg RG}bind store end readonly store 
[(_region_.prv/tmp5971SJc/preview.dsc)(r)file]aload exch dup 0 
setfileposition 596()/SubFileDecode filter cvx .runandhide aload pop 
dup dup 596 setfileposition 53()/SubFileDecode filter cvx<<>>preview-
do
Error: /typecheck in --setfileposition--
Operand stack:
   --nostringval--   --nostringval--   --nostringval--   --
nostringval--   755   755   755   702   702   702   649   649   649   
596
Execution stack:
   %interp_exit   .runexec2   --nostringval--   --nostringval--   --
nostringval--   2   %stopped_push   --nostringval--   --nostringval--   
%loop_continue   --nostringval--   --nostringval--   false   1   
%stopped_push   .runexec2   --nostringval--   --nostringval--   --
nostringval--   2   %stopped_push   --nostringval--
Dictionary stack:
   --dict:991/1684(ro)(G)--   --dict:0/20(G)--   --dict:80/200(L)--
Current allocation mode is local
Current file position is 28
GS<14>

Could someone please tell me what the problem is?

Here is some information that may help:

  • There is a file named preview.dsc in folder _region_.prv/tmp5971SJc/. I open this file (by Okular) and see nothing but blank pages. However, the file disappear when I close the tex file.
  • I can use C-c C-a to export pdf file, and it works flawlessly.
  • I use Emacs 25.3-1, AUCTeX 11.91.0 (which is installed by using the Emacs package manager integrated in Emacs), ghostscript 9.22-1 and TeX Live 2017 (I installed texlive-most and texlive-lang from Arch Linux Repository). I just made a full upgrade, so I'm quite sure it is the newest version.
  • There are some similar question here:
    AucTeX fails to generate previews on Mac OS X, Why does preview-latex not show some equations?, AUCTEX won't create dsc file. However, all of the answers are about updating to the newest version of AUCTeX or Ghostscript. I also change Preview GS options as in preview-latex in emacs auctex: empty boxes?, but it doesn't work.
  • I reinstall Ghostscript, Emacs, AUCTeX and Tex Live (from Arch Linux Repository and from ISO file) but no luck.

Important Note: According to this page, .runandhide extension was removed from ghostscript since version 9.22, so I downgraded it to version 9.21-3 (downloaded from https://archive.archlinux.org/packages/g/ghostscript/) and now Preview works again. It is definitely not an optimal solution, but I hope it could help.

Best Answer

Moderators, please don't remove this answer, I am aware that I should comment rather than answer, but I cannot comment as I don't have sufficient reputation. My Stack Overflow reputation doesn't carry over here.

We are looking to try and contact someone who maintains this package in order to address the problem. There is an open bug report for Ghostscript here:

https://bugs.ghostscript.com/show_bug.cgi?id=698680

We don't want to put DELAYSAFER and .runandhide back because they are, frankly, a gaping security hole. If you know someone who maintains this, and can either explain why this non-standard PostScript is required, or is able to make changes to the package so that this code is no longer required please ask them to get in touch.