%\iffalse -*- doctex -*- \fi
%
%% \RCS$Id: pmn-phbx.sty,v 1.2 2003/11/18 01:25:46 turtle Exp $
%% \RCS$Revision: 1.2 $
%% \RCS$Date: 2003/11/18 01:25:46 $
%
%\iffalse metacomment
%% (C) 2003 Peter Møller Neergaard
%%  
%%   This program may be distributed and/or modified under the
%%   conditions of the LaTeX Project Public License, either version 1.2
%%   of this license or (at your option) any later version.
%%   The latest version of this license is in
%%     http://www.latex-project.org/lppl.txt
%%   and version 1.2 or later is part of all distributions of LaTeX 
%%   version 1999/12/01 or later.
%
% This program consists of the file pmn-phbx.sty.
% 
% To print the documentation (which for the moment is uninteresting)
% remove (or comment out) the line
%
%   \endinput
%
% occurring immediately after
%
%   %<*documentation>
% 
%\fi
%
% \CheckSum{10}
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
% \MakeShortVerb{\"}
%
% \title{The \package{pmn-phbx} package\thanks
%   {This file has CVS revision \RCSRevision, dated \RCSDate.}}
% \author{Peter Møller Neergaard}
% \maketitle
%
% \begin{abstract}
%   This package provides two command:
%   \mcmd{\phantombox}\marg{phantom}\marg{stuff} typesets \meta{stuff}
%   with the spacing of \meta{phantom} and
%   \mcmd{ontop}\marg{stuff~A}\marg{stuff~B} which typesets
%   \meta{stuff~A} on top of \meta{stuff~B}.
% \end{abstract}
%
% \section{Package identification}
% 
% We identify ourselves.
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pmn-phbx}[2003/11/02 Phantom box]
%    \end{macrocode}
%
% \begin{macro}{\phantombox}
% \begin{macro}{\pmn@phbx@math}
% \begin{macro}{\pmn@phbx@math@i}
% \begin{macro}{\pmn@phbx@math@ii}
% \begin{macro}{\pmn@phbx@text}
% \begin{macro}{\pmn@phbx@fin}
%   \mcmd{\phantombox}\marg{phantom}{stuff} typesets \meta{stuff} as if it
%   filled \meta{phantom}.
%    \begin{macrocode}
\makeatletter
\newbox\pmn@phbx@boxA
\newbox\pmn@phbx@boxB
%    \end{macrocode}
% Choose the actual command depending on whether we are in math mode
% or not (see description of \cmd{\phantom} in the \TeX-book).
%    \begin{macrocode}
\newcommand{\phantombox}{%
  \ifmmode \expandafter\pmn@phbx@math
  \else \expandafter\pmn@phbx@text\fi}
