I noticed today that
\documentclass{article}
\begin{document}
[
\Big{(a + b \Big)}^2 % yikes, note the order of the brackets!
]
\end{document}
compiles to
How so? Shouldn't it be
{\Big(a + b \Big)}^2
?
I noticed today that
\documentclass{article}
\begin{document}
[
\Big{(a + b \Big)}^2 % yikes, note the order of the brackets!
]
\end{document}
compiles to
How so? Shouldn't it be
{\Big(a + b \Big)}^2
?
You provided no test file, but presumably your fragment is in math mode so
\documentclass{article}
\begin{document}
$\Big{(a + b \Big)}^2$
\end{document}
\Big takes an argument (intended to be the delimiter) but here it is (a + b \Big) by an accident of the implementation passing in multiple tokens does not error, the stretching is applied to the first delimiter and the following tokens are typeset. Then within that, comes \Big) the {} are absorbed to denote the argument of the first \Big they do not form a group around the expression so the ^ actually just attaches to the final ).
The markup would be better done as
$\Bigl(a + b \Bigr)^2$
{..} is same in any case.
– David Carlisle
Feb 10 '22 at 19:42
The \Big is defined as:
\def\Big#1{{\hbox{$\left#1\vbox to11.5pt{}\right.\n@space$}}}
So, your usage
\Big{(a + b \Big)}^2
takes (a + b \Big) to #1 and expands to
{\hbox{$\left(a + b \Big)\vbox to11.5pt{}\right.\n@space$}}^2
and the second \Big with parameter ) expands too. The result is
{\hbox{$\left(a + b{\hbox{$\left)\vbox to11.5pt{}\right.\n@space$}}\vbox to11.5pt{}\right.\n@space$}}^2
And this is correct from TeX's point of view.
In pragmatic terms, if you want to make this into an error that TeX could catch, you could define it as a command. For example:
\documentclass{article}
\usepackage{mathtools}
\DeclarePairedDelimiter\parens{\lparen}{\rparen}
\DeclarePairedDelimiter\bracks{\lbrack}{\rbrack}
\begin{document}
[ \bracks[\big]{\parens{a + b^2}}
]
\end{document}
It is impossible with this code to mismatch the sizes of the opening or closing delimiters, or to close the delimiters in the wrong order. If you mismatch the opening and closing parentheses, the compiler (and many editors) will catch it.
Is that more what you were looking for?
\Big{a long expression that happens to start with a delimiter}is valid (or at least does not give an error) – David Carlisle Feb 10 '22 at 19:40\Bigl(...\Bigr)^2is better. – egreg Feb 10 '22 at 23:11$(a+b)^2$and${(a+b)}^2$(the latter is what's wrongly recommended by ChkTeX). See https://tex.stackexchange.com/a/529940/4427 – egreg Feb 11 '22 at 09:08