%%   -------------- keybox.tex ----------------
% KEYBOX.TEX - makes a round-cornered box around a word or letter
%              Peter Flynn, November 1993 <pflynn@curia.ucc.ie>
%%%  from ttn3n1.sty
%% 15 DEC 93: appended keybox.tex, Peter Flynn's style file for his
%%            column, ``Typographer's Inn'' (Ch.)
%%%
%% font name, box name and dimension name have been changed
%%  to avoid conflict; "@" is added

\font\k@rings=lcircle10
\font\k@rm=cmss8

\newbox\k@box                             % box to test dimensions
\newdimen\k@wd\newdimen\k@ht\newdimen\k@dp  % the test dimensions
\newdimen\chk@ht\newdimen\z@ht             % and some more

\def\key#1{%
% find the height of a cap and a descender in the font we're using
\setbox\k@box=\hbox{{\k@rm Xy}}\k@ht=\ht\k@box
% find the width of the key name we're going to set
\setbox\k@box=\hbox{{\k@rm#1}}\k@wd=\wd\k@box
% make it 1em wide if it's actually a narrow character, then add some space
{\k@rm\ifdim\k@wd<1em\global\k@wd=1em\fi}\advance\k@wd by4pt%
% get the depth of descender, if any, in the text we are setting
\k@dp=\dp\k@box
% get the height of the text, and subtract it from the height of a capital
% if the text being set contains a cap, this leaves 0pt, otherwise it leaves
% the difference between x-height and cap-height.
\chk@ht=\ht\k@box\z@ht=\k@ht\advance\z@ht by-\chk@ht
% if the height of the text is indeed less than the height of a cap,
% subtract the difference calculated above from the cap-height
% and then subtract the x-height. This should leave just enough space
% to \vskip backwards to cover our tracks
\ifdim\chk@ht<\k@ht\advance\k@ht by-\z@ht\fi{\k@rm\global\advance\k@ht by-1ex}
% now set it in a \hbox, dropped 2pt to line up the baselines (roughly)
\setbox\k@box=\hbox{\lower2pt%
% containing a \vbox set to the width of the text plus the rule thicknesses
\vbox{\hsize=\k@wd\advance\hsize by.8pt%
% zoom leftwards because of the silly reference points of the corners
\advance\k@wd by-7.2pt%
% and make in internal \hbox for the ``lid'' containing the top LH corner,
\hbox to\hsize{{\k@rings\char'007}%
% the rule,
\kern-3.5pt\hbox to\k@wd{\hrulefill}\kern3pt%
% and the top RH corner, and don't gripe about it not fitting!
{\k@rings\char'004}\hss}\nointerlineskip% 
% shift up 1pt to make the lines meet, and also the amount we calculated
% above to hide the ascenders in the upper <corner><rule><corner> ``lid''.
\vskip-1pt\vskip-\k@ht
% set the \hbox in the middle with a rule, the text and a rule. The negative
% rule depth makes a 1pt rule to cover the gap caused by the height of the
% characters
\hbox to\hsize{\vrule height3pt depth-2pt\hss{\k@rm#1}\hss\vrule 
height3pt depth-2pt}\nointerlineskip%
% if there were descenders, now's the time to backtrack to fit them
% into the bottom of the box. It seems to need the extra -space, I dunno why.
\ifdim\k@dp>0pt\kern-\k@dp\fi\vskip-2.125pt%
% finally, fit together the bottom, the same way as the ``lid''.
\hbox to\hsize{{\k@rings\char'006}\kern-3.5pt\hbox to\k@wd{\hrulefill}%
\kern3pt{\k@rings\char'005}\hss}}}%
% then backtrack a bit because of the corner reference points being so odd
\kern-2pt\box\k@box}
%
% Here's a line to test it with
%
%This is a \key{Enter} key, this is \key{Esc} and the \key{x}\hfil\break 
%This is a second line with a \key{X} and \key{y} plus the \key{Nasty} one.
%\bye
