Actually the following method, that looks like reinventing the wheel, has been discarded once I have known the existence of preview
package.
% WithoutPreview.tex
\documentclass{article}
\usepackage{pstricks}
\newcommand\All{0.1}
\newcommand\Left{-\All}
\newcommand\Right{\All}
\newcommand\Bottom{-\All}
\newcommand\Top{\All}
%%%%%%%%%%%% BEGIN SETTINGS %%%%%%%%%%%%
\headheight=0pt
\headsep=0pt
\parindent=0pt
\topskip=0pt
\topmargin=-72.27pt
\oddsidemargin=-72.27pt
\paperwidth=\dimexpr\Right\psxunit-\Left\psxunit\relax
\paperheight=\dimexpr\Top\psyunit-\Bottom\psyunit\relax
\special{papersize=\the\paperwidth,\the\paperheight}
\pagestyle{empty}
%%%%%%%%%%%%% END SETTINGS %%%%%%%%%$%%%
\begin{document}
\begin{pspicture}(\Left,\Bottom)(\Right,\Top)
\psframe[linewidth=0.01](\Left,\Bottom)(\Right,\Top)
\end{pspicture}
\end{document}
The idea in WithoutPreview.tex
is to produce a single output with a tight paper size.
Using the following batch file,
rem batch.bat takes an input file name WITHOUT extension.
latex %1
dvips -D10000 -t unknown %1
gswin32c -r10000 -dAutoRotatePages=/None -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile=%1.pdf %1.ps
I get the following output that is not tight enough.
Note: There are random white spaces at the edges. Their exact position cannot be predicted. They are sometimes on the left and top edges, sometimes on the left and bottom edges, etc. They depend on the specified settings.
Once I have known the existence of preview
package and played with it, I discarded the method I used in WithoutPreview.tex
.
The following code use preview
package,
% WithPreview.tex
\documentclass{article}
\usepackage{pstricks}
\newcommand\All{0.1}
\newcommand\Left{-\All}
\newcommand\Right{\All}
\newcommand\Bottom{-\All}
\newcommand\Top{\All}
%%%%%%%%%%%% BEGIN SETTINGS %%%%%%%%%%%%
\usepackage[active,tightpage]{preview}
\PreviewBorder=0pt
\PreviewEnvironment{pspicture}
%%%%%%%%%%%%% END SETTINGS %%%%%%%%%$%%%
\begin{document}
\begin{pspicture}(\Left,\Bottom)(\Right,\Top)
\psframe[linewidth=0.01](\Left,\Bottom)(\Right,\Top)
\end{pspicture}
\end{document}
and when compiled with the same batch file, batch.bat
, it produces a tight output as follows.
Note: The random white spaces have gone!
The bad news came yesterday as I cannot use preview
package together with PSTricks related packages and animate
package.
Questions
Does preview
invoke pdfcrop
behind the scene? If preview
does not invoke pdfcrop
, what kind of magic does it do to produce a tight paper size? I am interested in extracting the fragment codes, that is used in preview
to produce a tight paper size, and insert them into my WithoutPreview.tex
.
Note: xelatex
can give better output than latex-dvips-ps2pdf
does, but xelatex
runs too slowly.
Another note: preview
package ignores \pagecolor{<non-white color>}
declared in the preamble. However, it is not a big issue as the non-white background can be obtained by a PSTricks' psframe*[linecolor=<non-white>](...,...)(...,...)
.
crop
option ofstandalone
v1.0. I implemented some boxing and page resizing for it which should be of interest for you. – Martin Scharrer♦ Dec 21 '11 at 16:24