# [texhax] Underline with numbers

Paul Isambert zappathustra at free.fr
Mon Dec 13 09:41:19 CET 2010


Le 12/12/2010 20:35, Reinhard Kotucha a écrit :
> On 12 December 2010 Paul Isambert wrote:
>
>   >  Le 11/12/2010 23:43, Evan Wessler a écrit :
>   >  >  I'm trying to create underlined text, but with numbers under the
>   >  >  underlines. (I need to refer to the underlined pieces of text by
>   >  >  number.) If that's confusing, imagine being able to do the same
>   >  >  thing with an underline as you're able to do with an arrow like
>   >  >  \xleftarrow[below]{above}, where the [below] and {above} text end
>   >  >  up below and above the arrow with subscript/superscript sizing,
>   >  >  respectively.
>   >  >
>   >  >  Of course, I tried \underline[option]{text}, but was sad to
>   >  >  discover no option existed.
>   >  >
>   >  >  Anyone have any advice?
>   >
>   >  If your underlined text is not supposed to break, then the
>   >  following might do:
>   >
>   >  \makeatletter
>   >  \newbox\uboxa
>   >  \newbox\uboxb
>   >  \def\unum{%
>   >     \@ifnextchar[
>   >       {\@unum}
>   >       {\@unum[\dp\uboxa]}%
>   >     }
>   >
>   >  \def\@unum[#1]#2#3{%
>   >     \setbox\uboxa=\hbox{#2}%
>   >     \setbox\uboxb=\vbox{%
>   >       \copy\uboxa
>   >       \kern.1em\hrule\kern.1em
>   >       \hbox to \wd\uboxa{\hfil#3\hfil}}%
>   >     \ht\uboxb=\ht\uboxa
>   >     \dp\uboxb=#1\relax
>   >     \quitvmode\box\uboxb
>   >     }
>   >  \makeatother
>   >
>   >
>   >  Then:
>   >
>   >  \unum[<depth>]{<text>}{<number>}
>   >
>   >  produces an underlined<text>  with<number>  below (or anything else, for
>   >  that matter); the depth of that is<depth>, which defaults to the
>   >  natural depth of<text>  (as if the rule and the number below did not
>   >  exist). The line
>
> Hi Paul,
> nice macro.  However, if you don't provide the optional argument
> consecutive lines overlap.  It seems that you determine \dp\uboxa
> before something is put into the box.  Replacing the default with
> \baselineskip yields reasonable results.
>
> \def\unum{%
>     \@ifnextchar[
>       {\@unum}
>       {\@unum[\baselineskip]}%

It was on purpose: let the text have its natural depth, i.e. as if lines
and numbers did not exist. So consequently multiple lines overlap
indeed. Anyway that was probably not the best default setting, but I
don't know where Evan want such text to occurr.

> Furthermore, if you want all lines to be aligned vertically, you can
> put a \strut in front of #2.  It's also quite convenient to replace #3
> by {\scriptsize#3} or {\tiny#3}.  If appropriate, #3 can be replaced
> by a counter.

Yes, yes and yes. Especially the strut.

Best,
Paul