# Overlapping hboxes

How can I change the following macro to get a rule in hbox 2 that is just as wide as the text in hbox 1 and remove parameter #2?

\def\m#1#2{
\leavevmode
\hbox to#2{
\hbox to#2{\hfil\lower9pt\hbox{\it#1}\hfil}% hbox 1
\hss


P.S. Solutions just with TeX and plain TeX are preferred.

-

There is no need for manual measuring. \hrule automatically extends to the width of the surrounding vertical box (if the parameter width is not given):

\def\m#1{%
\leavevmode
\vtop{%
\hrule
\kern2pt % vertical space between rule and text
\hbox{\it#1\/}%
}%
}
abc\m{foo bar}def\m{man}ghi
\bye


Or if the distance between rule and text base line should be constant.

\def\m#1{%
\leavevmode
\vtop{%
\hrule
\vbox to .7\baselineskip{%
\vfill
\hbox{\it#1\/}%
}%
}%
}
abc\m{foo}def\m{man}ghi\m{gpq}jkm
\bye


Remark:

• Both examples add an italics correction at the end of the text.
-
Why does this solution need the \leavevmode command? –  Angel Tsankov Jun 9 at 14:07
@AngelTsankov: \leavevmode is inherited from the question. You can also use it without. Then it does not start a paragraph in vertical mode. –  Heiko Oberdiek Jun 9 at 14:11