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.

Find spaces only (no returns or tabs) with InDesign’s GREP

When learning GREP, the syntax for a space is usually shown as \s. This works in most situations, but it is worth pointing out that this syntax represents any space, including tabs and returns, not just horizontal space between words. For finding spaces only but ignoring returns and tabs, we need a different GREP string.

Take the following example where there are double spaces (or worse) in a text frame. With the assistance of the GREP editor script from Peter Kahrel, we can identify every result that will be found using the \s syntax plus the {2,} (identifies two or more of the same result).

The yellow highlights show the search results and while the double spaces have been identified, so have the double returns and space plus returns. If all of these spaces were to change to single spaces, all returns would be lost and the type would all be in one paragraph – an unintended result.

There is a pre-made GREP search built into the find/change dialog and it is called Multiple Space to Single Space, and the code looks like this:

[~m~>~f~|~S~s~<~/~.~3~4$ ]{2,}

If this is keyed into the GREP editor, the result is as follows:

The double spaces and longer can now be found without accidentally selecting returns or tabs, but the GREP code is quite unwieldy. Perhaps it can be copied each time it is required – let’s go to the find/change dialog box, call up the Multiple Space to Single Space search and copy the result.

Now let’s paste it into the GREP editor

The syntax hasn’t placed, but instead been represented by the actual characters that the GREP code represented. I can type the required syntax manually, but it’s a long piece of code that I don’t want to remember all of the time.

Use \p{Zs} instead

InDesign’s GREP allows for specific Unicode properties that aren’t available from the find/change dialog box, but they are accessible via the GREP editor script. Click on the insert wildcard or character class button in the top left of the GREP editor dialog box.

A new dialog box will open. From here, unfurl the Unicode properties, then unfurl the separator, and choose Space Separator.

This dialog also includes other Unicode properties that may be of interest, but for now it reveals that the syntax to use is \p{Zs}. Let’s try that in the GREP editor, along with the {2,} to find two or more instances of the same syntax.

Fantastic, it has done the same thing that InDesign’s Multiple Space to Single Space has done with a quarter of the syntax.

Additionally, now that the syntax is known, we don’t have to go through the GREP editor subdialog each time, the syntax is easy to remember – \p{Zs}.

Lastly

The GREP editor script is a fantastic utility made by Peter Kahrel that allows users to see the results of GREP code in real-time, and also provides access to snippets of GREP code that aren’t available from InDesign’s own find/change panel. An added bonus is that searches can also be directly applied to paragraph styles as GREP styles, rather than copying the syntax and pasting it into the paragraph style (or rewriting it on paper and re-keying it because the GREP gets translated into what it actually represents). I highly recommend this script and if you find it useful as well, make sure you let Peter know by making a donation his way.

Additionally, Peter is the author of GREP in InDesign: an InDesignSecrets guide – a fantastic resource for anyone wishing to learn how to use GREP in Adobe InDesign; or to build more sophisticated searches. If you would like to purchase a copy of this title, please click on this affiliate link here.

Planning your Wall Planner in advance

Between September and December, most of my working days are devoted to preparing school diaries and planners. One pain-point that I encounter with some diaries is the addition of a year-to-two pages planner. The planners usually look like this:

Apart from the events for each day that are on a layer above and updated each year, the base planner itself has two major wholesale changes:

  • The initials for the days of the week; and
  • The shading for weekends.

The initials are usually 365 threaded text frames that sits above a table containing the weekend shading. The text frames contain the initials of the days of the week, corresponding to the month and day they relate to, so changing the initials is easy. However, shading the cells containing Saturdays and Sundays on the table below takes time. Even if cell styles were used, they still have to be removed from the previous year’s appearance and applied to the appropriate year’s cells – subject to operator error.

Ideally, I was after a solution that would:

  • Easily update all planner base dates in one go
  • Shade all of the weekends without having to do this manually
  • Adjust automatically for leap years
  • Reduce any mis-dating via operator error

Didn’t I already write a script for this?

In 2018, I’d prepared a script to assist in the creation of wall planners that would allow for four types of layout configuration; and in 2020 was further improved to allow an output in one of 14 languages.

That said, this article isn’t meant to be a shameless plug of this script. The script is a great solution for creating new yearly planners. However, this solution requires updating existing planners. An additional solution had to be created.

The simple solution first

As I mentioned earlier, linked text frames that contain the appropriate days of the week initials. However, rather than use one paragraph style for these initials, each day of the week was given its own paragraph style e.g. Monday, Tuesday, etc.

