6

I am using chemmacros in my thesis and have the following problem:

When using \mbox{} within \iupac{} in a \section{} or \subsection{} it leads to "@x " being printed in the running title. Also, the following error messages are produced:

Undefined control sequence. \end{document}
Missing number, treated as zero. \end{document}

However, \mbox{} works fine outside of \iupac{} without any error messages.

Here is my MWE:

\documentclass[twoside,open=right]{scrreprt}

\usepackage[automark]{scrpage2}
\pagestyle{scrheadings}

\usepackage{chemmacros}

\begin{document}
    \section{It works fine here: awe\mbox{-}some}
    \cleardoublepage
    \section{It does not work here: \iupac{2,2,6,6\mbox{-}Tetramethylpiperidine}}
\end{document}

Why is this so important? Compound names should never have a linebreak after numbers. However, in my thesis there are some very long names that are sometimes split like this:

... 1,1'-
biphenyl ...

I appreciate your help!

Kind regards,
basseur

  • 1
    “Compound names should never have a linebreak after numbers.” is this your opinion or is this a IUPAC recommendation (source?) – clemens Oct 3 '17 at 12:11
  • @clemens I am quite certain I read it somewhere back in 2014, but of course, I cannot find it anymore. So let's call it my own opinion. ;) I came across this IUPAC project. Since there is no visible progress, I have mailed the task group leader. – basseur Oct 3 '17 at 13:22
  • I have actually received an answer and could forward it to your email address. It is quite interesting stuff and basically supports what I said. – basseur Oct 3 '17 at 14:18
5

While \mbox is not usually considered to be fragile, in this context it is, due to the processing done by \iupac.

You might use \protect\mbox{-}, but I wouldn't recommend it. Rather define a new macro for this hyphen:

\documentclass[twoside,open=right]{scrreprt}

\usepackage[automark]{scrpage2}
\pagestyle{scrheadings}

\usepackage{chemmacros}

\NewDocumentCommand{\nbh}{}{\mbox{-}\nobreak\hspace{0pt}}

\begin{document}

\section{It works here: \iupac{2,2,6,6\protect\mbox{-}Tetramethylpiperidine}}

\section{It works here: \iupac{2,2,6,6\nbh Tetramethylpiperidine}}

\parbox[t]{0pt}{It works here: \iupac{2,2,6,6\protect\mbox{-}Tetramethylpiperidine}}
\hfill
\parbox[t]{0pt}{It works here: \iupac{2,2,6,6\nbh Tetramethylpiperidine}}
\hfill\mbox{}

\end{document}

As you see from the zero width boxes (to force hyphenation at all feasible points), the \mbox{-} will not allow breaks after it, whereas \nbh does.

enter image description here

As the package author suggests, one can also add a shorthand:

\NewChemIUPACShorthand{=}{\nbh}

that allows to input the compound as 2,2,2,6=Tetramethylpiperidine.

Full example:

\documentclass[twoside,open=right]{scrreprt}

\usepackage[automark]{scrpage2}
\pagestyle{scrheadings}

\usepackage{chemmacros}

\NewDocumentCommand{\nbh}{}{\mbox{-}\nobreak\hspace{0pt}}
\NewChemIUPACShorthand{=}{\nbh}

\begin{document}

\section{It works here: \iupac{2,2,6,6=Tetramethylpiperidine}}

\parbox[t]{0pt}{It works here: \iupac{2,2,6,6=Tetramethylpiperidine}}

\end{document}

enter image description here

  • 2
    And maybe even \NewChemIUPACShorthand={\nbh} and then \iupac{2,2,6,6=Tetramethylpiperidine} (or similar) – clemens Oct 3 '17 at 12:16
  • @clemens That's great. The feature request stands. ;-) – egreg Oct 3 '17 at 12:17
  • I'll add something to the next release – clemens Oct 3 '17 at 12:29
  • 1
    @basseur This should be raised on the GitHub site for chemmacros: github.com/cgnieder/chemmacros – egreg Oct 3 '17 at 13:51
  • 1
    @basseur Maybe adding the source code would be better. – egreg Oct 3 '17 at 14:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.