[Tex/LaTex] Roman numerals with over- and underline

fontsroman numerals

This question led to a new package:
romanbar

(using a variation of egreg's code, and stating this in the manual; the package isn't really new now, sorry for the delayed announcement)

I have read about "How to get Roman numerals" but asked myself how to get Roman numerals formatted as in

Roman VI

i.e. with fitted over- and underline (without manually using boxes and such)?
I'm curious for your answer(s)!

Best Answer

\def\barroman#1{\sbox0{#1}\dimen0=\dimexpr\wd0+1pt\relax
  \makebox[\dimen0]{\rlap{\vrule width\dimen0 height 0.06ex depth 0.06ex}%
    \rlap{\vrule width\dimen0 height\dimexpr\ht0+0.03ex\relax 
            depth\dimexpr-\ht0+0.09ex\relax}%
    \kern.5pt#1\kern.5pt}}

\barroman{I} \barroman{XI}