The paragraph styles are based upon a base style that defines its basic appearance, with flourishes added to Saturday and Sunday in the form of paragraph shading. Each paragraph starts in its own text frame, and each paragraph style also refers to a next style feature to go to the next day’s style.

The days of the week are easy enough to prepare. The first way is quick but allows for operator error, and that is to type the 7 initials and their respective line breaks; and copying them 52 times, starting January 1st on the appropriate day.

The second (and more accurate way) is to make a new Excel file, type the start date in cell A1 and then with the cell selected, go to Fill, Series, and fill out the dialog box as shown

Once done, go to cell B1 and type: =CHOOSE(WEEKDAY(A1), “S”, “M”, “T”, “W”, “T”, “F”, “S”) and press return.

In the resulting cell, double-click the green square on the bottom right corner of cell B1 to automatically fill the remaining entries in the column.

From here, select column B, copy and paste it into the threaded text frames in InDesign.

Note – if it came in as a table, make sure to briefly change InDesign’s clipboard handling preferences to handle text and tables from other applications as text only.

Last thing to do is apply the paragraph styles. Take note of what day’s initial appears on January 1 (Friday in this case) and with the text cursor still visible in the text frame, select all type (Command A). From the paragraph styles panel, right click on the Friday paragraph style and choose Apply “Friday” then Next Style.

But this solution only fills two of the four criteria:

  • Easily update a planner dates in one go
  • Shade all of the weekends without having to do this manually
  • Adjust automatically for leap years
  • Reduce any mis-dating via operator error

This solution does not take February 29 in leap years into account. In these instances, an extra text frame needs to be threaded to take in February 29, so is not completely automatic.

The over-engineered solution

I did prepare a solution outside of work hours that would meet all four criteria; but the setup of the file took more time than simply adjusting the previous planner. It would also be difficult for other operators unfamiliar with my techniques to carry out the alterations unless they were trained beforehand. Ultimately, the solution wasn’t practical for my day-to-day work and was never implemented, but it is worth looking at the solution as it uses a variety of InDesign’s features such as:

  • GREP styles
  • Table and Cell styles
  • Rule above within Paragraph styles
  • Linking to an Excel file

Both the InDesign file and Excel file can be downloaded here.

First thing is to create an XLS file that contains the yearly information that changes and link it in InDesign. Linking to an excel file can be done via InDesign’s preferences.

Linking to an XLS file can be fiddly and I’ve found the best way to maintain appearances of linked tables that are updated is to make sure that table and cell styles are applied to the table that will contain the incoming XLS data.

A glimpse at the XLS file shows that it contains the initials of the appropriate days of the week. Note that the initial letter is represented by two letters rather than one (which will be explained shortly). The year is off to the right-hand side for ease of updating the planner by just adjusting the year.

An even closer look at the XLS file shows hidden columns. If we unhide these columns, the workings behind the technique are revealed. To compensate for leap years, the calculation for February 29 has an if-else statement that says if a date appears here, add the appropriate weekday initial, but if there is nothing, leave it blank.

Back in the InDesign file, all cells contain a paragraph style that have a GREP style instruction that makes the first letter minuscule in size and width.

Why two letters for the days of the week and not one?

It is to do with how the shading of the cell is automated. The first letter is used to identify a weekend with the initial S and that letter is colorised with an appropriate color for the weekend. If the letter was a weekday, the first letter is set to none. To control the background color of the cell, the rule above feature of the paragraph style is used as it allows the [Text Color] option to be selected, and this color is the first character that the paragraph style encounters. The rule above is then made thick enough to fill the cell, and then the offsets are applied to fill the remaining parts of the cell.

Why not use the paragraph shading feature? Unfortunately, this feature does not have access to the [Text Color] option from the color dropdown.

Updating the data can present a trap, as instead of simply changing the date in excel and updating the file, the art needs to be relinked and then selected with the show import options dialog to only bring in specific cells, as the date at the far right isn’t required. In this instance, it is changing the cell range from A1:AA32 toA1:Y32 as shown:

So this will make the base for the planner, and all the further information into the particular dates is done on a layer above using a table with the same cell dimensions.

As mentioned, this is an over-engineered solution that wasn’t implemented, but its use of combining linked Excel files, GREP styles and Cell styles may have application for other purposes.

GREPgraphing – Beyond 2000

