%% Save file as: CROPMARKS.TEX                  Source: FILESERV@SHSU.BITNET
%% Author:  Philip Taylor (RHBNC) <P.Taylor@vax.rhbnc.ac.uk>
%% Date received: Wed. Feb. 12, 1992
%%
%%% Cropmarks.TeX   Copyright (C) Philip Taylor, MCMLXXXXI

%%%  Usage:
%%% \input cropmarks
%%% \topcropmark = <dimen> [plus <dimen>] [minus <dimen>]
%%% \bottomcropmark = <dimen> [plus <dimen>] [minus <dimen>]
%%% \leftcropmark = <dimen> [plus <dimen>] [minus <dimen>]
%%% \rightcropmark = <dimen> [plus <dimen>] [minus <dimen>]
%%% \lrcropmarkstrue ;;; iff you want alternating left and right cropmarks only
%%% \rvcropmarkstrue ;;; iff you want recto and verso specified independently
%%%                     (in which case the first four variables are two-valued
%%%                      as \recto<var> and \verso<var>).

%%% Square brackets indicate optional items, and the <dimen>s are
%%% respectively (and all measured w.r.t. the origin, which is the
%%% top left corner of the notional, rather than physical page; the
%%% exact origin will need to be determined by inspection)

%%% 	The distance to the centre of the cross;
%%% 	The distance which the cross extends beyond the page limits;
%%% 	The distance which the cross extends within the page limits.

%%% Any or all can be zero <unit>s.  For conventional (exo-) cropmarks, the
%%% `plus' component indicates the length of the mark, and the `minus' component
%%% should be omitted or zero.  For inverted (endo-) cropmarks, the `plus'
%%% component should be omitted or zero, and the `minus' component indicates the
%%% length of the mark.  `Plus' and `minus' components will never be negative;
%%% the first and only mandatory component may be negative to cope with
%%% pathological origins.

%
%%% A test which will allow us to be read regardless of the \catcode of `@'
%

\newif \ifatletter
\ifcat @A\atlettertrue \else \catcode `\@ = 11 \atletterfalse \fi

