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 am trying to label a plot with an equation. The problem is that Mathematica formats things almost well but not exactly. The parenthesis are of the wrong size, and the powers are not high enough.

For example:

testplot = RegionPlot[x^2 + y^3 < 2, {x, -2, 2}, {y, -2, 2}];
Overlay[{testplot, 
        Text[(10^-3/\[Beta])^2  (("1")/g') < 2, BaseStyle -> {FontSize -> 18}]}, 
        Alignment -> {0.9, 0.85}
       ]

I need the equation to look like it would on Latex, but here is what I get instead: Mathematica evaluates the expression instead

I tried putting the equation between "" but the parenthesis would be the wrong size and the powers are off. Just like this:

Formatting the equation as text

Any suggestions? Thanks! L.

share|improve this question
2  
Here are two suggestions: 1. type "", then go between the quotes, press Ctrl-9 and type the equation using "2D notation". 2. use TraditionalForm and HoldForm. The second one gives better spacing around <. dropbox.com/s/44g6prc26sy7xsf/… –  Szabolcs Feb 19 at 22:58
    
Actually, (1.) above doesn't give a very good result. However, if you type the formula in a text cell the same way (starting with Ctrl-9), then copy and paste it into a string, it will be formatted much better, with proper spacing. –  Szabolcs Feb 19 at 23:22
    
That helps a lot but still does not fix the parenthesis problem, which I want to show exactly as it is. If it's the the power of 2, they stay as they are, but if they are (1/g), then Mathematica tried to simply the equation for me. –  Lina Feb 19 at 23:28
    
If I type into a text cell (insert it with Alt-7), I get this: dropbox.com/s/mbc3dbdg5nweg4f/… Then you can copy that into a string. I realize this is not generally a good solution, but it's at least a workaround, so you can move on with your work and not get stuck at annoying little details like this one. –  Szabolcs Feb 19 at 23:33

3 Answers 3

up vote 4 down vote accepted

I believe the OP almost had the (or a) solution entering the formula between quotes. The only step I added was to create an inline cell (ctrl-9) before typing the first parenthesis. I also wrapped the string with Text to get the output typeset in TraditionalForm.

Mathematica graphics

Mathematica graphics

If you want the fraction bigger, you can use Style to set FractionBoxOptions:

Mathematica graphics

Mathematica graphics

share|improve this answer
1  
The whole issue of formating on plots and graphics in M really needs an overhaul. There should be a simple way to use Latex directly to do this. Matlab supports using Latex directly for plots. I do not see why M can't do the same. –  Nasser Feb 20 at 2:26
    
@Nasser Related: mathematica.stackexchange.com/questions/16955/… –  Michael E2 Feb 20 at 3:05

One way to format formula, where one enjoys a complete control on it, is the using of the Box language. This way, for instance:

    RegionPlot[x^2 + y^3 < 2, {x, -2, 2}, {y, -2, 2},
 Epilog -> 
  Inset[RawBoxes[
    StyleBox[
     RowBox[{SuperscriptBox[
        RowBox[{"(", FractionBox[SuperscriptBox[10, "-3"], "\[Beta]"],
           ")"}], 2], "(", 
       FractionBox[1, "\!\(\*SuperscriptBox[\(g\), \(\[Prime]\)]\)"], 
       ")", "<", 2}], SpanMaxSize -> Infinity, FontSize -> 16, 
     FontSlant -> Italic]], Scaled[{0.8, 0.9}]]  ]

That is what should appear on the screen: enter image description here You can play with the FontSize and occasionally with the FonSlant (needed, or not). You can possibly add FontFace->Bold, if desired.

In case you like this idea you might be interested in the following tutorials: Menu/Help/tutorial/RepresentingTextualFormsByBoxes Menu/Help/tutorial/StringRepresentationOfBoxes guide/LowLevelNotebookStructure Have fun.

share|improve this answer

This is a tough one because something like a (1/g) is always converted to a/g and no HoldForm helps. Your label falls in the same category which means the form you want will always be destroyed by Mathematica except when you work with a string. Unfortunately, the rendering of a string formula differs from the usual input and here on Linux I cannot get the parenthesis large and the overall formula looks awful.

One crappy idea is to input your label in a input cell which is in TraditionalForm and then convert it into a Bitmap with Cell->ConvertTo. This image (!!) can then be used as label which looks OK here

Mathematica graphics

Nevertheless, I'm keen to hear other alternatives.

share|improve this answer
    
+1 for being so bold to propose "crappy" ideas. –  bobthechemist Feb 20 at 3:43

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.