# Line Break with mhchem

I use the mhchem package for setting chemical formulas. In some occasions the formula just hangs over the end of the line. Is there any solution to fix this?

Für die Abscheidung von \ce{Al2O3} werden als Reaktionsmittel Trimethylaluminium (\ce{C6H18Al2}) und Wasser (\ce{H2O}) verwendet.

The result looks like this:

This is a job for sloppypar. The first paragraph doesn't have it, the 2nd does.

The downside of "sloppy" is excessive inter-word space on the 1st line of the 2nd paragraph.

\documentclass{article}
\textwidth 5.5in
\usepackage{mhchem,lipsum}
\begin{document}
Für die Abscheidung von \ce{Al2O3} werden als Reaktionsmittel Trimethylaluminium (\ce{C6H18Al2}) und Wasser (\ce{H2O}) verwendet. \lipsum[1]

\begin{sloppypar}
Für die Abscheidung von \ce{Al2O3} werden als Reaktionsmittel Trimethylaluminium (\ce{C6H18Al2}) und Wasser (\ce{H2O}) verwendet. \lipsum[1]
\end{sloppypar}
\end{document}

# Rewording

I'm not sure what you want LaTeX to do. Ideally, you would reword the text so that LaTeX would be able to properly justify the text.

## Why the Formula Hangs Over

The fact that LaTeX allowed the formula to hang over the right margin indicates that it was not able to find a way to fit the formula into the text the way it was worded; it is impossible for LaTeX to properly typeset the text without breaking typographical specifications.

Logically, the formula (\ce{C6H18Al2}) is either (case 1) forced on the first (printed) line or (case 2) allowed to move to the second printed line. Case 1: If (\ce{C6H18Al2}) is on the first line, then there isn't enough room to fit all the material in the line, so (\ce{C6H18Al2}) must hang over. Case 2: If (\ce{C6H18Al2}) is on the second line, then the first line doesn't have enough words to fill the entire line (putting only Für die Abscheidung von \ce{Al2O3} werden als Reaktionsmittel Trimethylaluminium on a single line would cause too much space between the words with full justification.)

# Forcing a Line Break

The other option, which is not typographically preferable, is to force a line break and allow LaTeX to justify the text before the line. Note that this will lead to excessive spacing between the words. The \linebreak command accomplishes this (it causes the line to be stretched accordingly).

\documentclass[11pt]{article}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{amsmath,amssymb}
\usepackage{mhchem}
\usepackage{geometry}

\begin{document}
Für die Abscheidung von \ce{Al2O3} werden als Reaktionsmittel Trimethylaluminium
\linebreak (\ce{C6H18Al2}) und Wasser (\ce{H2O}) verwendet. Das Trägergas für die
Reaktionsmittel ist Distickstoffmonoxid (\ce{N2O}). Der Abscheidungsprozess kann
in vier Schritte eingeteilt werden.
\end{document}