Members Only

Harnessing the Power of Text Variables and IDML

Learn how Jeff Potter built a system for harnessing the power of text variables and IDML to save time and reduce errors in newspaper production.

InDesign Magazine issue 138 coverThis article appeared in Issue 139 of InDesign Magazine.

Let InDesign do more of the work for you by harnessing the power of Text Variables—and IDML!

Story time: In 1986, when I was in college, I worked at a weekly newspaper. One week, my boss found that her cataract surgery had been scheduled for production day, and I was suddenly entrusted with laying out the entire newspaper for the very first time in my professional career. I worked hard to make those pages shine. Unfortunately, my beautiful manual paste-up job was compromised by the fact that I inadvertently left the previous week’s folio lines on the pages, meaning that the paper had the wrong date!

Fast forward to 2020. Even with today’s technology, you know how easy it still is to make a stupid mistake like this. If you’re working with InDesign on a newspaper or other project with data that changes consistently, the good news is that you can take some steps—in varying degrees of geek-cred magnitude—to get that information into your files quickly, consistently, and correctly.

Those steps involve text variables, which have a number of practical uses. But are they for you? Here are some examples of when text variables may be helpful:

  • Packaging design: You must print a specific number both on the product label and on the carton.
  • Book design: You constantly need to use the International Standard Book Number (ISBN) and title not only in the book’s production but also for related marketing materials.
  • Legal design: You work on multiple documents for the state legislature and must reference precise bill numbers and official names quickly and accurately.

What if you

had one resource available to you—and to other coworkers—with info that could be pulled into any number of working InDesign templates?

Enter Text Variables

InDesign’s Text Variables feature lets you define a chunk of text that you can change by assigning it a name and a value via the  Edit Text Variable panel (Type > Text Variables > Define, Figure 1). Once it’s defined, you can place this data anywhere in your InDesign layout by positioning your cursor in a text frame and selecting the variable with Type > Text Variables > Insert Variable.

Figure 1. You can insert text variables into any text throughout your document—on master pages or anywhere in the flow of text. For example, I used this NEWSPAPER DATE variable on almost every one of the 31 master pages in the newspaper’s template. You can change the date all at once by editing the value of the variable or by loading a new value from a different InDesign or IDML file.

The goal of using text variables is to ensure consistency and eliminate ambiguity throughout your document. By redefining the value of the text variable, you can change every instance of that text at once. If you use a text variable for your publication folio lines, for example, you can use that single variable on as many master pages as you want. Redefine the text of that variable once, and you’re good to go, knowing that the text has changed everywhere in your document.

Even better, if you use the Book feature for your publication, as I do, you can easily select a source document and synchronize text variables through the rest of the files in the book.

For several years, I would create a fresh edition of the newspaper each week from my template file, and I would then go in and manually redefine the values of the text variables. That in itself was a huge improvement on manually updating the issue dates on multiple master pages, as we all had to do prior to InDesign CS3.

But I was always worried about introducing errors when typing data under deadline stress—or outright forgetting to do so (the ghost of 1986 still haunts me).

Was there a better way?

The Problem with Text Variables

InDesign’s Text Variables feature is awesome, but it does have one serious weakness: line breaks. Specifically, text variables cannot break from one line to another. If you put one in a column or text frame that is too narrow, the variable will squish down to fit—even to the point of being unreadable! Adobe has talked about finding a solution in the future that would allow text variables to break from one line to the next, but until they figure it out, keep your variables short or convert the variable to text once the data is in your InDesign file.

Can This Document Be Made?

As part of my obsessive desire to automate as much of my newspaper production as possible, I had a eureka moment. I realized that the data I needed to update the text variables for each issue was stored in our web database. And, like styles, PDF presets, workspaces, and so many other settings, text variables can be loaded from other documents (Figure 2). Next I wondered if I could automatically generate a document from which we could load the correct text variables for a particular week’s newspaper.

Figure 2. You can load new values of text variables from other files.

Types of Text Variables

You can define 10 types of InDesign text variables: Chapter Number, Creation Date, Custom Text, File Name, Last Page Number, Metadata Caption, Modification Date, Output Date, Running Header (Paragraph Style), or Running Header (Character Style).

Text variables defined as Custom Text let you define any text and insert it anywhere in your document.

Most of the other variables types enable you to reference metadata about your document and are helpful for outputting proofs. The running headers are great for book design, letting InDesign pull data from text on the page to reference in folio lines.

All of these flavors of text variables have their own options to configure, giving you ample flexibility in your template, document, or workflow. Play with them, and, most importantly, think of new ways you can let InDesign do more work for you!

IDML to the rescue

You can’t build a native InDesign file yourself without a copy of InDesign, but InDesign does offer a clever back door: InDesign Markup Language (IDML) files. Most InDesigners are familiar with IDML only as the file format that permits you to save for backward compatibility or for scrubbing a native InDesign file of fragile instabilities. That is how Adobe describes IDML within the program itself. But this file format offers a whole lot more.

Let’s geek out for a moment. An IDML file is, technologically speaking, an InDesign document expressed as valid XML, which means that every single aspect of your file exported in this way is represented in plain old text. Unlike a standard INDD file, which is a proprietary database format that InDesign itself can use (but you as a user can’t successfully modify), IDML is an open format, specifically designed so that other applications and technologies can create and modify InDesign-compatible files.

As it turns out, an IDML “file” is nothing of the sort. It’s really a ZIP archive full of other folders and XML documents in disguise (Figure 3).

Figure 3. An IDML file is actually a ZIP archive of XML files and folders.

So back to my challenge: You’ll recall that my goal was to create an InDesign file with the text variables already defined. If we could just find a way to put text variables and IDML together…

From database to text variables

Over the years, I’ve become reasonably adept at PHP, a popular and flexible web development language that powers a huge proportion of the web, including WordPress and Facebook. PHP is itself open-source software, and a worldwide community of developers has freely shared a huge body of code over many years.

For my newspaper workflow, I was able to write a PHP script that would automatically build an IDML version of a template with the text variables defined with dummy values (Figure 4). Note: When I use the term script here, I’m talking about a web application that is accessed as a website in a browser, not the ExtendScript, AppleScript, or Visual BASIC script that might run in InDesign’s Scripts panel.

Figure 4. This snippet of code opens one of the sub-documents in the IDML file, replaces the dummy values with real data, and then saves the file on my server with the rest of the InDesign files for that week’s paper.

Here’s how it works: In my web browser I can enter in the URL of the script, which includes the sequential issue number of the newspaper. When that web address is accessed, the script looks up all the data associated with that issue in the database.

It then opens one of the XML documents inside a “template” IDML file, searches for the dummy values of those text variables, and replaces them with the date of the issue, the volume and issue numbers, the distribution, and the deadline for the next week’s paper (Figure 5). It then saves the IDML file anew, with all those variables set for me.

Figure 5. The same generated IDML file is also the source of the data loaded into the InDesign template for the newspaper’s masthead and reader services information. I then place that INDD into the main newspaper document.

Because I was running this PHP script on a local fileserver hosting all the rest of the files for the newspaper (a humble Mac Mini), I programmed the script to save the file where it belongs: in the folder with the rest of the files for that week’s paper. Boom!

If you have a fileserver and a local area network, you don’t need deep programming skills to adapt this code to run on a similar setup. If you aren’t a programmer yourself, you could hire a web developer to help you set up this code to churn out these files and save them somewhere where you can find them quickly. In the spirit of open source software, I’ve made this script available so you can test it, download the code from GitHub, and modify it to meet your own unique workflow needs (see “Try It Yourself”).

The InDesign Part of the Workflow

Now, each week, I can automatically generate an IDML file, and then set up the paper by creating an InDesign book with fresh files and importing this automatically generated IDML file into my A section template. Then I sync the values across the other documents (Figures 6 and 7).

Figure 6. When using the Book feature, you can change your text variables in your source document (indicated with the icon to the left of the file name in the Book panel) and use Synchronize Options in the panel menu.

Figure 7. Synchronize Options lets you use text variables from your source document consistently through the rest of the book.

I also have a second InDesign file for the newspaper’s masthead and reader information, which includes text variables for the date of the next issue and the deadline for news and advertising. That information can easily be calculated from the same data and put into the same IDML file (Figure 8).

Figure 8. My script uses an IDML file with dummy values of text variables like this one. It replaces them with real values from a database query.

Recently, I generated a form that I can use for planning the editorial content of a particular issue and keeping track of random hard-copy flotsam pertaining to that particular week’s newspaper. How do I actually insert all this stuff into my layout files? You guessed it: I load the variables from the IDML file (Figure 9).

Figure 9. The same generated IDML file with the issue’s text variables can customize a form for editorial planning.

There is one minor stumbling block that I should point out: When you load the text variables, you will probably find the IDML file grayed out. By default, only INDD files show up as eligible for importing. But all you need to do is change the window’s Enable field from All Readable Documents to All Documents. IDML files are, in fact, “readable,” even if InDesign tells you otherwise (Figure 10).

Figure 10. You can load text variables from an IDML file—even if InDesign implies otherwise!

Other Cool Ways Text Variables Can Help You

If you’re putting together newspapers, magazines, or similar projects, you can find other ways of using text variables to keep your data consistent throughout your publication.

Keep jump lines accurate

You know those jump lines you need to add at the bottom of some columns—the See Blah Blah, page 000 lines to direct your readers inside your publication, and the Blah Blah, from page 000 headline with the rest of the text thread? That’s what I’m talking about.

Considering these design elements—the jump line and the jump head, respectively—are intended to help your reader navigate through your publication. The Blah Blah text needs to match. So do the page numbers. It’s dangerously easy to screw these up, especially if text, ads, and pages shuffle around on deadline.

You can use text variables and special InDesign character markers to make the software do the work of solving these two problems. (That is why you’re using a computer, right?)

  1. In the jump frame, add text as a placeholder. I use the eminently boring phrase TEXTVARIABLE.
  2. For the page number, choose Type > Insert Special Character > Markers > Next Page Number. InDesign will insert the page number for the page on which you’re working (Figure 11).
  3. Save the text frame in a library (CC or traditional) so you can place it at any time into your section cover layout.

Figure 11. When your text frame includes a Next Page Number special character, it will automatically display the page number on which the text thread continues.

Next, you will want library items for your jump lines. I have a range of them for all the variants of my template. But all of them have similar placeholder text.

In making this item, you can type from page as your placeholder text, and then choose Type > Insert Special Character > Markers > Previous Page Number to insert that special character.

Now, when you want to jump your story:

  1. Drag the jump line from your library into your layout. Superimpose the frame onto the last line of the text. The page number will show up as the page on which the text continues!
  2. Choose Type > Text Variables > Define to define a new text variable for that story; select Custom Text (see “Types of Text Variables”). Tip: Start the variable’s name with an underscore so it will show up at the top of the list in the dialog box.
  3. Choose Type > Text Variables > Insert Variable, and select the variable you defined in the previous step.
  4. Go to the page on which the story continues. Hint: If you’ve forgotten where you placed it, look at the jump line!
  5. Drag your jump line item from the library to the page. Make sure this frame touches one of the threaded text frames in the story. The page number should immediately display as the page from which the story jumped.
  6. Choose Type > Text Variables > Insert Variable, and then select the same variable you defined for that story (Figure 12).

Figure 12. Create a text variable and use it twice: first, in place of the dummy text in the jump line, and then on this jump head on the inside page. You’ll never accidentally mismatch that text element or get the page number wrong, even if you shuffle pages or move the text thread at the last minute.

Now, if you change your mind about a jump, redefine the variable. Both the jump line and the jump head text will change. If you move the jump or shuffle pages, the jump line page number reference will change automatically.

Version your proofs

You can use text variables to slug your page proofs, as well. Create a text variable of the type Modification Date. On a master page, you can insert the variable in the slug area to output the date and time the document was last modified, in whatever format you wish, with additional text before and after the date element.

A Final, Cautionary Note

I hope you now have some ideas for making your work easier and more precise with text variables, even if you don’t make use of all the fancy PHP-IDML stuff. But no matter which way you go, here’s a final word of advice: Don’t let your guard down.

In August, I discovered that when I updated the data in the web database for all our issues this year, I failed to advance the volume number. It’s a small detail, but it had been wrong for 36 weeks in a row and no one caught it.

Despite my focus on accuracy and automation, human error still crept in. I realized that in the end, I still got the folios wrong, just as I did in 1986. As they say—garbage in, garbage out. And never, ever underestimate the value of a good proofreader!

Try It Yourself

I’ve put together a version of my PHP script at textvariables.commonsnews.org both for you to customize if you can and to demonstrate how text variables work. That page lets you fill in up to ten variables, and then download an IDML file you can look at. Before trying to open the file in InDesign, be sure the file name extension is .idml (some browsers will change it or add .html to the file name). In the examples, to see the “magic” (the text variables you defined in the web browser), choose Type > Text Variables > Define.

  1. You can make a custom IDML file using text variables in a Mad Libs–type of example. (Not practical, but a lot of fun!) For simpler projects, you could use the code to merge your text variables directly into a customized version of your template. That will directly generate an IDML file that will become your working INDD document.
  2. My workflow automatically generates the IDML file, when I start a new issue of the newspaper, and I can import all the data about that week’s paper into multiple InDesign projects that need to use the same body of data. You can see how you might use this workflow by the example of an imaginary book publishing company, using data in the IDML file for a bunch of different InDesign files: book cover, copyright page, and marketing sell sheet. 
  3. You can create your own variable names and assign values to them, then download an IDML file to try for yourself. Build your own InDesign files and import and use your IDML file.

Impressed? Want to try this PHP-to-IDML technique on your own server? If so, you can download my code from a link to a repository on github.com.

Bookmark
Please login to bookmark Close

Not a member yet?

Get unlimited access to articles and member-only resources with a CreativePro membership.

Become a Member

Comments (1)

Leave a Reply

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

  1. Frederick Yocum

    Thanks Jeff. Very in-depth! Not doing regular periodical projects at the moment, but saving the link for the future me.