# How to manage a document with a huge number of PSTricks figures?

I am writing a mathematics book that makes use of a huge number of PSTricks pictures. For the sake of re-usability and maintaining separation of concern, I always put the self-contained PSTricks code in a separate .tex file. The following code shows an example of self-contained PSTricks input file:

% gridon.tex
\documentclass{minimal}
\usepackage{pstricks}
\pagestyle{empty}

\begin{document}
\begin{pspicture}[showgrid=true](4,3)
\end{pspicture}
\end{document}


Then I compile the gridon.tex using the following batch file to produce gridon.eps.

latex %1.tex
dvips -R %1.dvi
ps2pdf -dCompatibilityLevel#1.5 -dPDFSETTINGS#/prepress %1.ps %1-temp.pdf
pdfcrop --restricted --hires %1-temp.pdf %1.pdf
pdftops -eps %1.pdf %1.eps


From my main .tex file, I will then import the gridon.eps as follows

% main.tex
\documentclass{minimal}
\usepackage[hiresbb]{graphicx}
\usepackage{pst-node}
\begin{document}

\includegraphics[scale=2]{gridon}
\vspace{5mm}

I am \rnode[tl]{A}{xport} not \rnode[tr]{B}{xpert}.
\ncarc[angle=90,linecolor=blue,arrows=<->]{A}{B}

\end{document}


Note that in the main.tex file I also have inline PSTricks codes in between the text so I cannot put them in separate files. The main input file is then compiled using latex->dvips->ps2pdf.

How to manage a document with a huge number of PSTricks figures?

-
hmmm. I think that your question is not focused enough...I'd suggest splitting your "approach" into it's bare parts and ask a separate question about each one (-1) – Yossi Farjoun Dec 30 '10 at 9:37
Well, your own "answer" seems to imply that there's an issue with the BBox...so that's a separate issue. compile time seems to be another issue. Automation, a third issue...am I mistaken? – Yossi Farjoun Dec 30 '10 at 11:53
Inline PSTricks code can also be put into a separe file! You only have to choose the same page setting and fonts. – Herbert Jul 9 '11 at 20:39
And I do not unserstand the advantage of having external files when you already run the latex->dvips->ps2pdf sequence. I have more than 1000 PSTricks images in a book which I write out as external documents, run it vis a makefile and insert them all as a pdf. – Herbert Jul 9 '11 at 20:45

I wrote the standalone package to allow the compilation of pictures (tikz or pstricks) and other material as part OR separately from the main document. While mainly thought for fast recompilation during picture creation, it can also be used to create eps or pdf images from your pictures which are then inserted in your main document. So instead recompiling every picture every time the main document is compiled, you can compile it once and then only use the image. Should not degrade the quality if done right.

Example:

% Self-contained, compilable PSTricks picture
% e.g. "pic001.tex"
\documentclass{standalone}
\usepackage{pstricks}
\begin{document}
\begin{pspicture*}(4,3)
\psframe[fillcolor=red,fillstyle=solid](4,3)
\end{pspicture*}
\end{document}


.

% Main document
\documentclass{book}
\usepackage{standalone}
\usepackage{pstricks}

\newcommand*{\mypstrickspic}[1]{%
\IfFileExists{#1.eps}%
{\includegraphics[<options>]{#1.eps}}%
{\input{#1.tex}}%
}
% Replace .eps with .pdf if main file uses pdflatex

\begin{document}
%...
\mypstrickspic{pic001}
%...
\end{document}


Then you compile the picture file first and convert it to a .eps (dvi->ps, simply rename .ps to .eps) or .pdf.

The above code is not full tested, because I don't have pstricks installed on my machine. I'm a PGF/TikZ fan and minded the disk space required by pstricks. I'm planning a build-in feature like that for the next release of 'standalone'.

-
Are you sure we can get EPS from PS produced by dvips by renaming the extension as you said above, i.e., changing from .ps to .eps? – xport Jul 9 '11 at 15:37
@xport: AFAIK the basic difference between EPS and PS is that EPS can't contain multiple pages and requires specific headers (for bounding box etc.) which are not mandatory of PS. However, often PS files have these headers as well and if they only hold one page then renaming the file ending works usually. I did that for a while, but it depends on the tools which produce the file and which use it later again. It's of course not a 100% safe thing. However, using dvips -E instead should do it anyway. I didn't though about that when I wrote the post. I will edit my post. – Martin Scharrer Jul 9 '11 at 15:49
@xport: I tested it now and have some issues getting the correct bounding box in all stages. It should work actually after the manual of the preview package which is used internally by standalone. I might delete my answer. – Martin Scharrer Jul 9 '11 at 16:43