Re: Brace, bracket pretty format needed
- To: mathgroup at smc.vnet.net
- Subject: [mg99056] Re: Brace, bracket pretty format needed
- From: "Rolf.Mertig at gmail.com" <Rolf.Mertig at gmail.com>
- Date: Sat, 25 Apr 2009 04:51:29 -0400 (EDT)
- References: <200904110757.DAA22326@smc.vnet.net> <gspgqs$o1t$1@smc.vnet.net>
On Apr 23, 12:44 pm, Andrew Meit <meit... at gmail.com> 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[ "Balance"]]] 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.): CreatePalette[ Button["ColorBalance", Block[{c, col, color, n, r, s}, s = StyleBox[#1, FontColor -> #2, TaggingRules :> "ColoredBracket"] &; FrontEndTokenExecute["Balance"]; 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