# Weird new line using \cmpd from chemnum in long headingtitles

I have a problem using \cmpd in a heading, that is too long. For some weird reason, the compound number gets put on a new line, even though there is no need. I already have a workaround using ~, but this is not what I want. A little explanation: within \iupac{} you can add a possible breakpoint using \|. As you will see, the linebreak will be placed after (hydroxy), but the (1) will be put on a new line. I inserted two headings. The first is the one, giving me a headache, the second one is working fine. The fourth is the workaround.

Here is my (almost) MWE:

\documentclass[12pt,english]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[english]{babel} % Silbentrennung, etc.
\usepackage{chemnum} % provides \cmpd{Name.Sub}
\usepackage{chemmacros} % provides iupac and loads siunitx

\begin{document}

\subsection{\iupac{\tert\-Butyl 2\-((\S\-2,2\-dimethyl\-1,3\-dioxolan\-4\-yl)\|(hy\|droxy)\|methyl)\|acryl\|ate} (\cmpd{iPrtBuAcrylate})}

\subsection{\iupac{Sodium \S\-2,2\-dimethyl\-1,3\-dioxolane\-4\-carboxylate} (\cmpd{iPrCarboxylate})}

\subsection{\iupac{\tert\-Butyl 2\-((\S\-2,2\-dimethyl\-1,3\-dioxolan\-4\-yl)\|(hy\|droxy)\|methyl)\|acryl\|ate}~(\cmpd{iPrtBuAcrylate})}
Problematic subsection with a workaround.

\end{document}

• Unrelated comment: in headings you should use \cmpd+{<id>} in order to avoid that the numbering starts in the table of contents. – clemens Sep 19 '13 at 12:46
• It's curious that if you add at the end \|, the bad line break doesn't happen. However, this doesn't happen with article; the difference is that scrartcl uses raggedright section titles. – egreg Sep 19 '13 at 12:57
• @cgnieder actually, I am already using \cmpd+ in my document. I don't know why I took it out again. ;) Thanks for the advice though! @egreg this actually seems to be a simple workaround as well. Thanks! – basseur Sep 19 '13 at 19:10
• @cgnieder I remember: I took the + out, because it would have lead to empty parentheses in the MWE. :) – basseur Sep 19 '13 at 19:24
• @basseur yes, the + plus variant doesn't declare a label, it only refers to one. You'd have to declare it elsewhere then, e.g. somewhere in the text... – clemens Sep 19 '13 at 19:28

This has nothing to do with the chem macros. The default headings in scrartcl are set \raggedright via the command \raggedsection. Ragged right environments demonstrate the problem you have. One way around this is to use the ragged2e package and set \raggedsection to \RaggedRight:

\documentclass[12pt,english]{scrartcl}

\usepackage[T1]{fontenc}
\usepackage[english]{babel}
\usepackage{ragged2e}

\begin{document}

\subsection{Averylongword\-averylongwordaverylong\-wordaverylongwordavery\-long\-word X}

\begin{flushleft}
Averylongword\-averylongwordaverylong\-wordaverylongwordavery\-long\-word\-averylongwordaverylong\-wordaverylongwordavery\-long\-word X
\end{flushleft}

\let\raggedsection\RaggedRight

\subsection{Averylongword\-averylongwordaverylong\-wordaverylongwordavery\-long\-word X}

\end{document}

• Will this only affect the sectionheadings? What possibly bad repercussions are there to using this method? – basseur Sep 19 '13 at 20:03
• scrartcl introduces \raggedsection explicitly for use in sectioning headings and uses this code nowhere else. So this is the right command to customize. – Andrew Swann Sep 20 '13 at 9:24