[Tex/LaTex] Make Legendre symbols the same size

math-mode

I've been having a bit of trouble typesetting (n-th power) Legendre symbols. I've set up the command

\newcommand{\Leg}[3][]{\left(\frac{#2}{#3}\right)_{#1}}

But, when I type e.g.

$$\Leg[3]{\pi}{\theta} = \Leg[3]{\theta}{\pi}$$

the symbol on the left is smaller than the one on the right:

img

I'd be very grateful if someone could suggest a way to make the symbols the same size. (Either a way to set up the \Leg command so it always outputs symbols of the same size, or an ad hoc way of adjusting the size each time I use \Leg would be great.)

Best Answer

You can (and should) use \genfrac:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\genlegendre}[4]{%
  \genfrac{(}{)}{}{#1}{#3}{#4}%
  \if\relax\detokenize{#2}\relax\else_{\!#2}\fi
}
\newcommand{\legendre}[3][]{\genlegendre{}{#1}{#2}{#3}}
\newcommand{\dlegendre}[3][]{\genlegendre{0}{#1}{#2}{#3}}
\newcommand{\tlegendre}[3][]{\genlegendre{1}{#1}{#2}{#3}}

\begin{document}

We can use the Legendre symbol $\legendre{\pi}{\theta}$
\[
\legendre[3]{\pi}{\theta} = \legendre[3]{\theta}{\pi}
\]
We can also choose the size
\[
\frac{\dlegendre[2]{\pi}{\theta}+1}{3}
\]
\end{document}

The command \legendre, \dlegendre and \tlegendre act the same as \frac, \dfrac and \tfrac.

enter image description here

The \genfrac command takes six arguments:

  1. left delimiter (if empty, no delimiter);
  2. right delimiter (if empty, no delimiter);
  3. the thickness of the fraction line (if empty, standard thickness);
  4. the math style to use (if empty, use the current style); styles are denoted by 0 (display style), 1 (text style), 2 (script style), 3 (scriptscript style);
  5. the numerator;
  6. the denominator.

Thus we get \legendre from \genlegendre by passing nothing as fourth argument to \genfrac, \dlegendre by passing 0.

The \if\relax\detokenize{#1}\relax trick is for avoiding an empty subscript that would generate \scriptspace nonetheless.