Forcing Mathematica to typeset parentheses

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

Attributes[equation] = {HoldAll, HoldAllComplete};


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$$]\)\)]


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]]


Any ideas on how to improve?

-
Thanks for the reply. This sounds like a lot of fiddeling. I still hope there is a more generic way :) –  Markus Roellig Mar 25 '14 at 11:42

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]


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

ClearAll[parens];

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


-
this is cool. Thanks! Is there a way to control the height of the parentheses? The fraction apears to be somewhat higher. –  Markus Roellig Mar 26 '14 at 17:06
@MarkusRoellig Please see update. –  Michael E2 Mar 26 '14 at 23:52
@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. –  Kuba Apr 2 '14 at 8:00
@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. :) –  Michael E2 Apr 2 '14 at 10:15
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 :) –  Kuba Apr 2 '14 at 10:51

Something like this:

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


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

-
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. –  Markus Roellig Mar 25 '14 at 14:39
@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´. –  Alexei Boulbitch Mar 27 '14 at 8:18