I am attempting to do a seemingly-simple task: label ordered pairs in a Plot that display with parentheses that grow to match the expression within. I've trawled the documentation and searched the posted questions here to no luck.

The problem is that parentheses are internally special, so they are very difficult to force into a displayed expression. I can use something similar to Graphics[Text[f[0,1/2]]] and the resulting output form has correctly-sized parenthesis, albeit with the pesky f.

I can use any bracketing operator to achieve the same result, e.g. Graphics[Text[\[LeftAngleBracket]0,1/2\[RightAngleBracket]]], but no luck with parentheses. Am I missing something incredibly simple?


Perhaps what you're looking for is this:

Graphics[Text[""[0, 1/2]]]

or also

Graphics[Text["\[InvisibleSpace]"[0, 1/2]]]

However, the "more correct" way is this:

   "\!\(\*FormBox[\(TraditionalForm\`\((0, \*FractionBox[\(1\), \


Regarding how to enter the low-level formatting constructs of the previous example by hand, I would usually type them in a TraditionalForm math environment (e.g., a DisplayedEquation and then copy and paste into a String within a FormBox, as I showed in the movie in the answer lined here. To decipher the resulting String expressions, it helps to look at the documentation on String representation of Boxes.

But if you prefer to create such expressions by hand in a source-oriented (as opposed to interactive editing) way, you would be better off doing it this way:

  DisplayForm[RowBox[{"(", 0, ",", FractionBox["1", "2"], ")"}]]]]

Here I didn't have to specify TraditionalForm explicitly because it is the default in Graphics. If you plan to use this in a different context where that's not the default format, you can wrap the expression like this:

   FormBox[RowBox[{"(", 0, ",", FractionBox["1", "2"], ")"}], 

This shows the same low-level constructs that are used above, without wrapping them in a String. They get converted to the desired output by DisplayForm.

  • $\begingroup$ To see how one can enter FormBox expressions relatively easily, have a look at the movie in this answer. $\endgroup$ – Jens Jul 21 '13 at 23:22
  • $\begingroup$ Great answer and helpful link. Can you elaborate a little on your code? It looks like a ! or Run[] but it is obviously not running an OS command but a string of internal commands. I can reduce your code to Graphics[Text[TraditionalForm["\*FormBox[TraditionalForm\((0, \*FractionBox[1, 2])\), TraditionalForm]"]]] without breaking it. I'm having problems finding what the seemingly-important \* is doing here. $\endgroup$ – Westley T. Jul 22 '13 at 1:22
  • $\begingroup$ A good reference for this is the documentation on String representation of Boxes. The specific string in my answer was actually created along the lines of what I showed in the linked movie, not constructed by hand. $\endgroup$ – Jens Jul 22 '13 at 15:43

I would create a wrapper for this:

ParenthesisForm /: MakeBoxes[ParenthesisForm[e__], form_] := RowBox[{
    "(", MakeBoxes[Row[{e}, ","],form], ")"

Here is an example:

Graphics[{Text[ParenthesisForm[0, 1/2]]}, ImageSize->50]

enter image description here


I would use MaTeX (sorry Mathematica, but no matter how good your low level Boxes are, they will not match LateX in typesetting :)

Compare the above example with MaTeX

Graphics[MaTeX["\\left( 0, \\frac{1}{2} \\right)",Magnification->2]]

Mathematica graphics

Mathematica graphics


Mathematica graphics

Graphics[Text[TraditionalForm["\!\(\*FormBox[\(TraditionalForm\`\((0, \*FractionBox[\(1\), \(2\)])\)\),

Mathematica graphics

Notice that LaTeX parentheses fit very well the content.

One might complain that this method is not build-in and requires LaTeX be installed on the system and also using external package. But these are all free and available everywhere.

I think WRI should integrate MaTeX and LaTeX in its installation. Matlab comes with LaTeX ability build-in for example.

  • $\begingroup$ +1 for telling the truth... ;o) $\endgroup$ – Henrik Schumacher Dec 5 '17 at 7:20

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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