The \stylesheet control word introduces the style sheet group, which contains definitions and descriptions of the various styles used in the document. All styles in the document's style sheet can be included, even if not all the styles are used. In RTF, a style is a form of shorthand used to specify a set of character, paragraph, or section formatting.
The style-sheet group has the following syntax:
<stylesheet> | '{' \stylesheet <style>+ '}' |
<style> | '{' <styledef>?<keycode>? <formatting> <additive>? <based>? <next>? <stylename>? ';' '}' |
<styledef> | \s |\*\cs | \ds |
<keycode> | '{' \keycode <keys> '}' |
<additive> | \additive |
<based> | \sbasedon |
<next> | \snext |
<autoupd> | \sautoupd |
<hidden> | \shidden |
<formatting> | (<brdrdef> | <parfmt> | <apoctl> | <tabdef> | <shading> | <chrfmt>)+ |
<stylename> | #PCDATA |
<keys> | ( \shift? & \ctrl? & \alt?) <key> |
<key> | \fn | #PCDATA |
For <style>, both <styledef> and <stylename> are optional; the default is paragraph style 0. Note for <stylename> that Microsoft Word for the Macintosh interprets commas in #PCDATA as separating style synonyms. Also, for <key>, the data must be exactly one character.
Control word | Meaning |
\*\csN | Designates character style. Like \s, \cs is not a destination control word. However, it is important to treat it like one inside the style sheet; that is, \cs must be prefixed with \* and must appear as the first item inside a group. Doing so ensures that readers that do not understand character styles will skip the character style information correctly. When used in body text to indicate that a character style has been applied, do not include the \* prefix. |
\sN | Designates paragraph style. |
\dsN | Designates section style. |
\additive | Used in a character style definition ('{\*'\cs...'}'). Indicates that character style attributes are to be added to the current paragraph style attributes, rather than setting the paragraph attributes to only those defined in the character style definition. |
\sbasedonN | Defines the number of the style on which the current style is based (the default is 222—no style). |
\snextN | Defines the next style associated with the current style; if omitted, the next style is the current style. |
\sautoupd | Automatically update styles. |
\shidden | Style does not appear in the Styles drop-down list in the Style dialog box (on the Format menu, click Styles). |
\keycode | This group is specified within the description of a style in the style sheet in the RTF header. The syntax for this group is '{\*'\keycode <keys>'}' where <keys> are the characters used in the key code. For example, a style, Normal, may be defined {\s0 {\*\keycode \shift\ctrl n}Normal;} within the RTF style sheet. See the Special Character control words for the characters outside the alphanumeric range that may be used. |
\alt | The alt modifier key. Used to describe shortcut-key codes for styles. |
\shift | The shift modifier key. Used to describe shortcut-key codes for styles. |
\ctrl | The ctrl modifier key. Used to describe shortcut-key codes for styles. |
\fnN | Specifies a function key where N is the function key number. Used to describe shortcut-key codes for styles. |
The following is an example of an RTF style sheet
{\stylesheet{\fs20 \sbasedon222\snext0{\*\keycode \shift\ctrl n}
Normal;}{\s1\qr \fs20 \sbasedon0\snext1 FLUSHRIGHT;}{\s2\fi-720\li720\fs20\ri2880\sbasedon0\snext2 IND;}}
and RTF paragraphs to which the styles are applied:
\widowctrl\ftnbj\ftnrestart \sectd \linex0\endnhere \pard\plain
\fs20 This is Normal style.
\par \pard\plain \s1\qr\fs20
This is right justified. I call this style FLUSHRIGHT.
\par \pard\plain \s2\fi-720\li720\fs20\ri2880
This is an indented paragraph. I call this style IND. It produces
a hanging indent.
\par}
Some of the control words in this example are discussed in later sections. In the example, note that the properties of the style were emitted following the application of the style. This was done for two reasons: (1) to allow RTF readers that don’t support styles to still retain all formatting; and, (2) to allow the additive model for styles, where additional property changes are “added” on top of the defined style. Some RTF readers may not “apply” a style upon only encountering the style number without the accompanying formatting information because of this.