4

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
4

Here's an implementation for two or more operators:

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

\ExplSyntaxOn
\NewDocumentCommand{\multiadjustlimits}{m}
 {% the argument should be a comma separated list of items of the form
  % <operator>_{<limit>}
  \group_begin:
  \multiadjustlimits_measure:n { #1 }
  \multiadjustlimits_print:n { #1 }
  \group_end:
 }

\tl_new:N  \l__multiadjustlimits_operator_tl
\tl_new:N  \l__multiadjustlimits_limit_tl

\cs_new_protected:Nn \multiadjustlimits_measure:n
 {
  \clist_map_function:nN { #1 } \__multiadjustlimits_measure:n
 }
\cs_new_protected:Nn \__multiadjustlimits_measure:n
 {
  \__multiadjustlimits_measure:NNn #1
 }
\cs_new_protected:Nn \__multiadjustlimits_measure:NNn
 {
  \tl_put_right:Nn \l__multiadjustlimits_operator_tl { #1 }
  \tl_put_right:Nn \l__multiadjustlimits_limit_tl { #3 }
 }

\cs_new_protected:Nn \multiadjustlimits_print:n
 {
  \clist_map_function:nN { #1 } \__multiadjustlimits_print:n
 }
\cs_new_protected:Nn \__multiadjustlimits_print:n
 {
  \__multiadjustlimits_print:NNn #1
 }
\cs_new_protected:Nn \__multiadjustlimits_print:NNn
 {
  \mathop { \vphantom{\l__multiadjustlimits_operator_tl} \mathopen{} #1 }
  \limits
  \sb{ \vphantom{\l__multiadjustlimits_limit_tl} #3 }
 }

\ExplSyntaxOff

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

\begin{document}

\begin{equation*}
\multiadjustlimits{
  \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.

enter image description here

  • 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? – Robert Wolfe Jan 29 at 16:52
  • 1
    @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 at 16:54
2

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
\NewDocumentCommand{\multiadjustlimitsR}{m}
 {
  \group_begin:
  \multiadjustlimits_measure:n { #1 }
  \multiadjustlimits_print:n { #1 }
  \group_end:
 }

\dim_new:N \l__multiadjustlimits_ht_dim
\dim_new:N \l__multiadjustlimits_dp_dim
\tl_new:N  \l__multiadjustlimits_operator_tl
\tl_new:N  \l__multiadjustlimits_limit_tl

\cs_new_protected:Nn \multiadjustlimits_measure:n
{
  \__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
  \tl_put_right:Nn \l__multiadjustlimits_operator_tl { #1 }
  \tl_put_right:Nn \l__multiadjustlimits_limit_tl { #3 }
  \__my_map_dlf:nnn
}

\cs_new_protected:Nn \multiadjustlimits_print:n
 {
  \__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
  \__multiadjustlimits_print:NNn {#1}{#2}{#3}
  \__my_map_dlf_print:nnn
}
\cs_new_protected:Nn \__multiadjustlimits_print:NNn
 {
  \mathop { \vphantom{\l__multiadjustlimits_operator_tl} \mathopen{} #1 }
  \limits
  \sb{ \vphantom{\l__multiadjustlimits_limit_tl} #3 }
 }

\ExplSyntaxOff

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

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

 \end{document}

enter image description here

0

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}

enter image description here

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.