3

So this question is actually two, but I think they'll be solved in the same way, so I'm putting them together. The form \textstyle\lim_{n\to\infty} always bothers me, because it takes up lots of horizontal space, while \displaystyle\lim_{n\to\infty} doesn't take up too much extra vertical space. I tried to use \DeclareMathOperator*{\mylim}{{\displaystyle\lim}} to create a new limit command, so that I wouldn't have to type \displaystyle a million times, but it doesn't work. Can anyone help with this?

Also, I tried to do a similar thing with \DeclareMathOperator*{\mysum}{{\textstyle\sum}}, but that didn't work either. Is the fix the same as above?

MWE:

\documentclass[12pt]{letter}
\usepackage{amsmath,amssymb,amsthm}

\DeclareMathOperator*{\mylim}{{\displaystyle\lim}}
\DeclareMathOperator*{\mysum}{{\textstyle\sum}}

\begin{document}
$\mylim_{n\to\infty} x_n = \displaystyle\lim_{n\to\infty} x_n$

\begin{equation*}
     \mysum_{n=1}^\infty x_n = \displaystyle\sum_{n=1}^\infty x_n
\end{equation*}
\end{document}
4
  • 2
    I am confused by your descriptions of the problem. What do you mean by “it doesn’t work”? It appears that you are mixing mathstyles with \limits/\nolimits placements of sub-/superscripts. For the \sum, does \DeclareMathOperator{\mysum}{\textstyle\sum} help? Commented Oct 5, 2018 at 2:27
  • Sorry for the ambiguity. By "it doesn't work", I mean that using "\mylim" in inline math mode doesn't create a display-style limit, and using "\mysum" in display mode doesn't create a text-style sum. I've confirmed that this isn't an environmental problem, as manually typing "\displaystyle" and "\textstyle" creates the desired effect in both instances. Commented Oct 5, 2018 at 3:51
  • the form \displaystyle\sum_{n=1}^\inft is rather odd as where it is used in an equation it does nothing as the expression is displaystyle anyway, and if you used it in an inline expression it would make the entire following expression displaystyle not just the \sum Commented Oct 5, 2018 at 6:59
  • 1
    I'm not sure what you mean by the display form of \lim "doesn't take too much vertical space"? It does take too much vertical space for the intended use of inline math mode: fitting in a line of a paragraph without increasing the linespacing. Commented Oct 5, 2018 at 7:06

2 Answers 2

5

By amsmath’s default (more specifically, amsopn):

  • The starred version \DeclareMathOperator* creates a large operator which places subscript/superscript like \sum and \lim; that is, below/above in display math while, lower-/upper-right in inline math.
  • The non-starred version \DeclareMathOperator creates a large operator which places subscript/superscript like \sin and \log; that is, always lower-/upper-right.

So, if you want a \sum that 1) always puts scripts on the right and 2) is always in \textstyle (the latter being the tricky part), you can simply do

\DeclareMathOperator{\mysum}{\textstyle\sum}% <- The effect of \textstyle is local!

Okay, the “scripts always below/above” part is the actual tricky part, and you want the operator to always be in \displaystyle (the latter is questionable in your current setting, so I’ll give two different approaches).

Update: I will use a macro \mustlimits@, which mirrors \nolimits@ from amsopn, in the following solutions. Since the macro name contains @, the following code snippets should be wrapped inside \makeatletter ... \makeatother.

  1. You just want \limits and don’t actually want \displaystyle. Since \lim is essentially just Roman text, it comes with only one style. To force below/above scripts, simply do

    \newcommand{\mylim}{\lim\mustlimits@}
    
  2. You do want \displaystyle (although \lim has only one style!). Well, as you wish:

    \newcommand{\mydisplaylim}{%
      \mathop{\hbox{$\displaystyle\m@th\operator@font lim$}}\mustlimits@
    }
    \newcommand{\mydisplaysum}{%
      \mathop{\displaystyle\sum}\mustlimits@
    }
    
  3. So what is \mustlimits@ exactly? Here is its definition:

    \newcommand*{\mustlimits@}{\@ifnextchar\nolimits{\limits\@gobble}{\limits}}
    

MWE:

\documentclass[12pt]{letter}
\usepackage{amsmath,amssymb,amsthm}

\DeclareMathOperator{\mysum}{\textstyle\sum}% <- The effect of \textstyle is local!
\makeatletter
\newcommand{\mylim}{\lim\mustlimits@}
\newcommand{\mydisplaylim}{%
  \mathop{\hbox{$\displaystyle\m@th\operator@font lim$}}\mustlimits@
}
\newcommand{\mydisplaysum}{%
  \mathop{\displaystyle\sum}\mustlimits@
}
\newcommand*{\mustlimits@}{\@ifnextchar\nolimits{\limits\@gobble}{\limits}}
\makeatother

\begin{document}
$\mylim_{n\to\infty} x_n = \lim_{n\to\infty} x_n$

\begin{equation*}
     \mysum_{n=1}^\infty x_n = \sum_{n=1}^\infty x_n
\end{equation*}

$\mydisplaylim_{n\to\infty} x_n = \lim_{n\to\infty} x_n$

$\mydisplaysum_{n=1}^\infty x_n = \sum_{n=1}^\infty x_n$
\end{document}

styles


Added: As @DavidCarlisle pointed out in the comments, \mylim and \mydisplaylim will very likely increase line spacing. I would not recommend using any of \mylim, \mysum, \mydisplaylim or \mydisplaysum.

3
  • Thank you, this works perfectly! Quick question, but why does it work when using "newcommand" but not "DeclareMathOperator"? I'd been under the impression that the latter was the more general way to make new commands. Commented Oct 5, 2018 at 4:58
  • 1
    @Isomorphism \DeclareMathOperator is a specialized command designed to, well, declare a math operator. For example, \DeclareMathOperator*{\argmax}{arg\,max} and \DeclareMathOperator{\arccot}{arccot}. However, \newcommand is a more general way of, well, creating new commands. It’s not about “why does one work while the other doesn’t”. You must separate the math “styles” from the placements of \limits. These are two very different concepts. Commented Oct 5, 2018 at 15:31
  • @Isomorphism BTW, I updated my answer to use \mustlimits@ instead of \limits. Commented Oct 5, 2018 at 16:11
3

You may use \newcommand instead, together with \limits and \nolimits.

\documentclass[12pt]{letter}
\usepackage{amsmath,amssymb,amsthm}

\newcommand{\mylim}{\lim\limits}
\newcommand{\mysum}{\sum\nolimits}

\begin{document}
$\mylim_{n\to\infty} x_n = \displaystyle\lim_{n\to\infty} x_n$

\begin{equation*}
     \mysum_{n=1}^\infty x_n = \displaystyle\sum_{n=1}^\infty x_n
\end{equation*}
\end{document}

enter image description here

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .