# Horrific Looking Contour Integral in Mathematica Plot:

I'm attempting to display the geometric meaning of a contour integral

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

• 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? Commented Mar 10, 2013 at 2:45
• "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?...
– rm -rf
Commented Mar 10, 2013 at 2:52
• possible duplicate of Fixing quirky typesetting in plot labels
– Jens
Commented Mar 10, 2013 at 3:40
• wow, that is hideous (it's not anti-aliased)
– amr
Commented Mar 10, 2013 at 5:41

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$$,
Offset[{0, 0}, {.7, .35}]]}, ColorFunction -> "Pastel",
BaseStyle -> Large]


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.

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

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


• Posted simultaneously, it seems (+1).
– Jens
Commented Mar 10, 2013 at 3:58
• I would guess you are not using V9. This doesn't work there. Commented Mar 10, 2013 at 6:46
• @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. Commented Mar 10, 2013 at 7:10
• See my answer. Your example behaves the same as my first example in V9. Commented Mar 10, 2013 at 7:12

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.

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.

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

• 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)? Commented Mar 14, 2013 at 23:03
• @OleksandrR. If my understanding of SE's goals is correct, this should be considered an achievement. Commented Mar 15, 2013 at 13:24