%    \end{macrocode}
% In text mode, we just type set the two commands in a box.
%    \begin{macrocode}
\newcommand{\pmn@phbx@text}[2]{%
  \bgroup
  \setbox\pmn@phbx@boxA\hbox{#1}% 
  \setbox\pmn@phbx@boxB\hbox{\makebox[\wd\pmn@phbx@boxA][c]{#2}}%
  \pmn@phbx@fin}
%    \end{macrocode}
% If we were inside math mode, we have to shift back into (that is why
% we are using \cmd{\mathpalette} above) and then typeset the box.
%    \begin{macrocode}
\newcommand{\pmn@phbx@math}[2]{%
  \mathpalette\pmn@phbx@math@i{{#1}{#2}}}
\newcommand{\pmn@phbx@math@i}[2]{\pmn@phbx@math@ii{#1}#2}
\newcommand{\pmn@phbx@math@ii}[3]{%
  \bgroup
  \setbox\pmn@phbx@boxA\hbox{$\m@th#1{#2}$}%
  \setbox\pmn@phbx@boxB\hbox{\makebox[\wd\pmn@phbx@boxA][c]{$\m@th#1{#3}$}}%
  \pmn@phbx@fin}
%    \end{macrocode}
% As \cmd{\mathpalette} takes only one argument we need to pack the
% two arguments up as one argument, and unpack it again
% with~\cmd{\pmn@phbx@math@i}.
%
% Finally, we can stretch the box of \meta{stuff} to the dimensions
% of~\meta{phantom}.
%    \begin{macrocode}
\newcommand{\pmn@phbx@fin}{%
  \dp\pmn@phbx@boxB\dp\pmn@phbx@boxA\relax
  \ht\pmn@phbx@boxB\ht\pmn@phbx@boxA\relax
  \box\pmn@phbx@boxB\egroup}
%    \end{macrocode}
% \end{macro} ^^A \pmn@phbx@fin
% \end{macro} ^^A \pmn@phbx@text
% \end{macro} ^^A \pmn@phbx@math@ii
% \end{macro} ^^A \pmn@phbx@math@i
% \end{macro} ^^A \pmn@phbx@math
% \end{macro} ^^A \phantombox
%
% \begin{macro}{\ontop}
% \begin{macro}{\pmn@ontop@math}
% \begin{macro}{\pmn@ontop@math@i}
% \begin{macro}{\pmn@ontop@math@ii}
% \begin{macro}{\pmn@ontop@text}
% \begin{macro}{\pmn@ontop@fin}
%   \mcmd{\overlap}\marg{stuff~A}{stuff~B} typesets \meta{stuff~A} and
%   \meta{stuff~B} on top of each other.  The dimensions become the
%   biggest of the two.
%
% Choose the actual command depending on whether we are in math mode
% or not (see description of \cmd{\phantom} in the \TeX-book).
%    \begin{macrocode}
\newcommand{\ontop}{%
  \ifmmode \expandafter\pmn@ontop@math
  \else \expandafter\pmn@ontop@text\fi}
%    \end{macrocode}
% In text mode, we just type set the two commands in a box.
%    \begin{macrocode}
\newcommand{\pmn@ontop@text}[2]{%
  \bgroup
  \setbox\pmn@phbx@boxA\hbox{#1}% 
  \setbox\pmn@phbx@boxB\hbox{#2}%
  \pmn@ontop@fin}
%    \end{macrocode}
% If we were inside math mode, we have to shift back when we start
% typesetting the box.  This is accomplished with \cmd{\mathpalette}.
%    \begin{macrocode}
\newcommand{\pmn@ontop@math}[2]{%
  \mathpalette\pmn@ontop@math@i{{#1}{#2}}}
\newcommand{\pmn@ontop@math@i}[2]{\pmn@ontop@math@ii{#1}#2}
\newcommand{\pmn@ontop@math@ii}[3]{%
  \bgroup
  \setbox\pmn@phbx@boxA\hbox{$\m@th#1{#2}$}%
  \setbox\pmn@phbx@boxB\hbox{$\m@th#1{#3}$}%
  \pmn@ontop@fin}
%    \end{macrocode}
% As \cmd{\mathpalette} takes only one argument we need to pack the
% two arguments up as one argument, and unpack it again
% with~\cmd{\pmn@ontop@math@i}.
%
% Finally, we typeset the material with the width of the largest box.
% The depth and height will be right automatically.
%    \begin{macrocode}
\newcommand{\pmn@ontop@fin}{%
  \ifnum\wd\pmn@phbx@boxA>\wd\pmn@phbx@boxB
    \mbox{%   
      \makebox[\wd\pmn@phbx@boxA][c]{\unhbox\pmn@phbx@boxB}%
      \hskip-\wd\pmn@phbx@boxA
      \unhbox\pmn@phbx@boxA}%
  \else
    \mbox{%   
      \makebox[\wd\pmn@phbx@boxB][c]{\unhbox\pmn@phbx@boxA}%
      \hskip-\wd\pmn@phbx@boxB
      \unhbox\pmn@phbx@boxB}
   \fi\egroup}
%    \end{macrocode}
% \changes{}{2003/11/17}{Added}
% \end{macro} ^^A \pmn@ontop@fin
% \changes{}{2003/11/17}{Added}
% \end{macro} ^^A \pmn@ontop@text
% \changes{}{2003/11/17}{Added}
% \end{macro} ^^A \pmn@ontop@math@ii
% \changes{}{2003/11/17}{Added}
% \end{macro} ^^A \pmn@ontop@math@i
% \changes{}{2003/11/17}{Added}
% \end{macro} ^^A \pmn@ontop@math
% \changes{}{2003/11/17}{Added}
% \end{macro} ^^A \phantombox
%
% \StopEventually{}
% 
% And finally the commands to typeset the documentation.  All enclosed in
% "<*documentation>"$\ldots$"</documentation>" so we exclude it if we
% ever make a docstrip file.  For now, we simply stop input with
% \cmd{\endinput} so the file can be used directly as a package file.
%    \begin{macrocode}
%<*documentation>
\endinput
%    \end{macrocode}
% We undefine \cmd{\RCS} before loading \package{pmn-ldoc} where it is
% also defined:
%    \begin{macrocode}
\documentclass{pmn-ldoc} 
\usepackage[latin1]{inputenc}
\newcommand{\docdate}{2003/11/02}
 % \OnlyDescription
 % \DisableCrossrefs
\begin{document}
  \DocInput{pmn-phbx.sty}
\end{document}
%</documentation>
%    \end{macrocode}
% \Finale \sloppy \PrintChanges
