MathGroup Archive 2009

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

Search the Archive

Re: Brace, bracket pretty format needed

  • To: mathgroup at
  • Subject: [mg99056] Re: Brace, bracket pretty format needed
  • From: "Rolf.Mertig at" <Rolf.Mertig at>
  • Date: Sat, 25 Apr 2009 04:51:29 -0400 (EDT)
  • References: <> <gspgqs$o1t$>

On Apr 23, 12:44 pm, Andrew Meit <meit... at> wrote:
> Hey, late help is still help ;-) Thank you.
> um, can that keyboard action you mentioned be put into a button, and
> work repeatedly as I click it each time??
> I am just so surprised that there is not a pretty print/formating
> menuitem, button, or code around. Anyone up for the challenge? Am
> doing the reformatting by hand that uses up time and energy on my
> disabled fingers. ;(
> andrew

This can be done easily:

CreatePalette[Button["Balance", FrontEndTokenExecute[

Coloring the brackets is somewhat more involved, but also doable ( the
code should
be improved since editing the expression after applying the button
will be unwanted colored eventually. There must be
a trick to tell a StyleBox to not extend its reach to the right, but I
could not figure this out.):

  Block[{c, col, color, n, r, s},
   s = StyleBox[#1, FontColor -> #2,
      TaggingRules :> "ColoredBracket"] &;
   r = NotebookRead[SelectedNotebook[]];
   c = 1 + Mod[Count[r, "ColoredBracket", -1], 9];
   col = ColorData["DarkBands"][0.1 c];
   color = Function[x,
     x /. {i : "[" | "]" :> s[i, col], j : "(" | ")" :> s[j, col],
       k : "{" | "}" :> s[k, col],
       m : "\[LeftDoubleBracket]" | "\[RightDoubleBracket]" :>
        s[m, col]}];
   n = Replace[r,
     RowBox[{a_, b___, c_}] :> RowBox[{color[a], b, color[c]}]];
   NotebookWrite[SelectedNotebook[], n, All]]]]

Rolf Mertig
GluonVision GmbH
Berlin, Germany

  • Prev by Date: Re: Paste image directly into V7 notebook on Linux/X11
  • Next by Date: Re: Mathematica JLink and comm.javax.CommPortIdentifier
  • Previous by thread: Re: Brace, bracket pretty format needed
  • Next by thread: Axes in 3D?