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

Needed: script or GREP search to standardize dash spacing

Return to Member Forum

  • Author
    Posts
    • #75860

      Hi InDesigners!

      [Cross-posted at the Adobe forum as well.]

      When typesetting novels, I frequently need to go through and manually standardize the spacing of em dashes within the text. Wondering to what extent this can be automated either with a script or with a GREP find/replace. I want either a script or GREP search that can be run on the entire document and produce the following results:

      ———

      If an em-dash occurs in the middle of sentence, between two words, add a normal word space on both sides of the dash.
      (Example: I like cake — it’s delicious.)

      If an em-dash is preceded by an opening quotation mark, or followed by a closing quotation mark, do NOT put a space between the dash and the quote mark. (Applies to both single and double quotes.)
      (Example: “What the —”)

      If an em-dash is preceded by a closing quotation mark, or followed by an opening quotation mark, DO put a space between the dash and the quote mark. (Applies to both single and double quotes.)
      (Example: “How” — she paused for emphasis — “did you find me?”)

      Put a space between an em-dash and any other adjacent punctuation mark.
      (Example: I saw the cake — did you see it? — before the party.)

      If the word prior to the em-dash is the last word in the paragraph, then the space before the dash must be a nonbreaking space.

      If the word prior to the em-dash is the last word before a closing quotation mark, then the space before the dash must be a nonbreaking space.

      If the em-dash is immediately preceded by an opening quotation mark, then the space after the dash must be a nonbreaking space.

      The script must account for the fact that some dashes may already be spaced correctly, or partially correctly, and some may not. (Though it’s highly unlikely that nonbreaking spaces will already be present in the text.)

      ———

      Many thanks in advance to anyone who wishes to help me put something together.

      Thanks,

      Josh

    • #75862
      Aaron Troia
      Participant

      Hey Josh,

      You shouldn’t need a script, this is a good case for using GREP, try this, my replace is just an example of inserting fixed non-breaking spaces before and after, you can replace the ~s (fixed width non-breaking space) with what ever you need. For the GREP search itself, I have included both a regular space (you could try using as well, instead of a literal space), non-breaking space (~S), and fixed width non-braking space (~s), you can add/subtract the types of spaces that might be used throughout.

      Find: ( |~S|~s)?(—)( |~S|~s)?(?<!~})
      Replace: ~s$2~s

      Let me know if that helps or if it needs modification/tweaking.

      Aaron

    • #75863

      Thanks, Aaron, this is a great start.

      Do you think the exceptions relating to dashes falling adjacent to quotes could be incorporated into this search or would that be better handled with a second search? How about the nonbreak spaces implemented under certain circumstances? Can GREP handle things like “only if the word prior to the dash is the last word in the paragraph”?

    • #75888
      Aaron Troia
      Participant

      Joshua,

      Your right, you will probably will need a second or third search as well. I realize I did make a mistake on the first GREP search I posted so I thought I would make that correction and give you a few more searches as well as one might not catch everything you want it to. I think these should just about cover all your parameters, I tried to explain what each does to make it easier,

      Search 1: Em Dash with some type of space on both sides, but not at the the end of a line/paragraph
      Find: ( |~S|~s)?(—)( |~S|~s)?(?!(~}|$))
      Replace: ~s$2~s

      Search 2: Em Dash followed by closing parenthesis or end of line/paragraph
      Find: ( |~S|~s)?(—)(?=(”|$))
      Replace: ~s$2

      Search 3: Em Dash preceded by opening parenthesis
      Find: ( |~S|~s)?(—)( |~S|~s)?(?=~{)
      Replace: ~s$2

Viewing 3 reply threads
  • You must be logged in to reply to this topic.
Forum Ads