Highlighting the benefit of GREP… literally

I’m a fan of the GREP feature of the Find/Change dialog box in Adobe InDesign as it allows me to search for patterns of characters within text based on regular expressions.

As handy as this feature is, I always require assistance writing my GREP searches, just in case my patterns are either too greedy; or not greedy enough. For example, I have a GREP search to find duplicate entries and remove them, but in InDesign the only way to know if I have this correct is to press the Find Next button in the search.

A better way to identify if I have my GREP search correct is to see it in real-time. Luckily, text editors such as BB Edit have this feature.

InDesign’s latest rival, Affinity Publisher, not only has its own flavour of GREP, but also shows all results in the Find and Replace dialog box, though I have to click on each result in this dialog to see where they are.

But it would be great if InDesign highlight the GREPs ahead of time like these two applications. The good news is that it can, but it requires the GREP editor script from Peter Kahrel that has been featured on Colecandoo before.

Thanks to Peter’s GREP editor, I’m now able to see that in this example there are three search results and they are all highlighted.

This tool comes in very handy as it assists me to write more complicated GREP searches, such as this one that is looking for time formatting. This lets me know in real-time if my selection is selecting too much information, or not enough – and in this example, it isn’t enough as the times without the minutes aren’t getting selected.

As for longer, more complicated chains of GREP code, there are resources out there that have pre-baked search chains that other users have already submitted to sites such as RegExLib.com or the Treasures of GREP Facebook group.

Stop Press!

After this article was initially published, I was alerted to another InDesign javascript by Kerntiff Publishing System that has a similar behaviour to Affinity Publisher’s search. The script is called GREP Xtra.

There is also an additional script released in 2013 by Roland Dreger that performs as a combination between Peter Kahrel’s script and the InDesign user interface. That script is called Highlight GREP.

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.

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.

Quick and Dirty comb-style forms using GREP Styles

I was recently asked to assist with the creation of a large amount of forms that were intended for a print output. The forms themselves were a “boxy” format that also had comb-style fields to indicate how many letters each area of the form should be.

combgrep1

The challenge with this particular brief was how to prepare the forms not only before the deadline, but so that they were also uniform in appearance. The solution was to create a paragraph style that had four GREP styles that would assign parts of the form, namely:

  • The start or end of the form
  • A letter space
  • A small comb
  • A large comb

Each part of the form is a monospaced font such as Courier New that has no fill or stroke, but has an underline and strikethrough that go to making the appearance. Take the following example that shows the style that represents the letter space:

combgrep2

The character styles that represent the start/stop lines or the small/large comb fields are effectively the same, but the horizontal scale is reduced to 3% and the underline and strikethrough options are changed to show different amounts of white (or none at all).

