14

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

0

2 Answers 2

9

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

6
  • 1
    What if I don't want the hyphen?
    – Sverre
    May 20, 2014 at 17:02
  • 2
    @Sverre change \- to \linebreak[0] :-) May 20, 2014 at 17:06
  • 3
    @Sverre You do want the hyphen. ;-)
    – egreg
    May 20, 2014 at 17:09
  • 1
    No I don't: Leipzig glossing rules :)
    – Sverre
    May 20, 2014 at 17:12
  • 1
    Hyphen and period mean two different things in this tradition, so that's just the way it is ...
    – Sverre
    May 20, 2014 at 17:41
15

LaTeX will normally break after a full stop (at the space). If you have a specialist use where there is no following space one easy way is to use url package and

\url{f.dat.sg.indef}

or by hand

f.\linebreak[0]dat.\linebreak[0]sg.\linebreak[0]indef}
4
  • What does the [0] after \linebreak do?
    – Sverre
    May 20, 2014 at 16:43
  • 1
    It allows a break without saying it's good or bad (\penalty0 in plain) the option can be 0 to 4 where 4 is the default and forces a break May 20, 2014 at 16:54
  • Both answers are equally acceptable, but I like the \gloss macron defined by egreg.
    – Sverre
    May 21, 2014 at 14:03
  • @Sverre oh no, not to egreg that's a disaster:-) May 21, 2014 at 14:44

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .