%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Cropmark.tex
% version 1.0
%
% 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
%
% 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
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% save the old \shipout command
\let\xshipout\shipout

% define a new one: investigate what's being shipped
\def\shipout{\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=2pt

\newdimen\croppadtop \croppadtop=0pt
\newdimen\croppadbot \croppadbot=0pt
\newdimen\croppadlr  \croppadlr=0pt

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

\def\shipAfterRegister
   {\setbox0\vbox
       {\offinterlineskip
        \dimen0\cropsep\advance\dimen0\croplength
        \setbox2\hbox to \wd0
               {\kern-\croppadlr\kern-.5\cropwidth
                \cropvrule\hfil\cropvrule
                \kern-.5\cropwidth\kern-\croppadlr}
        \setbox4\hbox to \wd0{\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
        % padding
        \kern\croppadbot
        % and now the top in reverse
        \kern-.5\cropwidth
        \box4
        \kern-.5\cropwidth\kern\cropsep
        \box2
    }
    \xshipout\box0\relax}
\endinput
