[texhax] Underline with numbers

Paul Isambert zappathustra at free.fr
Sun Dec 12 17:34:39 CET 2010


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

     \kern.1em\hrule\kern.1em

in the definition of \@unum can be modified to set the amount of space 
surrounding the rule.

Now if you want your text to break across lines, it'll be a little bit 
harder...

Best,
Paul


More information about the texhax mailing list