I want to use file operations in postscript: right now I need them to print large debugging data, which otherwise I have to copy and paste from the standard output.

More importantly, in the future, I want to use file operations to cache results of large computations (for example, a rendered 3d figure).

However, the code below does not work. I checked using my gs interpreter: when the code is directly executed via gs, it creates a file successfully. What is the issue? How can I gain standard postscript file access via LaTeX/pstricks? Thanks!

Answer by AlexG (many thanks!) compile with

ps2pdf -dNOSAFER
pdflatex -shell-escape   

[Edit:] after a tiny bit of digging into the documentation of auto-pst-pdf I found out what options to turn on to make it work with pdflatex as well :)

That appears to solve the problem! Have not tested the remaining file operations yet. The file needs to be closed too.

%Compile with: 
%    pdflatex -shell-escape   
\usepackage[dvips={-o -Ppdf}, pspdf={-dNOSAFER -dAutoRotatePages=/None}, pdfcrop={}]{auto-pst-pdf}

(./myFile.txt) (w) file 

The issue appears to be one of file access permissions: the error I get is from the postscript interpretter:

This is dvips(k) 5.993 Copyright 2013 Radical Eye Software
(www.radicaleye.com) ' TeX output 2014.10.09:1519' ->


</usr/share/texlive/texmf-dist/dvips/base/special.pro>. [1]

Error: /invalidfileaccess in --file-- Operand stack: (./myFile.txt)
(w) Execution stack: %interp_exit .runexec2 --nostringval--
--nostringval-- --nos

tringval-- 2 %stopped_push --nostringval-- --nostringval--
--nostringval-- false 1 %stopped_push 1916 1 3 %oparray_pop 1915 1 3
%oparray_pop 1899 1 3 %oparray_pop 1787 1 3 %oparray_pop
--nostringval-- %errorexec_pop .runexec2 --nostringval--
--nostringval-- --nostringval-- 2 %stopped_push --nostringval--
Dictionary stack: --dict:1176/1684(ro)(G)-- --dict:0/20(G)--
--dict:118/200(L)-- --dict:100/300(L)-- Current allocation mode is
local Last OS error: No such file or directory Current file position
is 85884 GPL Ghostscript 9.10: Unrecoverable error, exit code 1

Prozess endete normal

On tangentially related note, here's the kind of image I am computing and need to cache. This is an example of a Moebius strip, but I can plot arbitrary geometry with reasonably accurate Z-buffering. My contours are much finer than what you get with a simple triangle mesh (my mesh interior is a straight line approximation, but the contours are sampled much finer). Notice how all contour lines on the background are drawn with a dotted line.

a Moebius strip rendered by my code

The 3d library is rather long, contained here: the needed pstricks-commands.sty file

Modulo my library, here's what the code for drawing the strip will look like:

\usepackage[dvips={-o -Ppdf}, pspdf={-dNOSAFER -dAutoRotatePages=/None}, pdfcrop={}]{auto-pst-pdf}
%file pstricks-commands to be found here:
\begin{pspicture}(-1, -1)(2,2)
\fcBoundingBox{-3}{-3}{4}{4} %
\fcSurfaceInScene[iterationsU=33, iterationsV=5]{0}{-1}{360}{1}{%
[10 dict begin
/R 2 def
/r {0.8 v mul} def
/theta u def
/phi {u 0.5 mul} def
/A {phi cos r mul R add} def
theta cos A mul theta sin A mul phi sin r mul
end %
\fcFinishIIIdScene % <- this operation is really expensive.
%need to cache it's output so that it's computed only once for a given input.

  • Are you compiling this will all the goodies enabled? --enable-write18 and/or --shell-escape?
    – Werner
    Commented Oct 9, 2014 at 18:28
  • Yes, the -shell-escape option is set. Commented Oct 9, 2014 at 19:19
  • That may just be it - it's not allowed. Someone with more PS knowledge can chime in...
    – Werner
    Commented Oct 9, 2014 at 19:22
  • 3
    @Werner ps2pdf -dNOSAFER ..., perhaps.
    – AlexG
    Commented Oct 10, 2014 at 6:19
  • -dNOSAFER solved the problem for the dvi->ps->pdf toolchain, thanks a lot! Commented Oct 14, 2014 at 16:52

1 Answer 1


It makes no real sense to use it with pst-pdf. However, you have to use the postscript environment and a dummy character inside this environment because it will be inserted as an image later.

\usepackage[pspdf={-dNOSAFER -dAutoRotatePages=/None}, crop=off]{auto-pst-pdf}

  /DataFile (myFile.txt) (w) file def 
DataFile (foo) writestring
DataFile (bar) writestring
DataFile closefile


It works for me with pdflatex --shell-escape <file>

  • "It makes no real sense to use it with pst-pdf". I understand that pst-pdf uses on the background the dvi->ps->pdf toolchain, so technically running with pdf-latex is redundant. However, I am making lecture slides being compiled on various machines by various people with even more varying technical skills. If someone checks out my repo and compiles with pdflatex, I want no error messages displayed. Would save me 15 minutes of emailing and explanations every time I get a new user of the slides! Commented Oct 14, 2014 at 19:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .