5

I would like to define a macro that expands to the same symbol as \sum but using the inline style (\textstyle) even when used in a displayed environment.

Here's what I got:

\newcommand{\Alt}{\@ifstar{\sum}{{\textstyle\sum}}}

the starred version allows me to selectively enable displaystyle in exceptional situations. This is not a strong requirement however.

If I was not wrapping this in a macro I would have accomplished this by doing

bla {\textstyle \sum_a^b bla} bla

I am slightly uncomfortable with wrapping \sum in a group in the macro definition, only to limit the scope of \textstyle.

My question is: are there situations where spacing can be broken by the extra group around \sum?

  • 1
    Hi! Would you please care to show a formula where you consider it better to use the smaller symbol? – yo' Sep 27 '14 at 22:38
  • @tohecz I am using the \sum operator as an indexed form of "choice" in process algebra, not for "numerical" formulae. – Bordaigorl Sep 27 '14 at 22:49
  • you can use: \DeclareMathOperator*{\barr}{\textstyle\sum} to retain the smaller size. But limits will change position for display and text style. Is that OK? – Steven B. Segletes Sep 27 '14 at 22:53
  • 2
    @Bordaigorl Isn't then \Sigma what you look for? – yo' Sep 27 '14 at 22:53
  • @StevenB.Segletes is \DeclareMathOperator going to set \textstyle for everything following \barr as well? – Bordaigorl Sep 27 '14 at 23:38
1

Based on comment discussion, I had suggested something similar to the answer at How are big operators defined?, in the form of \DeclareMathOperator*{\barr}{\textstyle\sum}. However, that approach still places displaystyle limits above and below the summation (ex. 1). Nonetheless, we know that the spacing provided by \barr in textstyle (ex. 2) is the proper spacing the OP seeks.

I was able to recreate that spacing and sub/superscript placement in ex. 3-5, using different approaches. Ex. 3 tricks the result in displaystyle by using a \mathord instead of a \mathop, but of course, the pre- and post- spacing need adjustment to match the proper (ex. 2) spacing.

Ex. 4 and 5 are variations on the OP's proposed approach. In ex. 4, I add pre- and post- material inside his braces. However, depending on the nature of the material, this approach may not be available for use.

Ex. 5 is the OP's approach, except that thin spaces have been added, since the braces remove the ability of the sum's \mathopedness to extend its reach outside of the braces.

This in fact answer's the OP's question of "are there situations where spacing can be broken by the extra group around \sum?", because without the thin spaces in ex. 5, the spacing of the OP's approach will not be correct.

\documentclass{article}
\usepackage{amsmath}
\DeclareMathOperator*{\barr}{\textstyle\sum}
\begin{document}
\centering
\verb|\barr| in \verb|\displaystyle|:
\[
A\barr_{i=3}^{6}B
\]

\verb|\barr| in \verb|\textstyle|:

\medskip inline: \(A A\barr_{i=3}^{6}B B\)

\verb|\mathord| with thin spaces added
\[
A A\,\mathord{\textstyle\sum}_{i=3}^6\, B B
\]

OP's original approach \textit{if} pre- and post- content embraced
\[
A {A \textstyle \sum_{i=3}^6 B} B
\]

OP's original approach, with no embraced pre- and post- content, but thin spaces added

\[
A A {\,\textstyle \sum_{i=3}^6\,} B B
\]
\end{document}

enter image description here

| improve this answer | |
  • Excellent answer! So is there any way in your opinion I can avoid blocking \mathop and still limit the change to textstyle to the symbol? – Bordaigorl Sep 28 '14 at 18:04
  • @Bordaigorl I'm sorry, but no obvious way around the manual correction jumps out at me, but ex. 5 or even {{}\textstyle \sum_{i=3}^6{}} might give you what you want. – Steven B. Segletes Sep 28 '14 at 19:49
  • I am accepting your answer since it shows when the spacing can be wrong, which was my initial concern. @egreg's answer is also very helpful for a possible fix – Bordaigorl Oct 1 '14 at 10:09
2

You may want to have an abstract approach to this; we can exploit the fact that amsmath changes all operator names taking limits in a uniform way, by adding @ at the end of the name to mean the symbol.

