Discussion:
Using GREP to find both sides of a compound word
(too old to reply)
K***@adobeforums.com
2007-06-22 04:09:37 UTC
Permalink
I'm just beginning to figure out GREP.

Is it possible to find the words on both sides of a hard hyphen and
apply a character style to each word but not to the hyphen? For example,
for the compound word "African-American", I want to find "African" and
"American" and apply a No break character style to each so that the
compound word is allowed to break only on the hyphen.

I know how to do this in NoteTab using regex on a tagged text file, but
I don't see a way to do it within ID.
--
Kenneth Benson
Pegasus Type, Inc.
www.pegtype.com
G***@adobeforums.com
2007-06-22 08:18:01 UTC
Permalink
As far as I can tell the replace formatting applies to the entire replaced string.

So my guess is that you have to do this in two goes:
- either use positive lookahead / lookbehind to search for words that are followed by - and format those
- or search for words with - between them, reformat and then use lookahead / lookbehind to reformat the -
Peter Kahrel
2007-06-23 11:51:42 UTC
Permalink
As Gerald said, you'll have to use two passes. You can apply formatting to part of a string, but that part must be contiguous and you want to apply formatting to two separate parts of the string. One method is to apply No-break to all compounds by searching \w+-\w+ and setting No break in the Change Format area. The second pass would be to remove No break from all hyphens.

Peter
K***@adobeforums.com
2007-06-23 12:35:56 UTC
Permalink
Thanks, two passes should work nicely.
--
Kenneth Benson
Pegasus Type, Inc.
www.pegtype.com
K***@adobeforums.com
2007-06-30 16:58:31 UTC
Permalink
It turns out two passes applies the style to both sides of a
compound-hyphenated word combination quite nicely.

However, hyphenation on compound words seems to work differently now in
CS3 than it did in CS2. After finishing two books, every time I apply No
Break to everything except the hyphen in a combination like
"semi-automated", the entire combination moves to the next line. It
appears that setting "automated" for No Break disallows a break on the
hard hyphen. Inserting a discretionary hyphen after the hard hyphen
appears to re-allow a hyphen break on the hard hyphen.

The first dozen or some times I encountered this I attributed it to the
Paragraph Composer, but after seeing this hundreds of times, it seems to
be the rule.

I'm assembling a test file that illustrates how compound words hyphenate
differently in CS2 and in CS3, and I'll make it available when I have
enough of them to be convincing.
--
Kenneth Benson
Pegasus Type, Inc.
www.pegtype.com
Loading...