\left and \right not working on parentheses within the same line when internal fractions are changed
This is somewhat similar to this question.
The values in the fractions matter because the boxes of the characters have different sizes. The p
has a descender below the baseline which the x
doesn't, thus when you swap them, the box of the denominator get a little bigger and TeX uses a larger delimiter to make that fit.
You have a few possibilities to work around that (basically the same ones I listed in the linked question):
You can use a fixed delimiter size (
\bigg
or\Big
, for instance):$$\Bigl(\frac{x}{p}\Bigr)\Bigl(\frac{p}{x}\Bigr)$$ $$\biggl(\frac{x}{p}\biggr)\biggl(\frac{p}{x}\biggr)$$
You can
\raise
thep
so that TeX won't try to use a larger box:$$\left(\frac{x}{\raise0.35ex\hbox{$p$}}\right)\left(\frac{p}{x}\right)$$
or you can add an invisible
p
next to thex
so that the delimiter used will be the larger one:$$\left(\frac{x}{p}\right)\left(\frac{p}{\vphantom{p}x}\right)$$
Or you can change change TeX's
\delimiterfactor
(and\delimitershortfall
, which I didn't show here) and let TeX adjust the delimiters accordingly:$$\delimiterfactor=790 \left(\frac{x}{p}\right)\left(\frac{p}{x}\right)$$ $$\delimiterfactor=970 \left(\frac{x}{p}\right)\left(\frac{p}{x}\right)$$
Full code:
\documentclass{article}
\begin{document}
% \delimitershortfall=5pt % Default
% \delimiterfactor=901 % Default
$$\left(\frac{x}{p}\right)\left(\frac{p}{x}\right)$$
$$\Bigl(\frac{x}{p}\Bigr)\Bigl(\frac{p}{x}\Bigr)$$
$$\biggl(\frac{x}{p}\biggr)\biggl(\frac{p}{x}\biggr)$$
$$\left(\frac{x}{\raise0.35ex\hbox{$p$}}\right)\left(\frac{p}{x}\right)$$
$$\left(\frac{x}{p}\right)\left(\frac{p}{\vphantom{p}x}\right)$$
$$\delimiterfactor=790
\left(\frac{x}{p}\right)\left(\frac{p}{x}\right)$$
$$\delimiterfactor=970
\left(\frac{x}{p}\right)\left(\frac{p}{x}\right)$$
\end{document}
Output:
Use \genfrac
for this:
\documentclass{article}
\usepackage{amsmath}
\newcommand{\genlegendre}[3]{\genfrac{(}{)}{}{#1}{#2}{#3}}
\newcommand{\legendre}[2]{\genlegendre{}{#1}{#2}}
\newcommand{\dlegendre}[2]{\genlegendre{0}{#1}{#2}}
\newcommand{\tlegendre}[2]{\genlegendre{1}{#1}{#2}}
\begin{document}
\[
\legendre{x}{p}\quad\legendre{p}{x}\quad
\legendre{x}{x}\quad\legendre{d}{b}
\]
\end{document}
The variants \dlegendre
and \tlegendre
are analogous to \dfrac
and \tfrac
.