Remove one-letter word (orphans) from the end of line

In English an orphan is:

A paragraph-opening line that appears by itself at the bottom of a page or column, thus separated from the rest of the text

Thus, in English typography it is understood in the context of the whole paragraph. Single line of a new paragraph, left alone on the preceding page (before page break) is not allowed.

Polish language is more strict by that and “explores” an alternative (less known) definition of “orphan”. In Polish typography this term is understood in the context of single line and regarded as a:

Single word (single letter in most cases) left along at the end of line (next to right paragraph).

And similarly this is prohibited in Polish typesetting.

In this article you can find a Word macro for removing such orphans from your text.

The magic

There’s no magic feature or rule that can be applied here. The solution isn’t anything more than just a dully search and replace. Where each single letter (A, a, I, i, O, o, U, u, W, w, Z and z) is found and a regular space that follows it is replaced with non-breaking space.

This causes that single letter to be “glued” together with a word that follows it. If such single letter “lands” at the end of line, it is pushed to the next line, by the longer word that it is “glued” to.

For a very short text, you can obtain this manually:

  1. Read through your text, closely looking at a single characters by the end of line (next to right margin)
  2. Select each space that follows such single letter with Shift+
  3. Hit Ctrl+Shift+Space it replace it with a non-breaking space

For a longer blocks of text an automated solution is a must.

Microsoft Word macro

In Microsoft Word (example based on old Word 2010):

  1. Go to View tab → Macros frame and hit Macros button
  2. Put some name (i.e. OneLetterWordRemoval or OrphansRemoval into Marco name field
  3. Check, if Macros in field is set correctly (i.e. where you are creating your new macro)
  4. Hit Create button
  5. Paste following code and save the macro by hitting Ctrl+S or clicking Save button

The code to paste:

Sub OneLetterWordRemoval()
' OneLetterWordRemoval Macro
' Removes single letters (A, a, I, i, O, o, U, u, W, w, Z and z)
' from the end of each line by replacing simple space following
' each single letter with non-breakable space instead.
Dim sFind As String
Const cLets As String = "([AaIiOoUuWwZz]) "


With Selection.Find
    .Forward = True
    .Wrap = wdFindContinue
    .Format = False
    .MatchCase = False
    .MatchWholeWord = False
    .MatchWildcards = True
    .MatchSoundsLike = False
    .MatchAllWordForms = False
End With

sFind = " " & cLets

Selection.Find.Execute FindText:=sFind, _
ReplaceWith:=" \1^s", Replace:=wdReplaceAll

sFind = "^s" & cLets

Selection.Find.Execute FindText:=sFind, _
ReplaceWith:="^s\1^s", Replace:=wdReplaceAll
End Sub

Then save your file (see next part).

When later you open any document that contains your macro, you can again go to View tab → Macros frame and hit Macros button, then select OneLetterWordRemoval macro in the list and hit Run button.

A word about saving macros in Word

You can save your macro for either:

  • single usage (in .docm file — Macro-enabled Word Document) or
  • multiple usage (in .dotm file — Macro-enabled Word Template)

Note that this particular macro is “one-time runner”. You have your text, you process it one time to remove are single letters from the end of all line and you’re done. If you continue editing this text, you will most likely use manual method, described above, to avoid future “orphans”.

For this reason you don’t have to keep your text in .docm (macro-enabled document), a format which is considered a “risky” by many apps and services (since macros can contain viruses). Once you’re done with the automatic replacement, you can easily save your file as a regular document (.docx; macro-free document) and continue editing there.

Alternatively, you can:

  1. Open Microsoft Word with a blank document
  2. Add macro in the way described above, selecting Normal.dotm (global template) in Macros in:
  3. Save file in %APPDATA%\Microsoft\Templates as Normal.dotm template (overwriting original)

This is a little bit risky in some scenarios (you’re overwriting a global template after all). But as a result you will have your macro available in every Word document that you create, even those macro-free (.dotx).

You just have to make yourself sure that you are adding new macro to global template:

Note that there is a “shortcut” in thinking above. You can’t overwrite Normal.dotm file from Word, because this global template is locked (in use) when any copy of Microsoft Word is run. You have to instead:

  1. Save your macro in a different name (i.e. xxx.dotm)
  2. Close all copies of Word
  3. Delete original Normal.dotm file
  4. Rename xxx.dotm into new Normal.dotm
  5. Restart Word to see, if everything works.

This is the risky part.

Leave a Reply