A Cell Tags Button
John M. Novak
The mechanism provides a way to associate keywords or tags to notebook cells. Version 3.0 supports hyperlinks to cells with specified tags. Cell tags can also be used to compile an index for a notebook. Here is a simple button that adds selected text in a cell to the of that cell. (The button can be turned into a palette using Generate Palette from Selection under the File menu.)
To see the code that defines this button, select the button's cell and use Show Expression under the Format menu. This is what you should see:
Here is a brief explanation of the code. First we read the selected text from the .
(This implementation is not optimal because should be a local symbol, not in the global context.) If the selection is not a , we convert it to one.
We then move the selection to be the entire cell.
Lastly we modify for the cell to include .
We have to check if there are any existing and also if the is already present. is used to eliminate duplicate tags. Note that a single cell tag is saved as a , while multiple tags are stored as a .
There are a good many pitfalls in the design of button functions. The most likely problems involve button function argument handling, the syntax that the front end understands, and the distinction between and . Also, option handling is irregular (which is part of the reason for the slightly eccentric code above).
Presently, button programming is not well documented. To learn more about programming buttons, users should have a look at the examples in the help browser under "Getting Started/Demos." Look especially at the palette demos Polyhedron Explorer, Periodic Table, and Physical Constants.
Document converted by Mathematica of Wolfram Research