\documentclass{article}
\usepackage{amsmath,etoolbox}
\makeatletter
\newtoggle{reducedop}
\newcommand{\reduceoperatorsize}[1]{%
  \csletcs{#1saved}{#1}%
  \csletcs{#1@saved}{#1@}%
  \@namedef{#1}{%
    \@ifstar
      {\togglefalse{reducedop}\@nameuse{#1saved}}%
      {\toggletrue{reducedop}\@nameuse{#1saved}}%
  }
  \@namedef{#1@}{%
    \iftoggle{reducedop}
      {\reduced@operator{#1}}
      {\@nameuse{#1@saved}}
  }%
}
\newcommand{\reduced@operator}[1]{%
  \mathop{\mathpalette\reduced@operator@i{#1}\relax}%
}
\newcommand\reduced@operator@i[2]{%
  \ifx#1\displaystyle\textstyle\else#1\fi
  \csname #2@saved\endcsname
}
\makeatother

\reduceoperatorsize{sum}

\begin{document}
$\sum*_{k=1}^n$\quad$\sum_{k=1}^n$\quad$\sum\limits_{k=1}^n$
\[
\sum*_{k=1}^n\quad\sum_{k=1}^{n} k^2=\frac{n(n+1)(2n+1)}{6}
\]
\end{document}

The first line is meant to show that the usual behavior is respected.

enter image description here

The amsmath package redefines \sum with

\let\sum@\sum
\def\sum{\DOTSB\sum@\slimits@}

and does the same for \coprod, \bigvee, \bigwedge, \biguplus, \bigcap, \bigcup, \prod, \bigotimes, \bigoplus, \bigodot and \bigsqcup. This makes the symbols “dots aware” and respecting the sumlimits or nosumlimits option because of

\DeclareOption{sumlimits}{\let\slimits@\displaylimits}
\DeclareOption{nosumlimits}{\let\slimits@\nolimits}

Based on this, I redefine \sum to be

\togglefalse{reducedop}\sumsaved

if \sum* is found and

\toggletrue{reducedop}\sumsaved

otherwise. Here \sumsaved is the same as \sum as defined in amsmath. Then I redefine \sum@ to do \sum@saved if the toggle is set to false, where \sum@saved is the same as the original \sum@. If the toggle is set to true, instead, \mathop{\mathpalette\reduced@operator@i{sum}} is executed. Within \mathpalette I check the style: if it is \displaystyle, I use \textstyle, otherwise the current style and typeset \sum@saved. The surrounding \mathop is followed by \slimits@ as before.

| improve this answer | |
  • this does corresponds more closely to what I wanted to achieve. It's still looking like black magic, I'll read it more carefully later! Thanks! – Bordaigorl Sep 28 '14 at 19:27
1

I know this is an old post, but I was reading it today. What I use is this:

\newcommand{\sumt}[2][]{
    \ifthenelse{\isempty{#1}}
    {\textstyle \sum_{#2}      \displaystyle}
    {\textstyle \sum_{#2}^{#1} \displaystyle}
}

Note that it requires \usepackage{xifthen}.

I then, for example, call \sumt[n-1]{i=1} k_i to get the same as I would've got from \sum_{i=1}^{n-1} k_i. Note that this does enforce that everything after is in display-mode, which may or may not be unhelpful. Once an do a similar thing with \int and \prod. Note that this is written backwards compared with the usual.

Ideally I'd have both arguments optional, and in the order \sum[lower][upper]. (I'm not sure what effect the blank ^{} has.) Someone with greater tex prowess than me would need to be called up for that, though!


For example, the minimalistic code

\begin{align*}
    a &+ \sumt[n-1]{i=1} i = 3\\
    a &+ \textstyle\sum_{i=1}^{n-1} i = 3
\end{align*}

produces the following image.

enter image description here

| improve this answer | |
  • This will enforce \textstyle from \sumt on. – egreg May 11 '18 at 11:04
  • Ah yes, you are right. I missed a set of braces when typing it here (but not when I tested) – Sam T May 11 '18 at 11:07
  • The braces make the entire \sumt{#1}{#2} an ordinary symbol, not an Op atom, which can have adverse effects on spacing. Try with \sumt{i=1}{n-1}i and \textstyle\sum_{i=1}^{n-1}i. – egreg May 11 '18 at 11:20
  • Hmm, yes, I see. I had expected this behaviour, but then the example I tried didn't have this issue! The updated answer, I don't think, has this issue (but is starting to become a bit cumbersome)...? – Sam T May 11 '18 at 11:43
  • The difference is that \log is an operator; TeX inserts a thin space between an Ord and an Op or two Op atoms, but not between two Ord atoms. – egreg May 11 '18 at 11:57

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.