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)$?

2
  • 15
    You should use \pmod (from amsmath), perhaps utilizing the redefinition as in Removing extra space with \pmod command.
    – Werner
    Oct 9, 2013 at 5:45
  • 21
    and if one drops parentheses, \bmod also from amsmath is an option.
    – user4686
    Oct 10, 2013 at 15:36

4 Answers 4

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}
6
  • 1
    This is great! I like how \Mod{n} looks. The only problem I'm encountering with \Mod{n} is that the "mod" becomes italicized in theorem/lemma/example/proof/etc. environments. Aug 31, 2014 at 19:12
  • 1
    @Mathemanic: You can try using \textup (or perhaps \mbox) instead of \text.
    – Werner
    Aug 31, 2014 at 19:38
  • 4
    This should be \mathrm{mod}.
    – egreg
    Mar 9, 2017 at 13:23
  • 1
    @egreg why is it \mathrm over \operatorname? Nov 3, 2019 at 22:59
  • 1
    @It'sNotALie. Because this is not an operator.
    – egreg
    Nov 3, 2019 at 23:27
38

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

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}
4

This issue can easily be handled by using \pmod.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .