%                              highlight.tex
% macros for "highlighting" text using grey boxes generated on a postscript
% printer.
%
% tara@rutgers.edu (5/16/90)
%
% Usage: \graybox{#1} creates an hbox out of the argument text.
%        It is useful to highlight a word or two inline. The box 
%        generated is exactly the size of the bounding box of the
%        argument text.
%
%	 \grayvbox{#1} creates a highlighted vbox out of the argument
%        (which will have a width of \hsize). It is useful to highlight 
%        a paragraph or table. 
%
%        \highlight{#1} works more like a real "highlighter", drawing a 
%	 streak of gray across the words in the argument text, formatting
%        as usual.
%
\catcode`\@=11
\def\@SpecialCodeDriver{dvitps: }
% identifying message
\message{** using dvitps \string\specials **}

\newbox\swbox 
\newskip\sp@ht \newskip\sp@wd \newskip\sp@dp \newskip\oldparindent

\def\grayvbox#1{\oldparindent=\parindent
	\parindent=0pt\setbox\swbox=\hbox{\vbox{\hskip \oldparindent #1}}
	\sp@ht=\ht\swbox\sp@wd=\wd\swbox\sp@dp=\dp\swbox%
	\advance\sp@dp by \sp@ht\sp@ht=0pt
	\special{\@SpecialCodeDriver Gray %
	\the\sp@ht\space\the\sp@dp\space\the\sp@wd}\leavevmode\box\swbox\parindent=\oldparindent}


\def\graybox#1{\setbox\swbox=\hbox{#1}
	\sp@ht=\ht\swbox\sp@wd=\wd\swbox\sp@dp=\dp\swbox%
	\special{\@SpecialCodeDriver Gray %
	\the\sp@ht\space\the\sp@dp\space\the\sp@wd}\box\swbox}

% other spellings 
\def\greybox{\graybox}
\def\greyvbox{\grayvbox}

% Vararg code adapted from example in pre-release edition of
% _Another Look at Tex_,  Stephan v. Bechtolsheim
%
\newcount \va@argno
\def\va@args{%
%	\wlog{}
	\def\p@psfile{}%
%	\wlog{\string\va@args: begin}
	\va@argno=0
	\va@argsA
}

\def\va@argsA{%
	\futurelet\va@argstoken\va@argsmore
}

\def\va@argsmore{%
	\ifx\va@argstoken\va@end%
	  \let\next =\va@argsdone%
	\else%
	  \let\next=\va@argsdo%
	\fi%
	\next%
}

\def\va@argsdone \va@end{%
	\wlog{\string\va@args: end}
}

\def\va@argsdo #1 {%
	\advance\va@argno by 1%
%	\wlog{Argument \the\va@argno: "#1"}%
	\highlightword{#1}
	% recursive call; continue to parse arguments
	\va@argsA%
}


\def\highlightword#1{\setbox\swbox=\hbox{#1}%
	\sp@ht=\baselineskip \advance\sp@ht by -.75ex
	\sp@wd=\wd\swbox\advance\sp@wd by .6em\sp@dp=.75ex%
%	\message{sp@wd = \the\sp@wd,sp@dp=\the\sp@dp,sp@ht=\the\sp@ht}%
	\kern-.2em\hbox{\special{\@SpecialCodeDriver Gray %
	\the\sp@ht\space\the\sp@dp\space\the\sp@wd}}\kern.2em\box\swbox}

\def\highlight#1{\leavevmode\va@args #1 \va@end}
\catcode`\@=12
