Services & Resources / Wolfram Forums / MathGroup Archive

MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Brace, bracket pretty format needed

  • To: mathgroup at
  • Subject: [mg98660] Re: Brace, bracket pretty format needed
  • From: dh <dh at>
  • Date: Thu, 16 Apr 2009 04:10:18 -0400 (EDT)
  • References: <grpigs$lpc$>


here is a function that I once copied from a Wolfram site, but I can no 

more tell exactly where. Anyway, the function ColorBrackets will color 

bracket and braces. TransformBrackets and FindBrackets  are auxilliary 



TransformBrackets[f_, expr_] :=

   DisplayForm[FindBrackets[ToBoxes[expr], f]];

FindBrackets[startexpr_, f_] :=

   	Fold[Function[{expr, location},


      f[expr[[Sequence @@ location]], Length[location]], location]],



      RowBox[{a___, "{" | "[" | "(", b__, "]" | "}" | ")", c___}]],

     Length[#1] > Length[#2] &]];

ColorBrackets[expr_] :=


   StyleBox[AdjustmentBox[#1, BoxMargins -> {{0, 0}, {.5, .5}}],

     Background -> Hue[Mod[N[#2/10], 1], .5]] &, expr]


Using this, you may create a button, that takes the selection and writes 

a new cell with the colored selection. E.g.:


Button["ColorBrackets", (nb = SelectedNotebook[];

   SelectionCreateCell[nb]; SelectionMove[nb, All, Cell];

   NotebookApply[nb, "ColorBrackets[\[SelectionPlaceholder] ]", All];



Finally you may put this button in a palete.

hope ths helps, Daniel

meitnik wrote:

> Hi


> Due to my visual limitations, trying to keep track of all the braces/

> brackets can become very frustrating for me. I need some button on a

> palette that will indent and clean up the braces/brackets so I can

> tell what is going on. The color change for unmatched stuff is good

> but what I really want is a different color for each level of

> brace,bracket use. Anyone please have such a critter to share? Thank

> you


  • Prev by Date: Re: How to build a Tag Cloud Graph?
  • Next by Date: Re: Any way to make help browser remember the last position?
  • Previous by thread: Mathematica 7 problems
  • Next by thread: Re: Brace, bracket pretty format needed