Katex: Add support for \aftergroup / \DeclarePairedDelimiter

Created on 14 Dec 2019  路  4Comments  路  Source: KaTeX/KaTeX

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

enhancement

All 4 comments

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:
image

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?

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sophiebits picture sophiebits  路  3Comments

hagenw picture hagenw  路  3Comments

StaloneLab picture StaloneLab  路  3Comments

ylemkimon picture ylemkimon  路  3Comments

msridhar picture msridhar  路  3Comments