How is the \underline command defined? And how can one make a custom underline to be used just as a horizontal line but which respects a specified height or the height of text, math input, etc and of a specific width?
Here is my first attempt:
\newcommand{\ndfracunderline}[1]{\ensuremath{\underline{\phantom{\dfrac{2}{3\hspace*{#1}}}}}}
This works just fine but the following does not:
\newsavebox\underlinebox
\newcommand\cunderline[3][black]{%
\newlength{\cunderlineheight}%
\settoheight{\cunderlineheight}{#3}%
{\sbox\underlinebox{\cunderlineheight\hspace*{#2}}%
\rlap{\usebox\underlinebox}\color{#1}\rule[-1.2\dp\underlinebox]{\wd\underlinebox}{0.5pt}}}


\underlineis defined in the kernel in the following way:\def\underline#1{\relax \ifmmode\@@underline{#1}\else $\@@underline{\hbox{#1}}\m@th$\relax\fi}, where\@@underlinehas been previously\letto the TeX's primitive\underline:\let\@@underline\underline. – Gonzalo Medina Sep 21 '12 at 1:04\show\underlinebut thought there was another definition because of the use of\@@underlinewhich seemed redundant. – azetina Sep 21 '12 at 1:16\tikzmark? :-) – Peter Grill Sep 21 '12 at 3:51