4
$\begingroup$

I'm attempting to display the geometric meaning of a contour integralenter image description here

but as you can see, the typesetting of the contour integral (created via the Epilog function) looks awful because the contour integral is too high relative to the integrand. In addition, the text is too small. How can this be fixed? My code for this figure is

a = 1.5;
b = 1;
RegionPlot[
    q^2/a^2 + p^2/b^2 <= 1, {q, -a - .1, a + .1}, {p, -b - .1, b + .1},
    AspectRatio -> Automatic,
    Axes -> True,
    AxesLabel -> {q, p},
    Frame -> False,
    PlotStyle -> Directive[Green, Opacity[0.9]],
    Ticks -> False,
    Epilog -> {Text["\[ContourIntegral]p\[DifferentialD]q", 
    Offset[{0, 0}, {.7, .35}]]},
    ColorFunction -> "Pastel"]
$\endgroup$
4
  • $\begingroup$ The text looks fine when rendered on my screen. It looks like you are exporting this to generate this image, to what format are you exporting? $\endgroup$
    – Guillochon
    Commented Mar 10, 2013 at 2:45
  • 3
    $\begingroup$ "looks awful... How can this be fixed?" — You should be more explicit in why you think the typesetting is awful and what how you want it to look like, else we'll only be wasting our time guessing how to make it less "awful to you" when we don't know why. Is it the kerning? Is it the $\mathbf{d}$? Is it the spacing? Is it the baseline alignment? Is it the colour?... $\endgroup$
    – rm -rf
    Commented Mar 10, 2013 at 2:52
  • $\begingroup$ possible duplicate of Fixing quirky typesetting in plot labels $\endgroup$
    – Jens
    Commented Mar 10, 2013 at 3:40
  • $\begingroup$ wow, that is hideous (it's not anti-aliased) $\endgroup$
    – amr
    Commented Mar 10, 2013 at 5:41

3 Answers 3

7
$\begingroup$

Not sure if this is what you mean, but a FormBox might work:

a = 1.5;
b = 1;
RegionPlot[
 q^2/a^2 + p^2/b^2 <= 1, {q, -a - .1, a + .1}, {p, -b - .1, b + .1}, 
 AspectRatio -> Automatic, Axes -> True, AxesLabel -> {q, p}, 
 Frame -> False, PlotStyle -> Directive[Green, Opacity[0.9]], 
 Ticks -> False, 
 Epilog -> {Text[
     Style["\!\(\*FormBox[\(\[ContourIntegral]\\\ p\\\ \[DifferentialD]q\),
TraditionalForm]\)", Magnification -> 2], 
    Offset[{0, 0}, {.7, .35}]]}, ColorFunction -> "Pastel",
 BaseStyle -> Large]

formbox

To see how I entered the integral correctly, follow my answer to "Formula Formatting is Small and Chunky" where I show a movie of how to enter formatted matter into a TraditionalForm command - but in your case replace TraditionalForm by the Text command instead.

$\endgroup$
2
  • $\begingroup$ (+1) back at you. It's always good to know multiple ways to do the same thing! $\endgroup$
    – Xerxes
    Commented Mar 10, 2013 at 3:59
  • $\begingroup$ This is great! Your help is much appreciated. $\endgroup$
    – user14717
    Commented Mar 10, 2013 at 4:41
4
$\begingroup$

The reason it looks so bad is that you are using a String instead of a mathematical expression. Unfortunately, ContourIntegral does not have a built-in display form, so we need to build one first.

MakeBoxes[ContourIntegral[expr_, var_], form_] := 
 RowBox[{"\[ContourIntegral]", 
   RowBox[{MakeBoxes[expr, form], 
     RowBox[{"\[DifferentialD]", MakeBoxes[var, form]}]}]}]

It would also help to make the text a bit bigger, which I've done with Style:

a = 1.5;
b = 1;
RegionPlot[
 q^2/a^2 + p^2/b^2 <= 1, {q, -a - .1, a + .1}, {p, -b - .1, b + .1}, 
 AspectRatio -> Automatic, Axes -> True, AxesLabel -> {q, p}, 
 Frame -> False, PlotStyle -> Directive[Green, Opacity[0.9]], 
 Ticks -> False, 
 Epilog -> {Text[Style[\[ContourIntegral]p \[DifferentialD]q, 16], 
    Offset[{0, 0}, {.7, .35}]]}, ColorFunction -> "Pastel"]

Contour Integral

$\endgroup$
4
  • $\begingroup$ Posted simultaneously, it seems (+1). $\endgroup$
    – Jens
    Commented Mar 10, 2013 at 3:58
  • $\begingroup$ I would guess you are not using V9. This doesn't work there. $\endgroup$
    – m_goldberg
    Commented Mar 10, 2013 at 6:46
  • $\begingroup$ @m_goldberg I'm not sure if an expression not having a built-in 2d form counts as a bug, but I gave the necessary code to add one above. $\endgroup$
    – Xerxes
    Commented Mar 10, 2013 at 7:10
  • $\begingroup$ See my answer. Your example behaves the same as my first example in V9. $\endgroup$
    – m_goldberg
    Commented Mar 10, 2013 at 7:12
1
$\begingroup$

Normally I would say that your mistake was passing a string as the first argument of text, but in this case there is a problem in V9.0.1 with passing the contour integral expression directly.

You should be able to do it this way.

With[{a = 1.5, b = 1},
  RegionPlot[
    q^2/a^2 + p^2/b^2 <= 1, {q, -a - .1, a + .1}, {p, -b - .1, b + .1}, 
    AspectRatio -> Automatic,
    Axes -> True,
    AxesLabel -> {q, p},
    Frame -> False,
    Ticks -> False,
    ColorFunction -> "Pastel",
    Epilog -> {Text[\[ContourIntegral]p \[DifferentialD]q,  Offset[{0, 0}, {.7, .35}]]}]]

Note the lacke of quotes around \[ContourIntegral]p \[DifferentialD]q.

But that doesn't work because the conversion to traditional form promised by the Mathematica documentation is not made.

enter image description here

I think this is a bug because

With[{a = 1.5, b = 1},
  RegionPlot[
    q^2/a^2 + p^2/b^2 <= 1, {q, -a - .1, a + .1}, {p, -b - .1, b + .1}, 
    AspectRatio -> Automatic,
    Axes -> True,
    AxesLabel -> {q, p},
    Frame -> False,
    Ticks -> False,
    ColorFunction -> "Pastel",
    Epilog -> {Text[\[Integral]f[x] \[DifferentialD]x,  Offset[{0, 0}, {.7, .35}]]}]]

works as expected.

enter image description here

Note

Jens' method of using a FormBox does work in V9.0.1.

Update

I brought this to the attention of WRI technical support. Their reply was almost a verbatim quote Jen's answer.

$\endgroup$
2
  • $\begingroup$ I wonder if it's a good thing that WRI support consider our site authoritative, or bad that it seems to be so difficult to coax them into giving any more information than we already know (and that one can quickly find on one's own rather than e-mailing support)? $\endgroup$ Commented Mar 14, 2013 at 23:03
  • $\begingroup$ @OleksandrR. If my understanding of SE's goals is correct, this should be considered an achievement. $\endgroup$
    – m_goldberg
    Commented Mar 15, 2013 at 13:24

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.