Chemnum:与章节相关的编号?

Chemnum:与章节相关的编号?

首先,我刚开始使用 LaTeX。到目前为止,我一切都正常,包括chemnum

但是我想将论文分成几章。化合物的编号应该是 1.1、1.2、1.3 等。下一章将从 2.1、2.2、2.3 开始。

有没有办法做到这一点chemnum? 找不到任何内容。

答案1

补充 2014/03/14:

两天前,v1.0chemnum发布了。其中有各种变化。其中之一是内置了以下情况的可能性:

\documentclass{book}
\usepackage{chemnum}

\makeatletter
% new counter format for chemnum:
\newcmpdcounterformat{chapter}{\thechapter.\@arabic}
\makeatother

\setchemnum{
  counter-within = chapter ,
  counter-format = chapter % use new counter format
}

\begin{document}

\chapter{First}
\cmpd{a} and \cmpd{b}

\chapter{Second}
\cmpd{a} and \cmpd{c}

\end{document}

原始答案:

基于的临时解决方案Heiko 的回答

\documentclass{book}
\usepackage{chemnum}

\ExplSyntaxOn
\cs_new:Npn \int_to_chapter:n
  { \thechapter . \int_to_arabic:n }

% add the new choice to the options:
\keys_define:nn { chemnum }
  {
    cmpd-counter .generate_choices:n =
      { arabic , alph , Alph , greek, Greek , roman , Roman , Symbol , chapter }
  }
\ExplSyntaxOff

% choose the new option:
\cmpdsetup{cmpd-counter=chapter}

% reset counter every new chapter:    
\usepackage{etoolbox}
\preto\chapter{\cmpdreset}

\begin{document}

\chapter{First}
\cmpd{a} and \cmpd{b}

\chapter{Second}
\cmpd{a} and \cmpd{c}

\end{document}

答案2

添加章节编号的技巧:

\documentclass{book}
\usepackage{chemnum}

\begingroup
  \makeatletter
  \catcode`\_=11 %
  \catcode`\:=11 %
  \global\let\org@cmpd\cmpd
  \gdef\cmpd#1{%
    \begingroup
      \cmpdsetup{cmpd-counter=Symbol}%
      \def\int_to_Symbol:n{%
        \thechapter.\int_to_arabic:n
      }%
      \org@cmpd{#1}%
    \endgroup
  }%
  % reset numbers at chapters
\@firstofone{\endgroup
  \let\c@chemnum@counter\g__chemnum_cmpd_int
  \@addtoreset{chemnum@counter}{chapter}%
}
\endgroup

\begin{document}
\chapter{First}
\cmpd{a} and \cmpd{b}
\chapter{Second}
\cmpd{a} and \cmpd{c}
\end{document}

结果:

第1章:1.11.2
第2章:1.12.1

相关内容