Applying character styles over character styles

There may be occasions where more than one character style has to be applied to the same words, such as a highlight, italic, etc. I recently saw this request over at the InDesign requests page.

In the request, the requestor does hint at a way that this can already be achieved in InDesign, though it can be time consuming. Let’s start from the beginning and look at some text that has an italic character style applied to it.

But if I apply a separate highlight character style that I’ve also made…

The highlight appears but the italic is removed. Reapplying the italic character style to the word only changes the word back to italic and doesn’t preserve the underline.

One solution is to do a local override – that is to manually apply the appearance but without using a character style

Note the plus that appears to the right of the Paragraph Style 1 – this indicates a local override is present.

That works, but let’s say that the client asks for all italics to now be a tint of the colour initially used. That’s fine if character styles were applied as the italic style needs to be changed once in the properties of the character style. However, all the italics applied using local overrides will need to have their fills reapplied with the new settings.

Yes, the eyedropper tool and find/change can assist, but if character styles were applied, these additional steps would not be necessary.

In this circumstance, making a third style that has both the underline and italic would make sense.

In this case, it adds one more character style – not a big deal, but in a large document, the quantity of character styles can grow fast.

GREP Styles to the rescue

Take this chemical equation in a science textbook. It currently looks like this:

The subscripts in this equation have been applied with a character style that I’ve named sub. However, the author wants the reaction only in bold. If the equation is highlighted and then has a bold character style applied, this happens:

All of the subscript formatting of the numbers are lost.

I can then create a second style called “bold sub” that has bold and subscript properties and base the style on the bold formatting, but I then have to make sure I correctly apply the newly created style to the appropriate numbers… this now introduces a level of human error.

But what if I could apply the bold style and keep the subscripts? It is possible using GREP styles. Using the GREP code from this CreativePro post (look for Laurent Tournier’s post dated Oct 9 2010 in the comments) apply it to the paragraph style.

[editor’s note – I’ve adjusted mine to account for the naming of elements 113-118 as of 2018, so if you want that amended code, contact me via my contact page]

Now apply the paragraph style to the recently bolded text.

Brilliant! Note how the I-beam cursor is between two subscript numbers, yet the character style shows that this is bold only.

This technique can also be applied to other formatting where subscripts or superscripts need to be preserved, such as:

  • Ordinal Numbers
  • Numbers written with scientific notation
  • Squared or cubed measurements

It just requires the right GREP syntax. All of the above examples used GREP styles to format the subscripts and superscripts only. To learn this technique and others, apply to join the Treasures of GREP Facebook page.

Once again to illustrate the point, the author wants these six lines in bold. By highlighting the lines and applying the bold character style, the subscripts and superscripts stay in tact.

Nested styles

Similarly, this can also be achieved with Nested styles. Take the last two lines in the last example prior to applying the bold – if I want the ordinal number at the start of the line to be bold, I don’t have to write a GREP style but I can use a nested style such as the one below.

That will give me this result without applying any manual character styles to the text:

There are catches to this technique

The first catch is that the character styles must have the minimal amount of style changes only. That is the sub character style only changes the position of the character to subscript, so that is the only item that style will apply, while maintaining the rest of the paragraph style’s formatting.

The second catch is to be aware of the style hierarchy. The following list is in order of what style overrules another (from most to least dominant):

  • Local override
  • Local character style
  • Nested style
  • GREP style lowest in list in the paragraph style settings
  • GREP style highest in list in the paragraph style settings

There can be several advantages to layering character styles by using GREP styles:

  • Less character styles.
  • Time saving for commonly formatted items such as ordinal numbers.
  • Consistency based on GREP patterns for words.

Similarly, there can be drawbacks with this technique:

  • Looks for particular words or phrases, so not appropriate for instances where dozens of words or phrases may make more GREP styles than are manageable.
  • Applies to paragraph styles, if used over many paragraph styles, the GREP style needs to be applied repeatedly. Scripts can help with this, such as one I wrote on my scripts page, or GREP Editor from Peter Kahrel.
  • Can’t take a bold style and italic style and combine them – it can only apply additional attributes that weren’t there previously.
  • GREP styles (along with live preflight, page thumbnails, dynamic spellcheck and any other service that has to run while the document is being composed) can slow the processing speed of the machine, particularly on larger documents.

Please fix Text Variables so they behave like regular text

Within the type menu of Adobe InDesign is the Text Variables feature. This allows users to insert a special character that will display one of the following items:

  • A chapter number
  • A file-related date such as the creation date, modification date or output date
  • Filename
  • Image Name (aka captions setup)
  • Last Page Number
  • Running Header based on either a used paragraph or character style
  • Custom static text

Unfortunately, there is an unwanted behaviour of the text variables – InDesign treats them as a single character rather than the actual content within the variable. This has a few unwanted consequences:

  • Long variables that would normally break over several lines are squished into one line;
  • They cannot be formatted using GREP or Nested styles, nor can specific words be manually selected for formatting.

It’s an issue that is “in backlog” by the Adobe InDesign team to address, but that was first stated in 2017.

If the issue was resolved, it would have enabled my GREPGraph solution to be applied in the following InDesignSecrets article.

As it turns out, it is also affecting another solution that would make lives easier for anyone who has to create diaries and planners on a regular basis.

The brief:

A planner is created by making a base template and then creating threaded text for the dates that are represented only by numbers. This makes populating a diary from week to week relatively easy…

…until the other material has to be populated, such as what month it is, what term it is, and what week it is. This is best illustrated in the first two minutes of a Youtube video by Rob Cubbon.

Incidentally in Rob’s video, he uses frame breaks between each record, but that isn’t required. Instead, adjust the paragraph style of the numbers by going to the Keep Options and from the Start Paragraph dropdown, select In Next Frame.

The technique:

Instead of populating the text frames simply with numbers, what if the frames were populated with more information that can be called upon by running header text variables, such as the month?

I can make a list in excel that contains the day of the week and the month in one column. This is also done without a space intentionally for reasons that will become evident soon.

I can then copy this text to my InDesign file. However, note that the text overflows and isn’t correct – that is because the flowing numbers need to have a character style that will hide the text that we want to be visible elsewhere. To do this, I’ve created a character style called hidden, and its properties are:

  • .1 point high;
  • 1% wide;
  • No fill or stroke.

That’s fine, but applying that manually to everything but the numbers will be a nuisance, so the paragraph style for the numbers has to be modified using Nested Styles.

The nested style will apply a style of [None] to the digits as they need to be visible, but will intentionally hide the month.

So why I am I intentionally hiding the month? Because I’m only interested in the information it represents, and this can be called upon by a text variable. I will go to the master page and insert a text variable for a running header showing me the first result of hidden on the page.

The issue with the technique

That’s fine until I get to a spread that contains two months. I’d rather both months be present rather than the earlier month. For example, I’d like the headline to read April/May instead of April. I can do this by returning to my master page, apply my blinking text cursor to the text variable that is already there, type a slash and then create a new text variable that is a running header looking for hidden character style in the last instance.

Once I’ve inserted the variable and returned to that spread, that now looks fine, but all others are now affected.

I should be able to make a GREP style that will look for a word, then a backslash, and the same word it initially found. I’ll create a new text frame with some sample text to see if it works. The GREP code I’ll use is this:

Apply style: Hidden

GREP: (.+?)\K\/\1

Looks like its working in my demo, but as I check the document it isn’t… I’ll find a spread where I know the months split.

But that should work. I saw it work on plain text, why isn’t it working on text variables? That’s because GREP styles and Nested Styles don’t work on text variables. If I want this technique to work, I’ll have to use a workaround.

The workarounds:

  • Use a script to convert the text variables to plain text. Marijan Tompa used to have such a product via the Adobe Exchange, but it has since been removed, and it is not mine to give away. Other scripts do exist on the Adobe InDesign forums, but they are not as flexible as Marijan’s original script. It also works only one way, and can’t convert the text back to variables.
  • Don’t attempt to use the GREP style to hide the duplicate month, but instead only add a Running Header for the first instance on a page and add the others manually by overriding the affected master pages;
  • Create the desired date in Excel using a formula.

The issue with the first two solutions is that it prevents the solution from remaining live. The last solution will work but requires in-depth knowledge of Excel and – for many diaries – requires having an Excel file on stand-by for this purpose.

Ultimately, I’d love to see a fix for this issue as it would open up many possibilities. If you feel that this needs attention now rather than later, please cast your vote here.

%d bloggers like this: