Doing it with Styles

I blogged earlier about one of the more subtle problems we created when we decided to allow paragraph styles to take on character formatting—a decision made very early in Word’s history. In that post, I gave a very basic description of how styles work, but some of the comments suggest that a few folks would benefit from a more thorough description of how styles work. Also, Nate wants to know more about the work we did in Word 2004 to make using styles much easier, so I’ll describe the differences between Word X and Word 2004 near the end of this post. I’ll also give some tips about ways to define or modify styles.

Word has two basic types of styles: paragraph and character. For Word 2004, we added table and list styles a la Word XP for Windows. Other than note that table and list styles exist, I’ll not discuss them in this post. I’ll talk a bit about character styles, and when you might want to use them, but you can’t use Word without using paragraph styles. For the sake of brevity, I’ll often drop the word “paragraph” when talking about paragraph styles or styles in general. When I mean to talk about character styles in particular, I’ll refer to them as “character styles.”

Try this: start up Word, select “Styles…” from the Format menu, select “Heading 1” in the list of style names, then click the “Modify…” button. At this point, you’re staring at the New/Modify Style dialog box. The dialog box is pretty much the same whether you’re defining a new style or modifying an existing style, with only minor behavioral differences depending on which task you’re performing. The top part of that dialog box has the style’s name, its type, the style that style is based on and the style of the following paragraph (i.e. what style will be applied to the new paragraph when you place the insertion point at the end of an existing paragraph and hit the <return> key).

The “Based on” style is important to understanding how styles work. Take a look at the style’s description near the bottom of the dialog box. For the “Heading 1” style, you’ll see that the description begins with “Normal +”. This means that the “Heading 1” style contains all of the formatting of the “Normal” style plus any of the formatting that’s been applied to the “Heading 1” style (the rest of the description after the “+” sign). Note that the style listed in the “Based on” dropdown control is also the “Normal” style.

You can base a style definition on any other style. For example, you can create a new style based on the “Heading 1” style. This new style will contain all of the formatting of the “Normal” style, all of the formatting of the “Heading 1” style and any direct formatting that you apply to this new style. We refer to this linkage between styles as the “based-on chain,” and base styles are known as being “below” the styles based on them. In this example, “Normal” is below “Heading 1” in the based-on chain, and our new style is above the “Heading 1” style in this particular based-on chain.

Because the formatting of a style inheres to any style that’s based on it, changing the base style also changes the styles above it in the based-on chain. For example, if you change the alignment of the “Normal” style from “left” to “right,” then all the “Heading” styles will become right-aligned. You can experiment with this a bit to see how it works. In Word, select “Styles…” from the Format menu. In the “List” dropdown, select “All Styles.” Scroll to the top of the list, select “Body Text” and click the “Modify…” button. Change its alignment to “Justified,” note the style description, then click “OK”. Back in the “Styles” dialog box, select “Styles in Use” in the “List dropdown”. Select “Normal” in the style list, then click the “Modify” button. Change the alignment of the Normal style to “Justified,” then click “OK”. Back in the “Styles” dialog box, select “Body Text” in the list of style names, and note the style description.

In Word X (or 98 or 2001), you change the style’s alignment by clicking on the “Format” dropdown in the New/Modify Style dialog box, selecting “Paragraph…” in the list, selecting “Justified” in the Alignment dropdown, and clicking “OK” in the “Format Paragraph” dialog box. Yuk. You have to go three dialogs deep just to change a paragraph style’s alignment. I’ll talk about how much easier this is in Word 2004 a bit later. We still have a bit more to understand about the based-on chain.

In order to save space, Word doesn’t store the entire set of all possible character and paragraph properties with a style definition. Word actually stores the differences between the style’s definition and the formatting of the style that it’s based on. In the case of styles that have no base style (like the “Normal” style), Word stores the differences between the style’s definition and what’s known as “standard” character and paragraph formatting. You can actually see this when you look at the description of the “Normal” style. Users can’t change the definitions of these standard property sets, nor would you want to. If you could, then your document’s eventual formatting would change depending on which version of Word you used to open the file.

Word goes through, essentially, a three step process to fetch the formatting for any run of text. It starts with standard character and paragraph formatting. Word then walks the based-on chain of paragraph styles, starting at the base of the chain and moving upward, applying the differences that are stored between each link in that chain. If the run of text also has a character style applied, then Word walks the based-on chain for that character style starting with “Default Paragraph Font” (which is the character style equivalent of the “Normal” paragraph style). Lastly, Word then adds any direct formatting that you’ve applied to the text independent of any style (i.e. when you just select some text and apply “Bold” to it).

It’s important to understand that style properties are applied as differences relative to the style below it in the based-on chain. To see why, try this in Word: select “Style…” from the Format menu, and click “Heading 1” in the list of style names. Note that the description says that the font is bold. Now, select “Normal” in the list of style names, click the “Modify…” button and change the font to bold (in Word X, select “Character…” from the “Format” dropdown, etc.). Click “OK” in the New/Modify Style dialog box to get back to the Style dialog box, select “Heading 1” in the list of style names. Note that the description now says that the font is “Not Bold.”

