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.
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.)
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.
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.
31 Jan. 2024: The script now creates all necessary styles on the fly. And the handling of paragraph numbers was simplified after some discussion on Adobe's InDesign user forum.
28 Jan. 2024: Posted.
Consider making a donation. To make a donation, please press the button below. This is Paypal's payment system; you don't need a Paypal account to use it: you can use several types/brands of credit and debit card.
Installing and running scripts
Back to the main page on indexing
Questions, comments? Get in touch