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?

  • 2
    $\begingroup$ Why all these downvotes? It is about TraditionalForm and I always thought that e.g. differently colored or sized brackets could help sometimes. $\endgroup$ – Rolf Mertig Feb 1 '13 at 20:55

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

  • $\begingroup$ 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 $\endgroup$ – Pipe Feb 1 '13 at 22:13
  • $\begingroup$ 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. $\endgroup$ – Rolf Mertig Feb 2 '13 at 0:44
  • $\begingroup$ but it is not working automatically when I have large term with many coupled brackets? $\endgroup$ – Pipe Jun 18 '13 at 18:36

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.