I use the definitions from this post to typeset formulas in lecture slides. This is my function definition:

Attributes[equation] = {HoldAll, HoldAllComplete};
equation[eq___] := Panel[TraditionalForm[Style[HoldForm@Defer[eq], 21]]]

I also had to set:

SetOptions[$FrontEndSession,  UnderoverscriptBoxOptions -> {LimitsPositioning -> False}]

It works nicely in many cases. For instance:

equation[\[ScriptCapitalP][k, "N", \[Rho]] == \[ScriptCapitalP][X <= k] == \!\(\*UnderoverscriptBox[\(\[Sum]\), \(n = 0\), \(k\)]\(Binomial["\<N\>", 
 m] \*SuperscriptBox[\(\[Rho]\), \(n\)] \*SuperscriptBox[\((1 - \[Rho])\), \("\<N\>" - n\)]\)\)]

enter image description here

Now, there are some things, the frontend just refuses to typeset, for instance parentheses it considers superfluous. For example, I want to reproduce:

$$ \overline{\left(\frac{X}{y}\right)}_\mathrm{geom}=\frac{\overline{X}_\mathrm{geom}}{\overline{Y}_\mathrm{geom}} $$

The best I could get was:

equation[Subscript[(\!\(\*OverscriptBox[\((\*FractionBox[\(X\), \(Y\)])\), \(_\)]\)), geom] == Subscript[\!\(\*OverscriptBox[\(X\), \(_\)]\), geom]/Subscript[\!\(\*OverscriptBox[\(Y\), \(_\)]\), geom]]

enter image description here

Any ideas on how to improve?

  • $\begingroup$ Thanks for the reply. This sounds like a lot of fiddeling. I still hope there is a more generic way :) $\endgroup$ Commented Mar 25, 2014 at 11:42

2 Answers 2


If you're going to be doing this programmatically (as opposed to typing directly into a Text cell) and doing it often, then perhaps a function that is typeset as parentheses would be useful.

Format[parens[e_]] := DisplayForm@RowBox[{"(", MakeBoxes@e, ")"}]

equation[Subscript[OverBar[parens[X/Y]], "geom"] == foo]

Mathematica graphics

If you need to adjust the space around the expression e, an AdjustmentBox can be used.

Format[parens[e_, opts : OptionsPattern[AdjustmentBox]]] := 
 DisplayForm@RowBox[{"(", AdjustmentBox[MakeBoxes@e, opts], ")"}]

  Subscript[OverBar[parens[X/Y, BoxMargins -> {{0, 0}, {0, 0.5}}]], "geom"] == foo]

Mathematica graphics

  • $\begingroup$ this is cool. Thanks! Is there a way to control the height of the parentheses? The fraction apears to be somewhat higher. $\endgroup$ Commented Mar 26, 2014 at 17:06
  • $\begingroup$ @MarkusRoellig Please see update. $\endgroup$
    – Michael E2
    Commented Mar 26, 2014 at 23:52
  • $\begingroup$ @MichaelE2 +1ed ofc but I have a question. Is Format necessary in definition of parens? I mean, what does it change because I'm always confused with that formatting functions. $\endgroup$
    – Kuba
    Commented Apr 2, 2014 at 8:00
  • $\begingroup$ @Kuba I suppose it's not strictly necessary. The difference is in what is stored in the kernel, parens[e] or DisplayForm[...]. Probably not a big difference in this case, in fact, but I guess I use Format for typesetting expressions out of habit. I suppose using an InterpretationBox could be more robust. One could make a typeset expression that is interpreted as parens[e]. Thanks for the upvote. :) $\endgroup$
    – Michael E2
    Commented Apr 2, 2014 at 10:15
  • $\begingroup$ Ok, thanks :) some sort of compact comparison whould be useful. I mean: "use Format when, use Interpretation when... and not Format because.". Now there are multiple ways to get the result but beginners or me :P don't know if they are just different but the same or it really matters. p.s. documentation is not compact :) $\endgroup$
    – Kuba
    Commented Apr 2, 2014 at 10:51

Something like this:

     RowBox[{"(", FractionBox[OverscriptBox["X", "_"], "y"], ")"}], 
     "geom"], "=", 
    FractionBox[SubscriptBox[OverscriptBox["X", "_"], "geom"], 
     SubscriptBox[OverscriptBox["Y", "_"], "geom"]]
  , SpanMaxSize -> Infinity] // DisplayForm

It gives this: enter image description here I am not quite sure about the line over the letters. All lines I have seen in the palette are short.

  • $\begingroup$ Thanks Alexei. This is not exactly what I wanted. The overbar is for the whole fraction X/Y, not only the numerator, so it should span the parentheses. $\endgroup$ Commented Mar 25, 2014 at 14:39
  • $\begingroup$ @Markus Roellig that's right, this was also my point. I did not find the way of doing that. The focus in my answer is the way of stretching the parentheses. This is fixed by the option ´SpanMaxSize -> Infinity´. $\endgroup$ Commented Mar 27, 2014 at 8:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.