I would like to have a command \catlim which behaves differently in inline vs in display mode. Namely, in inline mode, it should be equivalent to \lim and in display mode, it should be equivalent to \varprojlim (or some nicer version of it) with arrow below the limit. Here is an example what the result should look like:

% arara: lualatex


Inline \(\lim_{i \in \mathbb{N}} \mathbb{Z} / p^i \mathbb{Z}\) and display:
  \varprojlim_{i \in \mathbb{N}} \mathbb{Z} / p^i \mathbb{Z}.

  • Just don't forget that inline math style is also used in displayed math, e.g. fractions and the standard cases env.
    – daleif
    Oct 18, 2019 at 8:18
  • 2
    Another alternative to the solutions below is the plain TeX command \mathchoice.
    – Davislor
    Oct 19, 2019 at 0:32
  • @Davislor: You are right, of course, but, as I say in my answer, we cannot tell exactly what the OP’s idea of “being in display mode” is.
    – GuM
    Oct 19, 2019 at 9:11

2 Answers 2


Since you are using LuaTeX, you can simply query \mathstyle.


        % 0 = \displaystyle
        % 1 = \crampeddisplaystyle
        % all other styles


Inline \(\catlim_{i \in \mathbb{N}} \mathbb{Z} / p^i \mathbb{Z}\) and display:
  \catlim_{i \in \mathbb{N}} \mathbb{Z} / p^i \mathbb{Z}.


enter image description here


It’s not clear what you want to do when you explicitly reset the math style. The following solution, which requires amsmath but works also with the “classical” typesetting engines, discriminates based on the \if@display switch. This purposely ignores the math style (\displaystyle vs. other styles), and decides which command to use (\varprojlim vs. \lim) considering only if the formula is being displayed or typeset in-line.

I insist that it is not clear from your question whether you consider this a bug or a feature. See also @daleif’s comment.

The code:

% My standard header for TeX.SX answers:
\documentclass[a4paper]{article} % To avoid confusion, let us explicitly 
                                 % declare the paper format.

\usepackage[T1]{fontenc}         % Not always necessary, but recommended.
% End of standard header.  What follows pertains to the problem at hand.

\usepackage{mathtools} % also loads "amsmath"






In line:
\( \catlim_{i\in\N} \Z/p^{i}\Z \).

In line, but with \verb|\displaystyle|:
\( \displaystyle \catlim_{i\in\N} \frac{\Z}{p^{i}\Z} \).

In display:
    \catlim_{i\in\N} \frac{\Z}{p^{i}\Z}

In display, but with \verb|\textstyle|:
    \textstyle \catlim_{i\in\N} \Z/p^{i}\Z

An example with \texttt{cases} (starred version requires the 
\textsf{mathtools} package):
    G =
            \catlim_{i\in\N} \frac{\Z}{p^{i}\Z} & first case \\
            \catlim_{i\in\N} \frac{\Z}{q^{i}\Z} & second case
Note how the fraction is typeset: this too shows that
\verb|\textstyle| is in force.


The printout:

Output of the code

  • +1 but there is a point you might want to clarify: \if@display won't work with something like $\displaystyle...$. Just to be thorough.
    – campa
    Oct 18, 2019 at 10:28
  • @campa: Thank you for your suggestion; please see edit.
    – GuM
    Oct 18, 2019 at 22:35

Your Answer

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