Creating Palettes
Palettes are like extensions of your keyboard. They can be used to perform many actions in
Mathematica, including entering typesetting characters, styling notebooks, and performing evaluations. As with any notebook, creating palettes can be done with a menu item or programmatically.
| CreatePalette[expr] | create and open a palette notebook containing expr in the front end |
| PaletteNotebook[{cell1,cell2,...}] | an in-cell representation of a palette notebook that can be manipulated by the front end |
|
| create a palette notebook from the current selection in the front end |
| a user-customizable palette |
Palette creation tools.
Palette notebooks have a unique property. They can be a currently selected notebook but cannot normally be an
InputNotebook. This allows the palette to perform operations on the notebook into which keyboard input in the front end is directed. See
"Manipulating Notebooks from the Kernel" for further information.
Generating a Palette Programmatically
CreatePalette[expr] creates an unsaved palette notebook containing
expr and opens it in a separate window. To save the palette, close the window and save the file when the save dialog appears or save the palette notebook programmatically using
NotebookSave.
Below is a palette that uses
PasteButton to paste characters into the input notebook.
PasteButton is specifically designed to work with palettes. It pastes its contents directly into the input notebook at the insertion point. When used in conjunction with
RawBoxes,
PasteButton will paste uninterpreted boxes into the input notebook.
Alternatively, use
PaletteNotebook to create an in-cell representation of a palette notebook. A separate window containing the notebook can be opened in the front end by clicking the

button or wrapping
CreatePalette around the
PaletteNotebook expression.
| Out[40]= |  |
Since
RawBoxes[boxes] inserts
boxes verbatim without further interpretation, the characters can be used as part of an input expression or textual cell.
Cell[BoxData["\<\" \"\>"],"cellstyle"] | interpreted box structure |
Cell[BoxData[" "],"cellstyle"] | uninterpreted box structure |
Box structure comparisons.
If the box structure for
"
" is interpreted as a string in the palette, then regardless of the cell style, the front end will always treat
"
" as a string.
"

"
This next palette inserts styled cells into the active notebook using front end tokens. Front end tokens perform front end commands from within the kernel that would normally be done using the menus. For a complete listing of front end tokens, see
"Front End Tokens".
The palette below links to the Wolfram
Mathematica Documentation Center, allows the deletion of all output cells in the input notebook, and can also quit the kernel.
| Out[4]= |  |
CreatePalette was used to create several
Mathematica palettes, including the
Basic Math Assistant palette.
Generating a Palette from a Selection
Palettes can also be created by selecting a cell or its contents and choosing . To save the palette, close the window and save the file when the save dialog appears.
For example, consider the grid below, which pastes input templates into the input notebook.
| Out[76]= |  |
Create a palette by selecting the grid and choosing . The unsaved palette will appear in a separate window.
Although this can sometimes be useful for temporary or experimental purposes, this is not the best method for palette development. Using
CreatePalette allows you to write a program that, when evaluated, can fully automate the creation of palettes. The menu item requires manual intervention, which can be subject to errors. This can lead to the creation of palettes that will be difficult to recreate if you wish to tweak them or fix bugs in them.
Finalizing and Saving the Palette
CreatePalette and by default create a notebook with options set so as to be suitable for the appearance and behavior of a typical palette. However, options such as
Magnification and

may also be useful.
1. To set these options programmatically, specify each of the options above in a
CreatePalette statement. For example:
Note: Setting
True should only be done when the palette functionality has been completely debugged and is in a ready-to-use state, as this prevents the front end from aborting a dynamic evaluation that may or may not contain bugs.
2. To set these options using the
Option Inspector, select the palette and open the
Option Inspector:
In , explicitly set
Magnification to avoid inheriting the global setting.
In, explicitly set
True to enable
Dynamic even if dynamic updating is disabled in the user's front end.
To save the palette, click the close button in the palette window and you will be prompted to save the palette or save the palette notebook programmatically using
NotebookSave.
Installing the Palette into Mathematica
A palette must be installed on the
PalettePath for it to appear in the main menu.
| Out[10]= |  |
The simplest way install a palette is to choose , provide the source file, palette name, and installation directory to the
Install Mathematica Item dialog, and click
Finish.
Palettes can also be installed as part of a
Mathematica application. To add a palette to your application, create a FrontEnd\Palettes\ directory within the application folder and save the palette to this location. For example, the palette MyPalette.nb would be placed in MyApplication\FrontEnd\Palettes\.
Extended Examples
Dependent Opener Views
The second argument of
Dynamic can be used to control the state of an opposite opener view so that only one remains open at any given time.
Palette states can also be tracked and controlled using
TaggingRules. Unlike dynamic variables,
TaggingRules are automatically cached by the front end so that installed palettes can remember their control object states across multiple front end sessions, even if they cannot be saved. This topic is beyond the scope of this document, but a detailed discussion and set of examples can be found in
"Storing and Tracking Palette States".
Applying and Evaluating Functions
Palettes can run evaluations and return the results to a notebook.
| Out[17]= |  |
Consider the following polynomial. Highlight the expression and choose
Expand
from the palette above.
Mathematica will apply the function to the selection and evaluate the resulting expression in place.