[Tex/LaTex] Breakable period

line-breaking

LaTeX will not insert a line break before or after a period . I understand why you'd want to avoid line break before a period, since you'd otherwise get stranded periods at the end of sentences. I assume there are good reasons for not allowing breaks after a period also (perhaps to avoid splitting abbreviations such as e.g.)

But sometimes you do want to be able to break a line after a period, or at least allow the line to be broken at that juncture. In linguistics, for example, words in foreign languages are commonly glossed with the morphology explicitly explained with grammatical codes separated by periods without space, as in e.g. f.dat.sg.indef. In the following example, the line should be broken as 'f.dat.sg. - indef'.

Is there a way to use such "breakable periods" in LaTeX?

\documentclass{article}
\usepackage{lipsum}
\begin{document}
\lipsum[1]
Abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd ab `f.dat.sg.indef'.
\end{document}

enter image description here

Best Answer

A simple application of expl3:

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\gloss}{m}
 {
  \tl_set:Nn \l_tmpa_tl { #1 }
  \tl_replace_all:Nnn \l_tmpa_tl { . } { .\- }
  `\tl_use:N \l_tmpa_tl'
 }
\ExplSyntaxOff

\begin{document}

Abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd ab `f.dat.sg.indef'.

Abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd ab \gloss{f.dat.sg.indef}.

\end{document}

We just replace every period by .\- (with a discretionary hyphen).

enter image description here

If you have to obey to rules that don't care about the reader, then

\documentclass{article}

\usepackage{xparse}

\ExplSyntaxOn
\NewDocumentCommand{\gloss}{m}
 {
  \tl_set:Nn \l_tmpa_tl { #1 }
  \tl_replace_all:Nnn \l_tmpa_tl { . } { .\discretionary{}{}{} }
  `\tl_use:N \l_tmpa_tl'
 }
\ExplSyntaxOff

\begin{document}

Abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd abcd ab \gloss{f.dat.sg.indef}.

\end{document}

will do.

enter image description here

Related Question