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
\documentclass{article}
\usepackage{pstricks}
\usepackage[dvips={-o -Ppdf}, pspdf={-dNOSAFER -dAutoRotatePages=/None}, pdfcrop={}]{auto-pst-pdf}
\begin{document}
\begin{pspicture}
\pstVerb{
(./myFile.txt) (w) file
closefile
}
\phantom{A}
\end{pspicture}
\end{document}
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' ->
using-files-pstricks-autopp.ps
</usr/share/texlive/texmf-dist/dvips/base/tex.pro>
</usr/share/texlive/texmf-dist/dvips/config/alt-rule.pro>
</usr/share/texlive/texmf-dist/dvips/pstricks/pstricks.pro>
</usr/share/texlive/texmf-dist/dvips/pstricks/pst-algparser.pro>
</usr/share/texlive/texmf-dist/dvips/pst-tools/pst-tools.pro>
</usr/share/texlive/texmf-dist/dvips/pstricks/pst-dots.pro>
</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.
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:
\documentclass{article}
\usepackage{pstricks}
\usepackage[dvips={-o -Ppdf}, pspdf={-dNOSAFER -dAutoRotatePages=/None}, pdfcrop={}]{auto-pst-pdf}
\usepackage{../pstricks-commands}
%file pstricks-commands to be found here:
%https://sourceforge.net/p/freecalculus/code/651/tree/trunk/lectures/pstricks-commands.sty
\pagestyle{empty}
\begin{document}
\begin{pspicture}(-1, -1)(2,2)
\fcBoundingBox{-3}{-3}{4}{4} %
\fcStartIIIdScene%
\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.
\end{pspicture}
\end{document}
--enable-write18
and/or--shell-escape
?ps2pdf -dNOSAFER ...
, perhaps.