Sometimes, having all double brackets [[...]] transformed into \\[LeftDoubleBracket] ... \\[RightDoubleBracket] can really facilitate code reading.

On a given notebook, how to transform all occurrences automatically (on input cells)?

The other way around is easier, but a couple of buttons interface will get extra... thanks.

  • 2
    $\begingroup$ the lefts are easier :) $\endgroup$ – Dr. belisarius Oct 29 '15 at 17:18
  • $\begingroup$ Cell>Convert To>StandardForm does this (it is what i use), but it also makes other changes that may not be desirable $\endgroup$ – Mike Honeychurch Oct 29 '15 at 22:37

Palette button

 Button["Compact Part",
       celldata = NotebookRead[cell],
       pattern = RuleDelayed[
         RowBox[{h__, "[", RowBox[{"[", spec___, "]"}], "]"}],
         RowBox[{h, "\[LeftDoubleBracket]", RowBox[{spec}], 
       Not @ FreeQ[celldata, First @ pattern],
       SelectionMove[cell, Cell, All, AutoScroll -> False];
         ReplaceRepeated[celldata, pattern], AutoScroll -> False
   {cell, Cells[InputNotebook[], CellStyle -> "Input"]}


It may happen that it will miss an example from time to time, it should be rare though. In heavily edited notebook I have faced box structures that were not "proper" but good enough for FrontEnd to understand. So it may happen this "proper" pattern won't catch them.

  • $\begingroup$ I tried it on ref/Part and it works. $\endgroup$ – Kuba Oct 29 '15 at 18:44
  • $\begingroup$ Tried it on a 700 pages notebook, and, although it seems to work, the end message doesn't appear. When I have a little time, I will try to trace if it is the notebook size or some specific code content. $\endgroup$ – P. Fonseca Oct 31 '15 at 20:49
  • $\begingroup$ @P.Fonseca it may be that's the size :) $\endgroup$ – Kuba Oct 31 '15 at 20:50

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.