I'm busy answering a question by constructing a new math operator that uses the sum symbol and some TikZ placed on top. My answer as it stands can be found here. It looks (I think) pretty good in display style, but too large when shown inline. Even if it automatically set the sum symbol into inline size, the placement of the TikZ would be off.

Is there a way to define different code for when the operator is used in display mathematics environments, and when it's inline? Alternatively, is there a way to detect when you are in display or inline mode?

From the aforementioned example, here is the code I constructed:


% Modify the coordinate (-0.3ex,0) to adjust alignment, and (0.1) to adjust the size.
    \begin{tikzpicture}[baseline=(char.base), inner sep=0, outer sep=0]
        \draw (-0.3ex,0) circle (0.1); 
        \node (char) at (0,0) {$\displaystyle\sum$};  % Want to define a second symbol for inline...


G=\osum_a^b H

And now in inline mode the equation $G=\osum_a^b H$ is obviously too big.


TeX features a special primitive for this very case. However, you will have to specify code for all four math styles:


See TeX by Topic for more information.

| improve this answer | |

Taking the definitions you make in the other question, here's a way: \mathchoice has four arguments, stating what's to be done in the various situations; \mathop states how the symbol should be considered with respect to spacing and ending with \displaylimits ensures the same behavior as \sum:


  \begin{tikzpicture}[baseline=(char.base), inner sep=0, outer sep=0]
    \draw (-0.3ex,0) circle (#2);
    \node (char) at (0,0) {$#1\sum$};


\[\osum_a^b x\]

$\osum_a^b x$


enter image description here

If you need more parameters to adjust the circle's position in smaller styles, modify accordingly the definition. Using a two-step approach makes the code more easily maintainable.

| improve this answer | |
  • I was just in the process of condensing it down like this. I'm a little confused about the placement of the #1 though... – qubyte Mar 1 '12 at 16:13
  • \buildosum has two parameters: the style to use and the circle diameter. – egreg Mar 1 '12 at 16:16
  • Ah, I see now. I didn't read the brackets properly. – qubyte Mar 1 '12 at 16:21
  • 2
    I've added them for greater clarity; they are not strictly necessary as the first unbraced token will be the first argument anyway. When I'm writing low level code, I'm influenced by the old habits developed when I was using Plain TeX or AMSTeX. :) – egreg Mar 1 '12 at 16:26
  • I added a new version partly based on this in my answer. Thanks for the help. :) – qubyte Mar 1 '12 at 16:30

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.