Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

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 trying to improve TraditionalForm's output by using different brackets when there are more than one. For instance, instead of $u(v(r(b))))$, I'd like to get $u\{v[r(b)]\}$.

I am not sure how to recognize order of brackets when I have lot of brackets. How can I do this?

share|improve this question
Why all these downvotes? It is about TraditionalForm and I always thought that e.g. differently colored or sized brackets could help sometimes. – Rolf Mertig Feb 1 '13 at 20:55
up vote 10 down vote accepted

This is a nice exercise on boxing:

MakeBoxes[u[v_[r_[b_]]], TraditionalForm] :=
 Module[{b1, b2, b3, t},
  t = ToBoxes[#, TraditionalForm] &;
  {bl1, bl2, bl3} = 
   StyleBox[#1, #2] & @@@ { {"{", {20, Orange}}, {"[", {15, 
       Purple}}, {"(", {12, Blue}}};
  {br1, br2, 
    br3} = {bl1, bl2, bl3} /. {"[" -> "]", "{" -> "}", "(" -> ")"};
  RowBox[{"u", bl1, t@v, bl2, t@r, bl3, t@b, br3, br2, br1

Mathematica graphics

share|improve this answer
Thank you very much Rolf, but what to do with this TraditionalForm[( y - y2 (y3 + y4 (2 y1 + y5)))/((y3^2 - y1) [Alpha]^2)] code doesn't work – Pipe Feb 1 '13 at 22:13
In general that is hard to do. You can do some special cases yourself, but in general I would just not do this. If you want to find out which bracket belongs where, then either use Ctrl Shift B (Check Balance of the Edit menu) or just put the cursor before the bracket (in Mathematica 9 at least) and you get already a greenish highlighting of the matching bracket. That is usually all good enough. – Rolf Mertig Feb 2 '13 at 0:44
Thank you very much Rolf – Pipe Feb 2 '13 at 2:25
but it is not working automatically when I have large term with many coupled brackets? – Pipe Jun 18 '13 at 18:36

Your Answer


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.