In 2016, I developed a concept of creating bar graphs using GREP styles. Put simply, when a number was typed such as 1423, several different GREP styles would kick in to transform the number into a bar graph. In the above example:

  • if there’s a one for the 1 followed by three digits, make the one character 1000% wide;
  • If there’s a 4 followed by two digits, make the four character 400% wide;
  • If there’s a 2 followed by one digit, make the two character 20% wide;
  • If there’s a 3 as the last character, make the three 3% wide.

To successfully work with any whole number between 1-1999, this technique requires creating 29 different types of GREP styles and character styles. It uses a fixed width font and takes advantage of GREP styles to adjust the width of the numbers to represent them as their appropriate value as a bar graph. I’ve written about this technique in more detail over at InDesignSecrets.

In 2018, I expanded upon this idea and made a script so that anyone wishing to use the technique without typing the 29 character and GREP styles could simply run a script:

Beyond 2000

One catch with this technique is that it stops at 1999 as the character style to represent 2000 can’t be made by creating a 2000% width as the maximum character width is 1000%. However, there is a workaround – create a new character style called 2000, based on the 1000 style, but give it a tracking of 600.

Adjust the GREP graph paragraph style and underneath the 1000% GREPstyle, make a new one using the new 2000% character style that was made and give it the following pattern:

2(?=\d\d\d\b)

To test this, I have two different GREPgraph styles containing the 1000 figure and have put them side by side. In the text frame underneath, if I type 2000 into the text frame with the GREPgraph beyond 2000 style applied to it, it should be the same width, right?

Absolutely. If I make an additional 3000% character style based on the 2000% style but changed its tracking to 1200, and added a GREPstyle to the paragraph style to apply the 3000% character style to the pattern 3(?=\d\d\d\b), this will work too.

From here, a pattern can now be seen: to get to the next 1000 in width, add another 600 to the tracking of that thousand’s character style and add a new GREP style pattern to the GREPgraph style. This will work until the tracking hits its maximum of 10,000.

Doing all this in less GREP steps

As stated earlier, the original technique required 29 GREP styles to create a GREPgraph, but what if I said it was possible to achieve the numbers 1-1999 (actually a few more – 2047) using 12 GREP styles? This can be done too, but requires a technique in Excel, and that is to convert the original base-10 number into a 16-bit binary number. I’d actually described this technique back in 2011, but it was implemented differently and with more complications: this method is far simpler.

First, convert the desired base-10 number to a 16-bit binary number in Excel using the following formula:

=DEC2BIN(A1/256,8)&DEC2BIN(MOD(A1,256),8)

Now that the number is displayed in binary, copy the binary number into InDesign.

The technique basically works the same way as the original GREPgraph technique but has a slightly different implementation. First, the character styles need to be created that will change the widths, but instead of making 1-9, 10-90, 100-900 and 1000, only the character styles 0, 1, 2, 4, 8, 16, 32, 64, 128, 256, 512 and 1024 need to be created. For example, the character style 32 will only contain the width of 32%, and this pattern will apply to the other numbers mentioned.

Zero and 1024 are the exceptions. Zero will have a character style featuring a .1pt size, no fill or stroke, and 1% width. 1024 will have a character style of 1000% and a tracking of 14.

This will create a total of 12 character styles.

Now to make the paragraph style. To keep it simple, the appearance of the bar graph will controlled by the paragraph rule (though more advanced methods can be made using combinations of rule above, below, underlines and strikethroughs).

Here is where the magic happens – the GREP styles. Here are the styles and how they are implemented in the GREP style panel of the Paragraph style.

And here is the result:

So what’s happening here?

It’s important to understand how binary numbers are written compared to base-10 numbers. The following site gives a really good explanation, and that’s all that’s happening here – the GREP styles are being applied to the 1s in the binary number, based on their position in the binary number, and applying the appropriate GREP widths.

It can go larger

Just like the regular GREP graph, this too can be expanded to numbers larger than 2000 by creating an additional character style that has an added tracking applied. In this case, to represent the numbers 1-4095, a further character style can be added: 2048.

An advantage of this technique is that instead of creating an additional 9 character/GREP styles for each power of 10 using the base-10 GREP styles, the binary method will require a new style every time the total doubles e.g. 14th GREP style would be 4096, 15th GREP style would be 8192…

The obvious disadvantage with this technique: the numbers to be displayed as bar graphs have to be written out in binary first.

Is this something I would use? Probably not myself, as GREPgraphs are normally enough for my purposes, but I often hear the question “what if you need more than 1999 in a graph” so I felt that it was worth answering the question: It can be done, but it’s a lot of effort to get there.

%d bloggers like this: