% underline.sty   bert@mit.edu   Nov 25 1993
%
% This file fixes for two of LaTeX's stupid underlining problems:
%   * underlines cannot be broken across lines
%   * LaTeX draws underlines at varying depths, e.g. the underline in
%     \underline{high} will be below the one in \underline{low}, which is
%     especially annoying if they are next to each other.
%
% This method works well for text.  If you try to use this for
% underlining formulas, it will work for ``above'' things like $x^3$,
% but not for the things descending below the baseline like $A_0$ or
% $3\over4$.  If you need to use LaTeX's text underlining for things
% like this, it has been renamed to \lineunder.
%
% Note that this still doesn't allow the words to be hyphenated.  That
% would be a bit painful to implement...
%
% \underlinespaces controls if the interword spaces get displayed
% as blank space (\underlinespaces{blank}) or with the underline
% (\underlinespaces{underline}).  Default is {blank}.

% fixed definition of \underline (uses \text@underline if not in math mode)

\let\lineunder=\underline
\def\underline#1{\relax\ifmmode \@@underline{#1}\else\text@underline{#1}\fi}

% we must redefine TeX macro \underbar to use \@@underline

\def\underbar#1{$\setbox\z@\hbox{#1}\dp\z@\z@\m@th\@@underline{\box\z@}$}

% this separates the argument into words, etc.  Use the TeXbook, Luke.

\def\text@underline#1{{\expandafter\under@word\ignorespaces#1 }}
\def\under@word#1 {\underbar{#1}\futurelet\@tempa\under@cont}
\def\under@cont{\if\@tempa\egroup\else\under@space\under@word\fi}

% stuff for \underlinespaces: defines \under@space as whatever the spaces go to

\def\uspace@blank{\let\under@space=\space}
\def\uspace@underline{\def\under@space{\discretionary{}{}{\hbox{\underbar{ }}}%
\nobreak\hskip0pt minus1pt}}

\def\underlinespaces#1{\@nameuse{uspace@#1}}
\underlinespaces{blank}  % initialize default
