# Babel fails to hyphenate when the word contains periods

babel can hyphenate disputas:

\documentclass{article}
\usepackage[nynorsk]{babel}
\begin{document}
\parbox{0pt}{\hspace{0pt}disputas}
\end{document}


But it fails when the word contains a period:

\documentclass{article}
\usepackage[nynorsk]{babel}
\begin{document}
\parbox{0pt}{\hspace{0pt}Dr.-disputas}
\end{document}


Why, and how can I fix it?

• The period, in this case, is completely irrelevant. Words containing an explicit hyphen are only possibly broken at the hyphen. Use "- instead of - – egreg Aug 31 '15 at 17:06
• @egreg If the period is completely irrelvant, then why can't babel hyphenate Dr.disputas at all? – Sverre Aug 31 '15 at 17:07
• The case of Dr.disputas is completely different. – egreg Aug 31 '15 at 17:07
• @egreg Well, maybe, but then you see why I would think it was the period that prevented the hyphenation. – Sverre Aug 31 '15 at 17:08
• @egreg So there's no way to hyphenate Dr.-disputas? I tried \babelhyphenation{Dr.-dis-pu-tas}, but that throws an error. I can easily imagine a German word like un-<really long German compound word>, and I'd hate to think that babel has no way of hyphenating the compound. – Sverre Aug 31 '15 at 17:11

If you want to allow hyphenation in a word which already has a hyphen you can use in your language (as I can do it in german) "=

\documentclass{article}
\usepackage[nynorsk]{babel}

\begin{document}
\parbox{0pt}{Dr."=disputas}
\end{document}


• What's with the extra blank line? – Sverre Aug 31 '15 at 17:17
• Unfortunately this doesn't work, because my word Dr.-disputas is in my .bib file. Putting "= there results in syntax error: found "=", expected end of entry ("}" or ")") when I run biber. – Sverre Aug 31 '15 at 17:21
• @Sverre instead of the shorthand "= you can also use babel's explizit macro: Dr.\babelhyphen{hard}disputas. – cgnieder Aug 31 '15 at 17:23
• In bib-files you can use the biblatex command \hyphen, see the documentation of biblatex. And the blank like is because of the 0pt-box. – Ulrike Fischer Aug 31 '15 at 17:25
• Ok, both \babelhyphen{hard} and \biblatex's \hyphen seem to do what I want. Any reason to prefer one over the other? – Sverre Aug 31 '15 at 17:30

The cases of Dr.-disputas and Dr.disputas are completely different. An explicit hyphen makes TeX break the chunk only at it, ignoring hyphenation patterns in the rest of the word parts.

With babel for Norsk or Nynorsk you can use "- that allows hyphenation past the hyphen.

When Dr.disputas is considered, the general rule for hyphenation enters: it is explained on page 254 of the TeXbook, second doubly dangerous paragraph.

TeX looks for potentially hyphenatable words by searching ahead from each glue item that is not in a math formula. The search bypasses charac- ters whose \lccode is zero, or ligatures that begin with such characters; it also bypasses whatsits and implicit kern items, i.e., kerns that were inserted by TeX itself because of information stored with the font. If the search finds a character with nonzero \lccode, or if it finds a ligature that begins with such a character, that character is called the starting letter. But if any other type of item occurs before a suitable starting letter is found, hyphenation is abandoned (until after the next glue item).

So D is the starting letter and hyphenation is tried on Dr, because the zero \lccode of the period ends the trial word; of course Dr can't be hyphened. There's no glue, so .disputas is not good for hyphenation. Indeed,

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[nynorsk]{babel}

\begin{document}

\parbox{0pt}{
\hspace{0pt}disputas.disputas
}

\end{document}


gives

You can use the shorthand "" in this case:

\documentclass{article}
\usepackage[T1]{fontenc}
\usepackage[nynorsk]{babel}

\begin{document}

\parbox{0pt}{
\hspace{0pt}disputas.""disputas
}

\end{document}


will give

• As I just pointed out in my comment to Ulrike's answer, this won't work for me now because the word that I need hyphenated is in my .bib file, and if I put in codes like "- or "=, biber throws an error. Should I open a separate question about this (if there is a solution)? – Sverre Aug 31 '15 at 17:24
• @Sverre Yes, this is indeed a different problem. – egreg Aug 31 '15 at 17:27
• @Sverre babel also has \babelhyphen{empty} as explizit form for "" – cgnieder Aug 31 '15 at 17:27

If using LuaLaTeX is an option for you, you may give the following code a try:

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage[nynorsk]{babel}
\begin{document}
\parbox{0pt}{Dr.-\hspace{0pt}disputas}
\end{document}


Note that Lua(La)TeX doesn't possess the well-known problem of pdf(La)TeX and Xe(La)TeX of not being able to hyphenate the first word of a paragraph.