is now part of CreativePro.com!

Insert a Special Character with GREP Styles

23

You want to put a logo at the end of every story. Or you want to insert a special character or picture after each instance of a word in a document. Why not automate it in InDesign CS4 with GREP Styles? Well, because GREP Styles only lets you apply a character style, not perform a find/change… that is, you cannot insert or change any characters using this feature.

Or can you?

Here’s a fun workaround: You can replace any character in your story with another by choosing a different font! For example, if you apply a character style that is defined with the Zapf Dingbats font to the letter “n” you’ll get a black square.

So what if you change a character — say, the final period at the end of a story — to a font that has your logo in it? Or a dingbat of your choice? It’s easy to do: Just create a new font with a utility such as TypeTool. [Editor’s note: A newer tool, called IndyFont, let’s you do this right inside of InDesign.] For example, I opened a font (it’s easier to start with an exsiting font, I find), found the period character, and pasted this little logo into it:

I adjusted the right bearing (side) so that it would fit both the dot and the logo. Then I changed the font information (gave it a new name, etc.) and exported my new font. The whole thing took no more than 10 minutes. (Mostly just trying to get the outlines right in the character.)

After installing my font (I just put an alias of it in the Fonts folder inside the InDesign folder), I added a GREP Style to the paragraph style definition —  the paragraph style that I knew would be at the end of each story where I wanted that logo.

The backslash-period in the style above indicates a period. The backslash-Z means “at the end of the story.” The character style simply changes to my font that I created.

The result? InDesign automatically “inserts” my logo at the end of every story in that paragraph style:

And it does it on the fly, so if I add a new paragraph after this one, the logo drops off this one and is added to the new last paragraph. I love that.

I did something similar with the spacebar character: Just replaced the space with a special dingbat character (with space on either side of it). That way, I could make a grep style that searches for one space after a particular word.

Even better: When the text is exported, that formatting disappears (because the space is just a space, and the period is just a dot), so I just get the underlying story.

David Blatner is the co-founder of the Creative Publishing Network, InDesign Magazine, CreativePro Magazine, and the author or co-author of 15 books, including Real World InDesign. His InDesign videos at LinkedIn Learning (Lynda.com) are among the most watched InDesign training in the world.
You can find more about David at 63p.com

