Legacy Documentation

Publicon® (2004)

This is documentation for an obsolete product.
Current products and services

Documentation  / Publicon  / User Guide  / Advanced Features  / Creating Document Palettes  / Button Functions  /

Button Functions

CellWriteStyle

CellWriteStyle[args] applies the indicated style, inline cell, or list of cells to a notebook or selection. It can also set or move the cursor position within the cell(s), make selections, and/or apply a user defined function.

Input:
Here are some of the possible forms of input for CellWriteStyle:

"style"
{"style"}
Note: "style" is a cell style; for example: "Section".

{"style", Cell Expression}
Note: When the second element of the list is a cell expression, it is critical that the cell has the option TaggingRules RuleDelayed {...,"CellLabel" Rule True,...}.

For example:

Cell[ TextData[{ CounterBox[ "Section"], ". " }], "SectionLabel",
TaggingRules RuleDelayed {"CellLabel" Rule True}]

This can be used to create an inline cell containing counter information for a numbered section head.

{"style", {List of cells}}
{"style", Cell Expression, {List of cells}}
Note: If there is no current selection, this will write the list of cells. If a cell is selected, it will change the cell's style, and (if a Cell Expression is the second argument) add the cell expression in the second argument as an inline cell.

{"style", {List of cells}, positive number}
{"style", Cell Expression, {List of cells}, positive number}
Note: A positive number determines cursor position (moving upward) after writing the cell(s). For example, 1 will place the cursor at the end of the last cell written. 2 will move up one cell above the last, and so on.

{"style", {List of cells}, positive number, "AC"}
{"style", Cell Expression, {List of cells}, positive number, "AC"}
{"style", {List of cells}, positive number, "BC"}
{"style", Cell Expression, {List of cells}, positive number, "BC"}
Note: "AC" and "BC" stand for "after cell" and "before cell", respectively. Adding one of them to your argument will position the cursor before or after the cell you have moved to.

{"style", {List of cells}, negative number}
{"style", Cell Expression, {List of cells}, negative number}
{"style", {List of cells}, positive number, negative number}
{"style", Cell Expression, {List of cells}, positive number, negative number}
Note: A negative number determines cursor position (moving to the left) in the last cell written, or the selected cell if a positive number is listed first.

{"style", {List of cells}, "B"}
{"style", Cell Expression, {List of cells}, "B"}
{"style", {List of cells}, positive number, "B"}
{"style", Cell Expression, {List of cells}, positive number, "B"}
Note: "B" stands for "beginning" and will either move to cursor to the beginning of the cell, or after an inline cell (which must have the option TaggingRules RuleDelayed {...,"CellLabel" Rule True,...}).

{"style", {List of cells}, {"B", n}}
{"style", Cell Expression, {List of cells}, {"B", n}}
{"style", {List of cells}, positive number, {"B", n}}
{"style", Cell Expression, {List of cells}, positive number, {"B", n}}
Note: {"B", n} will move the cursor to the beginning (or just after an inline cell), and then move characters to the right.

{"style", {List of cells}, "F"}
{"style", Cell Expression, {List of cells}, "F"}
{"style", {List of cells}, positive number, "F"}
{"style", Cell Expression, {List of cells}, positive number, "F"}
Note: "F" (for "first") acts just like "B", but then selects the first character to the right.

{"style", {List of cells}, "S"}
{"style", Cell Expression, {List of cells}, "S"}
{"style", {List of cells}, positive number, "S"}
{"style", Cell Expression, {List of cells}, positive number, "S"}
{"style", {List of cells}, positive number, negative number, "S"}
{"style", Cell Expression, {List of cells}, positive number, negative number, "S"}
{"style", {List of cells}, {"S", positive number}}
{"style", {List of cells}, {"S", positive number, positive number}}
{"style", {List of cells}, positive number, {"S", pos. num.}}
{"style", {List of cells}, positive number, {"S", pos. num., pos. num.}}
Note: "S" stands for "select" and selects everything to the right of the cursor position. {"S", } will select n characters to the right of the cursor position. {"S", , } will move the cursor characters to the right, then select characters to the right of that.

