[texhax] Variable-thickness underline

Philip TAYLOR P.Taylor at Rhul.Ac.Uk
Sat Sep 19 20:20:47 CEST 2009



Germain BOYER wrote:

> Is it possible to have a new command \Underline for example with one optionnel argument. 
> The argument is the width of the rule created by \underline. 
> For example \Underline[1pt]{the text}.  

Bonjour, Germain.  I fear not.  The following code shews
how it might be accomplished, were it not for the fact that
TeX does not inspect \fontdimen 8 \textfont 3 (which
is from where the thickness and the separation are taken)
until the end of the maths formula, rather than at the time
that \underline is used.  Compare the following two versions,
the first of which restores \fontdimen 8 \textfont 3
immediately the underlining is complete whilst in the second
the restore is commented out.  Note also that even if it
were possible, the optional parameter would specify not
only the underline thickness but also the separation from
the <maths field> to which it applies.

Philip TAYLOR
--------
\newtoks \ULtoks
\newdimen \ULthickness

\def \ULdimen {\fontdimen 8 \textfont 3 }

\def \Underline #1#%
     {\edef \ULmacro
         {\ULthickness = \ULdimen
          \ifx \relax #1\relax \else \ULdimen = #1 \fi
          \underline {\noexpand \the \ULtoks}
          \ULdimen = \ULthickness
         }
      \afterassignment \ULmacro
      \ULtoks =
      }

$$\Underline 0 pt {Now }$$
$$\Underline 1 pt {is }$$
$$\Underline 2 pt {the }$$
$$\Underline 3 pt {time }$$
$$\Underline {for }$$

\def \Underline #1#%
     {\edef \ULmacro
         {\ULthickness = \ULdimen
          \ifx \relax #1\relax \else \ULdimen = #1 \fi
          \underline {\noexpand \the \ULtoks}
%        \ULdimen = \ULthickness
         }
      \afterassignment \ULmacro
      \ULtoks =
      }

$$\Underline 0 pt {Now }$$
$$\Underline 1 pt {is }$$
$$\Underline 2 pt {the }$$
$$\Underline 3 pt {time }$$
$$\Underline {for }$$
\end


More information about the texhax mailing list