Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm having difficulties in displaying a proper fraction in a label. Here's the 2D graphics which shows the problem :

PolarPlot[{
    LegendreP[5, Cos[theta]], 
    11/2 If[theta <= Pi,  1, -1]LegendreP[5, Cos[theta]]^2 Sin[theta]
    },
    {theta, 0, 2Pi},
    PlotStyle -> {
        Directive[Thickness[0.0025], Blue],
        Directive[Thickness[0.0025], Red]
        },
    PlotLabel -> Row[{
        Style[HoldForm[LegendreP[5, " cos \[Theta] "]], Blue, 16],
        "\n",
        Style[11/2 HoldForm[LegendreP[5, " cos \[Theta] "]^2 "sin \[Theta]"], Red, 16]
        }]
]

The label contains the fraction 11/2 which is badly formatted. I would like to have the fraction displayed as a small fraction in front of P_5(cos(theta))^2 sin(theta), without the big parenthesis.

Is that possible?

I am looking for a solution that works in Mathematica 7.

share|improve this question
1  
Wrap 11/2 in a Style. e.g. Style[Style[11/2, 10] HoldForm[ LegendreP[5, " cos \[Theta] "]^2 "sin \[Theta]"], Red, 16] – Edmund Mar 15 at 14:44
    
@Edmund, your suggestion works, but MMA still adds big parenthesis around the LegendreP. How to prevent that ? – Cham Mar 15 at 14:55
    
This issue bothered me too. There is no easy and satisfactory answer yet. For now I prefer to use the niceFrac function by Jens: mathematica.stackexchange.com/questions/15204/… – yanfyon May 11 at 20:03

Based on @Mike's answer here, add ScriptLevel -> 1 to Style.

Mathematica graphics

Mathematica uses the ScriptLevel value to determine when it should decrease the font size in equations. The script level increases with each nested fraction/subscript/superscript. I think that Mathematica switches to smaller fonts at a ScriptLevel of 1. In inline formulas (the ones you type with Ctrl-9 in text cells) the starting ScriptLevel is 1, thus fractions become small immediately. Otherwise it is usually 0, so the outermost fractions are large (but things written within them become small).


However, the ScriptLevel is already 1 in Column by default, as opposed to Row. Don't use Row[{..., "\n", ...}] if you mean a Column. You may want to specify alignment using the second argument of Column.

PolarPlot[{LegendreP[5, Cos[theta]], 
  11/2 If[theta <= Pi, 1, -1] LegendreP[5, Cos[theta]]^2 Sin[
    theta]}, {theta, 0, 2 Pi}, 
 PlotStyle -> {Directive[Thickness[0.0025], Blue], 
   Directive[Thickness[0.0025], Red]}, 
 PlotLabel -> 
  Column[{Style[
     "\!\(\*FormBox[\(\*SubscriptBox[\(P\), \(5\)](cos\\\ \
\[Theta])\),
TraditionalForm]\)", Blue, 16], 
    Style["\!\(\*FormBox[\(\*FractionBox[\(11\), \(2\)] \
\*SuperscriptBox[\(\*SubscriptBox[\(P\), \(5\)](cos\\\ \[Theta])\), \
\(2\)] sin\\\ \[Theta]\),
TraditionalForm]\)", Red, 16]}]]

Mathematica graphics

All this ugly SuperscriptBox stuff that you see above will format nicely in the front end if you paste it back:

Mathematica graphics

I typed it like this:

  • type "x"
  • select the x and press Control-Shift-T to convert to TraditionalForm
  • position the cursor next to the x, then type the formula as you normally would

Personally I prefer to type formulae directly into a single string rather than try to mix strings with HoldForm in a complicated way.

share|improve this answer

Update: According to the OP's comment, he is looking for a solution that works in Mathematica 7. MaTeX requires Mathematica 10. I am leaving this answer here in case others find it useful, but note that it does not solve the OP's problem.


If you're fussy about formula formatting, you'll be better off using MaTeX.

MaTeX["\\frac{11}{2} P_5(\\cos \\theta)^2 \\sin\\theta", 
 "DisplayStyle" -> False]

Mathematica graphics

I made MaTeX precisely because people I worked with were fussy about formatting.


Load package:

<<MaTeX`

Add the color package to the preamble and change to CM Bright sans-serif fonts:

SetOptions[MaTeX, 
 "Preamble" -> {"\\usepackage{cmbright}", 
   "\\usepackage{amsmath,amssymb}", "\\usepackage{color}"}]

PolarPlot[{LegendreP[5, Cos[theta]], 
  11/2 If[theta <= Pi, 1, -1] LegendreP[5, Cos[theta]]^2 Sin[
    theta]}, {theta, 0, 2 Pi}, 
 PlotStyle -> {Directive[Thickness[0.0025], Blue], 
   Directive[Thickness[0.0025], Red]}, 
 PlotLabel -> 
  MaTeX["{\\color{blue}P_5(\\cos\\theta)},\;\; \
{\\color{red}\\frac{11}{2} P_5(\\cos \\theta)^2 \\sin\\theta}", 
   "DisplayStyle" -> False, FontSize -> 16]]

Mathematica graphics

share|improve this answer
    
I don't know MaTeX (that's in Mathematica ?). The 11/2 fraction displayed above is what I want in MMA labels. However, your code doesn't appear to work in my old version 7. – Cham Mar 15 at 14:52
    
@Cham You have to click the link to see what it is, but it does not work with Mathematica 7. – Szabolcs Mar 15 at 14:54

I wasn't totally happy with this. Even in the LaTeX code by Szabolcs, the fraction is larger than the P right next to it. But this gives close to the same thing as his, but without an external package

PolarPlot[{
      LegendreP[5, Cos[theta]], 
      11/2 If[theta <= Pi,  1, -1] LegendreP[5, Cos[theta]]^2 Sin[
    theta]
      },
     {theta, 0, 2 Pi},
     PlotStyle -> {
           Directive[Thickness[0.0025], Blue],
           Directive[Thickness[0.0025], Red]
           },
     PlotLabel -> Row[{

    Style[HoldForm[LegendreP[5, " cos \[Theta] "]], Blue, 16],
            "\n",

    Row[Style[#1, Red, #2] & @@@ {{11/2, 
        8} , {HoldForm[
         LegendreP[5, " cos \[Theta] "]^2 "sin \[Theta]"], 16}}]
            }]
 ]

enter image description here

share|improve this answer

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.