To make the form appear, characters that would not generally be used within the form are used to activate the GREP styles. For example, the pipe symbol will not be used in the form details, so this can be used for a start/end of form. Here is a list of the GREP substitutions made in this example:

  • | = start/end of box
  • ^ = white space
  • ` = small comb
  • © = large comb.

combgrep3

The following illustration shows the GREP styles in use, how a form would appear, and then how the text appears in the story editor.

combgrep4

There are several advantages of using this method to quickly make comb style forms, such as consistent sizing in forms, or easy to copy and paste portions of a form within a document.

However, there is a significant down-side to this method of form construction, namely that it is for print purposes only. While the forms can be created quickly for a print publication, the form fields do not translate that well to interactive forms via Adobe Acrobat using Acrobat’s Identify Form Fields feature.

combgrep5

 

Of interest: New Data Merge techniques and quote bug

In the latest Colecandoo Youtube episode, four Data Merge specific features are covered, namely:

  • Adding faux-returns to a data merge field to split over lines, and subsequent limitations of this technique;
  • Using GREP styles to swap a character for a glyph during a Data Merge;
  • Highlighting field codes so that they are easier to see when not showing live data; and
  • A bug that occurs when a double-quote is at the start of any field in a Data Merge text file.

Faux returns within a field

The faux-returns technique is written about elsewhere, so rather than spoil their presentations, please read the articles directly from the appropriate sources:

I’m a fan of this trick, but emphasise that this is a workaround rather than a long-term solution, given that formatting is limited and there are more appropriate ways of accomplishing this task such as dedicated plug-ins or an XML workflow.

Swap characters for glyphs

Daniel Solis also features a clever trick to swap phrases with glyphs during a Data Merge that uses both GREP styles and ligatures. Again, rather than simply repeat the technique, please see his original video here.

A similar method can be employed using Indiscripts’ Indyfont script, but rather than swapping phrases with glyphs, will swap single characters.

Highlight Field Codes

The video also shows a method for highlighting field-codes when Data Merge is not in the preview mode. It relies on the [Basic Paragraph] style using a GREP style that contains a large highlight, and that any other styles in the document are based off of the [Basic Paragraph] style. It also means the document has to be styled correctly.

I’d demonstrated this technique following a real-world example of a live file where fields were very hard to see, and the file had to have an offset shell printed with variable data printed afterwards, so making sure the shell had no variable data on it was crucial. Using this technique would make finding the field codes much easier to see.

Double Quote bug

Also featured in the video was an issue that once again arose from a real-world example where a customer had provided a database that had double-quotes at the beginning of fields, but no closing quotes, resulting in rather unusual results.

 

Map GREP styles from one Paragraph Style to another… or many!

There’s no doubt that GREP styles are useful, but hiding the GREP style function within the Paragraph Style dialog box makes applying GREP styles difficult:

  • Previously saved searches made in the find/change dialog box cannot be selected;
  • GREP styles applied to one paragraph style cannot be easily applied to another existing paragraph style

Perhaps a GREP styles panel would be easier. The panel would be like any other panel available in InDesign, and would list the GREP searches by GREP style names (similar to Paragraph and Character styles). Upon double-clicking a GREP style, a dialog box would open and allow the style to be applied to one or many Paragraph styles at once, what Character style the GREP style should apply, and the ability to load previously saved GREP searches from the find/change dialog box (where appropriate).

Great huh? Well, there isn’t one. Perhaps enough people requesting such a panel on Adobe’s wishlist page might persuade the developers at Adobe make one… perhaps fix the footnotes feature at the same time – hint, hint!

Well, until the software developers at Adobe create such a panel, the next best thing is to use workarounds or third party solutions provided in the form of javascripts.

Map GREP styles from one Paragraph Style to one or many Paragraph styles:

A combination of two scripts by separate contributors on the Adobe Forums allowed what I had not thought possible to become possible – select a paragraph style with the desired GREP styles, and then select multiple destination paragraph styles for the GREP styles to be applied. The script can be found here.

Similarly useful GREP style utilities

Peter Kahrel has a page dedicated to his various GREP utilities. Apart from having many GREP tools, his utilities accomplish other GREP style tasks, such as:

  • Ability to map a newly created (or saved search) to one or many paragraph styles with a specific character style.
  • Ability to highlight the results of a GREP search in real time.

Marijan Tompa (aka Tomaxxi) has two GREP scripts, but of interest is TomaxxiGREP. This script presents a panel that shows what GREP styles are applied to highlighted text, and gives real-time ability to change the search code and character style of the GREP style without opening the Paragraph Styles panel.

General GREP assistance

Roland Dreger has a script that highlights the results of a GREP search in real-time in a similar fashion to Peter Kahrel’s GREP editor.

Jongware has a dedicated GREP help page and a script titled “whatthegrep” that takes a GREP search and shows in layman’s terms what is being searched for.

InDesignSecrets website has a dedicated page to providing information about GREP.

Virtuosi Media‘s website provided this gem that contains long GREP chains to find specific items such as date formats or, country postcodes.

Variable QR codes? Sort of possible…

splash

UPDATE 2014-07-22: Since the release of Adobe InDesign CC 2014, variable QR codes via Data Merge is now possible. A post will be written about this feature once it has been thoroughly tested, but in the meantime this article has been edited to reflect the update.

Since the invention of QR codes, a burning question has been “how to incorporate these barcodes into a Data Merge?” There are lots of ways to generate one-off QR codes such as:

  • QR code generating websites;
  • An InDesign Javascript written by Jongware that is suitable for CS4-6;
  • Built into InDesign CC and above; and
  • Third party plug-ins that offer one-off creation as a “taster”.

But what if there are 30, 300, 3,000 or 30,000+ codes that need to be made as a direct mail campaign? Creating 30,000 QR codes is not a task that anyone would want to do individually.

So can Adobe InDesign, fresh from the shelf, create a Data Merge with variable QR codes? Apart from the latest release of Adobe InDesign CC 2014, no – not without the use of a third party plug-in. However, this workaround does the next best thing: Creates lots of QR codes all at once, export them as uniquely named PDFs for reference in a Data Merge, and then use the built-in Data Merge feature from InDesign.

The following example is a business card for fictional clothing manufacturer “Mean Jeans”. The client would like QRcodes that feature the staff member’s email address, and if no email address appears then no QR code needs to appear. The client has supplied the database in Microsoft Excel.

There is a way to automate this task thanks to three scripts

  • QRcode.jsxbin by Jongware (as previously mentioned). When this script is used on its own, a user interface appears asking the user for the text to be coded and then a level of error correction. Jongware did allow other scripts to call upon the QRcode script, and that leads into the next script;
  • A slight modification of a script supplied by an Adobe Forums user by the handle of sergemca. The original script (found in the same Adobe Forum link as Jongware’s QRcode.jsxbin) by sergemca searched an open InDesign document for any textboxes that contained the starting words MECARD: and would then convert the contents of the complete textbox into a QR code and then apply formatting such as scaling and rotation. As this example is creating QRcodes from email addresses, the modification in this example searches an open InDesign document for any textboxes that contain the starting word mailto: . Modifications to this script are best dealt with by the scripting forum of the Adobe InDesign forum.
  • PDFStyleExporter.jsxbin by Loic Aigon. This script has featured on Colecandoo before and it is used to split a large InDesign file into single page PDFs with unique names. While researching this story I have noticed that Loic will update this script in due course, so stay tuned.

To create variable QR codes:

  1. Open the Excel file and create two fields in the database in addition to the other fields that need to appear: order, and ‘@QRcode (the ‘ will disappear in Excel after it is typed, this is intentional). In the order column, use the autofill function of Excel to add sequential numbers to this column. Leave the contents of the @QRcode field for now.1qr
  2. Save the Excel file but also save it as a “Windows Formatted Text .txt” file, and give it a name that reflects that this database is purely for the QRcoding only e.g. forcodingonly.txt2qr
  3. In Adobe InDesign, create a new file that will be used to create the QR codes first. In this example, a file that is business card size has been created (90x55mm). Once open, go to the Data Merge panel and select the data source as the recently created txt file. Once the data is available in the Data Merge panel, create two text boxes. One with the word mailto: followed by the <email> field, and another text box with the <order> field. The document should look like this3qr
  4. The order text will provide the filename in a later script, but it also must appear in the file but not get in the way of the QRcode graphic that will appear later. To make sure that this text will be live but not output in the resulting QRcode, select the textbox containing the <order> field, give the text a paragraph style called “order” – the only change is that it has no fill and stroke. Also, align the text box to be in the centre of the page. The document should now look like this4qr
  5. From the Data Merge panel, select “Create Merged Document” and merge to a new single page document.5qr
  6. This will create a large document that will contain one mailto: address per page. It is important at this stage that any mailto: addresses that don’t have email addresses in the text boxes be deleted (or else the QRcode script will make QRcodes that contain the word “mailto:” only and clearly won’t work). To delete these addresses open the Find/Change dialog box and in the GREP panel type in the word mailto:$ , leave the change field blank (as well as the formatting fields) and click Change All.6qr
  7. The document is ready to have the QR codes applied. To do this, the altered version of sergemca’s script needs to be run.
var _d = app.documents[0];
var _allStories = _d.stories;
for(var nx=_allStories.length-1;nx>=0;nx--){
    var _storyAllTextFrames = _allStories[nx].textContainers;
    for(var mx=_storyAllTextFrames.length-1;mx>=0;mx--){
         _storyAllTextFrames[mx].select(); // change page
         if(_storyAllTextFrames[mx].contents.indexOf('mailto:')==0){
             var obj = app.doScript(new File(app.activeScript.path+'/qrcode.jsxbin'), ScriptLanguage.JAVASCRIPT, [_storyAllTextFrames[mx].contents, 3], UndoModes.ENTIRE_SCRIPT);
             _storyAllTextFrames[mx].contents = "";
         };
    };
};

7qr

If done successfully, the InDesign file should now contain QRcodes in place of the text that contained the email addresses.

To export these QRcodes with their unique names

  1. Run the script PDFStyleExporter.jsxbin (called PDFExportCropper.jsxbin on my machine)8qr
  2. In the user interface that appears, select the paragraph style “order” and leave the rest of the dialog box as it is. In the PDF options dropdown field, select the destination to save the resulting PDFs. Once done, click the Export button.9qr

Again, if done successfully, the resulting PDF QR codes should now save to the nominated directory.

There are other ways to export single page PDFs but Loic’s script is used in the example in case a reference other than a sequential number is to be used, such as a person’s name, phone number, etc.

To incorporate these QR codes into the data merge:

  1. Return to the Excel file and in the @QRcode field, use the CONCATENATE function to take the order number and apply the .pdf suffix to it. The formula to use is: =CONCATENATE(A2,”.pdf”)10qr
  2. Save the Excel file and again, also save it as a “Windows Formatted Text .txt” file, and give it a name that reflects that this database has been qrcoded QRcoding only e.g. qrcoded.txt
  3. In Adobe InDesign, create (or open) the card that needs the QRcodes applied. Once ready for the data, go to the Data Merge panel and select the data source as the newly created txt file. Place the name, address references etc as necessary, and create a frame for the QR codes to appear.11qr
  4. Apply the qrcode field to this frame and go to the Data Merge panel and select Content Placement Options. In the dropdown field “Image Placement” select the fitting “Fill frames proportionally”.12qr
  5. Instead of using the “preview” function, go to the Data Merge panel and select the Export to PDF function and export one record only. In the example, page 7 was chosen at random.13qr
  6. Once satisfied that the merge looks like it will work, again use the Export to PDF function to export the entire merge to a PDF.

For the barcodes to fit the image, the PDFs need to import PDFs based on the bounding box. If the images are not fitting the frame properly, an additional script originally by Dave Saunders (but improved upon by Marc Autret) will allow the import option to change. The script is available from this forum and once loaded and run into InDesign, the option to select is “Content All Layers”

14qr

So there it is. It is worth noting that this is a workaround and not a direct live Data Merge solution. There are limitations to this solution:

  • Resulting codes can’t be colorised on-the-fly;
  • If the database changes, this will mean repeating the entire process, rather than simply updating the data in the data merge file once, and removing all  QRcodes created previously.
  • Because the codes are not human readable without a decoder, there is added emphasis to check, recheck and check again to make sure the merge is behaving properly.

While this is a workaround, there is no doubt that a turnkey solution is preferable. There are enough third party providers making variable barcode solutions for Adobe InDesign. The full list is available here. From memory here is a list of third party providers that provide variable QR codes as part of a complete VDP package:

  • Rorohiko’s Tada QR;
  • XMPie’s uDirect;
  • Meadows Publishing Software
  • Cacidi LiveMerge;
  • Teacup Software’s BarcodeMaker;
  • DirectSmile;
  • Objectif Lune’s Printshop Mail;

Several edits since this was first published:

  • Added a list of third party providers who provide variable QR codes and moved a reference to an individual one earlier on in the article into that list;
  • Fixed type within field chevrons that did not appear when the article was published;
  • Acknowledged that variable QR codes via Data Merge are now possible in Adobe InDesign CC 2014

Perform multiple find/change (or GREP) queries at once

The find/change dialog box is a useful tool in InDesign until many searches need to be done at once. For example, an imported word processor file contains double spaces, double returns, spaces at the start of lines etc that need to be tidied. Using solely find/change, each item needs to be found and changed before the next item can be found and changed, meaning typing in the find field, then the change field, then change (or change all). This applies to GREP searches as well.

Ultimately, is there a way to perform many find/changes to text at once? Luckily, the answer is yes, there are several. Will they also change more than the text (such as formatting), not all methods outlined will do this. Some solutions listed below are still in Beta testing, while others may or may not work with Creative Cloud. Links to the providers of each solution has been provided for those seeking more information.

First method – default script (with outside assistance)

There is a script that ships with InDesign called findchangebylist.jsx. This script runs many find/change commands that are stored as text in another file called FindChangeList.txt.

By changing specific lines in the script and making and renaming copies of the FindChangeList.txt file, many different “chained searches” can be made and stored for later use.

Because the code used in the FindChangeList.txt file is rather cody, scripter Kasyan Servetsky has created a script that will take whatever is in the find/change dialog box and turn it into code that can be cut and pasted into the FindChangeList.txt file.

For regular visitors to this site, this article may seem like déjà vu, and that is because this solution has been discussed on Colecandoo before:

Second method – scripts:

GREP Queries Manager by Peter Kahrel

Unlike the first method, this has a user interface and deals with GREP searches rather than both GREP and find/change searches.

For full details on how it works, please visit this site

Doquery by Mikhail Ivanyushin

Again, this has a user interface and can use find/changes or GREP searches that have been previously used and saved with the find/change dialog box.

For full details on how it works, go to: http://adobeindesign.ru/2012/10/27/doquerylist-programma-obrabotki-teksta-zaprosami/

Batch find and replace by Fabiantheblind

This solution does not have a user interface but rather works in a similar fashion to InDesign’s default script but uses Fabian’s own expression language.

For full details on how it works, go to: https://github.com/fabiantheblind/batch-find-and-replace

Kerntiff’s Xchange

This solution has a user interface and can perform many find/changes at once, whether regular find/change or GREP.

For full details on how it works, go to: http://www.kerntiff.co.uk/free-stuff/xchange-strings-xstrings

Third method – plug-ins

Automatication

This plug-in has a user interface and what the find/change dialog box in InDesign should really have shipped by default. Nevertheless it is cheaper than a slab of beer and will last much much longer.

For full details on how it works, go to: http://automatication.com/

Action Recorder (Rorohiko)

While still in the Beta stage, Rorohiko is attempting to make what is arguably missing from the InDesign menu: the Actions palette.  Other than running find/change commands, this extension allows much more chaining and automation of other non-text based tasks, but at the time of writing is still too early to tell.

For full details on how to become involved, go to: http://www.rorohiko.com/wordpress/2013/08/06/action-recorder-beta-released/

Features or Speed… why not both InDesign?

porquenolosdos

After a recent post discussing the complications of indexing a rather large InDesign file (1600+pp), it is worth mentioning another issue encountered with the project, namely the reduced speed of InDesign.

There are already several articles concerning “slowdowns” while working with InDesign, namely:

http://indesignsecrets.com/why-is-indesign-soooo-slow.php

http://forums.adobe.com/message/4815713#4815713

Put simply, the larger the file became, the harder it was to work on. Little things such as placing the text cursor between words resulted in a spinning beachball of death for five minutes before the cursor once again became a text cursor.

Disabling several features in InDesign made the file somewhat workable:

1. Display performance – to these settings :

slowdown01
2. Pages panel – turn off the preview for the actual pages:

slowdown04
3. Turn the preflight panel off:

slowdown05
4. Live screen drawing – never:

slowdown03
5. Dynamic spelling off:

slowdown02
6. Do not use GREP styles or Nested styles
7. Do not use index entries or cross references

While this made the file workable, it was at the expense of the good features of InDesign. The slowdown was to the stage where using a word processor to accomplish the same task was considered!

Within the preferences, there is no ability to control the amount of RAM reserved for InDesign to use, nor is there the ability to control how often InDesign autosaves to its backup… something that is possibly slowing InDesign down even further.

Some of the features of InDesign were not necessary for this task as the project was completely black text supplied by the client, so having a lower quality display performance without seeing the page previews was not an issue. Preflight was not a concern with this particular file given that it was black text within one rather long text-frame and the spelling was to remain as the client provided the artwork.

Initially there was concern that turning GREP styles off would limit the control of “runt lines”. GREP styles had also been used for formatting of particular words, but because no type was going to be added, performing a one-off find/replace using the relevant GREP was able to remove the need for GREP styles. It was amazing to see the difference in speed when the file had the GREP styles turned on, opposed to when they were not applied – in this project the GREP styles were a major contributing factor to the file’s slow performance.

Followers of this blog will be familiar with several GREP styles that have been used to correct names or details within variable data campaigns. After this experience, it would appear that GREP styles are better suited to projects where content will be added dynamically (such as a Data Merged file) or constant alterations need to be made; rather than static documents – especially where no new content will be added.

The project DID have to be indexed (as discussed in a previous post) and found that once the file was indexed, the speed of the file slowed to a crawl.

%d bloggers like this: