Text Variables in Adobe InDesign CS3
Text Variables
Believe it or not, we’ve met a number of graphic designers who are scared of the word “variable.” It’s not that frightening—a variable is simply something that can change. Text variables in InDesign provide a way for you to insert text that can change depending on various factors, such as times, dates, and page references. In a way, the automatic page number special character is a sort of text variable, because it changes depending on the page on which it appears. You’re not scared of the automatic page number marker, are you?
It’s important to understand the difference between text variables and text variable instances. A text variable is the definition of the variable itself; a text variable instance is the marker in the text that inserts the content of the text variable. It’s entirely possible to have a text variable in a document for which no text variable instance exists in the layout (though there’s really no reason to).
Text variables come in a variety of flavors, and are subject to a variety of limitations. First, let’s take a look at the text variable types InDesign supports.
-
Chapter Number. A text variable that refers to the number of the current chapter (chapter numbering is defined by the book containing the document—for more on books, see Chapter X, “Long Documents”).
-
Creation Date. A text variable that refers to the date and time you created the document (not when you made the variable).
-
Custom Text. A string of any text you can type.
-
File Name. The name of the document.
-
Last Page Number. The number of the last page in the file.
-
Modification Date. The date and time of the last modification made to the document.
-
Output Date. The date and time the document was printed.
-
Running Header (Character Style). Refers to the first or last instance of text on the page containing the text variable instance that has been formatted using a specified character style.
-
Running Header (Paragraph Style). Refers to the first or last paragraph on the page containing the text variable instance that has been formatted using a specified paragraph style.
Text variables provide a number of features InDesign users have long wanted, such as the ability to add running headers and footers that are based on the first or last instance of a given paragraph style on a page. If you work on books, as we do, you’re probably curious about using text variables for cross references—this is where the “limitations” we mentioned earlier come in. You can’t refer to an arbitrary string of text using text references, which means that you can’t use them for cross references to your figure numbers, or to other sections of a book.
Worse, in some ways, is that text variables are considered as a single character for purposes of text composition. This means that InDesign will not enter a line break inside a text variable instance. This was already true for the composition of section markers and automatic page numbers, but it can be even more of a problem with text variables because they usually contain a longer run of text (see Figure 3-35).
Don’t get us wrong—text variables are a great thing. But we point out the problems because we think it’s important that you understand how they work. Before you’re on a deadline.
Showing Text Variable Instances
When you want to see when text is a text variable instance, choose Show Hidden Characters from the Type menu. InDesign will display a (very pale!) box around each text variable instance in the text (see Figure 3-36).
Text Variable Options
Each type of variable has its own options. For example, most of the text variable types give you the option of adding text before and/or after each text variable instance, but almost all of them provide other options, as shown in Table 3-3.
Text Variables
Variable Type |
Option |
Definition |
---|---|---|
All Formats (except Custom Text) |
Text Before |
Text to enter before the text variable. |
Text After |
Text to enter after the text variable. |
|
Chapter Number |
Numbering Style |
Choose Arabic (1, 2, 3), lowercase Roman (i, ii, iii), uppercase Roman (I, II, III), lowercase letters (a, b, c), or uppercase letters (A, B, C). |
Custom Text |
Text |
Enter the text you want to have appear in the text variable instances. |
File Name |
Include Entire Folder Path |
Set this option to true to include the full path to the document file. |
Include File Extension |
Set this option to true to include the file extension of the document file. |
|
Last Page Number |
Numbering Style |
Choose Arabic (1, 2, 3), lowercase Roman (i, ii, iii), uppercase Roman (I, II, III), lowercase letters (a, b, c), or uppercase letters (A, B, C). |
Scope |
Choose Section to specify the last page in the section; choose Document for the number of the last page in the document. |
|
Creation Date, Output Date, Modification Date |
Date Format |
Enter a date format by selecting items from the pop-up menu. You can enter spaces or punctuation between the time/date placeholders. See Table 3-4 for a list of the placeholders (you can simply type them, rather than having to choose them from the menu). |
Running Header (Character Style), Running Header (Paragraph Style) |
Style |
The character or paragraph style to use. |
Use |
Choose Last on Page to use the last instance of the style on the page, choose First on Page to use the first instance. |
|
Delete End Punctuation |
Remove the punctuation at the end of the text, if any. |
|
Change Case |
Choose a case option for the text that will appear in the text variable instances. You can choose uppercase, lowercase, sentence case, or title case. |
Inserting a Text Variable
Before we get into the details of how to create your own variables, let’s look at how you can insert a variable at the current cursor location. Assuming that you have an active text insertion point in a text frame or story, choose the name of the text variable from the Insert Variable submenu of the Context menu (see Figure 3-37) or from the Insert Variable submenu of the Text Variables submenu of the Type menu. InDesign adds the text variable instance.
Creating a Text Variable
The preset text variables are all well and good, but the real fun lies in defining your own. Maybe you just want a more formal time and date format, or maybe you want to enter a custom text variable—either way, it’s easy, and the range of possible text variables is vast (even within the limitations we mentioned earlier).
Date Format Shortcuts
Category |
Type |
Placeholder |
Example |
---|---|---|---|
Time |
Hour (1-12) |
h |
1 |
Hour (01-12) |
hh |
01 |
|
Hour (1-23) |
H |
1 |
|
Hour (01-23) |
HH |
01 |
|
Minute |
m |
1 |
|
Minute (00) |
mm |
01 |
|
Second |
s |
1 |
|
Second (00) |
ss |
01 |
|
AM/PM |
a [*] |
AM |
|
Time Zone |
zzzz |
Pacific Daylight Time [**] |
|
Time Zone (Short) |
z |
PDT |
|
Day |
Number |
d |
1 |
Number (01) |
dd |
01 |
|
Name |
EEEE |
Tuesday |
|
Name (Short) |
E |
Tue |
|
Month |
Number |
M |
4 |
Number (01) |
MM |
04 |
|
Name |
MMMM |
April |
|
Name (Short) |
MMM |
Apr |
|
Year |
Number |
yyyy |
2007 |
Number (Short) |
y |
07 |
|
Era |
G [***] |
AD |
|
Era (Long) |
GGGG |
Anno Domini |
To create a text variable, follow these steps (see Figure 3-38).
- Choose Define from the Text Variables submenu of the Type menu. InDesign displays the Text Variables dialog box.
- Click the New button. InDesign displays the New Text Variable dialog box. If you had a variable selected when you clicked the New button, the dialog box will be filled in with the default properties of that variable (as though you duplicated it).
- Enter a name for the text variable in the Name field.
- Select a text variable type from the Type pop-up menu. When you do this, the dialog fills in with the options for that variable type.
- Make changes to the options shown in the dialog box to define your new text variable. When the settings look the way you want them to, click the OK button to close the dialog box and return to the Text Variables dialog box.
- Click the Done button to close the Text Variables dialog box.
Text variables are stored within the current file. If you want to create a text variable that is available in all new documents, define it when no documents are open. When you do this, the variable will appear in each new document you open.
Editing a Text Variable
You can change the definition of a text variable at any time. When you edit a text variable, all of the text variable instances of that variable will update to reflect the changes you’ve made. If your variable instances are inside paragraphs, be prepared for text to reflow and line endings of composed text to change when you edit a variable.
To change the definition of a text variable, follow these steps.
- Choose Define from the Text Variables submenu of the Type menu. InDesign displays the Text Variables dialog box.
- Select a text variable and click the Edit button. InDesign opens the Edit Text Variable dialog box.
- Make changes in the Edit Text Variable dialog box. When the settings look the way you want them to, click the OK button to close the dialog box and return to the Text Variables dialog box.
- Click the Done button to close the Text Variables dialog box.
At this juncture, we are obligated to point out that you can modify any of the built-in text variable instances. You could, for example, change the Chapter Number instance to enter the creation date, as Ole accidentally did when he first tried to create a new text variable. We urge you not to do this.
Loading Text Variables
To load text variables from another document, follow these steps (see Figure 3-39).
- Choose Define from the Text Variables submenu of the Type menu. InDesign displays the Text Variables dialog box.
- Click the Load button in the Text Variables dialog box. InDesign displays the Open A File dialog box.
- Locate and select an InDesign document, then click the Open button. InDesign imports the text variables from the selected document into the current document.
- InDesign will display the Load Text Variables dialog box, which shows a list of the incoming text variables. If the document you’ve selected contains text variables with the same name as text variables in the current document, you can choose whether to override the definitions of the existing text variables or to leave then unchanged (by renaming the incoming variable). Click the OK button once you’ve finished, and InDesign will import the text variables from the selected document.
As usual, if the definition of any text variable used in your text has changed, check for text reflow.
Deleting a Text Variable
To delete a text variable, follow these steps (see Figure 3-40). Note that you can use this process to merge two text variables.
- Choose Define from the Text Variables submenu of the Type menu. InDesign displays the Text Variables dialog box.
- Select the text variable you want to delete and click the Delete button. If the variable has been used in the document, InDesign displays the Delete Text Variables dialog box.
- If you want to replace the text variable with another text variable, select the replacement variable from the Existing Variable pop-up menu. To convert all instances of the text variable to text, select the Text option. To delete all of the text variable instances linked to the selected text variable, select the Nothing option.
- Click OK to close the dialog box. InDesign applies the changes you’ve specified.
You can delete an individual text variable instance as you would delete any other text: Select it and press Delete.
Converting Text Variable Instances to Text
You can, at any time, convert text variable instances to normal text, in effect “freezing” them in their current state. Of course, if the variable instance is inside a paragraph, this will often cause text to reflow, as InDesign is now free to apply its normal text composition rules to the text of the variable. You can choose to convert individual text variable instances to text, or you can convert all of the text variable instances associated with a text variable to text.
To convert an individual text variable instance to text, follow these steps (see Figure 3-41).
- Select the text variable instance with the Type tool.
- Choose Convert Variable to Text from the Context menu (or from the Text Variables submenu of the Type menu). InDesign converts the text variable instance to normal text.
To convert all instances of a text variable to text, follow these steps. Note that this does not delete the text variable itself.
- Choose Define from the Text Variables submenu of the Type menu. InDesign displays the Text Variables dialog box.
- Select a text variable and click the Convert to Text button. InDesign converts all instances of the text variable to normal text.
- Click OK to close the Text Variables dialog box.
Again, we have to point out that this may cause text recomposition and reflow. Make certain that the line breaks in the document are where they should be after converting the text variable.
You can also use find and change to work with text variable instances—see the section on finding and changing text, later in this chapter, for more information.
Text Variable Examples
In the following sections, we’ll present a series of “recipes” that show you how to use text variables for a variety of common page layout tasks.
Creating a Time and Date Stamp
We often like to enter the date and time a file was printed, but we can’t always use the built-in time and date stamp from the Print dialog (because the page size is the same as the printer paper size). In the past, Ole has created custom printer’s marks files that move the page information up onto the page, but text variables have rendered that bit of esoteric knowledge obsolete. Note, however, that if you plan to omit the time and date stamp from your final printed version, you’ll need to make arrangements to suppress the printing of the text variables (such as moving them to a non-printing layer).
To create a text variable that will print the time and date a file was printed, follow these steps.
- Choose Define from the Text Variables submenu of the Type menu. InDesign displays the Text Variables dialog box.
- Click the New button.
- Enter a name for the variable and choose Output Date from the Type pop-up menu.
- Enter the placeholders and any punctuation or spacing for the date format in the Date Format Field. We use “EEEE, d MMMM, yyyy h:mm a zzzz”—not only does it print the date and time in a civilized format, but it’s fun to say aloud.
- Click OK to close the dialog box, then click Done to close the Text Variables dialog box.
Simple Custom Text
Many people, on first hearing about custom text variables, immediately think that they’d be a good way to enter commonly-used text. Don’t do that. There are many other, better ways to accomplish the same end (for example, you can trick autocorrect into entering text for you, as shown in the section on the autocorrect feature, later in this chapter).
Instead, think of custom text variables as a way to enter short pieces of text which might change before your layout is finished. To do this, follow these steps (see Figure 3-42).
- Choose Define from the Text Variables submenu of the Type menu. InDesign displays the Text Variables dialog box.
- Click the New button.
- Enter a name for the variable and choose Custom Text from the Type pop-up menu.
- Enter the text you want to have appear when you insert the text variable.
- Click OK to close the dialog box, then click Done to close the Text Variables dialog box.
Page X of Y
Ever wonder why so many financial and legal documents use a page numbering scheme that tells you how many pages there are in the document? For some documents, the simple knowledge that there is an end is required to maintain one’s sanity.
If, for whatever reason, you need to extend this sort of reassurance to the reader, it’s easy to do using text variables. There’s nothing to it, really—just enter an automatic page number special character, the text “to,” and insert the predefined Last Page Number text variable (see Figure 3-43).
Why didn’t we enter the “to” as part of the text variable? It’s because we’re following a general rule of keeping text inserted by text variables to a minimum to avoid potential composition problems. No, you can’t specify the last page of a multi-document book.
Running Headers
Many documents feature a layout in which the text of key paragraphs—usually, headings of a given level—appears in the header or footer of each page. Note that this text could also appear in a footer, in a tab on the side of the page, or, really, anywhere on the page. There’s nothing special about the text variable type that limits its use to text frames at the top of the page. That said, InDesign refers to this text variable type as a “header,” so we will, too.
To do this, you create a text variable, then insert that text variable in text on the page or on a master page. Follow these steps (see Figure 3-44).
- Choose Define from the Text Variables submenu of the Type menu. InDesign displays the Text Variables dialog box.
- Click the New button.
- Enter a name for the variable and choose Running Header (Paragraph Style) or Running Header (Character Style) from the Type pop-up menu.
- Select the style you want to use from the Style pop-up menu.
- Choose Last on Page or First on Page from the Use pop-up menu.
- Set up the controls in the Options section of the dialog box as necessary. For example, you’ll almost always want to turn on the Delete End Punctuation option.
- Click OK to close the dialog box, then click Done to close the Text Variables dialog box.
- Insert the text variable in text using the Insert Variable submenu of the Context menu.
In some layouts, you might need to create a pair of text variables. In a dictionary-style layout, for example, the left hand page header usually contains the first instance of text in a given style on the page, while the right hand page contains the last instance of the style (see Figure 3-45). If the right hand page is the first page in a section, however, it typically uses the first instance of the specified style (not the last, as would normally be the case for a right hand page). You can change the header of the page manually, or you can create a special master page to accomplish the same task.
When a page does not contain text formatted with the specified style, the variable in the header repeats the text from the previous instance of the same text variable. However, InDesign will not carry over the last instance of a given style when another instance of the same style appears on the page (see Figure 3-46). If this is the style of running heading your document calls for, you may have to adjust some pages manually.
Phone book Style Running Header
Another use for a running header is to show the range of a certain type of paragraph style on a given page. In a telephone directory or dictionary, for example, the page headers will show you the alphabetical range of names or topics shown on the page. Ole, for example, proudly shares a phone book page containing family names from “Kustyukov” to “Kwok”.
To set up this type of running header, you’ll need to create two text variables: one for the first instance of a given paragraph or character style on a page, another for the last instance of the same style. Then you create a page header that contains instances of both text variables, as shown in Figure 3-47.