Text Styles in Text Variables
Text variables strip styling (italic, bold) and automatic paragraph numbering. This page describes a workaround.
This script is part of the Book and Long Document Composition/Production collection. See the full collection here.
This script is part of the Type and Text collection. See the full collection here.
The problem
Text used in text variables loses all its formatting: styling, paragraph numbers, and who knows what else. The problem is illustrated in the following screenshot:

The heading title referenced in the running header contains two styled ranges (bold and italic) and has an automatic paragraph number. Both the styling and the number are stripped from the heading’s title in the text variable in the running header. The fix is not entirely straightforward.
A solution
Recently (January 2024) some forum posts and a private email raised these problems. The person who wrote the email reminded me of a blog post I had written in 2018 for Typefi. That post didn’t deal with InDesign’s text variables though the problem was similar. In the blog post I outlined a workaround which can, with some modifications, be used for InDesign’s text variables. A script can be used to expose all styles and numbering in running headers populated by text variables.
The solution makes changes to the document. To expose a paragraph number in the running headers, the script inserts the number as literal text in the paragraph and hides it using a character style (for details, see How it works, below). If there are no headings with text styling, that’s all that’s needed. So the only change in the document is the insertion of the paragraph numbers in the headings.
Exposing text styling is more involved. In order to apply styles in text variables, those variables must be converted to text, and to do that, the running-header text frames need to be overridden on to the document pages.
You should therefore run the script only when you’re ready to print and/or export the document. So save the document, run the script, export and or print, and discard the changed document. Anyway, to be on the safe side the script saves the document under a new name (it adds -rh to the document’s name.)
The script
Before you run the script you need to label, on the parent page(s), the text frames used for the running headers. Open your document and go to a parent page that contains a running-header frame. Select the frame and open the Layers panel.

To label a frame, do a slow double-click on its entry in the panel and type the label’s name: Running header (exact spelling). Do this with all running-header frames.
Secondly, save your document before you run the script. This is absolutely necessary (we’ll explain below).
For an initial test so that you can see what’s happening, you can use the attached document (it’s an IDML file, you can open it in any InDesign version). In this document the text frame for the running headers is already labelled on the parent page.
Open the document and run the script. When it’s done, the result looks as follows:

As mentioned earier, the fixed document is saved under a different name.
If you’re not interested in how all this works you can skip the rest of this page.
How it works
The script looks for paragraph styles that are section headings (it finds them in the Text Variables window). Then it looks for instances of those paragraph styles in the text.
If a heading is numbered automatically, the script inserts the number as literal text and applies the character style hide to it so you can’t see it. (The style is created on the fly, it sets the type size to 0.1 points, the horizontal scale to 1 per cent, and applies superscript.)
If the heading contains styling applied by any character styles, the script inserts text labels such as <it> and </it> in the heading. The labels are formed from the first two characters of a style’s name.
Those labels then appear in the text variable (made visible here for exposition, you won’t normally see them):

After marking up the document’s headings, the script adds GREP styles to the heading paragraph styles and the paragraph styles used for the running headers. These GREP styles apply formatting in the running headers and hide the text labels. The GREP styles are created on the fly by the script.
If any headings contain text styles, the script overrides the running headers on to the document pages and converts the text variables to text so that the GREP styles can be applied.
Peter Kahrel Script Repository
Hosted as a community service, and with deep appreciation, by CreativePro.com
Scripts by Topic | Script Index
Basic Script Installation and Use
How to Modify or Configure These Scripts
Resources for Scripting and Publishing Automation
About This Repository
Contact Peter Kahrel
Note to users: You run scripts at your own risk: CreativePro and the author accept no liability for anything that may be caused by any of these scripts. Always take the necessary precautions. We encourage you to save backups and test scripts on copies of your documents.
This article was last modified on August 22, 2026
This article was first published on November 3, 2025
Commenting is easier and faster when you're logged in!
Recommended for you
GREP Style Report
Print a report of all GREP styles defined in a document's paragraph styles (CS4...
InDesign Magazine Issue 97: Find/Change
We’re happy to announce that InDesign Magazine Issue 97 (May 2017) is now availa...
This Week in InDesign Articles, Number 23
It's a deluge of articles and videos and good InDesign stuff to dive into!
