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:

Subtle Emphasis
Intense Emphasis
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

9 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.

  4. Thanks so much for this set of instructions. However, I’m having some difficulties with getting Word to recognize the file once I retitle it a docx.
    1. For some reason, when I change the docx to zip, the “Archive Utility” program processes to a .zip.cpgz file (so, I use the “Unarchiver” app).
    2. Skipping all the actual xml editing, I immediately recompressed. I selected [Content_Types].xml plus three folders: customXml, docProps, and word (Note: there’s a fifth file present: _rels. I’ve tried selecting or not selecting, and neither way made a difference). I used the OS system “Compress 4 Items” feature to create a zip file.
    3. I change the suffix of the zip file back to docx.
    4. When attempting to open, MS Word notes that this is corrupt (“The file is corrupt and cannot be opened”).
    At first I went through and made changes to the styles.xml file and thought I may have messed things up. But when I went through just these steps (making no adjustments), I received the corrupt file notice. Any suggestions that you or your readers may have are very welcome. Thanks!

    • macOS users do have a couple of hassles when editing XML. One issue is with the GUI version of the Archive utility, which doesn’t seem to rezip files in a way that Office can parse. Another problem is with the operating system needing to create an invisible .DS_Store file in every folder that is displayed in the finder. My article about editing XML in macOS may help. Editing in a program that can read and write zip files, like newer versions of BBEdit, sidesteps both issues and should solve your problems.

      • Thanks again for the great help. I struggled to get the coding to work, even with the information on the “editing XML in macOS” article. However, that article pointed to the ability in BBedit to directly open docx files without unzipping/zipping. That process was simple, and I now have a fully customized Word doc. Thank you!

        On a related issue, the instructions above on reflowing Markup>Tidy are outdated. The most recent versions of BBedit do not support Tidy. The good news is that another wonderful person built a quick plugin that emulates that process very nicely: https://gist.github.com/ideabucket/5231db1261ed0f15bd59

Leave a Reply

*Required fields. Your email address will not be published.

Posting XML? To enter XML code, please replace all less than signs "<" with "&lt;" and greater than signs ">" with "&gt;". Otherwise, Wordpress will strip them out and you will see only a blank area where your code would have appeared.