37

I just had a problem with a linebreak after a word ending with a hyphen which was followed by a comma.

This example shows the problem:
(The example is constructed, but this just occurred to me in a real text!)

    \documentclass[11pt, a4paper]{scrartcl}

\usepackage[ngerman]{babel}

\begin{document}

aaDas ist ein Absatz. Das ist ein Absatz. Das ist ein Absatz. Es gibt zeit-, temperatur-,  und weggesteuerte Verfahren ein Absatz. Das ist ein Absatz.Das ist ein Absatz. Das ist ein Absatz.Das ist ein Absatz. Das ist ein Absatz.Das ist ein Absatz. Das ist ein Absatz.Das ist ein Absatz. Das ist ein Absatz.

    \end{document}

example image

As I can not imagine any scenario where a comma at the beginning of a line could make sense, I wonder how I could tell LaTeX to absolutely avoid that.

  • 2
    The problem, I suspect, is not so much with the comma as with the hyphen. There should be some way of producing a hyphen without TeX interpreting it as a valid place to break a word across a line. – Niel de Beaudrap Sep 29 '11 at 09:58
  • @NieldeBeaudrap: you're absolutely right. I just put it this way, as IMHO a comma should be never typeset at the beginning of a line, at least I could not imagine a case that makes sense at the moment. – MostlyHarmless Sep 29 '11 at 10:26
  • If you use LuaTeX, we could provide you a solution that forbids a line break before a comma. – topskip Sep 29 '11 at 10:27
  • @Patrick: I'm using the "normal" pdflatex - so I'm afraid this is not an option (at least for me). – MostlyHarmless Sep 29 '11 at 10:29
  • 4
    Notice that this is incorrect punctuation. In German, there is no comma before “und” in enumerations. (Unless they changed that with the Rechtschreibreform but I doubt that.) – Konrad Rudolph Sep 29 '11 at 15:52
  • 2
    @KonradRudolph While it's true that the comma is incorrect before "und", this is unrelated to OP's LaTeX problem. – Jan Sep 29 '11 at 16:56
  • @Jan Oh, absolutely. I just wanted to point it out because we’re here on tex.sx where people usually care about typography and punctuation, and because I’m a know-it-all. ;-) – Konrad Rudolph Sep 29 '11 at 17:07
  • @KonradRudolph: you're absolutely right that the comma before "und" is not correct, however without the "und" my example did not work and I did not have the time to create a gramatically perfect sentence which was also useful to demonstrate the problem. :-) – MostlyHarmless Sep 29 '11 at 19:13
  • @topskip The LuaTeX solution would be very interesting, Should I open a new question for it? – georgd Sep 21 '15 at 11:14
  • @georgd yes, please do so, although I cannot guarantee anything. – topskip Sep 21 '15 at 15:15

3 Answers3

28

You should use "~ for that. See the documentation for babel (texdoc babel).

aaDas ist ein Absatz. Das ist ein Absatz. Das ist ein Absatz. Es gibt zeit"~, temperatur"~, und weggesteuerte Verfahren ein Absatz.
Das ist ein Absatz.Das ist ein Absatz. Das ist ein Absatz.Das ist ein Absatz. Das ist ein Absatz.Das ist ein Absatz. Das ist ein
Absatz.Das ist ein Absatz. Das ist ein Absatz.
topskip
  • 37,020
  • Is there any equivalent for english texts? – barbaz Apr 11 '14 at 11:49
  • @barbaz you should ask a new question – topskip Apr 11 '14 at 16:00
  • well it would be pretty much the same question - since the questioner didn't restrict his problem to german documents in any way. Just the example texts are in german. Also your answer should mention that it works only for [german]{babel} (and a few other languages, however, not english) – barbaz Apr 13 '14 at 16:23
  • @barbaz The implicit restriction is set by the option ngerman to the package babel. Feel free to edit my question! – topskip Apr 13 '14 at 16:25
5

Enclosing the offending word in an \mbox works:

\mbox{temperatur-,}

I assume there is a neater way if there are lots of these hyphens where you don't want to allow breaks...

Seamus
  • 73,242
  • 2
    thanks - as you're writing, this is a one-time-workaround. However as I consider this (=comma at beginning of line) a total no-go, it should be just "forbidden" globally, IMHO. – MostlyHarmless Sep 29 '11 at 09:51
5

Use my macro \nobreakseq

\def \nobreakseq {\nobreak \hskip 0pt \hbox}

Es gibt zeit\nobreakseq{-,} temperatur\nobreakseq{-,}  und weggesteuerte Verfahren ein Absatz.

It is better than \hbox{temperatur-,} or \mbox{temperatur-,} beacuse of \hbox{temperatur-,} does not allow any hyphenation.