10

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

  • 1
    1) You're aware that \hom is a command in amsmath, right? 2) I fail to see how this question differs from the one at tex.stackexchange.com/q/49324/34551 : can't your find your answer there? – Clément Jan 30 '17 at 0:51
11

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
}
  • What exactly are mu units? – Avi Steiner Jan 31 '17 at 2:38
  • @AviSteiner 1mu is the 18th part of a quad in the math symbol font for the current math style, so it is particularly apt for math spacing. Such units can only be used in math mode, passed to \mkern or \mskip. – egreg Jan 31 '17 at 9:04
6

You can add/remove small spaces before and in the underlined material.

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\uHom}{\,\underline{\!Hom\!}\,}
\begin{document}
$\uHom_R$
\end{document}

enter image description here

6

this answer is much like steven's, but is a little more reserved about the sizes of the "small spaces".

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator{\uHom}{\underline{Hom\kern-.05em}\kern.1em}
\begin{document}
$\uHom_R$
\end{document}

output of example code

  • Why not \mkern1mu\underline{\mkern-1mu Hom\mkern-1mu}\mkern1mu? – egreg Jan 30 '17 at 1:08
  • @egreg -- a reasonable question. since \Hom isn't already defined (although \hom is, by amsopn, i defined it anew, and mu units were rejected with my first try. possibly a different problem, but i didn't pursue the matter. i like your symmetry better anyhow. – barbara beeton Jan 30 '17 at 14:08

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.