在 chemnum 中加入第三級化合物差異?

在 chemnum 中加入第三級化合物差異?

本質上,我想使用 為我的化合物編號添加一個「子子標籤」chemnnum

我為什麼以及如何想要這個

我正在描述一系列手性化合物,並對它們進行編號1a,1b, 等等。有時我還有化合物的另一種非對映異構物:可以說1b差向異構化位於第二位 - 我想命名它2-外延-1b(主管的偏好)。

我現在是怎麼做的

目前我只是重用現有的引用1b使用粗體前綴,如下所示:\textbf{2-epi-}\refcmpd{one.b},但我發現這不方便且容易出錯。

我想怎樣做

我正在考慮在第一個之後直接將適當的子計數器減 1 \cmpd{one.b},並立即聲明一個差向異構化合物,如下所示:\labelcmpd[pre-label-code=\textbf{2-epi-}]{one.b:epi}。不幸的是,我了解到沒有子計數器,因為chemnum將子標籤的當前 ID 號碼儲存為expl3 ints 並且我不知道如何與它們互動。

問題

是否可以手動將內部子標籤計數器減少 1 英吋chemnum?如果是,該怎麼做?或者也許有更好/替代的方法來為我的化合物的編號引入“子子標籤”?

答案1

在閱讀了套件的源代碼chemnum並學習了一些expl3程式設計之後,我想出了一種巧妙的方法來做到這一點。我創建了一個新命令來定義標籤(但不列印它,如\lebelcmpd),模仿給定的標籤和子標籤。代碼:

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

這樣我就可以為以前使用過的標籤提供不同/附加的選項。此方法需要一個新的主標籤,因為選項與主標籤關聯且無法變更。語法是\sublabelcmpd[<options>]{<main ID>}{<sub ID>}{<new main ID>},然後可以簡單地引用新複合\cmpd{<new main ID>}{<sub ID>}。舉個例子:

Compounds \cmpd{one.a} and \cmpd{one.b} are defined as usual.
Then a new compound is defined using
\verb#\sublabelcmpd[pre-label-code=\textbf{2-epi-}]{one}{b}{epi:one}#.
\sublabelcmpd[pre-label-code=\textbf{2-epi-}]{one}{b}{epi:one}
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}.

將產生:

使用 sub 子標籤定義化合物。

相關內容