%%% /usr/local/src/hoc/hoc-7.0.7.beta/doc/keyname.sty, Wed Jul 28 18:21:18 2004
%%% Edit by Nelson H. F. Beebe <beebe@math.utah.edu>
%%%
%%% ====================================================================
%%% Provide a convenient mechanism for typesetting oval boxes around
%%% keyboard keynames.  The user-accessible commands in this package
%%% are:
%%%
%%%     \keyname{keyname}               Typeset keyname in an oval box
%%%                                     at current font size.
%%%
%%%     \keynameprototype{keyname}      Longest and deepest keyname.
%%%                                     Change with \renewcommand.
%%%                                     default keyname: ESCape
%%%
%%%     \keynamebeforeafterskip         Horizontal glue before and
%%%                                     after the oval box. Change
%%%                                     with \setlength.
%%%
%%%     \keynameabovebelowskip          Vertical glue above and
%%%                                     below the oval box. Change
%%%                                     with \setlength.
%%%
%%%     \keynametest                    Typeset a test of sample
%%%                                     keynames in all standard font
%%%                                     sizes with a range of line
%%%                                     widths.  Change with
%%%                                     \renewcommand.
%%% ====================================================================

\ifx \keyname \undefined    % bail out if we have been loaded already
\else
    \endinput
\fi

\def \fileversion {1.00}%
\def \filedate    {2004/07/28}%

\ifx \ProvidesPackage \undefined
\else
    \ProvidesPackage{keyname}%
        [\filedate\space v\fileversion\space keyboard keynames in ovals for LaTeX]
\fi

\newsavebox{\@keynamebox}

\newlength{\@keynameboxdepth}

\newlength{\@keynameboxwidth}
\newcount \@keynameboxwidthcount

\newlength{\@keynameboxheight}
\newcount \@keynameboxheightcount

\newlength{\keynameabovebelowskip} % space above and below keybox to avoid box overlap on adjacent lines
\setlength{\keynameabovebelowskip}{1pt}

\newlength{\keynamebeforeafterskip} % space before and after ovalbox
\setlength{\keynamebeforeafterskip}{0.3em plus 0.1em minus 0.1em}

%%% Unfortunately, the LaTeX \oval command defined in latex.ltx:5391
%%% does not clearly define the extent of the oval created, so it took
%%% considerable experimentation to find reasonable dimensions of a
%%% bounding box that work for all LaTeX font sizes from \tiny to
%%% \Huge.

\newcommand{\keynameprototype}{ESCape} % should have descender

\newcommand{\keyname}[1]{%
    {%
        \savebox{\@keynamebox}{\texttt{\keynameprototype}}% keybox of fixed size big enough for longest key
        \settodepth{\@keynameboxdepth}{\usebox{\@keynamebox}}%
        \settowidth{\@keynameboxwidth}{\usebox{\@keynamebox}}%
        %
        \@keynameboxwidthcount = \@keynameboxwidth%
        \advance \@keynameboxwidthcount by 65535%
        \divide \@keynameboxwidthcount by 65536%
        \advance \@keynameboxwidthcount by 4
        %
        \settoheight{\@keynameboxheight}{\usebox{\@keynamebox}}%
        %%: \showthe\@keynameboxheight
        %%: \showthe\@keynameboxdepth
        %%: \showthe\@keynameboxwidth
        \@keynameboxheightcount = \@keynameboxheight%
        \advance \@keynameboxheightcount by 65535%
        \divide \@keynameboxheightcount by 65536%
        \multiply \@keynameboxheightcount by 20
        \divide \@keynameboxheightcount by 10
        %
        \setlength{\unitlength}{1pt}%
        %
        \savebox{\@keynamebox}{\texttt{#1}}%
        \setlength{\fboxsep}{0pt}%
        \setlength{\fboxrule}{1sp}%
        \kern \keynamebeforeafterskip             % leading removable space
        \mbox{%
            %
            % Height of bounding box
            %
            \dimen0 = \@keynameboxheight
            \advance \dimen0 by \@keynameboxdepth
            \advance \dimen0 by \keynameabovebelowskip
            \advance \dimen0 by 2pt % fudge factor
            %
            % Depth of bounding box
            %
            \dimen1 = \@keynameboxdepth
            \advance \dimen1 by \fboxsep
            \advance \dimen1 by \keynameabovebelowskip
            %
            % Bounding box strut
            %
            \vrule height \dimen0 depth \dimen1 width 0pt % strut that fills oval box
            %
            % Undo ovalbox horizontal centering
            %
            \kern 0.5\@keynameboxwidth
            %
            %  Undo ovalbox vertical centering
            %
            \dimen2 = \@keynameboxdepth
            \dimen2 = 0pt
            \advance \dimen2 by 0.5\@keynameboxheight
            %
            \raisebox{\dimen2}{\oval(\@keynameboxwidthcount,\@keynameboxheightcount)}%
            %
            % Move back to original starting position and typeset argument text
            %
            \kern -0.5\@keynameboxwidth
            \makebox[\@keynameboxwidth][c]{\usebox{\@keynamebox}}%
        }%
        \kern \keynamebeforeafterskip             % trailing removable space
    }%
}

\newcommand{\@keynamesample}{This is a test of the \keyname{ESCape} and \keyname{RETurn} and \keyname{TAB} keys.}
\newcommand{\@keynamebigsample}{\@keynamesample{ }\@keynamesample{ }\@keynamesample{ }\@keynamesample{ }}
\newcommand{\@keynamebiggersample}{\@parshape \@keynamebigsample{ }\@keynamebigsample{ }\@keynamebigsample{ }\@keynamebigsample{ }\bigskip}

\newcommand{\@parshape}{\parshape = 9
     0.45\textwidth 0.10\textwidth% indent and width
     0.40\textwidth 0.20\textwidth
     0.35\textwidth 0.30\textwidth
     0.30\textwidth 0.40\textwidth
     0.25\textwidth 0.50\textwidth
     0.20\textwidth 0.60\textwidth
     0.15\textwidth 0.70\textwidth
     0.10\textwidth 0.80\textwidth
     0.05\textwidth 0.90\textwidth
}

\newcommand{\keynametest}{%
    {%
        \clearpage
        \marginpar{\normalsize \bfseries tiny}\tiny \@keynamebiggersample

        \marginpar{\normalsize \bfseries footnotesize}\footnotesize \@keynamebiggersample

        \marginpar{\normalsize \bfseries small}\small \@keynamebiggersample

        \marginpar{\normalsize \bfseries normalsize}\normalsize \@keynamebiggersample

        \marginpar{\normalsize \bfseries large}\large \@keynamebiggersample

        \marginpar{\normalsize \bfseries Large}\Large \@keynamebiggersample

        \marginpar{\normalsize \bfseries LARGE}\LARGE \@keynamebiggersample

        \marginpar{\normalsize \bfseries huge}\huge \@keynamebiggersample

        \marginpar{\normalsize \bfseries Huge}\Huge \@keynamebiggersample
        \clearpage
    }%
}
