Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
Thanks for the reply. This sounds like a lot of fiddeling. I still hope there is a more generic way :) –  Markus Roellig Mar 25 at 11:42
add comment

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.

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

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

Mathematica graphics

share|improve this answer
    
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 at 17:06
    
@MarkusRoellig Please see update. –  Michael E2 Mar 26 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 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 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 at 10:51
add comment

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: 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.

share|improve this answer
    
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 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 at 8:18
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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