# Make Legendre symbols the same size

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:

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.)

• Welcome to TeX.SX! Basically you want to abandon \left and \right in favor of manual size specifications, because you do not want auto-sizing, but manual size (so that both have equal height). – TeXnician May 28 '18 at 17:38
• use \Bigl(..\Bigr) and also don't use $$ in LaTeX. – David Carlisle May 28 '18 at 17:44 • This is exactly what I wanted, thank you! @DavidCarlisle is there an alternative to$$ you'd recommend? – Rob Smith May 28 '18 at 18:21
• @RobSmith any documented latex math environment! tex.stackexchange.com/questions/503/why-is-preferable-to/… – David Carlisle May 28 '18 at 18:23

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.

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.

• To make the use of \genfrac more understandable, you could use \genfrac{(}{)}... instead of \genfrac().... – Paul Gaborit May 30 '18 at 6:11
• @PaulGaborit Done; added also some information about \genfrac. – egreg May 30 '18 at 6:53

A solution with \mathstrut and the mleftright package:

\documentclass{article}
\usepackage[utf8]{inputenc}%
\usepackage{mathtools}
\usepackage{mleftright}
\newcommand{\Leg}[3][]{\mleft(\frac{#2\mathstrut}{#3}\mright)_{\mkern-6mu#1}}

\begin{document}

$\Leg{\pi }{\sigma}\quad \Leg[3]{\pi }{\theta}\quad \Leg{\theta}{\pi}$

\end{document}


I've changed your syntax a bit: The optional argument now is a size command and your index is mandatory. Just play around with the sizes you like.

The problem with your command is that you automatically apply auto-sizing (left and right), which will not result in same output if different input is given (especially with different sizes).

• @მამუკაჯიბლაძე Look here tex.stackexchange.com/questions/503/why-is-preferable-to. – TeXnician May 29 '18 at 6:48
• @Itai Not quite. See above. – TeXnician May 29 '18 at 6:48

Here’s an alternative that allows you to still use automatic scaling. It defines a \Legmatch command, with an additional two dummy arguments. These give the other Legendre expression whose size this one should match.

Internally, it inserts a \vphantom box, with the same height as the contents of the contents of the other expression and zero width, inside the paired delimiters.

\documentclass[varwidth, preview]{standalone}

\usepackage{mathtools}
\usepackage{unicode-math}

\newcommand{\Legmatch}[5][]{\left(\vphantom{\frac{#4}{#5}}\frac{#2}{#3}\right)_{#1}}

\begin{document}
$\Legmatch[3]{\pi}{\theta^{\frac{\alpha^2}{2}}}{\theta}{\pi} = \Legmatch[3]{\theta}{\pi}{\pi}{\theta^{\frac{\alpha^2}{2}}}$
\end{document}


I particularly like Bernard’s answer, which uses mleftright. This one might still come in handy in a few special cases, such as if you want to split lines or introduce other struts on the same line.