I want to create an operator that works like a minus sign (including the spacing), but has the characters res on top (in \textrm mode). The length of the minus sign should be adjusted to look like underlining the res characters, and it needs to work in a subscript. Currently I am using


which means in particular the operator I am using is


but it leaves a bit of space between the two dashes (especially in subscripts), and in inline or display mode, there's too much line to the left of the letters res.

What is a better way to produce this symbol?

  • While code snippets are useful in explanations, it is always best to compose a fully compilable MWE that illustrates the problem including the \documentclass and the appropriate packages so that those trying to help don't have to recreate it. Apr 25, 2014 at 4:31

2 Answers 2


The following example defines macro \res with an optional argument for a different text than res:

  • The size of the text is the size of a superscript (\scriptsize or \scriptscriptsize). Smaller sizes are not recommended to avoid the need for magnifying glasses.

  • The vertical distance between the text and the minus sign is approximately the distance between the text and the underline by \underline.

  • A longer minus sign is created by appending minus signs with some overlapping.



% test for different fonts

\setlength{\res@sidebearing}{1.5mu}% e.g. 1.5mu/CM, 1mu/MnSymbol
  % #1: math style
  % #2: text
  \setbox4=\copy2 %
  \ifdim\wd4<\wd0 %
      \ifdim\dimen@<\wd0 %
        \setbox4=\hbox to \wd0{%
  % \sbox8{$#1\mathop{}\limits^{}$}% alternative
  \sbox8{$\res@style#1\underline{}$}% ht8 + dp8 = 5 theta; sep = 3 theta
  \mkern1.5mu %
  \hbox to \wd4{%
    % \raisebox{\dimexpr\dp0+\ht6+.5\ht8\relax}{\copy0}% alternative
  \mkern1.5mu %

% Test: "res" and long word "garbage" with descender
  \displaystyle      A \res B \res[garbage] C \res[r] D \\
  \textstyle         A \res B \res[garbage] C \res[r] D \\
  \scriptstyle       A \res B \res[garbage] C \res[r] D \\
  \scriptscriptstyle A \res B \res[garbage] C \res[r] D


Difficulties and properties of the minus sign:

  • The line thickness is not known. Thus the line thicknesses of \underline or \frac might be different.

  • In many fonts, the line ends are rounded. The lines of \underline and \frac are not, because they are rules or rectangles.

  • The side bearings, horizontal space at both ends, are not known. The implementation defines a math skip register \res@sidebearing for fine tuning.

  • At least the vertical position is known, this should be the math axis.


  • Box 0 contains the test in superscript size.

  • Box 2 contains the minus sign minus side bearings.

  • Box 4 is constructed with as many boxes 2 as needed to get a line that is long enough for the text.

  • The height of box 6 is the math axis.

  • Box 8: \underline{...} is similar to:

      \kern 3θ
      \hrule height θ
      \kern θ

    Box 8 contains an empty \underline{} and allows the calculation of the separation space 3θ: 0.6\dimexpr\ht8+\dp8\relax.

    Also the half height of the minus rule needs to be added and it is approximated by θ/2 (the part above the math axis).

  • \m@th is short for \mathsurround=0pt to avoid additional horizontal spacing, if \mathsurround is set.

  • \mathpalette helps to set the formula for the current math style.


Perhaps the following works for you; I changed the notation slightly from \residue{A}{B} to A \residue B:

enter image description here


  \texttt{Original} & \texttt{Choice 1} & \texttt{Choice 2} \\

  $\residue{A}{B}$ \par
  $C^{\residue{A}{B}}$ \par



  $A \residue B$ \par
  $C^{A \residue B}$ \par
  $C^{D^{A \residue B}}$


    {\overset{\text{\raisebox{.15em}{res}}}{\smash{-\mkern-5mu-}}}% \displaystyle
    {\overset{\text{\raisebox{.15em}{res}}}{\smash{-\mkern-5mu-}}}% \textstyle
    {\overset{\text{\raisebox{.15em}{res}}}{\smash{-\mkern-5mu-}}}% \scriptstyle
    {\overset{\text{\raisebox{.1em}{\scalebox{.8}{res}}}}{\smash{-\mkern-5mu-}}}% \scriptscriptstyle

  $A \residue B$ \par
  $C^{A \residue B}$ \par
  $C^{D^{A \residue B}}$

  • Choice 1 uses \mathpalette to provide the switching between math styles (see The mysteries of \mathpalette).

  • Choice 2 employs \mathchoice directly to allow for a better scaling of res at the \scriptscriptstyle level since there is no \scriptscriptscriptstyle (as an \overset of a \scriptscriptstyle argument - in a super-super/sub-sub script technically needs that).

  • 1
    The OP mentioned that the spacing around the new composite symbol should be like that of a minus sign, i.e., of type mathbin. You may want to mention that if that's what the OP really wants, he/she should use \mathbin rather than \mathrel in the definition of the \residue` macro.
    – Mico
    Apr 25, 2014 at 5:59
  • @Mico: Absolutely correct. Imma gonna stick with Charles' original request of type \mathbin.
    – Werner
    Apr 25, 2014 at 6:03
  • I'm accepting Heiko Oberdiek's answer, but let it be known that Werner's answer would have been entirely adequate for my needs and should be upvoted. Apr 25, 2014 at 16:10
  • @Mico: Thanks for pointing that out; you are entirely correct. Apr 25, 2014 at 16:10

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.