# \adjustlimits for more than two consecutive operators

I know I can use \adjustlimits to align limits of two consecutive operators. Is there any way to align limits of more than two consecutive operators? For example, think of the case

\begin{equation*}
\limsup_{n\uparrow\infty}\inf_{x\in \mathcal{X}}\sup_{\beta\in [0,1]}.
\end{equation*}


Thank you very much!

• (1) welcome, (2) as always on this site, please make a full minimal example. People might not know that \adjustlimits comes from the mathtools package. Currently \adjustlimits only supports two operators. It would probably be possible to reimplement it a bit more generally using latex3 code, but someone have to make the code. – daleif Jan 10 '18 at 11:06

Here's an implementation for two or more operators:

\documentclass{article}
\usepackage{amsmath,mathtools}
\usepackage{xparse}

\ExplSyntaxOn
{% the argument should be a comma separated list of items of the form
% <operator>_{<limit>}
\group_begin:
\group_end:
}

{
}
{
}
{
}

{
}
{
}
{
\mathop { \vphantom{\l__multiadjustlimits_operator_tl} \mathopen{} #1 }
\limits
}

\ExplSyntaxOff

\newcommand{\cX}{%
\makebox[0pt]{\smash{\vrule depth 0.1pt width 3cm}}% for debugging
\mathcal{X}%
}

\begin{document}

\begin{equation*}
\limsup_{n\uparrow\infty},
\inf_{x\in \cX},
\sup_{\beta\in [0,1]}
}
A(n,x,\beta)
\end{equation*}

\end{document}


The definition of \cX has been used in order to show the common baseline of the subscripts, of course it should be removed in a production version.

• Very interesting, my pseudo code alg for it is very similar. I'm wondering, since the macro encloses the operators, can't we process the argument as triples and thus get rid of the need to rewrite it to a comma separated list (which seems unnatural to the reading of the code) – daleif Jan 10 '18 at 13:35
• @daleif It could be done, but frankly I prefer a list like this. – egreg Jan 10 '18 at 14:55
• @egreg WOW! It looks great! – Marco Jan 10 '18 at 15:06
• I'm curious how his works as the spacing doesn't change when the arguments are permuted. Have you set the baseline to account for the worst-case scenario and padded for that? Or have you told it to not cramp things unnecessarily? – user45054 Jan 29 '19 at 16:52
• @RobertWolfe I cumulate all limits and use a \vphantom with all of them. The result is not the same as when there's just an operator, but the alignment is right. – egreg Jan 29 '19 at 16:54

This is just me playing around with @egreg 's solution. I find it unnatural to have to add commas if you want to apply \multiadjustlimits, so I made a recursive version instead. It will read arguments in trios and leave it if there is no trio. In a trio, the second part is assumed to be equivalent to _.

\documentclass{article}
\usepackage{amsmath,mathtools}
\usepackage{xparse}

\ExplSyntaxOn
{
\group_begin:
\group_end:
}

{
\__my_map_dlf:nnn #1 \q_recursion_tail \q_recursion_tail \q_recursion_tail
\q_recursion_stop
}

\cs_new_protected:Nn \__my_map_dlf:nnn {
\quark_if_recursion_tail_stop:n {#1}
\quark_if_recursion_tail_stop:n {#2}
\quark_if_recursion_tail_stop:n {#3}
% here, we got 3 good args
\__my_map_dlf:nnn
}

{
\__my_map_dlf_print:nnn #1 \q_recursion_tail \q_recursion_tail \q_recursion_tail
\q_recursion_stop
}

\cs_new_protected:Nn \__my_map_dlf_print:nnn {
\quark_if_recursion_tail_stop:n {#1}
\quark_if_recursion_tail_stop_do:nn {#2}{#1}
\quark_if_recursion_tail_stop_do:nn {#3}{#1#2}
% here, we got 3 good args
\__my_map_dlf_print:nnn
}
{
\mathop { \vphantom{\l__multiadjustlimits_operator_tl} \mathopen{} #1 }
\limits
}

\ExplSyntaxOff

\newcommand{\cX}{%
\makebox[0pt]{\smash{\vrule depth 0.1pt width 3cm}}% for debugging
\mathcal{X}%
}

\begin{document}
\begin{equation*}
\limsup_{n\uparrow\infty}
\inf_{x\in \cX}
\sup_{\beta\in [0,1]}
\sum F
}
A(n,x,\beta)
\end{equation*}

\end{document}


Here is an ad hoc approach. I replaced \inf with \mathop{\vphantom{p}\inf}\limits. I also added \vphantom{[} to the n... and x... subscripts.

\documentclass{article}
\usepackage{amsmath}

\begin{document}

\begin{equation*}
\limsup_{\vphantom{[}n\uparrow\infty}\mathop{\vphantom{p}\inf}\limits_{\vphantom{[}x\in
\mathcal{X}}\sup_{\beta\in [0,1]}.
\end{equation*}

\end{document}


Once can see the baselines of the three subscripts are aligned.