5

EDIT (supplement): the behaviour is the same within all use-cases (environment as well as \ch command) provided by the chemmacros package.

In a chemmacros reactions environment I tried to switch from the "to" or in German "bis" to just a "--" for the \SIrange-given temperature range on top of a reaction arrow.

with loaded

\usepackage{chemmacros}
                 % includes \usepackage{chemformula}
\usechemmodule{all}
                
\chemsetup{
                %
    language=auto,
                %
    charges/circled = all,
                %
    redox/parse = false,
                %
    redox/pos = top,
                %
    formula=chemformula
                %
}

I tried

\begin{reactions}
        A &->[\SI{200}{\degreeCelsius}] C+ 3 C ^ \\
    2 D + C &->[\SIrange[range-units=single,range-phrase = -- ]{200}{300}{\degreeCelsius}] 2 E ^ + F
\end{reactions}

and get a bunch of errors. The first one is "Package siunitx Error: Unknown option 'range-phrase\tl_use:N" without a line-number, followed by "Package siunitx Error: Invalid token '\chemformula ' in numerical input. \end" and "Package siunitx Error: Invalid numerical input '\chemformula_subscript:n(siunitx) {0}\chemformula_subscript:n {0}'. \end" referring the line of "\end{reactions}". The following are mostly referring to missing or to much "}".

So I tried with the same result

\begin{reactions}
    \sisetup{
        range-units=single,
        range-phrase = -- , 
    } %
    A &->[\SI{200}{\degreeCelsius}] C+ 3 C ^ \\
    2 D + C &->[\SIrange{200}{300}{\degreeCelsius}] 2 E ^ + F
\end{reactions}

Without the

range-phrase = -- ,

option statement everything runs smoothly, in both cases.

Maybe it's only a typo ? But range-phrase is looked up with the manual of siunitx. Hence I'm wondering on the first errors statement ("Unknown option 'range-phrase")

EDIT (supplement): Tried in equation – and eqnarray – environment: same situation.

The environment used is the actual MikTex.

Any ideas how to set that range-phrase option ?

EDIT (supplement): Liked to an issue on chemmacros github.

6
  • Did you already try using the \sisetup outside of the reactions environment? { \sisetup{ range-units=single, range-phrase = {--} , } % \begin{reactions} A &->[\SI{200}{\degreeCelsius}] C+ 3 C ^ \\ 2 D + C &->[\SIrange{200}{300}{\degreeCelsius}] 2 E ^ + F \end{reactions} }
    – leandriis
    Jun 25, 2020 at 7:39
  • No, I didn't. Tried now. That has results like expected. But then the change is active outside the environment as well... So I would have to set it back to default after the environment, but what is default, that way that it is respects the language settings? And why is range-units=single working inside properly ?
    – Henning
    Jun 25, 2020 at 8:52
  • If you surround the sisetup and the corresponding reactions command with a set of {} as I did in my comment, the sisetup is local to the part in {}, so no need to reset it later.
    – leandriis
    Jun 25, 2020 at 9:09
  • Thanks @leandriis. Good idea. Could have come up with it myself ;-).
    – Henning
    Jun 25, 2020 at 9:14
  • (Almost) every input inside of a reaction environment behaves as if it was input directly into \ch{}.
    – cgnieder
    Jun 25, 2020 at 10:12

1 Answer 1

4

Let's see, where the problem is. Almost everything inside a reactions environment acts the same as if it were put directly into chemformula's \ch. (Almost because things like & or \\ need to work differently here…). Now let's look at the following example:

\documentclass{article}
\usepackage{chemformula}
\begin{document}

\ch{A -- B}

\end{document}

enter image description here

This seems surprising unless you think about it: chemformula splits this into three pieces: A, --, and B. None of these match special input so they're all treated as compounds. Inside a compound - is replaced with a single bond unless it is superscripted. A trailing - is treated as if it were superscripted. This is to allow the following input:

\ch{CH3-CH2-O-}

which gives

enter image description here

And the same happens with an input like

\ch{\SIrange[range-phrase= -- ]{10}{20}{\celsius}}

\ch sees three compounds: \SIrange[range-phrase=, --, and ]{10}{20}{\celsius}. You probably see now why this leads to errors. Even worse here: the numbers are treated as subscripts just like the number in \ch{H2O}

Long story short: if you don't want something to be parsed as formula you need to tell chemformula about it! It has an escape mechanism for this – "...":

\documentclass{article}
\usepackage{chemformula,siunitx}
\begin{document}

\ch{A ->[ "\SIrange[range-phrase=--]{10}{20}{\celsius}" ] B}

\end{document}

enter image description here

So what about this:

\documentclass{article}

\usepackage{chemmacros}
\chemsetup{modules={reactions,units}}

\begin{document}

\begin{reactions}
  "\sisetup{range-units=single,range-phrase=--}"
  A &->[\SI{200}{\celsius}] C + 3 C ^ \\
  2 D + C &->[\SIrange{200}{300}{\celsius}] 2 E ^ + F
\end{reactions}
  
\end{document}

Well it compiles but it doesn't give the desired output. Why? Because reactions is align underneath and align is just a sophisticated kind of tabular. All of them have in common that single table cells form a group. And since \sisetup assignments are local they are forgotten after the next & or \\.

The simplest solution in your case is

\documentclass{article}

\usepackage{chemmacros}
\chemsetup{modules={reactions,units}}

\begin{document}

\begin{reactions}
  A &->[ "\SI{200}{\celsius}" ] C + 3 C ^ \\
  2 D + C
    &->[ "\SIrange[range-units=single,range-phrase=--]{200}{300}{\celsius}" ]
    2 E ^ + F
\end{reactions}
  
\end{document}

enter image description here

4
  • Thanks for the detailed explanation. And the hint to the solution.
    – Henning
    Jun 25, 2020 at 16:30
  • @Henning you're welcome
    – cgnieder
    Jun 25, 2020 at 16:33
  • Thanks as well for improving the question.
    – Henning
    Jun 25, 2020 at 16:36
  • Something is still strange:in a reactions-environment another similar \SIrange- Command :A + B &->[ "\SIrange[range-units=single,range-phrase={~--~}]{20}{30}{\celsius}" ] C + D causes Errors:"Package siunitx Error: Unknown option 'range\chemformula_single_bond:(siunitx) units\chemformula_double_bond: single'. \end" and "Package siunitx Error: Unknown option 'range\chemformula_single_bond:". As I puzzled out, the {...} in the range-phrase option is the root of the evil. range-phrase=\ --\ is without errors. Outside the environment both versions are o.k.
    – Henning
    Jun 25, 2020 at 19:59

You must log in to answer this question.

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