Chemmacros 分配标签时出错

Chemmacros 分配标签时出错
    \documentclass[german=false,thesistype=master, nolistoffigures,
     nolistoftables]{tubsthesis}

     \usepackage{booktabs} 
     \usepackage{colortbl}
     \usepackage[nottoc]{tocbibind}
     \usepackage{enumitem}
     \usepackage[english]{babel}
     \usepackage{graphicx}
     \usepackage{subfigure}
     \usepackage{chemmacros,environ}

     % in older versions there is no \IfChemCompatibilityT
     \providecommand\IfChemCompatibilityT[3]{}

     % load the `reactions' module in newer versions:
     \IfChemCompatibilityT{>=}{5.0}{
     \usechemmodule{reactions}
      }

     % redefine the environments:
     \RenewEnviron{reaction}
     {\begin{equation}\expandafter\ch\expandafter{\BODY}\end{equation}}
     \RenewEnviron{reaction*}
     {\begin{equation*}\expandafter\ch\expandafter{\BODY}\end{equation*}}
     \RenewEnviron{reactions}
     {\begin{align}\expandafter\ch\expandafter{\BODY}\end{align}}
     \RenewEnviron{reactions*}
     {\begin{align*}\expandafter\ch\expandafter{\BODY}\end{align*}}
     %\usechemmodule{reactions}
     %\usepackage{cleveref}
    \chemsetup{modules={all}}
     \usepackage{longtable}
     \usepackage{tabu}
    \usepackage{siunitx}
     %%%%%%%%%%% Mathemodus
    \usepackage{amssymb}
    \usepackage{amsmath}
    \numberwithin{equation}{section}
    \usepackage[parfill]{parskip}
    \usepackage{romannum} 
    \usepackage{ragged2e,array,longtable}
   \usepackage{hyperref}
    \usepackage[%
    nonumberlist, % keine Seitenzahlen anzeigen
    automake,%
    xindy={language=german-din},% Sortiert Einträge im Verzeichnis
    acronym, % Abkürzungsverzeichnis erstellen
    nomain, % kein Glossar
    translate=babel,%
    nogroupskip,% Vertikaler Spalt
    toc,% Verlinkung im Inhaltsverzeichnis
    section=chapter,%
    ]{glossaries}

% Code were error occurs
 
 \underline{\parbox{\linewidth}{\textbf{Overall redox reaction}}}  
 \begin{reactions}     
16 Li + S8 &<=> 8 Li2S\label{reac:Overall} 
\intertext{\underline{\parbox{\linewidth}{\textbf{Anode reaction}}}} 
Li &<=> Li+ + e-\label{reac:Li}
\end{reactions}
\underline{\parbox{\linewidth}{\textbf{Cathode reactions}}} \begin{minipage}[t]{0.4\textwidth}
    \begin{center}
    \textit{Electrochemical reactions}\\    
    \end{center}
\begin{reactions}       
S8 + 2 e- &<=> S8^{2-} \label{reac:S82}
% 
S8^{2-} + 2 e- &<=> 2 S4^{2-} \label{reac:S42} \\   
S42^{2-} + 2 e- &<=> 2 S2^{2-} \label{reac:S22} \\
S22^{2-} + 2 e- &<=> 2 S2^{2-}\label{reac:S2}                   
\end{reactions} 
\end{minipage}%
 \begin{minipage}[t]{0.6\textwidth}
    \begin{center}
    \textit{Precipitation/dissolution reactions}\\  
    \end{center}
 \begin{reactions}
   S8 \lqd &<=> S8 \sld  \label{reac:S8s} \\
   2 Li+ + S2^{2-} \lqd &<=> Li2S2 \sld \label{reac:Li2S2} \\
   2 Li+ + S2- \lqd &<=> Li2S \sld    \label{reac:Li2S} \\
   Li2S2 \sld  + 2 Li+ + 2 e- \lqd &<=> 2 Li2S  \sld \label{reac:2_Li2S}  
\end{reactions} 
\end{minipage}  \\

...

不幸的是,小页面中的标签在编译时会出现错误:

'! Undefined control sequence.
<argument> reac:S\chemformula 
                              _subscript:n {8}\chemformula _subscript:n {2}
l.144 ...ral working principle}{equation.2.1.3}{}}'

我希望这足以说明我的问题(这是我在 Stack Exchange 上提出的第一个问题)当我注释掉 minipages 中的标签并仅保留前两个标签时,一切正常。即使不更改参考编号,问题也会出现。

答案1

您的代码可以简化为以下更短的示例,但在编译时仍会产生错误消息:

\documentclass{report}
\usepackage{chemmacros}
\chemsetup{modules={all}}

\begin{document}
  \begin{reactions}       
    S8 + 2 e-       &<=> S8^{2-}   \label{reac:S82}              
  \end{reactions} 
\end{document}

为了修复这个问题,\label用一组包围" ... "

\documentclass{report}
\usepackage{chemmacros}
\chemsetup{modules={all}}

\begin{document}
  \begin{reactions}       
    S8 + 2 e-       &<=> S8^{2-}   "\label{reac:S82}"              
  \end{reactions} 
\end{document}

另请参阅:手册的“8.转义输入”一节chemformula

将其应用到您的示例中,我们最终得到以下 MWE,它应该编译时不会出现错误消息:

\documentclass{report}

\usepackage{chemmacros}
\chemsetup{modules={all}}


\begin{document}
\noindent\underline{\parbox{\linewidth}{\textbf{Overall redox reaction}}}  
\begin{reactions}     
  16 Li + S8 &<=> 8 Li2S   \label{reac:Overall} 
  \intertext{\underline{\parbox{\linewidth}{\textbf{Anode reaction}}}} 
  Li         &<=> Li+ + e- \label{reac:Li}
\end{reactions}
\underline{\parbox{\linewidth}{\textbf{Cathode reactions}}}
\begin{minipage}[t]{0.4\textwidth}
  \centering
    \textit{Electrochemical reactions}
  \begin{reactions}       
    S8 + 2 e-       &<=> S8^{2-}   "\label{reac:S82}"\\
    S8^{2-} + 2 e-  &<=> 2 S4^{2-} "\label{reac:S42}" \\   
    S42^{2-} + 2 e- &<=> 2 S2^{2-} "\label{reac:S22}" \\
    S22^{2-} + 2 e- &<=> 2 S2^{2-} "\label{reac:S2}"                   
  \end{reactions} 
\end{minipage}%
\begin{minipage}[t]{0.6\textwidth}
  \centering
    \textit{Precipitation/dissolution reactions}
  \begin{reactions}
    S8 \lqd                           &<=> S8 \sld{}     "\label{reac:S8s}" \\
    2 Li+ + S2^{2-} \lqd              &<=> Li2S2 \sld{}  "\label{reac:Li2S2}" \\
    2 Li+ + S2- \lqd                  &<=> Li2S \sld{}   "\label{reac:Li2S}" \\
    Li2S2 \sld{}  + 2 Li+ + 2 e- \lqd &<=> 2 Li2S \sld{} "\label{reac:2_Li2S}"  
  \end{reactions} 
\end{minipage}  

\end{document}

相关内容