You can also set up many of the above inputs without the "style" argument.

In addition, you can have as your last argument a user defined function. If a user defined function is specified, it will evaluate only when a new cell or list of cells is being written.

Behavior:
If the input is just a cell style ("style", {"style"}) and the cursor is between cells, this will write an empty cell of the specified "style". If a cell is selected, its style will be changed to the specified "style". Inline cells (with the option TaggingRules RuleDelayed {...,"CellLabel" Rule True,...} applied) will be eliminated from selected cells.

If the input contains a cell expression as its second argument, CellWriteStyle will write a cell with the cell expression as an inline cell. If the cell bracket(s) of a cell (or group of cells) is selected, the style of the cell(s) will be changed to the specified "style", and the cell expression of the second argument will be written as an inline cell at the beginning of the cell(s). If the cells already have inline cells (with the option TaggingRules RuleDelayed {...,"CellLabel" Rule True,...} applied), they will be replaced by the cell expression in the function.

If a portion of a cell is selected, the cell will be split into 1, 2, or 3 cells at the current selection and "style" will be applied to the cell that corresponds to what had been selected. If the input does not have a "style" argument, the cursor will move after the cell and then the action taken will be the same as if the cursor had initially been at that location.

If the cursor is inside a cell, but not selecting a portion of the cell's contents, the cursor will move after the cell and then the action taken will be the same as if the cursor had initially been at that location.

A simple way CellWriteStyle may be used is as follows:

ButtonBox["Section", ButtonStyleRule"StyleApply"]

CellWriteStyle is used in the style definition of "StyleApply".

Options:
To ensure that only certain styles of cells may follow one another, apply the option ContextValidation Rule True. (The default for CellWriteStyle is ContextValidation Rule False.) To specify that a cell with style "style" may only be inserted following cells with styles "style1", "style2", etc., put TaggingRulesRuleDelayed{"AllowedToFollow" Rule {"style1", "style2",...}} in the style definition for "style". If a cell with style "style" may be inserted only at the top of a document, put "$None" in the "AllowedToFollow" tagging rule.

To specify that a cell with style "style" may not be inserted following cells with styles "style1", "style2", etc., put TaggingRulesRuleDelayed{"NotAllowedToFollow" Rule {"style1", "style2",...}} in the style definition for "style". If a cell with style "style" may not appear at the top of a document, put "$None" in the "NotAllowedToFollow" tagging rule.

CellWriteStyle also takes the option FindCellStyle. The default value of FindCellStyle is None. With FindCellStyle Rule "style", where "style" is a user specified string, CellWriteStyle first checks to see if there is a cell with style "style" in the document after the present cursor position. If such a cell exists, its cell bracket will be selected and no further action will be taken. If not, CellWriteStyle behaves normally. FindCellStyle Rule True and a first argument of "style", CellWriteStyle behaves the same as FindCellStyle Rule "style".

SerialCursorPosition is another option, that enables the repeated insertion of a cell sublist into a document. The default is SerialCursorPosition Rule True. To work, the input for CellWriteStyle must be of the form {"style", {List of cells}, ...} or {"style", Cell Expression, {List of cells}, ...} and the entire contents of a cell must be selected in the document and match the first cell in {List of cells}. To specify that the above behavior be enabled when the entire contents of a cell are selected, except for an inline cell at its beginning, give the inline cell the option TaggingRules RuleDelayed {...,"CellLabel" Rule True,...}.

SerialCursorPosition Rule n can be used when additional cells are written using a user defined function. An example of this is the Table buttons in Publicon's document palettes. CellWriteStyle writes the title and note cells of the table, while an additional function writes the table body cell and selects the contents of the title cell. In this case SerialCursorPosition is set to 2.

CellWriteStyle also takes the options GenerateProceedDialog and SpecifiedNotebookToActOn. See their usage messages for information.