Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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.

enter image description here

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.

enter image description here

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>](...,...)(...,...).

share|improve this question
    
Wow. I love the enthusiasm! –  user02138 Aug 7 '11 at 2:27
    
Have a look at the new crop option of standalone 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

1 Answer 1

up vote 6 down vote accepted
+1000

preview does not invoke pdfcrop. Here is the relevant code from preview inserted into your example. As you can clearly see it simply takes the tex box size in sp and converts that into the postscript page size using the relevant conversion factor (65781.76):

\documentclass{article}
\usepackage{pstricks}

\newcommand\All{0.1}
\newcommand\Left{-\All}
\newcommand\Right{\All}
\newcommand\Bottom{-\All}
\newcommand\Top{\All}

\makeatletter
\newbox\prv

\begin{document}
    \setbox\prv\vbox{\noindent
       \begin{pspicture}(\Left,\Bottom)(\Right,\Top)
        \psframe[linewidth=0.01](\Left,\Bottom)(\Right,\Top)
        \end{pspicture}
    \par\unskip\setbox0\lastbox
    \nointerlineskip\hbox{\unhbox0}%
    }
   \voffset=-\ht\prv
   \hoffset=0pt\relax
   \shipout\vbox{%
      \@begindvi
      \special{!userdict begin/preview-bop-level 0 def%
      /eop-hook{/preview-bop-level dup load dup 0 gt{1 sub}if store}bind def
      /bop-hook{preview-bop-level 0 le{7{currentfile token not{stop}if
       65781.76 div DVImag mul}repeat 72 add 72 2 copy gt{exch}if 4 2 roll
       neg 2 copy lt{exch}if dup 0 gt{pop 0 exch}
      {exch dup 0 lt{pop 0}if}ifelse 720 add exch 720 add 3 1 roll
      4{5 -1 roll add 4 1 roll}repeat
      <</PageSize[5 -1 roll 6 index sub 5 -1 roll 5 index sub]%
       /PageOffset[7 -2 roll [1 1 dtransform exch]%
       {0 ge{neg}if exch}forall]>>setpagedevice}if%
      /preview-bop-level dup load dup 0 le{/isls false def%
          /vsize 792 def/hsize 612 def}if 1 add store}bind def end}
     \special{ps::0 0 0 0
     \number\ht\prv \space\number\dp\prv \space\number\wd\prv \space}
     \box\prv
}
\end{document}
share|improve this answer
    
I have tested it for some scenario and it works in the same way the preview package works. It also fails to work with PSTricks and animate package. However, I am satisfied with this answer. :-) –  xport Aug 7 '11 at 9:07
    
I'm glad to help! –  Lev Bishop Aug 11 '11 at 18:31

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.