I'm trying to build a script to semi-automatically fix orphan words. To do that I need a way to write an auxiliary file that contains some data. The idea is to have a command like:

Wor\OrphansSpotter[keyword]{d W}ord.\n\n

The function of such a command should be to write a line:

keyword X Y

in an auxiliary file, where X is the line number (of the page?) of the first char in the command argument and Y is the line number of the last char in the command argument.

In my temporary modified .tex file I shoud have some occurrences of such a command and my final auxiliary file content should be something like:

keyword1 15 15
keyword2 20 21
keyword3 3 3
keyword4 11 12

Scanning this file, if X!=Y, I could run a query-replacement command, e.g.

"Word Word." --> "Word~Word."

in my text editor (emacs).

Unfortunately I have no idea how to do it (I mean the LaTeX stuff).

  • It could be that you want to modify really \parfillskip and \emergencystretch? This not analyze in any way which word is, but can avoid last lines with less of X % of the test width, or even avoid incomplete lines of any length, like here.
    – Fran
    Mar 16 '20 at 18:18

I'm not sure what you mean by "orphan word". Is it the last word in a paragraph on a line by itself?

In 2007 I wrote a column in TUGboat describing how to adjust paragraph shapes among which was one whereby the last line was "not too short" which may answer your problem. See https://tug.org/TUGboat/tb28-2/tb89glister.pdf

  • Yes, Your "orphan word" definition matches what I mean. Unfortunately I need to fix orphans in the way I described above. I'm not allowed to redefine LaTeX settings (or define new ones). Mar 15 '20 at 18:19
  • @GabrieleNicolardi How strange you are not allowed to alter your LaTeX code. Why not just hand edit your document? It seems to me that you will want to use \OrphanSpotter on the last word in every paragraph. Why not just read the printed output to spot any orphans and adjust your text appropriately? Mar 15 '20 at 18:51
  • It'a complicated... I'm not an author but an editor and my boss does not allow me to do certain things on the LaTeX code. I indeed want to use \OrphanSpotter on the last word in every paragraph. But not manually. I'm very goog with emacs-lisp and regular expressions. I'm always looking for ways to do my job faster. Mar 15 '20 at 19:04
  • Obviously, in the and I will read the printed output and adjust text appropriately, but i'm trying to reduce manual interventions. Mar 15 '20 at 19:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.