XML Hacking: Managing Styles

Are you managing styles in your Word documents? A hallmark of a professionally-created template is the appearance of the Quick Style Gallery. If I open a template and see this:

Not Managing Styles

I realize the person who constructed the file doesn’t know better or doesn’t care. The clue are the 4 zombie styles on the right side. If you expand the gallery, you’ll see 8 more zombie styles. These 12 are automatically generated in every new installation of Word. Nobody uses them, they just clutter the interface. If you’re managing styles, you’ll make them disappear.

These 12 can’t be deleted, they are termed built-in styles and the Delete button is disabled in the style management dialog. But in Word for Windows, there is a Style Management panel called Recommended, where you can Hide them or optionally apply Hide Until Used. This last attribute keeps the style out of the Quick Style Gallery until the first time you apply it in a document, at which time it becomes visible.

But where is the Recommended panel in Word for Mac? Did someone Hide that too? No, it’s just not an option for Mac users. Microsoft left it out (speculate at will). But all is not lost: You can still manage style visibility on the Mac, you just have to do it with XML Hacking.

Begin by creating your template and creating the styles needed for that document. When you’re ready, we’re going to unzip the Word file, modify the XML, then re-zip the files. On a Mac, you have to take some extra steps to ensure that Mac attributes are not added to the files and folders by the Finder. Please take a moment to read my previous post about Editing XML in OS X

When you first open an Office XML field, the content is linearized and difficult to read. In BBEdit, apply Markup>Tidy>Reflow Document, leave the options at their defaults and click on the Reflow button. Voila! Readable XML!

Managing Styles with XML Editing

The style order in the XML file has nothing to do with the order of styles in the user interface, so it’s best to search for them. Start with the Title style. The default listing looks like this: (You may see a somewhat different collection of tags from different Word versions.)

<w:lsdException w:name="Title" w:semiHidden="0" w:uiPriority="10" w:unhideWhenUsed="0" w:qFormat="1"/>
Managing Styles: the master Styles List

The Styles list: a good place to display occasionally-required typestyles.

To make this style disappear from the Quick Style Gallery, but still appear on the Styles list, just delete the w:qFormat="1" tag. If you want to remove a style not only from the Quick Style Gallery, but also from the master list of recommended styles, then don’t bother with w:qFormat="1", just remove w:semiHidden="0". Finally, to give the style the ability to remain on the Styles list, then be added to the Quick Style Gallery when it is first used, leave the other tags as is and change w:unhideWhenUsed="0" to w:unhideWhenUsed="1".

Besides the Title style, the other zombie styles you’ll probably want to remove are:

Subtitle
Subtle Emphasis
Emphasis
Intense Emphasis
Strong
Quote
Intense Quote
Subtle Reference
Intense Reference
Book Title and
List Paragraph

Another useful edit you can make to styles is to change the number beside w:uiPriority. Decreasing this number moves a style up the list, while increasing it moves it down. For all styles that have the same level number, they are displayed in alphabetical order. I usually rank them in the order they are likely to be used, with the body text and headings at the top, followed by bulleted, numbered and lettered styles. Often you’ll have styles that serve a function in a Word file, like unique styles that are referenced by StyleRef fields. If the user doesn’t need to apply a style, hide it. The simpler you make their interface, the fewer mistakes they can make.

Save the XML file, then in the finder select [Content_Types].xml plus the folders. Right-click and choose Compress 4 Items. Change the ending of the resulting Zip file to .docx and click on the Use .docx button when OS X asks. Open the file and check out the beautifully clean Quick Style Gallery, thanks to you managing styles!

1:44 am

6 thoughts on “XML Hacking: Managing Styles

  1. Does this work with Word 2016 Mac?

    I have followed the instructions precisely. And checked that the edits were saved.

    But when I open the doc in Word nothing that changed. very strange.

    • Yes, styles work the same in all XML versions of Office. Use of some of the parameters is not very intuitive. I covered a few different things you could do, like hiding styles or changing their order. What is it that you’re trying to change about them? If you want, you can email me (production at brandwares dot com) the before and after versions, and I’ll take a look at them. This helps me refine my article to make it more useful.

  2. I used your “w:uiPriority” tip and at first I didn’t quite work. My styles have a leading number code to put them in order, but they wouldn’t jump to the top when I assigned them to “1”. I noticed that many styles didn’t have a priority setting at all, so I just removed them entirely and voila! They’re now in numerical order. Thanks!

  3. Thank you for the article. I think I will link to it in http://addbalance/usersguide/styles.htm

    I use Strong and Emphasis on a regular basis and have even switched the keyboard shortcuts for Bold and Italic to use them. I also use (less frequently but at least once a week Title and Subtitle. I seldom deliberately use Normal. I generally manage my styles using the Manage Styles dialogs.

    • Hi Charles, Thanks for your comments. The Word for Windows user interface is a much easier way to manage styles. This article is primarily for Mac users, who don’t have that same facility. The user interface doesn’t allow reordering styles, so a hack is necessary.

Leave a Reply

*Required fields. Your email address will not be published.
To enter XML code, please replace greater than > and less than < signs with &gt; and &lt; or Wordpress will strip them out.