% $OpenXM: OpenXM/doc/Papers/cropmark.sty,v 1.1 2001/11/19 01:02:30 noro Exp $
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Cropmark.sty or .tex
% version 1.1 (minor enhancements see below)
%
% This will put crop marks on everythings that's \shipout'ed.
% It will work with any format, since it relies on redefinition
% of \shipout. Exception: if you declare \output{} you will
% not get crop marks.
%
% Cut along the center of the rules to get exactly the shipped
% out box. To get padding around this box, use the parameters below.
%
% User adjustable parameters:
% \croplength    length of the crop rules
% \cropwidth     width of the crop rules
% \cropsep       separation between rule and page box
% \croppadtop    padding in case page box looks bigger than it is
% \croppadbot    (for instance with plain TeX head/footline)
% \croppadlr
%
% Version 1.0 - Date: 17 March 1992
%
% Author:
%    Victor Eijkhout
%    Department of Computer Science
%    University Tennessee at Knoxville
%    104 Ayres Hall
%    Knoxville, TN 37996
%    USA
%
%    eijkhout@cs.utk.edu
%
% "Enhancements":
% \thispagecropped   enables cropmarks for the current page only
% \allpagescropped   enables cropmarks on all subsequent pages
% \nopagecropped     stops cropmarks
% \ifbottomcrops     conditional for copmarks at the bottom of the page
% left marks shifted by \@themargin
%
% Version 1.1 - Date: 21 July 1993
%
% Author:
%    Frank Holzwarth
%    Springer-Verlag
%    Abteilung Neue Techniken/Produktentwicklung
%    Tiergartenstrasse 17
%    D-69121 Heidelberg
%    FRG
%
%    holzwarth@vax.ntp.springer.de
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% save the old \shipout command
\let\xshipout\shipout

% define a new one: investigate what's being shipped
\def\cshipout{\futurelet\SomeBox\yshipout}

% if its a box register, do postprocessing with \afterassignment,
% otherwise do \afterassignment which will do \aftergroup
\def\yshipout
   {\ifx\SomeBox\box        \let\next\shipAfterRegister
    \else \ifx\SomeBox\copy \let\next\shipAfterRegister
    \else                   \let\next\shipAfterBox \fi\fi
    \afterassignment\next\setbox0=
    }
\def\shipAfterBox{\aftergroup\shipAfterRegister}

% now we have whatever is being shipped in box0,
% so we can insert crop marks
\newdimen\croplength \croplength=20pt
\newdimen\cropsep    \cropsep=10pt
\newdimen\cropwidth  \cropwidth=0.5pt

\newdimen\croppadtop \croppadtop=-5pt % difference normal \baselineskip
%                                       to height of a \small\strutbox
\newdimen\croppadbot \croppadbot=0pt
\newdimen\croppadlr  \croppadlr=0pt
\newif\ifbottomcrops \bottomcropsfalse

\def\crophrule{\vrule height\cropwidth depth0pt width\croplength}
\def\cropvrule{\vrule width\cropwidth depth0pt height\croplength}

{\catcode`@=11 % use @ as a normal character
\expandafter\ifx\csname @themargin\endcsname\relax
\global\let\@themargin=\z@\fi

\gdef\shipAfterRegister
   {\setbox0\vbox
       {\offinterlineskip
        \dimen0\cropsep\advance\dimen0\croplength
        \setbox2\hbox to \wd0
               {\kern-\croppadlr\kern-.5\cropwidth
                \kern\@themargin
                \cropvrule\hfil\cropvrule
                \kern-.5\cropwidth\kern-\croppadlr}
        \setbox4\hbox to \wd0{\kern\@themargin
                              \llap{\crophrule\kern\cropsep\kern\croppadlr}
                              \hfil
                              \rlap{\kern\croppadlr\kern\cropsep\crophrule}}
        % go a bit up, put vertical rules, put horizontal rules
        \kern-\dimen0
        \copy2
        \kern\cropsep\kern-.5\cropwidth
        \copy4
        \kern-.5\cropwidth
        % padding
        \kern\croppadtop
        % the box to be shipped
        \box0
        \ifbottomcrops
           % padding
           \kern\croppadbot
           % and now the top in reverse
           \kern-.5\cropwidth
           \box4
           \kern-.5\cropwidth\kern\cropsep
           \box2
        \fi
    }
    \xshipout\box0\relax
    \if Y\CROP\else\global\let\shipout=\xshipout\fi}}%

\let\CROP=N%
\def\thispagecropped{\global\let\shipout=\cshipout}
\def\allpagescropped{\global\let\CROP=Y\thispagecropped}
\def\nopagecropped{\global\let\CROP=N\global\let\shipout=\xshipout}

\endinput
