One can define optimal hyphenation of a single word in the preamble of a LaTeX document that will be used if line length is awkward.

\hyphenation{biblio-philia} % Just an example

What if I wanted to be more general and define hyphenation for word parts:

% not real but imagined command:

Adding a discretionary hyphen to any word that ends with ophilia after the o?

  • 2
    no, you could define a pattern but (unless you are using luatex) that requires building a new format, you can't use \patterns in a normal document run (and tex patterns are not regex like that but you could match those characters at end of any word) – David Carlisle Oct 3 '18 at 14:32
  • Good to know! I'm actually using xelatex and not luatex. – snoram Oct 3 '18 at 14:34
  • The standard setting for American English hyphenates bib-lio-philia – egreg Oct 3 '18 at 17:30
  • @egreg right, I'm not working in English, it's just an abstract example. – snoram Oct 3 '18 at 17:33

You can see the effect of patterns using Luatex

Underfull \hbox (badness 10000) in paragraph at lines 8--8
[] \TU/lmr/m/n/10 bibliophilia bibliophilias thingophilia

Underfull \hbox (badness 10000) in paragraph at lines 13--13
[] \TU/lmr/m/n/10 biblio-philia bibliophilias thingophilia

Underfull \hbox (badness 10000) in paragraph at lines 18--18
[] \TU/lmr/m/n/10 biblio-philia bibliophilias thingo-philia

Underfull \hbox (badness 10000) in paragraph at lines 25--25
[] \TU/lmr/m/n/10 biblio-philia biblio-philias thingo-philia

which is the terminal output from

% don't use the default US English patterns as biblio-philia already allowed there
% which spoils the example


% nothing hyphenates
\showhyphens{bibliophilia bibliophilias thingophilia}


% just bibliophilia
\showhyphens{bibliophilia bibliophilias thingophilia}

\patterns{o9philia.}% tied to end of word

% bibliophilia and thingophilia hyphenate
\showhyphens{bibliophilia bibliophilias thingophilia}

\patterns{o9philia}% not tied to end of word

% all hyphenate 
\showhyphens{bibliophilia bibliophilias thingophilia}


Essentialy the same code would work with pdflatex or xelatex but you would have to modify the language files and build new formats with initex, you can not use \patterns in a normal tex run with classic tex.


If you're free to switch from XeLaTeX to LuaLaTeX, it's straightforward to set up a Lua function that adds a discretionary hyphenation point in words that contain "ophilia". In fact, as the following example shows, one can easily generalize the function so that it treats all words that contain either the letter a or o followed by either philia or phobia.

The only constraint imposed by this approach on your document is that you mustn't create and employ macros that contain the following strings: aphilia, aphobia, ophilia, and/or ophobia. E.g., setting \newcommand{\agoraphobia}{zzz} or \newcommand{\arachnophilia}{yyy} will definitely throw an error message. Hopefully, though, this constraint isn't exactly binding. Incidentally, macros named \phobia, \philia, \AgoraPhobia, and/or \ArachnoPhilia, would be just fine...

enter image description here

function ophilia ( s )
   s = s:gsub ( "([ao])(philia)" , "%1\\-%2" ) 
   s = s:gsub ( "([ao])(phobia)" , "%1\\-%2" )
   return s
  "process_input_buffer", ophilia, "ophilia" )}}

%% just for this example:

bibliophilia cryptophilia necrophilia agoraphilia 
bibliophobia cryptophobia necrophobia agoraphobia 
  • but don't do \newcommand\agoraphilia {zzz} in that case:-) – David Carlisle Oct 3 '18 at 15:43
  • @DavidCarlisle - True, I hadn't considered this possibility for practical insanity. :-) I'll post an addendum to state explicitly that a person who employs the method shown above shouldn't create macros whose names contain [ao]philia or [ao]philia... – Mico Oct 3 '18 at 16:09
  • 1
    for the ending given command names are unlikely but a reader might be encouraged by success with that ending to make all words ending in tion hyphenate as -tion but then \section might not work too well..... – David Carlisle Oct 3 '18 at 16:12
  • @DavidCarlisle - Do you approve of the extra paragraph I added a minute ago? :-) – Mico Oct 3 '18 at 16:17
  • 1
    i even voted:-) – David Carlisle Oct 3 '18 at 16:20

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.