Describe the bug:
Trying to follow the advice in this SE post on how to improve the spacing around \left and \right, I'm getting
Undefined control sequence:
\aftergroup
To Reproduce:
See this minimal example.
Expected behavior:
With the following macros
\newcommand{\myleft}{\mathopen{}\mathclose\bgroup\left}
\newcommand{\myright}{\aftergroup\egroup\right}
I'm expecting
$\cos(x)$
and
$\cos\myleft(x\myright)$
to look identical, i.e. with the same white space around parentheses.
Environment (please complete the following information):
While we support \begingroup and \endgroup we do not support \aftergroup.
It's easy enough to rewrite your code to avoid using \aftergroup:
\newcommand{\myleft}{\mathopen{}\mathclose\bgroup\left}
\newcommand{\myright}[1]{\right{#1}\egroup}
\cos(x) \\
\cos\myleft(x\myright)
However, this code currently fails for a different reason in KaTeX: the error is "Converting circular structure to JSON". I'll open a separate bug report for this.
Oops, as ylemkimon points out, the correct code would be:
\newcommand{\myleft}{\mathopen{}\mathclose\bgroup\left}
\newcommand{\myright}[1]{\right#1\egroup}
\begin{array}{l}
\cos(x) \\
\cos\myleft(x\myright)
\end{array}
(No braces after \right.)
Rendering on demo site:

So this is a good workaround for @janosh until \aftergroup gets supported.
@edemaine That's indeed a great workaround.
I just discovered that there's another good solution for my use case: \DeclarePairedDelimiter from the mathtools package. It's more flexible than manually creating new macros for each delimiter type but produces the same output.
\DeclarePairedDelimiter\paren{\lparen}{\rparen}
Then \cos\paren{x} is equivalent to \cos(x) and \cos\paren*{x} is equivalent to \cos\myleft(x\myright).
Unfortunately, \DeclarePairedDelimiter is undefined in KaTeX. How about adding that?