# Is it just me or $f(x) = x^2 + 17 \mod 43$ adds too much space before the mod operator?

\documentclass[a4paper]{article}
\usepackage{amsmath}
\begin{document}

Instead of $f(x) = x^2 + 17 \mod 43$, I prefer $f(x) = x^2 + 17\hspace{-1mm}\mod 43$.

\end{document}


Why was the modulo operator defined with this apparent extra space? Is there a rationale behind it?

I'm on the brink of redefining it.

First and foremost: it is not an “operator”, but a traditional way to write a particular equivalence relation. Also the correct syntax is \mod{43}.

Plain TeX only has \pmod, defined as

% plain.tex, line 1089
\def\pmod#1{\allowbreak\mkern18mu({\rm mod}\,\,#1)}


so the space is 1em (in the math symbol font), because 18mu is 1em.

In the LaTeX kernel the definition is essentially the same, namely

% latex.ltx, line 4437:
\def\pmod#1{%
\allowbreak\mkern18mu({\operator@font mod}\,\,#1)}


On the other hand, amsmath also defines \mod and \pod. The former omits parentheses and the latter has parentheses but no “mod”.

\newcommand{\pod}{\allowbreak
\if@display\mkern18mu\else\mkern8mu\fi(#1)}
\renewcommand{\pmod}{\pod{{\operator@font mod}\mkern6mu#1}}
\newcommand{\mod}{\allowbreak\if@display\mkern18mu
\else\mkern12mu\fi{\operator@font mod}\,\,#1}


The definition of \pmod is in terms of \pod; you can see that a\equiv b\pod{n} will have, after b, 1em of space in display style or 8/18em in other styles, followed by (n). With \pmod the spacing before the parenthesis is the same, but after the parentheses “mod” and a space of 6/18em will precede n.

With \mod the spacing is essentially the same, but 12/18em would be used instead of 8/18em in text style or below. Note that \,\, is the same as \mkern 6mu.

So it's just you. ;-)

Of course you're free to change the spacing by redefining \pod and \mod.

• It's great that you prove your comments by showing the original definitions. – Joep Awinita Feb 13 '19 at 18:07

The even spaced version is \bmod as in Sebastiano's now deleted answer which has the spacing you seem to want but is the wrong thing here as it would mean x^2 + (17 mod 43) which is the wrong interpretation. You want the bigger space before mod to separate it from the 17 and make it clear that it's a side condition applying to the equality which is to be interpreted as a congruence mod 43.