# Curly bracket around iterated exponentials

I believe this problem must already have a solution but I cannot find one on the Internet.

Consider the following code.

\documentclass{article}

\usepackage{amsmath}

\begin{document}
\begin{equation*}
a=\left.\kern-\nulldelimiterspace
p^{p^{p^{\cdot^{\cdot^{\cdot^p}}}}}\right\}\text{$n$-many $p$'s}
\end{equation*}
\end{document}


How does one make the height of the curly bracket equal to the height of the iterated exponential without any manual calculations or adjustments?

I want the baseline of the a and baseline of the lowest p to align. In this case, the baseline of the \text{$n$-many $p$'s} would not align with the other baselines, but this text should be in the middle of the curly bracket in the usual way.

I believe there must be a clean solution using simple LaTeX without sophisticated packages like TiKZ.

You can vertically center the big expression, so the \rbrace can cover it exactly:

\documentclass{article}

\usepackage{amsmath}

\begin{document}

\begin{equation*}
\left.\kern-\nulldelimiterspace
\begin{array}{@{}c@{}}
a=p^{p^{\scriptstyle p^{\cdot^{\cdot^{\cdot^{\scriptstyle p}}}}}}
\end{array}
\right\rbrace
\text{\scriptsize $n$-many $p$'s}
\end{equation*}

\end{document}


A more powerful version:

\documentclass{article}
\usepackage{amsmath,amssymb}
\usepackage{xcoffins}

\NewCoffin{\repexpbasecoffin}
\NewCoffin{\repexptextcoffin}

\ExplSyntaxOn
\NewDocumentCommand{\repexp}{mom}
{
\wong_repexp:nnn { #1 } { #2 } { #3 }
}

\cs_new_protected:Nn \wong_repexp:nnn
{
\tl_set:Nf \l__wong_repexp_exp_tl { \tl_tail:n { #1 } }
\tl_if_novalue:nTF { #2 }
{
\tl_clear:N \l__wong_repexp_sub_tl
}
{
\tl_set:Nn \l__wong_repexp_sub_tl { #2 }
}
\tl_set:Nx \l__wong_repexp_base_tl
{
$\tl_head:n { #1 } \tl_map_function:NN \l__wong_repexp_exp_tl \__wong_repexp_exp:n \prg_replicate:nn { \tl_count:N \l__wong_repexp_exp_tl } { \c_group_end_token } \tl_if_empty:NF \l__wong_repexp_sub_tl { \tl_map_function:NN \l__wong_repexp_sub_tl \__wong_repexp_sub:n \prg_replicate:nn { \tl_count:N \l__wong_repexp_exp_tl } { \c_group_end_token } }$
}
\SetHorizontalCoffin{\repexpbasecoffin}{\tl_use:N \l__wong_repexp_base_tl}
\SetHorizontalCoffin{\repexptextcoffin}
{
$\left.\kern-\nulldelimiterspace \vphantom{\begin{tabular}{c}\tl_use:N \l__wong_repexp_base_tl\end{tabular}} \right\rbrace \text{\scriptsize #3}$
}
\JoinCoffins\repexpbasecoffin[r,vc]\repexptextcoffin[l,vc]
\TypesetCoffin\repexpbasecoffin
}

\cs_new:Nn \__wong_repexp_exp:n
{
\c_math_superscript_token \c_group_begin_token \scriptstyle
\str_if_eq:nnTF { . } { #1 } { \cdot } { \exp_not:n { #1 } }
}
\cs_new:Nn \__wong_repexp_sub:n
{
\c_math_subscript_token \c_group_begin_token \scriptstyle
\str_if_eq:nnTF { . } { #1 } { \cdot } { \exp_not:n { #1 } }
}
\ExplSyntaxOff

\begin{document}

\begin{gather}
\repexp{ppp...p}{$n$ many $p$'s}
\\
a=\repexp{ppp...p}{$n$ many $p$'s}
\\
\mathfrak{q}=\repexp{{\aleph_0}{\aleph_0}{\aleph_0}...{\aleph_0}}{$q$}
\\
\repexp{abcd...x}[bcd...x]{$n$ up, $m$ down}
\end{gather}

\end{document}


As you see, the big exponential can be used on its own. The syntax is also simplified: simple letters can be inserted directly, complex symbols should be braced; a period stands for \cdot.

The optional argument is for subscripts, see the final example.

• Thanks. I accepted your answer because it solves the problem as I stated it. However, the solution is unsatisfactory because semantically it puts the curly bracket on the equation, not the term on the right-hand side of the equation. Should I consider this a different question and pose it separately? Oct 15, 2018 at 13:16
• @LawrenceWong I can't see the difference. Do you need such a beast more than once in your document? Wasting time for “semantic satisfaction” doesn't seem good. ;-) Oct 15, 2018 at 13:18
• Unfortunately, I do need to use this many times in my document. In case you need a more specific reason, I am writing some notes about large countable ordinals, on which various processes iterate in the superscripts/subscripts. In particular, I will need to write equations involving these terms. Oct 15, 2018 at 13:32
• @egreg Wonderful your answers. I like very much for completeness, accuracy and setup. With sincerity my warmest regards. +1 Oct 15, 2018 at 15:26
• @LawrenceWong I added to the “power version" also subscripts. Oct 15, 2018 at 15:49