14

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

CarLaTeX
  • 62,716
Rob Smith
  • 143
  • 2
    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
  • 5
    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
  • 3
    @RobSmith any documented latex math environment! https://tex.stackexchange.com/questions/503/why-is-preferable-to/69854#69854 – David Carlisle May 28 '18 at 18:23

4 Answers4

15

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}

enter image description here

Bernard
  • 271,350
15

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.

egreg
  • 1,121,712
8

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

Btw: You should use \[...\] instead of the $$ syntax.

sizes

\documentclass{article}
\usepackage{amsmath}
\newcommand{\Leg}[4][big]{\csname #1l\endcsname(\frac{#3}{#4}\csname#1r\endcsname)_{#2}}

\begin{document}
\[
    \Leg[Bigg]{3}{\pi}{\theta} = \Leg[Bigg]{3}{\theta}{\pi}
\]
\[
    \Leg{3}{\pi}{\theta} = \Leg{3}{\theta}{\pi}
\]
\end{document}
TeXnician
  • 33,589
  • Why the \csname business? I read the body of your code without reading the preamble, and was very surprised to see \Leg[Bigg], which differs from the standard mathtools syntax. What about \DeclarePairedDelimiter{\@Leg}{(}{)} \newcommand*{\Leg}[4][\big]{\@Leg[#1]{\frac{#3}{#4}}_{#2}}, optionally adding \@ifstar support for \@Leg*? – wchargin May 29 '18 at 02:31
  • 1
    (Though \genfrac still seems cleaner to me—this is its purpose, after all.) – wchargin May 29 '18 at 02:33
  • @wchargin To use the left and right delimiters without additional packages. I know that you may use mathtools, but sometimes simple LaTeX is very sufficient ;) And yes, genfrac seems clearer (didn't come to my mind at that point). – TeXnician May 29 '18 at 04:31
  • 1
    Sorry for off, but could you explain why \[...\] is preferable over $$? – მამუკა ჯიბლაძე May 29 '18 at 05:54
  • @მამუკაჯიბლაძე - I was curious too - this seems to be the answer: https://tex.stackexchange.com/a/40531/112443 – Itai May 29 '18 at 06:04
  • 1
    @მამუკაჯიბლაძე Look here https://tex.stackexchange.com/questions/503/why-is-preferable-to. – TeXnician May 29 '18 at 06:48
  • 1
    @Itai Not quite. See above. – TeXnician May 29 '18 at 06:48
2

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}

Matching Legendre expressions

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.

Davislor
  • 44,045