Follow on LinkedIn here
  • alex says:

    David-

    Once again, you amaze me with your taking of simple things and combining them into an amazing use of InDesign.

    Alex

  • Fritz says:

    David,

    You need to legally change your name to Igor David or International Designer. Then when you put your icon at the end of the story, you are also putting your initials there too!

  • Well, granted, the “ID” logo I created for this tip isn’t a real logo. I just grabbed a few characters and threw them together.

    This tip was inspired, by the way, by the formatting at The National newspaper in Abu Dhabi, UAE, where I was just doing some training. All their news stories start with a city name followed by two slashes. I was horrified to think that someone sits and types slash-slash all day long. So I changed my font’s space character to look like a double-slash with some space on either side. Then a quick grep style automatically applies my font to the proper space after the city name.

  • Mike Perry says:

    Nice trick, but it’d be much better if ID’s character and paragraph styles let us specify start and end text strings for either sort of style, perhaps with their own character styles. Then an end of story logo would be easy, as would inserting text like “Name:” and “Price:” using Nested Styles when creating personnel lists and catalogs. And in technical writing, it’d allow terms like “Warning:” to be automatically inserted.

    Sigh! Yet another feature I miss from FrameMaker….

  • töff says:

    Ah, cool tip!

  • Maintainer says:

    @Mike

    You mean it can’t do that?

    In a way that’s actually a relief?as I’ve been searching high and low for a day looking for a way to do just that in ID CS3. At least I know I’ve all of a sudden forgot how to search!

    How or why that’s not available is really beyond me.

  • Mike and Maintainer: I believe you can do just that with the Formatting Tools plug-in from In-Tools.com

  • good post, thanks admin

  • I don’t want to hijack the discussion away from a useful use of grep styles, but…

    been having discussions w/ Legal teams about altering a font, or creation of new characters based on the original.

    I’m not a lawyer (and have yet to play one on TV) but my understanding is *modifying the font software is illegal* as it violates the license agreement. That is, the code that draws the characters is subject to copyright, and your license to use said software does not convey the right to modify or alter it.

    That said, the character *shapes* themselves – the plotted vectors and resulting typography resulting from the mathematical algorithms that define how the lines are drawn – are not subject to US copyright. (They are, I believe, in the UK.)

    You could still create a custom font – say, a logo as a character (I used to work for a publisher that had several such custom fonts) – and use that font wherever you’d use the logo (manually or via this tip).

    But what you’re specifically prohibited from doing is opening up one of your licensed fonts and making a change to the character set, even if you’re saving the change as a new font file.

  • Alexei says:

    You could still create a custom font ? say, a logo as a character (I used to work for a publisher that had several such custom fonts) ? and use that font wherever you?d use the logo (manually or via this tip).

    Or you can use a font that allows modification in its license, such as a SIL OFL, or Apache license.

  • Sue Spade says:

    For days I have been attempting to figure out how to take a self made .eps dingbat and have it appear on the first line of the first paragraph of my nested style group. I’m asking you…is there any way without doing the manouvers above you so adroitly figured out? I’m just a bit less inclined to download software at work for this. Thanks!

  • Hi! It’s amazing!
    How to add any word in any part of the text? For example:

    $ 88,88
    $ 88,88

    I need to add (*) at the end of the prices.
    $ 88,88*

  • Hi! It’s amazing!
    How to add any word in any part of the text? For example:
    $ 88,88
    $ 88,88
    I need to add (*) at the end of the prices.
    $ 88,88*

  • Luiz Silveira says:

    Hi. Nice tip! Worked fine but I’m having problems to adapt to my needs. I want to put a symbol from a font in the end of the paragraph. It’s the “k” char in that font that shows the symbol I want. Is that possible to make this GREP search for the “.” in the and and change it for the “k”?

    Thanks
    Luiz

  • Luiz Silveira says:

    Ignore me. :) I just did it with another tip of yours, that one with the “4z” search. :) Thanks a lot!

  • Ester Knudsen says:

    Just found these pages, nice tips :) One question. What if I want a red bullet after the . at the end of a story? Following your tip it gives me a red . and a red bullet … is there anyway to get a black . and a red bullet?

    • Luiz Silveira says:

      Hi.

      What I did here was a style that have in GREP:

      (?<=k)z applying a Character Style that makes text "desapear" (very small and white)

      and

      k(?=z) applying a Character Style that makes text Red and in the font "LL Record".

      With this style I just type ".kz" in the end of each paragraph I want a "pause" sign in the end (LL Record font has a pause sign in letter "z").

      Just the pause sign is red, not the dot because it find the ".kz" in the end and change the "k" by "disapear" and the "z" by the red pause sign.

      Hope it helps. :)

  • Orla Norup says:

    This is very nice. But what I need at the end of the story is a Right Indent Tab and then a character (black square). And this character shall not be a part of the text.
    I can use the last paragraph:
    “I did something similar with the spacebar character: Just replaced the space with a special dingbat character (with space on either side of it). That way, I could make a grep style that searches for one space after a particular word.
    Even better: When the text is exported, that formatting disappears (because the space is just a space, and the period is just a dot), so I just get the underlying story.”
    But i really don’t understand how do to this! Can you help with a hint?

  • Courtney says:

    I am trying to add some space between the letter f and a ?. Is there any way to do this. I was able to use the grep \<f(?=l) to add space between an f and an l. But can not figure out how to make it work with a ?
    Can anyone help?

  • Ross says:

    Hi, is there a way to insert a forward slash (/) automatically at the end of a paragraph using GREPs? I can’t work out the expression for this.

    Thanks in advance

  • >