2

Is there a command in the chemnum package that allows labels for a compound to be explicitly defined (for example, if I explicitly wanted a compound to be called A3 or another string), similar to the command \declarecompound in the chemcompounds package? In a different question the package author said that this was possible but I have not been able to find it in the most recent documentation.

3

It is possible with a little effort:

\documentclass{article}
\usepackage{chemnum}

\makeatletter
\newcmpdcounterformat{gobble}{\@gobble}
\makeatother

\begin{document}

\cmpd{foo1},
\cmpd{foo1}

\cmpd[pre-label-code=xx,post-label-code=yy]{foo2},
\cmpd{foo2}

\cmpd[pre-label-code=aa,post-label-code=bb,counter-format=gobble]{foo3},
\cmpd{foo3}

\cmpd{foo4},
\cmpd{foo4}

\cmpd{foo1,foo2,foo3,foo4}

\end{document}

enter image description here

In this workaround the actual label is empty and the pre- and post-code are used as label.


With an up to date version of chemnum (v1.2 2016/04/14 – should be available on CTAN already) a more direct way is possible:

\documentclass{article}
\usepackage{chemnum}[2016/04/14]

\ExplSyntaxOn
% this only works for main labels!
\NewDocumentCommand \declarecmpd {O{}mm}
  {
    \chemnum_compound_if_defined:nF {#2}
      { \chemnum_define_compound:n {#2} }
    \chemnum_compound_set_property:nnn {#2} {counter-representation} {#3}
    \chemnum_declare_compound:nn {#1} {#2}
    \chemnum_finalize_compound:n {#2}
  }
\ExplSyntaxOff

\begin{document}

\cmpd{foo1}

\cmpd+{foo2}

\declarecmpd{foo2}{AA}

\cmpd{foo1,foo2}

\end{document}

enter image description here

  • Thank you for the help! However, this seems unusually difficult. Given that chemnum seems to be an overall improvement over chemcompounds, was there a reason why you chose to forgo writing a new command to replace \declarecompound? – Bob Apr 11 '16 at 10:58
  • @Anthony chemnum exists since March 2014 and I can't remember that anyone ever wanted or needed the feature – it just didn't seem necessary. – clemens Apr 11 '16 at 11:04
  • Occasionally I find \declarecompound useful when I need a compound label to match some existing reports (perhaps a single 'A' label outside of a main sequence of Arabic numerals) or would like the label to be an abbreviation or acronym specific to a compound (such as when I would like a compound to be called ATP rather than just a numeral), though I do understand if others may mostly find it unnecessary. – Bob Apr 11 '16 at 11:11
  • I've wrapped it up into an xparse/LaTeX3 command in case I might need it again, though others may find it useful: % Defining compound labels \makeatletter \newcmpdcounterformat{gobble}{\@gobble} \makeatother \NewDocumentCommand{\declarecmpd}{om}{ \IfNoValueTF{#1} {\cmpd*{#2}} {\cmpd*[pre-label-code=#1,counter-format=gobble]{#2}} } – Bob Apr 11 '16 at 11:13
  • @Anthony I've added a second way which probably suits your needs better. – clemens Apr 11 '16 at 11:32

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.