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.

10
  • 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. Sep 29, 2011 at 9: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. Sep 29, 2011 at 10:26
  • If you use LuaTeX, we could provide you a solution that forbids a line break before a comma.
    – topskip
    Sep 29, 2011 at 10:27
  • 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.) Sep 29, 2011 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, 2011 at 16:56

3 Answers 3

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.
4
  • Is there any equivalent for english texts?
    – barbaz
    Apr 11, 2014 at 11:49
  • @barbaz you should ask a new question
    – topskip
    Apr 11, 2014 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, 2014 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, 2014 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...

1
  • 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. Sep 29, 2011 at 9: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.

2
  • 2
    I would have thought that avoiding hyphenation in temperatur would be a good thing in this case...
    – Seamus
    Sep 29, 2011 at 9:34
  • @Seamus: indeed, two hyphens in a word is to be avoided I think.
    – raphink
    Sep 29, 2011 at 10:06

You must log in to answer this question.

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