What I want is the ability to label things like: \cmpd{ln.eu.six} and get 10Eu.6H2O.

I've got the first part working., but chemnum out of the box only supports one level of sublabels.

There is a previous answer, but I don't understand it's code. I've got it partially working, but need help getting it the rest of the way (and, honestly, I have no idea if this is the best way to do this)

It gives a (self-described) hacky way to add a third level of sublabels to a compound, which is what I need. However, admit I don't understand what the code is doing, and thus I can't get it to work with my existing code to allow for a custom numbering scheme: Is it possible to adapt this?

MNEW example:


\int_new:N \l__chemnum_tmpnum_int

% #1: options, #2: main ID, #3: sub ID, #4: new main ID
\NewDocumentCommand {\sublabelcmpd} {O{ }mmm} {
    % stash main counter value
    \int_set:Nn \l__chemnum_tmpnum_int {\value{cmpdmain}}
    % set main counter, that it will produce #2 label again
    \setcounter {cmpdmain} {\int_eval:n {\cmpdproperty{#2}{number}-1}}
    % define new compound disguised as #2 with dummy sub compound
    \chemnum_cmpd:nnnn {\c_true_bool} {\c_false_bool} {#1} {#4.subundefined}
    % set sub counter to produce desired sub label #3
    \int_set:cn {g__chemnum_compound_#4_subcompound_int} {\subcmpdproperty{#2}{#3}{number}-1}
    % define new sub compound disguised as #2.#3
    \chemnum_cmpd:nnnn {\c_true_bool} {\c_false_bool} {#1} {#4.#3}
    % revert previous main counter state
    \setcounter {cmpdmain} {\l__chemnum_tmpnum_int}


\cs_new:Npn \canageek_int_to_lanthanide:n #1
    \int_to_symbols:nnn {#1} { 2 }
        { 1 } { La }
        { 2 } { Ce }


\cmpd{one.la} and \cmpd{one.ce}

\sublabelcmpd[post-label-code=\ch{. 6 H2O}]{one}{La}{6:one}

This newly defined compound will have the same label as \cmpd{one.la},
but with additional options, and can be referenced normally: \cmpd{6:one.la}



Output: When the second row of sublabels are used, it moves from 1La to 1a

Edit: I'm open to doing this alternate ways. I focused on this so that everything would be within one mechanism and I'd have a standard way of doing things. I could do something like \refcmpd{lnwater.eu}\ch{. 6 H2O} but I'm worried about adding spaces between the two by accident, and the formatting between the first and second parts being different (I've already got an issue in the MWE of the hydrate part not being in bold while the name is).

1 Answer 1


I just realized I was making things far too complicated, and that \newcommand\lnhydr[2]{\refcmpd{lnwater.{#1}}\textbf{\ch{. #2 H2O}}} will actually do everything I need it to, I don't need to use chemnum for this.

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.