24

When using the \pmod command as a subscript to a sum, I often encounter some extra unwanted space. For example, writing

\[ \sum_{n \equiv 1 \pmod{k}} ... \]

produces the following image:

enter image description here

Does anyone have any ideas to delete the extra white space between the 1 and the open parenthesis?

Peter Grill
  • 223,288
JavaMan
  • 405

2 Answers2

22

I'd define a variant of \pmod:

\makeatletter
\NewCommandCopy\@@pmod\pmod
\DeclareRobustCommand{\pmod}{\@ifstar\@pmods\@@pmod}
\def\@pmods#1{\mkern4mu({\operator@font mod}\mkern 6mu#1)}
\makeatother

You can use \pmod as before in all other situations and write

\[ \sum_{n \equiv 1 \pmod*{k}} ... \]

when you need it as a subscript to a sum.

enter image description here

Another way might be to load amsmath and redefine \pod (\pmod is defined in terms of it):

\usepackage{amsmath}
\makeatletter
\renewcommand{\pod}[1]{\allowbreak\mathchoice
  {\if@display \mkern 18mu\else \mkern 8mu\fi (#1)}
  {\if@display \mkern 18mu\else \mkern 8mu\fi (#1)}
  {\mkern4mu(#1)}
  {\mkern4mu(#1)}
}

This will avoid having to say \pmod* and the result will be the same as shown.

The original answer had \let\@@pmod\pmod, which worked at the time the answer was written, but later \pmod became a robust command.

egreg
  • 1,121,712
  • egreg, shouldn't the \allowbreak go before the \mathchoice? I was just looking at your comment on Andrew Swann's answer here: http://tex.stackexchange.com/questions/255584/errors-in-arguments-when-renewing-mod-with-mathchoice – justin Aug 03 '15 at 20:23
  • @justin You're perfectly right! – egreg Aug 03 '15 at 20:28
  • @egreg -- not sure why this one came up on my screen, but it did; \pod is already defined in amsmath, although i think it's not often used. however, the * version of \pmod is a good idea, and i've added it to the list of requests. – barbara beeton Jun 14 '17 at 20:41
1

This works for me.

\newcommand{\congruence}[3]{\ensuremath{{#1}\equiv {#2}\left(\bmod{#3}\right)}\xspace}

Then use it like so ...

\congruence{a}{b}{m}
Stefan Pinnow
  • 29,535
jblaskie
  • 11
  • 1