This may seem like somewhat strange behavior in that “Bold” becomes “Not Bold” without a direct change to the “Heading 1” style, but it makes sense if we think of styles as marking structure rather than formatting. For example, it’s rather common to use italics for emphasis, particularly within quotes. The problem, however, is that the formatting for emphasis depends on context. In a paragraph where the underlying formatting is already italics, emphasis is created by turning italics off. By storing style properties as differences (and applying them as differences), then a character style that signifies emphasis can do the Right Thing relative to the formatting of the underlying style of the paragraph. And, in fact, Word has a built-in character style named “Emphasis” that does exactly what I’ve described. Word also has a built-in character style, called “Strong” that does the same thing for bold.

While it’s important to understand that style properties are stored as differences, it’s also important to understand the order in which Word handles styles and direct formatting. The Emphasis character style will help to illustrate the point. When you apply direct formatting, Word actually goes through and toggles properties like bold or italics after having gone through and built up existing formatting as I’ve described above. However, the actual direct formatting is stored as absolute values after the differences have been determined. To see how this works, type a paragraph of text in a blank document. Select the paragraph, and apply italics using Cmd-I. Now select a few words within that paragraph, and apply the “Emphasis” character style. Note that the text remains italicized. Undo both the style and the italics. Now, reverse the order. Select a few words within the paragraph, apply the “Emphasis” character style, select the whole paragraph, and apply italics using Cmd-I. Note that the text that has the “Emphasis” style applied is now not italicized while the rest of the text is.

From all of this, we can come to a general rule for using styles. Type up your document using styles to mark structure (headings, emphasis, strength, etc.). Ignore formatting for now. Just concentrate on what you’re saying and think about formatting later. Once you’ve finished writing the content, then go through and change the formatting to suit the look you want. Change style definitions first, being mindful of the based-on chain, and apply any direct formatting last.

Some of you are wondering what you can do to save all of these style changes so that you can use them in other documents. That’s a discussion for another post on styles, templates and the “Organizer…” button. To get a head start, though, you can search for “copy styles” in Word’s online help.

Armed with an understanding of how styles work, we can now look at ways to define and modify styles. As we saw above, in order to change common properties, like font name, font size or paragraph alignment, in Word X and earlier, you have to drill down three dialogs deep, and you have to drill into two different dialog boxes in order to change both paragraph and character formatting. Well, that’s not entirely true. In Word X, it’s very easy to define a new style by example. Just create a paragraph, apply the formatting you want directly (including the style that you want your new style to be based on), and click “New…” in the Format/Style… dialog box. The new style will automatically have the current paragraph style as its base, and any direct formatting that you’ve applied will automatically be applied to the new style as differences from the base style.

In Word, you can also redefine a style by example, but it doesn’t always work. To do this, you first apply the style you want to modify, then you apply the changes you want to make directly to the paragraph. Having done that, if you re-apply the style, Word will notice that the paragraph already has that style, and will ask if you want to reapply the style or modify the style’s definition. As I said, however, this doesn’t always work. You can have Word automatically redefine styles as you make changes, but this feature should really be left to those who know what they’re doing.

In Word 2004, we made applying and modifying styles quite a bit easier, particularly for common style properties. The changes we made are based on the changes done for Word XP for Windows. The New/Modify Style dialog box now has a “Formatting” section that includes the same toolbar controls that you would use to change those properties directly. These include font name, size, bold, italics single underline for character properties, and the common alignment and spacing buttons for paragraph properties.

Where Win Word XP used their task pane to provide some direct access to styles and formatting, we did essentially the same thing by creating a new “Styles” pane on the Formatting Palette. For those of you familiar with Win Word XP, the controls, and their behavior, on the formatting palette in Word 2004 are almost identical to the controls, and their behavior, in the “Styles and Formatting” task pane of Win Word XP. This includes a “Current style of selected text” control that shows the style plus any direct formatting that’s been applied (as much as is possible in the space that’s available) and a button that will select all runs of text that have the same formatting as the current selection.

There’s also a “New…” button that takes you directly to the New/Modify Style dialog box without having to go through the Format/Style… dialog box. Lastly, there’s a list of available styles, and each item in the list is a drop-down menu that includes things you can do to, or with, that style. Another nice touch is that tooltips for individual items in the list of styles will show the complete style description as would be displayed in the Format/Style… dialog box. My only personal complaint is that the Style’s pane is always closed at startup, but that’s more my personal style. With all the panes that are on the formatting palette, it’s difficult to decide which ones should be open and which closed on startup. (We’ve already made the suggestion to remember pane states when quitting Word, but that work is largely in the hands of the Office Core development team and is dictated by their schedule and priorities, not Word’s.)

For my money, the new styles UI alone is worth the upgrade to the new version of Word, but I’m biased. You see, I did all of the work to implement the new styles UI.