111

I have been writing

$a \equiv r (\mod n)$

but this puts a space between the ( and mod. For example, r ( mod n ) instead of r (mod n). So, how do you write r (\mod n) without that space? What would be the correct way to write $a \equiv r (\mod n)$?

Werner
  • 603,163
T. Webster
  • 1,281

4 Answers4

115

The spacing issue is an obvious indication that it's not meant to be used that way. However, you could wing your own, depending on the sophistication you're after:

enter image description here

\documentclass{article}

\usepackage{amsmath}
\newcommand{\Mod}[1]{\ (\mathrm{mod}\ #1)}

\begin{document}

\begin{align*}
  a &\equiv r \mod n \\
  a &\equiv r \pmod{n} \\
  a &\equiv r \Mod{n}
\end{align*}

\end{document}
Werner
  • 603,163
38

I think $a \equiv r \;(\bmod\; n)$ does what you want (as mentioned by jfbu in the comment).

craastad
  • 501
11

Both the latex kernel and amsmath provide the command \pmod. In the latex kernel \pmod provides a fixed amount of space before (mod ...). The amsmath version is slightly more sophisticated, using a smaller amount of space when not in a display. So one way is to define a new command that temporarily switches off the display mode:

\usepackage{amsmath}

\makeatletter
\newcommand{\tpmod}[1]{{\@displayfalse\pmod{#1}}}
\makeatother

Sample output

\documentclass{article}

\usepackage{amsmath}

\makeatletter
\newcommand{\tpmod}[1]{{\@displayfalse\pmod{#1}}}
\makeatother

\begin{document}

Text (no change): \( a\tpmod{b} \) vs.\ \( c\pmod{d} \).

Display:
\begin{gather*}
  a\tpmod{b} \\
  \intertext{vs.}
  c\pmod{d}.
\end{gather*}

\end{document}
Andrew Swann
  • 95,762
4

This issue can easily be handled by using \pmod.

Mensch
  • 65,388