Skip to main content
Inspiring
Dec 2, 2021 5:42 PM UTC
Question

Avoid a single letter at the end of a line?

Hello

is it possible to automatically avoid having a single letter at the end of a line? 

 
Is it possible to set a minimum number of letters under which they must necessarily wrap as for the hyphenation?
Thanks

23 replies

Inspiring
Dec 10, 2021 5:13 PM UTC

I'm sorry, I thought I solved it but I can't get the result I'm looking for. I have tried to assign all the grep styles you have suggested but in no case can I avoid that single letters remain at the end of the lines. If anyone would kindly upload an example file (.idml because I use InDesign CS6 8.0.2 on Mac) to dropbox or drive, I would be very grateful.

Translate
James Gifford—NitroPress
Legend
Dec 10, 2021 5:26 PM UTC

The tendency of solutions to use GREP and scripts sometimes seems (to me) a bit like using a sledgehammer to drive a tack.

 

Do you have any single letters besides 'e' in your project? Is a simple search and replace for 'e ' (e space) to 'e^S' (e nonbreaking space) not sufficient, even if you occasionally have to repeat it? The nonbreaking space will disappear into whole lines, and prevent the e from being left at the end of any line.

 

If you have other letters, a wildcard in the search would get all of them. (' ^$ ' to ' ^$^S')

 

Not seamless, automated and elegant, but sometimes a simple solution is all you really need. I guess you could write a script to do it. though. 🙂

Translate
FRIdNGE
Dec 3, 2021 9:06 PM UTC

Just For \Grep Comment! …

 

 

As we talk about “no-break” (enough greedy, catching the following char), here, this Grep code will be simplistically enough:

 

\b\w\h

 

(^/)  The Jedi

Translate
Inspiring
Dec 10, 2021 8:27 AM UTC

Thanks all.

Translate
pixxxelschubser
Community Expert
Community Expert
Dec 3, 2021 8:31 PM UTC

 

I copied it from your post here above.

This is the test file:
https://drive.google.com/file/d/1qbNEd1tUX9tY2SywEUS-8QheHmZ2N60p/view?usp=sharing

ID CS6

this is the .idml file:
https://drive.google.com/file/d/1bMm35R3OezKaovg1I4ze5NVXnJY8Fyod/view?usp=sharing

thanks a lot


By @AntonioTheAnt

 

Unfortunately, you need an access authorization.

See:

 

Translate
Community Expert
Dec 3, 2021 7:55 PM UTC

Hi Peter,

pixxxelschubser's GREP Style is also working with InDesign CS6 version 8.1.0.420 on Windows 10.

 

 

Regards,
Uwe Laubender

( ACP )

Translate
Peter Spier
Community Expert
Community Expert
Dec 3, 2021 8:16 PM UTC

So it is.

Translate
pixxxelschubser
Community Expert
Community Expert
Dec 3, 2021 5:01 PM UTC

Did you write that grep? Or did you copy it from one of my recent posts?

 

If the latter, please highlight the entire grep code in the Grep Style tab. Perhaps you accidentally copied a space at the beginning or at the end.

 

Maybe you can also upload a test document without confidential data as Indd with specification of the exact InDesign version and link it here (e.g. Dropbox or similar). A filled text frame and your paragraph format + character format is sufficient.

Translate
Inspiring
Dec 3, 2021 5:55 PM UTC

I copied it from your post here above.

This is the test file:
https://drive.google.com/file/d/1qbNEd1tUX9tY2SywEUS-8QheHmZ2N60p/view?usp=sharing

ID CS6

this is the .idml file:
https://drive.google.com/file/d/1bMm35R3OezKaovg1I4ze5NVXnJY8Fyod/view?usp=sharing

thanks a lot

Translate
Peter Spier
Community Expert
Community Expert
Dec 3, 2021 7:01 PM UTC

I think the problem is CS6. I don't think that version recognizes the \h or \K parameters.

Translate
pixxxelschubser
Community Expert
Community Expert
Dec 3, 2021 11:34 AM UTC

That is one possible mistake.

 

Another one:

Did you applied the paragraph style?

Translate
Inspiring
Dec 3, 2021 12:26 PM UTC

Yes.
Is the grep correct in this way?

 

 

Translate
pixxxelschubser
Community Expert
Community Expert
Dec 2, 2021 9:48 PM UTC

Here are some more explanatory screenshots:

 

without grep style

 

with grep style

 

 

 

paragraph style with grep style and character style No Break (colored for better illustration)

Translate
Peter Spier
Community Expert
Community Expert
Dec 2, 2021 10:10 PM UTC

Ah, much better. I misread the post and was looking at it as end of paragraph rather than end of line.

For what it's worth I agree that a single character at the end of any line other than the last is not a compositional problem, though I would probably not want to see a single character followed by a hyphen, but that is controllable in the hyphenation settings.

The biggest problem I see with this kind of requirement is a major performance hit as the grep style must constantly look at the entire paragraph, or maybe even story, as text is entered or edited and the paragraph composer re-flows the exisitng text.

Translate
pixxxelschubser
Community Expert
Community Expert
Dec 2, 2021 8:55 PM UTC

If I had such a requirement, I would probably apply a grep style in paragraph style with character style No Break or something similar.

\h\K\w\h\w(?=\w+)

 

Translate
Inspiring
Dec 3, 2021 7:36 AM UTC

Thank you.

I tried to add your grep style to paragraph style:

but I don't see any change in text

 

what am I doing wrong?
I don't know anything about grep.

.

Translate
Peter Spier
Community Expert
Community Expert
Dec 3, 2021 10:26 AM UTC

Did your applied character style actually include application of the No Break attribute?

 

Translate
Peter Spier
Community Expert
Community Expert
Dec 2, 2021 5:56 PM UTC

Yes, it's possible, as part of a paragraph style. If you search for terms like runts or orphans you should find some other threads on this topic which discuss the pros and cons of doing this.

The short answer is you would need to add a GREP style to add a character style that consists of nothing but No Break to your chosen minimum number of characters. One expression that should work is .{N}$ where N is your desired number.

Translate
jmlevy
Community Expert
Community Expert
Dec 2, 2021 6:47 PM UTC

@Peter Spier if you look at the OP screenshot, the single letter (a e in its exemple) is not located at the end of a paragraph but at the end of a line, and AFAIK there is now way to choose “end of a line” using GREP. If it exists, I would love to know how!

Translate
Scott Falkner
Community Expert
Community Expert
Dec 4, 2021 1:36 AM UTC

You could apply no break to any single letter and space.

 

Below you can see I applied the style “No break” to the term. I added an underline to see where it is applied.

(?<=\s)[\l\u]\s

Translate
James Gifford—NitroPress
Legend
Dec 2, 2021 5:56 PM UTC

I don't think so, but that's because a single letter (usually a or I, in English) at the end of a line is not considered a wrapping fault. There's no demand for a rule to prevent it.

 

It's not a seamless fix, but I'd just use a hard space after that e and any like it (GREP or search/replace for all instances).

Translate