2

I write up problem sets in Mathematica.

One thing that I haven't figured out is position limit tokens.

In a text cell (cmd+7), when I type "ESC sum ESC ^_ x", it comes up like $\sum_x$.

How do I make it look like $\displaystyle \sum_x$?

m_goldberg
  • 107,779
  • 16
  • 103
  • 257
Marty B.
  • 133
  • 3

1 Answers1

4

To get the "display form" placement of the summation limits, you have to use the low-level option LimitsPositioning -> False. Since this is inconvenient to enter manually, I defined a keyboard shortcut EscsumEsc to do this for you. I used a TemplateBox to define the shortcut, so that it creates a construct similar to what the existing shortcut EscsumtEsc does. But I only include a single entry for the lower limit, and one more for the upper limit:

ClearAll[mySum]
inlineSumAppearance[x_, y_] := 
 TemplateBox[{x, y}, "mySum", DisplayFunction :> (
    UnderoverscriptBox["\[Sum]", #1, #2, 
      LimitsPositioning -> False] &), 
  InterpretationFunction :> (RowBox[{"mySum", "[", 
       RowBox[{#1, ",", #2}], "]"}] &)]

mySum /: MakeBoxes[mySum[n_, k_], StandardForm] := 
 inlineSumAppearance[ToBoxes[n], ToBoxes[k]]

SetOptions[EvaluationNotebook[], 
 InputAliases -> 
  DeleteDuplicates@
   Join[{"sum" -> 
      inlineSumAppearance["\[SelectionPlaceholder]", 
       "\[Placeholder]"]}, 
    InputAliases /. 
      Quiet[Options[EvaluationNotebook[], InputAliases]] /. 
     InputAliases -> {}]]

Now you can create a text cell and type something, like this:

sum inline

Here, I entered the sum within an inline cell, by using the above shortcut.

I just saw that you may not need an upper limit. In that case, you could simplify my definition by omitting the overscript template:

ClearAll[mySimpleSum]
inlineSimpleSumAppearance[x_] := 
 TemplateBox[{x}, "mySimpleSum", DisplayFunction :> (
    UnderoverscriptBox["\[Sum]", #1, "", 
      LimitsPositioning -> False] &), 
  InterpretationFunction :> (RowBox[{"mySimpleSum", "[", #1, "]"}] &)]

mySimpleSum /: MakeBoxes[mySimpleSum[n_], StandardForm] := 
 inlineSimpleSumAppearance[ToBoxes[n]]

SetOptions[EvaluationNotebook[], 
 InputAliases -> 
  DeleteDuplicates@
   Join[{"ssum" -> 
      inlineSimpleSumAppearance["\[SelectionPlaceholder]"]}, 
    InputAliases /. 
      Quiet[Options[EvaluationNotebook[], InputAliases]] /. 
     InputAliases -> {}]]

simple

This was entered using the shortcut EscssumEsc. These new shortcuts are valid in the current notebook, and they don't modify the behavior of the existing EscsumtEsc (i.e., the built-in template will still adjust its indices when in inline mode).

The main ingredient here is the same as in this related question: How to make underscript like underscript in InlineFormula of lim in Notebook and (inline) Latex.

Jens
  • 97,245
  • 7
  • 213
  • 499