Hack 54 Rename Built-in Styles


Word is often merely the input phase in a
production line that ends with a more formidable layout package, such
as Adobe InDesign or QuarkXPress. This hack shows you how to make
Word documents more palatable to other programs.
When Word is part of a
production
workflow, to work with it optimally would impose some restrictions on
other parts of the workflow. For example, your
company's designers probably prefer their own styles
to Word's. Those styles may have identical names to
Word's built-in styles, but chances are they
don't.
Many choose (or are forced) to create custom styles in Word that
correspond to those used by the layout software. But that means
missing out on some of the advantages of using
Word's built-in styles, such as being able to use
Outline view. The other (equally inconvenient) choice is to stick
with Word's styles and then perform a bunch of Find
and Replace operations on the files after you import them into the
layout software. Either option is a drag on your workflow.
Let's look at an example. Say you turn over some
Word files for layout to a design staff that uses InDesign.
They've got an extensive set of templates, and in
those templates the styles for the first four heading levels are
named HeadA, HeadB,
HeadC, and HeadD.
Typically, they import Word files directly into InDesign, then take
the time to replace Heading 1 with HeadA, Heading 2 with HeadB, and
so forth. Then they delete the imported Word heading styles from the
InDesign document. It would certainly be easier if you named your
heading styles the same as theirs, but again, that means losing out
on the benefits of using Word's built-in heading
styles.
While you can't change Word's
built-in style names, you can change anything you want about an RTF
file, which, after all, is just plain text. And whatever layout
program you use (Quark, InDesign, or FrameMaker) can definitely
import an RTF file.
The trick is to save the files as RTF, then modify
Word's style names to match those of the layout
software. Then, when you open the documents in the other program, the
text will assume the formatting defined by the styles with those
names in that program.
|
Continuing with the example above, to change the Heading 1 style to
HeadA, the Heading 2 style to HeadB, and so on,
you'll first need to get your file into RTF format
by selecting File
"Rich Text Format" from the
"Save as type" field. Next, open
the file in a standard text editor such as Notepad.
RTF stores information about each of the styles in a document in a
place called the style table. Everything about a
style is listed there, from its name to its indent amount. Each style
is also assigned a number, such as \s2. Whenever
text in the document uses a style, the number notes which style
should be applied. That means you only need to change the
style's name in the style table; everywhere else in
the document, the style is referenced by number, not by name. A
sample style table entry for the Heading 1 style in a Word document
is shown in Figure 6-7.
Figure 6-7. The Heading 1 style defined in an RTF file

If you change "Heading 1" in the
RTF file to "HeadA," when you open
the file in InDesign, any text that used the Heading 1 style in Word
will be formatted with the HeadA style defined in InDesign.
6.5.1 Hacking the Hack
While editing RTF files by hand can be quite educational,
it's also a bit tedious. It's
better to relegate the dirty work to a script, such as the following
Perl script, which changes Word's built-in Heading
1, Heading 2, Heading 3, and Heading 4 styles to HeadA, HeadB, HeadC,
and HeadD in an RTF file.
![]() | This section assumes that your have Perl installed on your system and that you can run Perl scripts from the DOS command line. To download a free version of Perl for Windows, go to the ActiveState web site at http://www.cpan.org. Save this script in the same folder as the file you're modifying and name it changestyles.pl. #!/usr/bin/perl On Windows, you'd run the script from a DOS prompt: > perl changestyles.pl MyFile.rtf
|