Essentially I would like to add a "sub-sub-label" to my compounds' numbering using chemnnum.

Why and how exactly I want this

I'm describing a series of chiral compounds, numbering them 1a, 1b, and so on. Sometimes I have also an another diastereomer of a compound: lets say 1b has epimerized in 2nd position - I would like to name it 2-epi-1b (supervisor's preference).

How I'm doing it now

Currently I'm just reusing existing references to 1b with bold prefix, like this: \textbf{2-epi-}\refcmpd{one.b}, but I find this to be not convinient and error-prone.

How I would like to do it

I was thinking about decreasing the appropriate sub-counter by 1 directly after first \cmpd{one.b} and immediately declaring an epimerized compound like this: \labelcmpd[pre-label-code=\textbf{2-epi-}]{one.b:epi}. Unfortunately, I've learned that there is no sub-counter, as chemnum stores current ID number of sub-label as an expl3 ints and I have no Idea how to interact with them.

The question(s)

Is it possible to manually decrease internal sub-label counter by 1 in chemnum? If yes, how to do it? Or maybe there is a better/alternative way to introduce a "sub-sub-label" to the numbering of my compounds?

1 Answer 1


After reading the source code of chemnum package and learning some expl3 programming, I've came up with a hacky way to do this. I've created a new command that defines a label (but does not print it, like \lebelcmpd), mimmicking a given label and sub label. The code:

\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}

This way I can provide different/additional options for what seems to be a previously used label. This method requires a new main label, because options are associated with main label and cannot be changed. The syntax is \sublabelcmpd[<options>]{<main ID>}{<sub ID>}{<new main ID>}, new compound can be then simply referenced with \cmpd{<new main ID>}{<sub ID>}. To give an example:

Compounds \cmpd{one.a} and \cmpd{one.b} are defined as usual.
Then a new compound is defined using
This newly defined compound will have the same label as \cmpd{one.b},
but with additional options, and can be referenced normally: \cmpd{epi:one.b}.

will produce:

Defining compound with sub sub label.

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.