If you want all PSTricks code to be imported from within the TeX main input file, then it will be better using xelatex
than using pdflatex
+auto-pst-pdf
. There are many limitations of using pdflatex
+ auto-pst-pdf
. I will list the details in the next edit.
If you want some PSTricks code to be imported in the TeX main input file and the remaining PSTricks code to be converted to PDF images, then use xelatex
+ preview
package.
If your PSTricks code
makes use of \label
as in the following example:
\begin{equation}\label{eq:Einstein}
\rnode{A}{E}=mc^\rnode{B}{2}
\ncbar[angle=90]{A}{B}
\end{equation}
or imports an image of type PNG, PDF, JPG as in the following example:
\newsavebox\IBox
\savebox\IBox{\includegraphics{image.jpg}}
\pspicture(\wd\IBox,\ht\IBox)
\rput[bl](0,0){\usebox\IBox}
\endpspicture
or works together with animate
package as in the following example:
\animateinline[palindrome,autoplay]{10}
\multiframe{11}{r=1+-0.1}{%
\pspicture(2,2)
\pscircle*[linecolor=red,opacity=0.5](1,1){\r}
\endpspicture}
\endanimateinline
then pdflatex -enable-write18
+ auto-pst-pdf
cannot be used to produce the correct result.
The solution: use xelatex
instead but it runs very very slowly if you compile the whole input files. To speed up the compilation, you should divide the your input file into several sub-files. Put each of "independent" PSTricks fragment into a separate input file and compile it to produce a single PDF output.
Note: An independent PSTricks fragment is a PSTricks code that does not
belong to the 3 cases mentioned above.
An example of an "independent" PSTricks fragment:
% frame.tex
\documentclass{article}
\usepackage{pstricks}
% preview must come after any pstricks package!
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt\relax
% Either
\PreviewEnvironment{pspicture}
% or
%\PreviewEnvironment{pspicture*}
\begin{document}
\begin{pspicture}(1,1)
\psframe(1,1)
\end{pspicture}
\end{document}
Compile it with xelatex
(slower than the snail) or latex-dvips-ps2pdf
(faster than the light) and you will get frame.pdf
.
Later, you can import the frame.pdf
from within your main input file as follows:
% main.tex
\documentclass{article}
\usepackage{graphicx}
\begin{document}
\includegraphics{frame.pdf}\newpage
\animateinline[palindrome,autoplay]{10}
\multiframe{11}{r=1+-0.1}{%
\pspicture(2,2)
\pscircle*[linecolor=red,opacity=0.5](1,1){\r}
\endpspicture}
\endanimateinline
\end{document}
Once again, compile the main input file using xelatex
only. But compilation becomes faster! Note: latex-dvips-ps2pdf
cannot import PDF images, that is why you have to use xelatex
only!
NOTE: The main input file must NOT load preview
package if you load
animate
package. Practically, you never need to load preview
in
the main input file, only sub-files need preview
.
I have no problem with
\documentclass[10pt]{article}
\usepackage{pst-all}
\usepackage[pspdf={-dNOSAFER -dALLOWPSTRANSPARENCY}]{auto-pst-pdf}
\begin{document}
\includegraphics[height=3.5cm]{tiger.pdf}
\begin{pspicture}(0,0)(18,10)
\pspolygon[fillstyle=solid,fillcolor=lightgray,linewidth=0](0,3)(0,0)(3,0)(3,3)
\end{pspicture}
\end{document}
However, running it with lualatex
(needs an up-do-date TeX distribution) makes life easier ....
\RequirePackage{pdfmanagement-testphase}% needed for transparency
\DeclareDocumentMetadata{}
\documentclass[10pt]{article}
\usepackage{pst-all,graphicx}
\begin{document}
\includegraphics[height=3.5cm]{tiger.pdf}
\begin{pspicture}(0,0)(3,3)
\pspolygon[fillstyle=solid,fillcolor=lightgray,linewidth=0](0,3)(0,0)(3,0)(3,3)
\end{pspicture}
\end{document}
Best Answer
the documentclass
standalone
cannot work together with theauto-pst-pdf
package and the[pstricks]
option forstandalone
. UseHowever, it makes no sense to use
standalone
andauto-pst-pdf
together.