\ifx \c@tcodeminus \undefined
\else \message {Warning: previous meaning of \string \c@tcodeminus \space lost}
\fi
\edef \c@tcodeminus {\the \catcode `\-}
\catcode `\- = 12

%
\message {CROPMARKS.TEX V1.3 Copyright (C) 07-Mar-1991 15:56:57 Philip Taylor}
%

%
%%% Miscellaneous variables
%
\newif    \iflrcropmarks			\lrcropmarksfalse
\newif    \ifrvcropmarks         		\rvcropmarksfalse
\newdimen \cropmarkwidth			\cropmarkwidth = 0.4 pt
\newdimen \t@pshift
\newdimen \b@ttomshift
\newdimen \l@ftshift
\newskip \topcropmark
\newskip \leftcropmark
\newskip \rightcropmark
\newskip \bottomcropmark
\newskip \rectotopcropmark
\newskip \rectoleftcropmark
\newskip \rectorightcropmark
\newskip \rectobottomcropmark
\newskip \versotopcropmark
\newskip \versoleftcropmark
\newskip \versorightcropmark
\newskip \versobottomcropmark
\newskip \m@rkskip
\newskip \m@rkplus
\newskip \m@rkminus
\newbox \p@gebox
\newbox \cr@pmarkbox
\newbox \topcr@pmarkbox
\newbox \bottomcr@pmarkbox
%
%%% Extraordinary arcanery, to parse <skip>s into <dimen>s; any better ways ?
%
\begingroup
\catcode `\P = 12 \catcode `\L = 12 \catcode `\U = 12 \catcode `\S = 12
\catcode `\M = 12 \catcode `\I = 12 \catcode `\N = 12 \catcode `\T = 12
\globaldefs = 1
\lowercase
{%
\def \p@rseskip #1%
	{\expandafter \p@rs@skip \the #1 PLUS 0.0PT MINUS 0.0PT \@ndparse #1 }
\def \p@rs@skip #1 PLUS #2 MINUS #3\@ndparse #4
	{%
	 \m@rkskip  = #1%
	 \m@rkplus  = #2%
	 \m@rkminus = #3%
	 \ifdim \m@rkminus = 0.0 pt
		\expandafter \p@rs@sk@p \the \m@rkskip MINUS 0.0PT \@ndparse
	 \fi
%%% 	 \message {#4 = \the \m@rkskip+\the \m@rkplus-\the \m@rkminus}%
	}%
\def \p@rs@sk@p #1MINUS #2\@ndparse {\m@rkskip = #1 \m@rkminus = #2 }
}
\endgroup
%
%%% Take control of \shipout, to force it to add cropmarks
%
\let \ship@ut = \shipout
\def \shipout {\futurelet \b@x \whichb@x}
\def \whichb@x
 	{%
 	 \ifx 	\b@x \vbox
	 	\def \n@xt {\setbox \p@gebox = }%
 	      	\afterassignment \Shipout
 	 \else 	\ifx 	\b@x \hbox
 			\def \n@xt {\setbox \p@gebox = }%
 	 	     	\afterassignment \Shipout
	 	\else 	\ifx 	\b@x \box
	 			\def \n@xt {\setbox \p@gebox = }%
 	 		   	\afterassignment \Ship@ut
	 		\else	\ifx 	\b@x \copy
	 				\def \n@xt {\setbox \p@gebox = }%
 	 	 			\afterassignment \Ship@ut
	 			\else
	 				\def \n@xt {\ship@ut}%
	 	 			\message {Sorry, can't understand
	 						what follows \shipout}%
	 			\fi
	 		\fi
	 	\fi
	 \fi
 	 \n@xt
	}
\def \Shipout {\aftergroup \Ship@ut}
\def \Ship@ut
	{%
         \ifrvcropmarks
                \ifodd \pageno
                        \topcropmark = \rectotopcropmark
                        \bottomcropmark = \rectobottomcropmark
                        \leftcropmark = \rectoleftcropmark
                        \rightcropmark = \rectorightcropmark
                \else
                        \topcropmark = \versotopcropmark
                        \bottomcropmark = \versobottomcropmark
                        \leftcropmark = \versoleftcropmark
                        \rightcropmark = \versorightcropmark
                \fi
         \fi
	 \setbox \topcr@pmarkbox = \hbox
		\bgroup
		\p@rseskip \leftcropmark
 		\iflrcropmarks
 		    \ifodd \count 0
 			\let \next = \phantom
 		    \else
 			\let \next = \relax
 		    \fi
 		\else
 		    \let \next = \relax
  		\fi
 		\next {%
 			\vrule height \cropmarkwidth depth 0 pt width \m@rkplus
 				\bgroup
 				\p@rseskip \topcropmark
 				\vrule	height \m@rkplus
 					depth \m@rkminus
 					width \cropmarkwidth
 				\egroup
 			\rlap {\vrule 	height \cropmarkwidth
 					depth 0 pt width \m@rkminus}%
 		       }%
		\hskip \m@rkskip
		\p@rseskip \rightcropmark
		\hskip \m@rkskip
 		\iflrcropmarks
 		    \ifodd \count 0
 			\let \next = \relax
 		    \else
 			\let \next = \phantom
 		    \fi
 		\else
 		    \let \next = \relax
  		\fi
 		\next {%
			\llap {\vrule	height \cropmarkwidth
 					depth 0 pt width \m@rkminus}%
 				\bgroup
 				\p@rseskip \topcropmark
 				\vrule	height \m@rkplus
 					depth \m@rkminus
 					width \cropmarkwidth
 				\egroup
 			\vrule height \cropmarkwidth depth 0 pt width \m@rkplus
 		       }%
		\egroup
	 \ht \topcr@pmarkbox = 0 pt
	 \dp \topcr@pmarkbox = 0 pt
	 \wd \topcr@pmarkbox = \wd \p@gebox
	 \setbox \bottomcr@pmarkbox = \hbox
		\bgroup
		\p@rseskip \leftcropmark
 		\iflrcropmarks
 		    \ifodd \count 0
 			\let \next = \phantom
 		    \else
 			\let \next = \relax
 		    \fi
 		\else
 		    \let \next = \relax
  		\fi
 		\next {%
 			\vrule	depth \cropmarkwidth
 				height 0 pt width \m@rkplus
 				\bgroup
 				\p@rseskip \bottomcropmark
 				\vrule	depth \m@rkplus
 					height \m@rkminus
 					width \cropmarkwidth
 				\egroup
 			\rlap {\vrule	depth \cropmarkwidth
 					height 0 pt width \m@rkminus}%
 		       }%
		\hskip \m@rkskip
		\p@rseskip \rightcropmark
		\hskip \m@rkskip
 		\iflrcropmarks
 		    \ifodd \count 0
 			\let \next = \relax
 		    \else
 			\let \next = \phantom
 		    \fi
 		\else
 		    \let \next = \relax
  		\fi
 		\next {%
 			\llap {\vrule	depth \cropmarkwidth
 					height 0 pt width \m@rkminus}%
 				\bgroup
 				\p@rseskip \bottomcropmark
 				\vrule	depth \m@rkplus
 					height \m@rkminus
 					width \cropmarkwidth
 				\egroup
 			\vrule	depth \cropmarkwidth
 				height 0 pt
 				width \m@rkplus
 		       }%
		\egroup
	 \ht \bottomcr@pmarkbox = 0 pt
	 \dp \bottomcr@pmarkbox = 0 pt
	 \wd \bottomcr@pmarkbox = \wd \p@gebox
	 \setbox \cr@pmarkbox = \vbox
	 	\bgroup
		\offinterlineskip
	 	\p@rseskip \leftcropmark	\l@ftshift = \m@rkskip
	 	\p@rseskip \topcropmark		\t@pshift = \m@rkskip
	 	\p@rseskip \bottomcropmark	\b@ttomshift = \m@rkskip
		\advance \l@ftshift by \m@rkplus
		\advance \l@ftshift by \cropmarkwidth
 		\vskip -\t@pshift
 			\moveleft \l@ftshift \box \topcr@pmarkbox
		\vskip +\t@pshift
 		\vskip +\b@ttomshift
 			\moveleft \l@ftshift \box \bottomcr@pmarkbox
 		\vskip -\b@ttomshift
	 	\egroup
	 \setbox \p@gebox = \vbox
		{\offinterlineskip
		 \box \cr@pmarkbox
		 \box \p@gebox}%
	 \ship@ut \box \p@gebox
	}
%
%%% Restore \catcode of `-' & `@'
%

\catcode `\- = \c@tcodeminus
\let \c@tcodeminus = \undefined
\ifatletter \else \catcode `\@ = 12 \fi

%%% All done

