Skip to content

FrontEnd

b3m2a1 edited this page Jun 19, 2018 · 1 revision

Load the package

 <<BTools`FrontEnd`

StyleSheets

StyleSheetEdit allows one to very easily edit stylesheets, even without opening the stylesheet. For example, we can make a notebook and edit its stylesheet programmatically:

 snb = CreateDocument[{Cell["Title", "Title"], Cell["A block of text...", "Text"]}]; 
 StyleSheetEdit[snb, 
  "Text",
  {
    FontColor->Red,
    FontFamily->"Helvetica"
    },
  "MakeCell"->True
  ]

frontend-6872989756726750125

Then we can find the style cell where this is implemented:

 StyleSheetCells[snb, "Text"]
(*Out:*)

frontend-3381609911906399936

On top of this we have:

  • StyleSheetNew - makes new style cells

  • StyleSheetEditAliases - edits the InputAliases for a given notebook

  • StyleSheetEditAutoReplacements - edits the InputAutoReplacements for a given notebook

  • StyleSheetEditEvents - edits the CellEventActions or NotebookEventActions for a given cell/notebook

  • StyleSheetEditTaggingRules - edits the TaggingRules for a given notebook

Block Indentation

MakeIndentable makes a Cell or Notebook block-indentable

 inb = CreateDocument[{NotebookRead@EvaluationCell[]}]; 
 MakeIndentable[inb]

frontend-8801250787185254727

The indentation methods themselves can be called with IndentationEvent or BatchIndentationEvent . The latter applies an indentation event to the entire notebook, which can be useful with the "Replace" event for turning "∖[IndentingNewLine]" indented into "\n" indented cells

Formatting elements

FormattingTools implements a number of useful formatting elements. Chief among these are the Gradient* family of elements, starting with GradientButton . For example, we can make a button bar:

 GradientButtonBar[{1:>2, 3:>4, 5:>6}, FrameMargins->5]
(*Out:*)

frontend-9046101401840380990

And we can use whatever colors we like:

 GradientButtonBar[
  {1:>2, 3:>4, 5:>6}, 
  FrameMargins->5,
  Appearance->
    {{Hue[0, .5, 1], Hue[0, 0, 1], Hue[.6, .5, 1]}}
  ]
(*Out:*)

frontend-1526923896790945062

Or one of a small collection of named styles:

 Row@
  Table[
    GradientButtonBar[{1:>2, 3:>4, 5:>6}, 
      FrameMargins->5,
      Appearance->app
      ],
    {app, {Automatic, Flat, "Retro", "Palette", "Shiny", "Negative", "Test1", "Test2"}}
    ]
(*Out:*)

frontend-2570629531543374290

There are also generalize nine-patch appearances. NinePatchCreate turns anything into a nine-patch to be used as an Appearance . It's used, for example, in NinePatchNameTag to make a nice name-tag appearances.

 Panel[
  StringTake[ExampleData[{"Text", "LoremIpsum"}], 1000],
  Appearance->
  NinePatchNameTag[
    {Background->Hue[.6,.5,.5], RoundingRadius->5},
    {Background->White},
    {Background->Hue[.6,.5,.5], RoundingRadius->5}
    ]
  ]
(*Out:*)

frontend-2260547031847133199

But we can use it on other things:

 Panel[
  StringTake[ExampleData[{"Text", "LoremIpsum"}], 1000],
  Appearance->
  NinePatchCreate@
  PillImage["", 
    FrameMargins->5, 
    Background->Lighter[Pink,.5],
    FrameStyle->Pink
    ]
  ]
(*Out:*)

frontend-4874399652568004251

NotebookTools

NotebookTools provides some useful functions for working with boxes and notebooks.

StoreExpression generates a compressed form of a variable (only OwnValues are currently supported) and writes a cell to restore that variable:

 var={1,2,3}; 
 StoreExpression@var
(*Out:*)

frontend-1601186910705832175

The Newlineate family of functions adds newlines to boxes:

 NewlineateCode@{1, 2, 3}
(*Out:*)

{
  1,
  2,
  3
  }

The primary difference between them is whether to use recursion and what type of newline to insert.

Front-End Resources

The SyntaxHiglighting stylesheet is most useful as a parent style. It defines a number of cell styles that can be used for more simply customizable syntax highlighting. An example of that is here .