[texhax] Underline with numbers

Reinhard Kotucha reinhard.kotucha at web.de
Sun Dec 12 20:35:28 CET 2010


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]}%

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.

Regards,
  Reinhard

-- 
----------------------------------------------------------------------------
Reinhard Kotucha			              Phone: +49-511-3373112
Marschnerstr. 25
D-30167 Hannover	                      mailto:reinhard.kotucha at web.de
----------------------------------------------------------------------------
Microsoft isn't the answer. Microsoft is the question, and the answer is NO.
----------------------------------------------------------------------------



More information about the texhax mailing list