[Tex/LaTex] Underlined math operator

math-modemath-operators

Is there a "best" way to define an underlined math operator? Right now, I've defined

DeclareMathOperator{\uHom}{\underline{Hom}}

This works, sort of, but the underline is too long—it tends to merge with subscripts, e.g. $\uHom_R$:

\uHom_R

Best Answer

Here's a slightly different version: I apply the shortening on both sides, for symmetry.

The shorthening depends on the value given to the parameter \uHomskip.

\documentclass{article}
\usepackage{amsmath}

\newmuskip\uHomskip
\DeclareMathOperator{\uHom}{%
  \mkern\uHomskip
  \underline{\mkern-\uHomskip Hom\mkern-\uHomskip}
  \mkern\uHomskip
}

\begin{document}
\newcommand{\test}[1]{%
  \begingroup\uHomskip=#1mu\relax
  \makebox[2em][l]{#1:}$\uHom_R$
  \endgroup\par
}

\test{0} \test{0.5} \test{1} \test{1.5} \test{2}

\end{document}

enter image description here

When you decide for the amount you want, just set it in the preamble, for instance

\newmuskip\uHomskip \setlength{\uHomskip}{1.5mu}
\DeclareMathOperator{\uHom}{%
  \mkern\uHomskip
  \underline{\mkern-\uHomskip Hom\mkern-\uHomskip}
  \mkern\uHomskip
}

The advantage of using mu units is that they automatically scale in subscripts/superscripts.

If you don't want the shortening at the left, just remove the relevant kerns:

\newmuskip\uHomskip \setlength{\uHomskip}{1.5mu}
\DeclareMathOperator{\uHom}{%
  \underline{Hom\mkern-\uHomskip}
  \mkern\uHomskip
}