Back

If your email is not recognized and you believe it should be, please contact us.

  • You must be logged in to reply to this topic.Login

GREP Style with Search/Replace?

Return to Member Forum

  • Author
    Posts
    • #55293
      CalvinFold
      Participant

      Probably not possible, but I thought of a “I wish InDesign could do this”:

      How often is it that our designers get called by the proofreaders to add more space on either side of an em-dash because the characters on either side are too tight. They usally kern them away, but of course this adds the “+”, which is annoying if you're a style fanatic. I've been teaching them to use thin/sixth/hair spaces instead of kerning, because I've been teaching them to be more style-aware.

      But wouldn't it be nice if a GREP Style (not a manual Search-and-Replace) could be told “whenever you see me type glyph+em-dash+glyph, please replace the em-dash with thin-space+em-dash+thin-space” (or sixth-space or hair-space depending on the font).

      I looked into if GREP had it's own Search/Replace built-in (having had some GREP experience with MailSmith), but only certain forms of GREP+Perl seem to be able to do this, otherwise you have to use GREP+sed. Not sure if InDesign supports all that within GREP Styles.

      If this isn't possible, I'll just nudge-nudge the hosts, who likely have the ear of Adobe to some degree… ;)

    • #55294
      Anonymous
      Inactive

      Well not having CS4 in front of me right now I can't really test this.

      But it could be possible with GREP Styles.

    • #55300

      .. I looked into if GREP had it's own Search/Replace built-in ..

      Say whuh? You would like to do a Search-and-replace inside a GREP expression or something like that?

      You are correct about the GREP styles, though — all they can do is apply formatting. I don't think it would be a wise move to “automagically” have it replace text … see also the discussion in one of the GREP Style threads on why it's a bad, bad idea to use GREP to “hide” double spaces and typos.

      You can try this: apply a style with lots of tracking (+100 or more) to

      .~_

    • #55301
      CalvinFold
      Participant

      You got it. I understand the dangers of “hiding” or “automagically” making corrections of these kinds. But on the other hand, the only people here who will even touch GREP-anything are the power-users, and what I'm looking at is a power-user solution. ;)

      I've been cruising the GREP threads here, but haven't bumped into the one you refer to…can you provide a URL, you have me curious. :)

      Your tracking idea is a good one, and I just did a quick test, and what would be needed was a pattern search like this:

      find: a glyph followed by an em-dash followed by a glyph

      apply: character style to the em-dash and the preceding glyph (since the tracking only applies to the space after a glyph when highlighting a single glyph)

      I've not quite wrapped my head around “look for this pattern but only apply the character style to these sub-elements of what you found”…any kind souls willing to point me in the right direction?

    • #55303
      Anonymous
      Inactive

      Why not have a character style that increases the spacing of a normal space.

      Then use the GREP styles to automagically, as jongware puts it, use this character style.

      At the end of the project, you could do a grep search and replace for the amount of spacing and then insert a figure space or something instead?

    • #55304
      CalvinFold
      Participant

      1…em-dashes do not have a space on either side, technically. They should be typed glyph+em-dash+glyph. With a good font this works just fine. With lesser-quality fonts, this doesn't work so well, hence my question. In retrospect, switching from Metrics to Optical might work, but this GREP line of thought is still worth pursuing for some fonts.

      2…It's a matter of time—specifically, rushing. Solving problems is my job (depending on the hat I have on at the time), and giving them a “just do this in GREP Styles” is one thing. Asking them to remember to do a GREP Search just before the job goes to production (and hope someone down the line doesn't edit or fiddle with it as it passes through multiple other hands on the way) is asking a bit much in our workflow.

      “Magic” solutions no one thinks twice about. If they have to do it manually, it'll never happen or will happen wrong. ;)

      You'd probably have to work here to understand why “search and replace” tips aren't viable here—solutions have to be automated and survive passing through alot of hands and stay correct at every stage (let's not confuse the proofreaders…). I have to admit even *I* wouldn't remember to do last-minute Search/Replace solutions when someone is breathing down my neck for the printouts…

    • #55307

      I haven't fully tested, but one work around might be to set a Character style with a large amount of tracking (you can't set kerning in a chara style) and apply that to the em dash AND the letter preceeding it. Seems the tracking only applies to the right side of the selected character, so the preceeding character needs it applied as well to get equal spacing on both sides of the em dash. You should be able to set teh GREP style to apply to the emdash and preceeding character pretty easily.

      I had to do a similar work around for TM followed by a comma or period. Grammatically it's correct to have the puncuation follow the TM, but visually it looks wrong. I created a chara style that changes the tracking for the TM/comma/period pair that moved them together for a better visual pair. The only “gotcha” was that to make it work, the puncuation has to be placed before the TM. So I have to run a find replace to swap those, but at least they're easy to spot in copy when I forget to replace them

      Good luck!

    • #55315

      Hello,

      Perhaps you could use Peter Kahrel's script “Adjust Kerning”. An other solution here : https://blog.smi.ch/2009/07/10/…..eite-grep/ Adjust it for your glyph+em-dash+glyph.

    • #55316

      Calvin:

      find: a glyph followed by an em-dash followed by a glyph

      apply: character style to the em-dash and the preceding glyph (since the tracking only applies to the space after a glyph when highlighting a single glyph)

      Ehm… That's what this GREP does

      .~_

      I admit it's a tiny one, so perhaps that's why you didn't notice it. It's “any character followed by an em dash”. As you noticed, it's not necessary to apply it to the next character as well. It's therefore also not necessary to include it in the GREP style.

      I've not quite wrapped my head around “look for this pattern but only apply the character style to these sub-elements of what you found”…any kind souls willing to point me in the right direction?

      That can be done in two ways. The first way only works with find-and-replace, and to use it you have to “mark” groups of characters to find with parentheses, (like) (this) — two groups. In the Replace With field, you refer to the found groups using $1, $2, $3 etc. (“$0″ is a special code for the entire found expression). So you can switch these two words around by putting “$2 $1″ into the Replace field. It's especially handy if you need to find “abc” and change only the “b” part. But —

      The other way to do it, is with Lookahead and Lookbehind. They are pretty cool features, with some amazing capabilities. What they do is look for text before and/or after what you want to find, but without marking them — they do not get highlighted when you press “Find Next”. Hence, they are not touched by anything you put in the Replace With field. Subscripting the “2″ in “H2O” is a good example, as you cannot do that with one regular Find/Replace. However, when Looking Behind for an “H”, searching for a “2″, and Looking Ahead for an “O”, you can do it in one go! This particular example would look like this:

      (?<=H)2(?=O)

      with this full explanation, provided by something I am (or should be) working on:

      (?<= Lookbehind Group

      H Literal text ‘H’

      ) End Lookbehind Group

      2 Literal text ‘2’

      (?= Lookahead Group

      O Literal text ‘O’

      ) End Lookahead Group

    • #55336
      CalvinFold
      Participant

      Yeah I missed it because it seem too simple…stupid me, and apologies to you. :/

      Thanks for your help, very effective! And the tutorial on pattern groups and look-ahead/behind I'll save for the next time I get hung-up on that idea. Will also be handy in MailSmith. :)

Viewing 9 reply threads
  • The forum ‘General InDesign Topics (CLOSED)’ is closed to new topics and replies.
Forum Ads