% \iffalse
%%
%% File: ncccropbox.dtx Copyright (C) 2002--2004 by Alexander I. Rozhenko
%%
%<package>\NeedsTeXFormat{LaTeX2e}
%<package>\ProvidesPackage{ncccropbox}
%<package>         [2004/11/24 v1.1 Crop Box Package (NCC)]
%
% \changes{v1.02}{2002/01/31}{This version is uploaded to CTAN}
% \changes{v1.03}{2002/02/08}{The package is renamed to ncccropbox}
% \changes{v1.1}{2004/11/24}{Documentation was prepared}
%
%<*driver>
\let\makeindex\relax
\documentclass{ltxdoc}
\usepackage{ncccropbox}
\GetFileInfo{ncccropbox.sty}
\begin{document}
\title{The \textsf{ncccropbox} package\thanks{This file
        has version number \fileversion, last
        revised \filedate.}}
\author{Alexander I. Rozhenko\\rozhenko@oapmg.sscc.ru}
\date{\filedate}
\maketitle
\DocInput{ncccropbox.dtx}
\end{document}
%</driver>
% \fi
%
% \section{User Interface}
%
% \DescribeMacro{\cropbox}
% The package implements the command
% \begin{quote}
%   |\cropbox|\oarg{width}\oarg{height}\marg{content}
% \end{quote}
% preparing a horizontal box with crop-marks at its corners looking like angles.
% The crop-box is aligned at the bottom and is lowered at the |\lineskip| value.
% The optional \meta{width} and \meta{height} parameters specify the width and
% height of the crop-box respectively. If some of them is omitted or is
% empty, the width or height of the crop-box \meta{content} is used for calculation
% the omitted dimension. In this case, the doubled value of the
% \textit{crop-box separation\/} parameter is added to the natural dimension
% of the box's \meta{content}. The \meta{content} is centered inside the crop-box.
%
% \DescribeMacro{\cropboxsep}
% The |\cropboxsep|\marg{length} command specifies the separation value to be used
% in calculation of crop-box dimensions when any of optional parameters is
% omitted or empty. The default is |\cropboxsep{5pt}|.
%
% \DescribeMacro{\croplinewidth}
% The |\croplinewidth|\marg{length} command specifies a width of crop-lines.
% The default is |\croplinewidth{.4pt}|.
%
% \DescribeMacro{\croplinelength}
% The |\croplinelength|\marg{length} command specifies a length and direction
% of crop-lines: the absolute value of \meta{length} specifies
% a length of crop-lines and the sign of \meta{length} specifies a direction.
% If the \meta{length} is negative, the angles look outside the crop-box.
% Otherwise, they look inside the crop-box.
%
% The following example shows how crop-boxes are docked together:
% \begin{center}
% \cropbox[30mm][10mm]{Box 1}\cropbox[30mm][10mm]{Box 2}\cropbox[30mm][10mm]{Box 3}\cropbox[30mm][10mm]{Box 4}\\
% \cropbox[30mm][10mm]{Box 5}\cropbox[30mm][10mm]{Box 6}\cropbox[30mm][10mm]{Box 7}\cropbox[30mm][10mm]{Box 8}
% \end{center}
% It was prepared as follows:
% \begin{quote}
% |\begin{center}|\\
% |\cropbox[30mm][10mm]{Box 1}\cropbox[30mm][10mm]{Box 2}%|\\
% |\cropbox[30mm][10mm]{Box 3}\cropbox[30mm][10mm]{Box 4}\\|\\
% |\cropbox[30mm][10mm]{Box 5}\cropbox[30mm][10mm]{Box 6}%|\\
% |\cropbox[30mm][10mm]{Box 7}\cropbox[30mm][10mm]{Box 8}|\\
% |\end{center}|
% \end{quote}
% You can see that crop-lines of neighbour boxes exactly coincide.
% \StopEventually{}
%
% \section{The Implementation}
%
% \begin{macro}{\croplinelength}
% \begin{macro}{\croplinewidth}
% \begin{macro}{\cropboxsep}
% Styling macros:
%    \begin{macrocode}
%<*package>
\newcommand*{\croplinelength}[1]{\def\CRB@length{#1}}
\newcommand*{\croplinewidth}[1]{\def\CRB@width{#1}}
\newcommand*{\cropboxsep}[1]{\def\CRB@sep{#1}}
%    \end{macrocode}
% \end{macro}
% \end{macro}
% \end{macro}
%
% \begin{macro}{\cropbox}
% The |\cropbox| command:
%    \begin{macrocode}
\newcommand*{\cropbox}[1][]{\@ifnextchar[{\CRB@box[#1]}{\CRB@box[#1][]}}
\def\CRB@box[#1][#2]#3{%
%    \end{macrocode}
% Calculate crop-box dimensions in |\@tempdima| and |\@tempdimb|:
%    \begin{macrocode}
  \@begin@tempboxa\hbox{#3}%
    \def\@tempa{#1}\ifx\@tempa\@empty
      \@tempdima\width \advance\@tempdima 2\CRB@sep\relax
    \else
      \setlength\@tempdima{#1}%
    \fi
    \def\@tempa{#2}\ifx\@tempa\@empty
      \@tempdimb\totalheight \advance\@tempdimb 2\CRB@sep\relax
    \else
      \setlength\@tempdimb{#2}%
    \fi
%    \end{macrocode}
% Prepare crop-marks in 0th box of zero width:
%    \begin{macrocode}
    \setbox\z@\hb@xt@\z@{%
      \linethickness{\CRB@width}%
      \setlength\unitlength{\CRB@length}%
      \ifdim\unitlength=\z@ \else
        \ifdim\unitlength>\z@
          \CRB@hcross\z@\z@\@ne\@ne
          \CRB@hcross\@tempdima\z@\m@ne\@ne
          \CRB@hcross\z@\@tempdimb\@ne\m@ne
          \CRB@hcross\@tempdima\@tempdimb\m@ne\m@ne
        \else \unitlength -\unitlength
          \CRB@hcross\z@\z@\m@ne\m@ne
          \CRB@hcross\@tempdima\z@\@ne\m@ne
          \CRB@hcross\z@\@tempdimb\m@ne\@ne
          \CRB@hcross\@tempdima\@tempdimb\@ne\@ne
        \fi
      \fi
    }%
%    \end{macrocode}
% Put crop-marks as a background for vertical box containing the
% crop-box content. We decrease the height of vertical box on
% the |\lineskip| to make the exact docking of vertically neighbour
% crop-boxes.
%    \begin{macrocode}
    \leavevmode \ht\z@\z@ \dp\z@\z@ \box\z@
    \advance\@tempdimb -\lineskip
    \vbox to\@tempdimb{\vss\vskip -\lineskip
      \hb@xt@\@tempdima{\hss\unhbox\@tempboxa\hss}\vss\kern\z@
    }%
  \@end@tempboxa
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\CRB@hcross}
% This command prepares a crop-mark.
%    \begin{macrocode}
\def\CRB@hcross#1#2#3#4{%
  \@killglue\raise#2\hb@xt@\z@{\kern#1\line(#3,0)\@ne\hss}\hss
  \@killglue\raise#2\hb@xt@\z@{\kern#1\line(0,#4)\@ne\hss}\hss
}
%    \end{macrocode}
% \end{macro}
%
% Initial settings:
%    \begin{macrocode}
\croplinelength{10pt}
\croplinewidth{.4pt}
\cropboxsep{5pt}
%</package>
%    \end{macrocode}
\endinput