summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/chemnum/chemnum.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2014-03-12 22:33:13 +0000
committerKarl Berry <karl@freefriends.org>2014-03-12 22:33:13 +0000
commit4c7bf2d42fecbd952b9d701396503f6374d14835 (patch)
tree347b9ec38e8951e3825eeab1d8a53cf9ebaf5dd6 /Master/texmf-dist/tex/latex/chemnum/chemnum.sty
parent44df6d09616942cb3a83276fba2978bc9cdee561 (diff)
chemnum (12mar14)
git-svn-id: svn://tug.org/texlive/trunk@33161 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/chemnum/chemnum.sty')
-rw-r--r--Master/texmf-dist/tex/latex/chemnum/chemnum.sty3101
1 files changed, 1677 insertions, 1424 deletions
diff --git a/Master/texmf-dist/tex/latex/chemnum/chemnum.sty b/Master/texmf-dist/tex/latex/chemnum/chemnum.sty
index af6e6c07c8f..39578d42ec5 100644
--- a/Master/texmf-dist/tex/latex/chemnum/chemnum.sty
+++ b/Master/texmf-dist/tex/latex/chemnum/chemnum.sty
@@ -1,1389 +1,1669 @@
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% - chemnum - chemnum.sty
-% - a comprehensive approach for the numbering of chemical compounds
-% -----------------------------------------------------------------------------
-% - Clemens NIEDERBERGER
-% - contact@mychemistry.eu
-% -----------------------------------------------------------------------------
-% - If you have any ideas, questions, suggestions or bugs to report, please
-% - feel free to contact me.
-% -----------------------------------------------------------------------------
-% - Copyright 2011-2013 Clemens Niederberger
-% -
-% - This work may be distributed and/or modified under the
-% - conditions of the LaTeX Project Public License, either version 1.3
-% - of this license or (at your option) any later version.
-% - The latest version of this license is in
-% - http://www.latex-project.org/lppl.txt
-% - and version 1.3 or later is part of all distributions of LaTeX
-% - version 2005/12/01 or later.
-% -
-% - This work has the LPPL maintenance status `maintained'.
-% -
-% - The Current Maintainer of this work is Clemens Niederberger.
-% -
-% - This work consists of the files
-% - chemnum.sty, chemnum_de.tex, chemnum_en.tex, chemnum_it.tex
-% - scheme-tmp.ps, scheme-bla.ps,
-% - README
-% - chemnum_de.pdf, chemnum_en.pdf, chemnum_it.pdf
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\RequirePackage { expl3 , xparse , l3keys2e , etoolbox , psfrag }
-
-\ProvidesExplPackage
- {chemnum}
- {2013/06/05}
- {0.6b}
- {a comprehensive approach for the numbering of chemical compounds}
-
-% --------------------------------------------------------------------------
-% check expl3 version:
-\@ifpackagelater { expl3 } { 2012/11/21 }
- { }
- {
- \PackageError { chemnum } { Support~package~expl3~too~old }
- {
- You~need~to~update~your~installation~of~the~bundles~'l3kernel'~and~
- 'l3packages'.\MessageBreak
- Loading~chemnum~will~abort!
- }
- \tex_endinput:D
+% ----------------------------------------------------------------------------
+\def\chemnumdate{2014/03/12}
+\def\chemnumversion{1.0}
+\def\chemnuminfo{a comprehensive approach for the numbering of chemical compounds}
+
+\RequirePackage{expl3}[2013/07/14]
+\RequirePackage{xparse,l3keys2e}
+
+% ----------------------------------------------------------------------------
+% provide the package:
+\ProvidesExplPackage{chemnum}
+ {\chemnumdate}
+ {\chemnumversion}
+ {\chemnuminfo\space (CN)}
+
+% ----------------------------------------------------------------------------
+% required packages:
+% language support:
+\RequirePackage{translations}[2013/07/12]
+% greek alphabet for the labels matching to chemmacros' selection:
+\RequirePackage{chemgreek}[2013/07/13]
+\RequirePackage{psfrag}
+
+% ----------------------------------------------------------------------------
+% messages:
+\msg_new:nnn {chemnum} {missing-label}
+ { The~ key~ `#1'~ has~ no~ label~ associated~ \msg_line_context: }
+
+\msg_new:nnn {chemnum} {erroneous-argument-combination}
+ {
+ Apparently~ you've~ used~ both~ the~ `*'~ and~ the~ `+'~
+ argument.~ This~ does~ not~ make~ sense.~ I'm~ doing~
+ nothing~ \msg_line_context:
}
-% --------------------------------------------------------------------------
-% error for missing packages
-\msg_set:nnnn { chemnum } { support-missing }
- { Support~package~#1~missing. }
+\msg_new:nnn {chemnum} {unknown-counter-format}
{
- Support~package~#1~seems~to~be~missing. \\
- Please~install~an~up~to~date~version~of~#1. \\
+ I~ do~ not~ know~ the~ counter~ format~ `#1'.~ I'll~ use~ `arabic'~
+ instead~ \msg_line_context:
}
-% warning, if textgreek has already been loaded AND option
-% "textgreek = <value>" is used
-\msg_set:nnnn { chemnum } { textgreek-loaded }
+\msg_new:nnn {chemnum} {compound-not-initiated}
+ { The~ compound~ `#1'~ has~ not~ been~ initiated~ \msg_line_context: }
+
+\msg_new:nnn {chemnum} {subcompound-not-initiated}
{
- The~package~textgreek~has~already~been~loaded. \\
- \tl_if_blank:nF { #1 } { Option~#1~will~not~be~used. }
+ The~ compound~ `#1\l__chemnum_compound_separator_tl #2'~ has~ not~ been~
+ initiated~ \msg_line_context:
}
+
+\msg_new:nnn {chemnum} {log-compound-silent}
{
- The~package~textgreek~has~already~been~loaded. \\
- \tl_if_blank:nF { #1 } { Option~#1~will~not~be~used. }
+ ................................................. \\
+ . ~ \msg_info_text:n {chemnum}: ~
+ defined~ new~ compound~ `#1'~with~output~
+ \chemnum_expandable_get_compound_property:nn {#1}
+ {counter-representation} . \\
+ .................................................
}
-% textgreek support and package options:
-\bool_new:N \l__chemnum_textgreek_bool
-\bool_set_false:N \l__chemnum_textgreek_bool
+\msg_new:nnn {chemnum} {log-compound-verbose}
+ {
+ ................................................. \\
+ . ~ \msg_info_text:n {chemnum}: ~ defined~ new~ compound: \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ ID ~=~ #1 \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ internal~ number ~=~
+ \chemnum_expandable_get_compound_property:nn {#1} {number} \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ label ~=~
+ \chemnum_expandable_get_compound_property:nn {#1}
+ {counter-representation} \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ pre~ label~ code ~=~
+ \chemnum_expandable_get_compound_property:nn {#1}
+ {pre-label-code} \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ post~ label~ code ~=~
+ \chemnum_expandable_get_compound_property:nn {#1}
+ {post-label-code} \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ pre~ main~ label~ code ~=~
+ \chemnum_expandable_get_compound_property:nn {#1}
+ {pre-main-label-code} \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ post~ main~ label~ code ~=~
+ \chemnum_expandable_get_compound_property:nn {#1}
+ {post-main-label-code} \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ format ~=~
+ \chemnum_expandable_get_compound_property:nn {#1}
+ {label-format} \\
+ .................................................
+ }
-\cs_new_protected:Npn \__chemnum_load_textgreek:n #1
+\msg_new:nnn {chemnum} {log-subcompound-silent}
{
- \AtEndPreamble
- {
- \file_if_exist:nTF { textgreek . sty }
- {
- \@ifpackageloaded { textgreek }
- { \msg_warning:nnx { chemnum } { textgreek-loaded } { #1 } }
- { \RequirePackage [ #1 ] { textgreek } }
- \bool_set_true:N \l__chemnum_textgreek_bool
- }
- {
- \msg_warning:nnx { chemnum } { support-missing } { textgreek }
- \bool_set_false:N \l__chemnum_textgreek_bool
- }
- }
+ ................................................. \\
+ . ~ \msg_info_text:n {chemnum}: ~
+ defined~ new~ subcompound~ `#2'~ with~ output~
+ \chemnum_expandable_get_subcompound_property:nnn {#1} {#2}
+ {counter-representation} \\
+ . ~ belonging~ to~ the~ main~ compound~ `#1'. \\
+ .................................................
}
-\cs_new:Npn \__chemnum_package_options:n #1
- { \keys_set:nn { chemnum / package } { #1 } }
-
-\keys_define:nn { chemnum / package } {
- textgreek .choice: ,
- textgreek / artemisia .code:n = \__chemnum_load_textgreek:n { #1 } ,
- textgreek / cbgreek .code:n = \__chemnum_load_textgreek:n { #1 } ,
- textgreek / euler .code:n = \__chemnum_load_textgreek:n { #1 } ,
- textgreek / false .code:n =
- { \bool_set_false:N \l__chemnum_textgreek_bool } ,
- textgreek .default:n = cbgreek
-}
-
-\ProcessKeysOptions { chemnum / package }
-
-\AtBeginDocument{
-\bool_if:NTF \l__chemnum_textgreek_bool
- {
- \cs_new_eq:NN \__chemnum_alpha: \textalpha
- \cs_new_eq:NN \__chemnum_beta: \textbeta
- \cs_new_eq:NN \__chemnum_gamma: \textgamma
- \cs_new_eq:NN \__chemnum_delta: \textdelta
- \cs_new_eq:NN \__chemnum_epsilon: \textepsilon
- \cs_new_eq:NN \__chemnum_zeta: \textzeta
- \cs_new_eq:NN \__chemnum_eta: \texteta
- \cs_new_eq:NN \__chemnum_theta: \texttheta
- \cs_new_eq:NN \__chemnum_iota: \textiota
- \cs_new_eq:NN \__chemnum_kappa: \textkappa
- \cs_new_eq:NN \__chemnum_lambda: \textlambda
- \cs_new_eq:NN \__chemnum_mu: \textmugreek
- \cs_new_eq:NN \__chemnum_nu: \textnu
- \cs_new_eq:NN \__chemnum_xi: \textxi
- \cs_new_eq:NN \__chemnum_omikron: \textomikron
- \cs_new_eq:NN \__chemnum_pi: \textpi
- \cs_new_eq:NN \__chemnum_rho: \textrho
- \cs_new_eq:NN \__chemnum_sigma: \textsigma
- \cs_new_eq:NN \__chemnum_tau: \texttau
- \cs_new_eq:NN \__chemnum_upsilon: \textupsilon
- \cs_new_eq:NN \__chemnum_phi: \textphi
- \cs_new_eq:NN \__chemnum_chi: \textchi
- \cs_new_eq:NN \__chemnum_psi: \textpsi
- \cs_new_eq:NN \__chemnum_omega: \textomega
- \cs_new_eq:NN \__chemnum_Alpha: \textAlpha
- \cs_new_eq:NN \__chemnum_Beta: \textBeta
- \cs_new_eq:NN \__chemnum_Gamma: \textGamma
- \cs_new_eq:NN \__chemnum_Delta: \textDelta
- \cs_new_eq:NN \__chemnum_Epsilon: \textEpsilon
- \cs_new_eq:NN \__chemnum_Zeta: \textZeta
- \cs_new_eq:NN \__chemnum_Eta: \textEta
- \cs_new_eq:NN \__chemnum_Theta: \textTheta
- \cs_new_eq:NN \__chemnum_Iota: \textIota
- \cs_new_eq:NN \__chemnum_Kappa: \textKappa
- \cs_new_eq:NN \__chemnum_Lambda: \textLambda
- \cs_new_eq:NN \__chemnum_Mu: \textMugreek
- \cs_new_eq:NN \__chemnum_Nu: \textNu
- \cs_new_eq:NN \__chemnum_Xi: \textXi
- \cs_new_eq:NN \__chemnum_Omikron: \textOmikron
- \cs_new_eq:NN \__chemnum_Pi: \textPi
- \cs_new_eq:NN \__chemnum_Rho: \textRho
- \cs_new_eq:NN \__chemnum_Sigma: \textSigma
- \cs_new_eq:NN \__chemnum_Tau: \textTau
- \cs_new_eq:NN \__chemnum_Upsilon: \textUpsilon
- \cs_new_eq:NN \__chemnum_Phi: \textPhi
- \cs_new_eq:NN \__chemnum_Chi: \textChi
- \cs_new_eq:NN \__chemnum_Psi: \textPsi
- \cs_new_eq:NN \__chemnum_Omega: \textOmega
- }
- {
- \RequirePackage { bm }% abhängig machen von textoption bold
- \cs_new:Npn \__chemnum_bm:n #1
- {
- \bool_if:NTF \l__chemnum_cmpd_bold_bool
- { \bm { #1 } }
- { #1 }
- }
- \cs_new:Npn \__chemnum_alpha: { \ensuremath { \__chemnum_bm:n { \mathrm { \alpha } } } }
- \cs_new:Npn \__chemnum_beta: { \ensuremath { \__chemnum_bm:n { \mathrm { \beta } } } }
- \cs_new:Npn \__chemnum_gamma: { \ensuremath { \__chemnum_bm:n { \mathrm { \gamma } } } }
- \cs_new:Npn \__chemnum_delta: { \ensuremath { \__chemnum_bm:n { \mathrm { \delta } } } }
- \cs_new:Npn \__chemnum_epsilon: { \ensuremath { \__chemnum_bm:n { \mathrm { \varepsilon } } } }
- \cs_new:Npn \__chemnum_zeta: { \ensuremath { \__chemnum_bm:n { \mathrm { \zeta } } } }
- \cs_new:Npn \__chemnum_eta: { \ensuremath { \__chemnum_bm:n { \mathrm { \eta } } } }
- \cs_new:Npn \__chemnum_theta: { \ensuremath { \__chemnum_bm:n { \mathrm { \theta } } } }
- \cs_new:Npn \__chemnum_iota: { \ensuremath { \__chemnum_bm:n { \mathrm { \iota } } } }
- \cs_new:Npn \__chemnum_kappa: { \ensuremath { \__chemnum_bm:n { \mathrm { \kappa } } } }
- \cs_new:Npn \__chemnum_lambda: { \ensuremath { \__chemnum_bm:n { \mathrm { \lampda } } } }
- \cs_new:Npn \__chemnum_mu: { \ensuremath { \__chemnum_bm:n { \mathrm { \mu } } } }
- \cs_new:Npn \__chemnum_nu: { \ensuremath { \__chemnum_bm:n { \mathrm { \nu } } } }
- \cs_new:Npn \__chemnum_xi: { \ensuremath { \__chemnum_bm:n { \mathrm { \xi } } } }
- \cs_new:Npn \__chemnum_omikron: { \ensuremath { \__chemnum_bm:n { \mathrm { o } } } }
- \cs_new:Npn \__chemnum_pi: { \ensuremath { \__chemnum_bm:n { \mathrm { \pi } } } }
- \cs_new:Npn \__chemnum_rho: { \ensuremath { \__chemnum_bm:n { \mathrm { \rho } } } }
- \cs_new:Npn \__chemnum_sigma: { \ensuremath { \__chemnum_bm:n { \mathrm { \sigma } } } }
- \cs_new:Npn \__chemnum_tau: { \ensuremath { \__chemnum_bm:n { \mathrm { \tau } } } }
- \cs_new:Npn \__chemnum_upsilon: { \ensuremath { \__chemnum_bm:n { \mathrm { \upsilon } } } }
- \cs_new:Npn \__chemnum_phi: { \ensuremath { \__chemnum_bm:n { \mathrm { \varphi } } } }
- \cs_new:Npn \__chemnum_chi: { \ensuremath { \__chemnum_bm:n { \mathrm { \chi } } } }
- \cs_new:Npn \__chemnum_psi: { \ensuremath { \__chemnum_bm:n { \mathrm { \psi } } } }
- \cs_new:Npn \__chemnum_omega: { \ensuremath { \__chemnum_bm:n { \mathrm { \omega } } } }
- \cs_new:Npn \__chemnum_Alpha: { \ensuremath { \__chemnum_bm:n { \mathrm { A } } } }
- \cs_new:Npn \__chemnum_Beta: { \ensuremath { \__chemnum_bm:n { \mathrm { B } } } }
- \cs_new:Npn \__chemnum_Gamma: { \ensuremath { \__chemnum_bm:n { \mathrm { \Gamma } } } }
- \cs_new:Npn \__chemnum_Delta: { \ensuremath { \__chemnum_bm:n { \mathrm { \Delta } } } }
- \cs_new:Npn \__chemnum_Epsilon: { \ensuremath { \__chemnum_bm:n { \mathrm { E } } } }
- \cs_new:Npn \__chemnum_Zeta: { \ensuremath { \__chemnum_bm:n { \mathrm { Z } } } }
- \cs_new:Npn \__chemnum_Eta: { \ensuremath { \__chemnum_bm:n { \mathrm { H } } } }
- \cs_new:Npn \__chemnum_Theta: { \ensuremath { \__chemnum_bm:n { \mathrm { \Theta } } } }
- \cs_new:Npn \__chemnum_Iota: { \ensuremath { \__chemnum_bm:n { \mathrm { I } } } }
- \cs_new:Npn \__chemnum_Kappa: { \ensuremath { \__chemnum_bm:n { \mathrm { K } } } }
- \cs_new:Npn \__chemnum_Lambda: { \ensuremath { \__chemnum_bm:n { \mathrm { \Lambda } } } }
- \cs_new:Npn \__chemnum_Mu: { \ensuremath { \__chemnum_bm:n { \mathrm { M } } } }
- \cs_new:Npn \__chemnum_Nu: { \ensuremath { \__chemnum_bm:n { \mathrm { N } } } }
- \cs_new:Npn \__chemnum_Xi: { \ensuremath { \__chemnum_bm:n { \mathrm { \Xi } } } }
- \cs_new:Npn \__chemnum_Omikron: { \ensuremath { \__chemnum_bm:n { \mathrm { O } } } }
- \cs_new:Npn \__chemnum_Pi: { \ensuremath { \__chemnum_bm:n { \mathrm { \Pi } } } }
- \cs_new:Npn \__chemnum_Rho: { \ensuremath { \__chemnum_bm:n { \mathrm { P } } } }
- \cs_new:Npn \__chemnum_Sigma: { \ensuremath { \__chemnum_bm:n { \mathrm { \Sigma } } } }
- \cs_new:Npn \__chemnum_Tau: { \ensuremath { \__chemnum_bm:n { \mathrm { T } } } }
- \cs_new:Npn \__chemnum_Upsilon: { \ensuremath { \__chemnum_bm:n { \mathrm { \Upsilon } } } }
- \cs_new:Npn \__chemnum_Phi: { \ensuremath { \__chemnum_bm:n { \mathrm { \Phi } } } }
- \cs_new:Npn \__chemnum_Chi: { \ensuremath { \__chemnum_bm:n { \mathrm { X } } } }
- \cs_new:Npn \__chemnum_Psi: { \ensuremath { \__chemnum_bm:n { \mathrm { \Psi } } } }
- \cs_new:Npn \__chemnum_Omega: { \ensuremath { \__chemnum_bm:n { \mathrm { \Omega } } } }
- }
-}
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% TOOLS
-\int_new:N \g__chemnum_cmpd_main_int
-\prop_new:N \g__chemnum_label_prop
-\int_new:N \g__chemnum_cmpd_int
-\int_new:N \l__chemnum_tmpa_int
-\tl_new:N \l__chemnum_tmpa_tl
-\tl_new:N \l__chemnum_tmpb_tl
-\tl_new:N \l__chemnum_tmpc_tl
-\seq_new:N \g__chemnum_cmpd_saved_seq
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% READ FROM PREVIOUS RUN, SAVE FOR NEXT RUN
-% save all labels in a clist
-\cs_new_protected:Npn \chemnum_cmpd_save:n #1
- { \seq_gput_right:Nn \g__chemnum_cmpd_saved_seq { #1 } }
-
-\msg_set:nnn { chemnum } { missing-cmpd-file }
- {
- The~file~ \c_job_name_tl .cmpd~hasn't~been~available~yet. \\
- Please~rerun~to~get~referencing~compound~labels~right.
- }
-
-\file_if_exist:nTF { ./ \c_job_name_tl . cmpd }
- { \file_input:n { ./ \c_job_name_tl . cmpd } }
- { \msg_warning:nn { chemnum }{ missing-cmpd-file } }
-
-% write ref commands for all labels in <jobname>.cmpd file to make them
-% available at the next run
-\AtEndDocument
- {
- \iow_new:N \__chemnum_aux_file:
- \iow_open:Nn \__chemnum_aux_file: { ./ \c_job_name_tl . cmpd }
- \seq_map_inline:Nn \g__chemnum_cmpd_saved_seq
+\msg_new:nnn {chemnum} {log-subcompound-verbose}
+ {
+ ................................................. \\
+ . ~ \msg_info_text:n {chemnum}: ~ defined~ new~ subcompound: \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ ID ~=~ #2 \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ main~ compound~ ID ~=~
+ \chemnum_expandable_get_subcompound_property:nnn {#1} {#2}
+ {main-compound} \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ internal~ number ~=~
+ \chemnum_expandable_get_subcompound_property:nnn {#1} {#2} {number} \\
+ . \c_space_tl \c_space_tl \c_space_tl
+ label ~=~
+ \chemnum_expandable_get_subcompound_property:nnn {#1} {#2}
+ {counter-representation} \\
+ .................................................
+ }
+
+\msg_new:nnn { chemnum } { deprecated-command }
+ {
+ The~ command~ `\token_to_str:N #1'~ \msg_line_context: \c_space_tl is~
+ deprecated.~ Use~ `\token_to_str:N #2'~ instead.~ `\token_to_str:N #1'~
+ may~ be~ removed~ in~ future~ versions.
+ }
+
+% ----------------------------------------------------------------------------
+% deprecated command names:
+% #1: old name
+% #2: new name
+\cs_new_protected:Npn \chemnum_deprecated_command:NN #1#2
+ {
+ \cs_new:Npn #1
{
- \iow_now:Nx \__chemnum_aux_file:
- {
- \use:c { cs_new:cpn } { chemnum_cmpd_ #1 _ref: }
- { \exp_not:f { \use:c { chemnum_cmpd_ #1 : } } }
- }
- \cs_if_exist:cT { chemnum_cmpd_ #1 _min: }
- {
- \iow_now:Nx \__chemnum_aux_file:
- {
- \use:c { cs_new:cpn } { chemnum_cmpd_ #1 _min_ref: }
- { \exp_not:f { \use:c { chemnum_cmpd_ #1 _min: } } }
- }
- }
- \cs_if_exist:cT { chemnum_cmpd_ #1 _max: }
- {
- \iow_now:Nx \__chemnum_aux_file:
- {
- \use:c { cs_new:cpn } { chemnum_cmpd_ #1 _max_ref: }
- { \exp_not:f { \use:c { chemnum_cmpd_ #1 _max: } } }
- }
- }
+ \msg_warning:nnnn { chemnum } { deprecated-command }
+ { #1 } { #2 }
+ #2
}
- \iow_close:N \__chemnum_aux_file:
}
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% COMPOUND LABELS
-% STYLE OF COMPOUND LABEL
-\tl_new:N \l__chemnum_style_tmp_tl
-\bool_new:N \l__chemnum_cmpd_style_is_macro_bool
-
-% default style
-\cs_new:Npn \chemnum_cmpd_style:n #1 { #1 }
+% ----------------------------------------------------------------------------
+% variants of kernel functions:
+\cs_generate_variant:Nn \prop_gput:Nnn { Nnx , cnx , cnV }
+\cs_generate_variant:Nn \prop_put:Nnn { NV , NVV , NVx }
+\cs_generate_variant:Nn \prop_if_in:NnTF { NV }
+\cs_generate_variant:Nn \quark_if_no_value:nTF { V }
+\cs_generate_variant:Nn \quark_if_no_value:nF { V }
+\cs_generate_variant:Nn \seq_set_split:Nnn { NV , NVV }
+\cs_generate_variant:Nn \seq_use:Nnnn { NVVV }
+\cs_generate_variant:Nn \tl_if_eq:nnF { Vx }
+\cs_generate_variant:Nn \tl_if_in:nnTF { VV }
+
+% ----------------------------------------------------------------------------
+% temporary variables:
+\tl_new:N \l__chemnum_tmpa_tl
+\tl_new:N \l__chemnum_tmpb_tl
+
+\seq_new:N \l__chemnum_tmpa_seq
+\seq_new:N \l__chemnum_tmpb_seq
+\seq_new:N \l__chemnum_tmpc_seq
+\seq_new:N \l__chemnum_tmpd_seq
+\seq_new:N \l__chemnum_tmpe_seq
+
+\int_new:N \l__chemnum_tmpa_int
+\int_new:N \l__chemnum_tmpb_int
+\int_new:N \l__chemnum_tmpc_int
+
+% ----------------------------------------------------------------------------
+% variables:
+\prop_new:N \l__chemnum_label_formats_prop
+
+% the main label counter:
+% not very expl3 like but allows `cmpdmain' to be added to the \cl@<ounter>
+% list, i.e., it can e.g. be reset for every chapter:
+\newcounter{cmpdmain}
+% counter for internal reference if needed. Will be a unique number in order
+% of declaration:
+\int_new:N \g__chemnum_main_int
+\int_new:N \l__chemnum_compound_replace_int
+
+\seq_new:N \g__chemnum_initiated_compounds_seq
+\seq_new:N \g__chemnum_defined_compounds_seq
+
+\tl_new:N \l__chemnum_label_format_tl
+\tl_set:Nn \l__chemnum_label_format_tl {\bfseries}
+\tl_new:N \l__chemnum_local_label_format_tl
+\tl_set_eq:NN \l__chemnum_local_label_format_tl \l__chemnum_label_format_tl
+\tl_new:N \l__chemnum_default_counter_representation_tl
+\tl_set:Nn \l__chemnum_default_counter_representation_tl {arabic}
+\tl_new:N \l__chemnum_default_subcounter_representation_tl
+\tl_set:Nn \l__chemnum_default_subcounter_representation_tl {alph}
+\tl_new:N \l__chemnum_pre_counter_default_tl
+\tl_new:N \l__chemnum_post_counter_default_tl
+\tl_new:N \l__chemnum_pre_label_default_tl
+\tl_new:N \l__chemnum_post_label_default_tl
+\tl_new:N \l__chemnum_pre_main_label_default_tl
+\tl_new:N \l__chemnum_post_main_label_default_tl
+\tl_new:N \l__chemnum_main_separator_tl
+\tl_set:Nn \l__chemnum_main_separator_tl {,}
+\tl_new:N \l__chemnum_sub_separator_tl
+\tl_set:Nn \l__chemnum_sub_separator_tl {,}
+\tl_new:N \l__chemnum_compound_separator_tl
+\tl_set:Nn \l__chemnum_compound_separator_tl {.}
+
+\tl_new:N \l__chemnum_sep_list_two_tl
+\tl_set:Nn \l__chemnum_sep_list_two_tl { \GetTranslation {chemnum-sep-two} }
+\tl_new:N \l__chemnum_sep_list_more_tl
+\tl_set:Nn \l__chemnum_sep_list_more_tl {,~}
+\tl_new:N \l__chemnum_sep_list_last_two_tl
+\tl_set:Nn \l__chemnum_sep_list_last_two_tl { \GetTranslation {chemnum-sep-last-two} }
+
+\tl_new:N \l__chemnum_sep_sublist_two_tl
+\tl_set:Nn \l__chemnum_sep_sublist_two_tl {,}
+\tl_new:N \l__chemnum_sep_sublist_more_tl
+\tl_set:Nn \l__chemnum_sep_sublist_more_tl {,}
+\tl_new:N \l__chemnum_sep_sublist_last_two_tl
+\tl_set:Nn \l__chemnum_sep_sublist_last_two_tl {,}
+\tl_new:N \l__chemnum_sep_sublist_range_tl
+\tl_set:Nn \l__chemnum_sep_sublist_range_tl {--}
+
+\tl_new:N \l__chemnum_compound_replace_tl
+\tl_new:N \l__chemnum_compound_replace_format_tl
+\tl_new:N \l__chemnum_compound_replace_local_format_tl
+\tl_set:Nn \l__chemnum_compound_replace_format_tl { \sffamily }
+\tl_new:N \l__chemnum_compound_replace_tag_tl
+\tl_set:Nn \l__chemnum_compound_replace_tag_tl { TMP }
+\tl_new:N \l__chemnum_psfrag_texpos_tl
+\tl_new:N \l__chemnum_psfrag_local_texpos_tl
+\tl_set:Nn \l__chemnum_psfrag_texpos_tl { b }
+\tl_new:N \l__chemnum_psfrag_pspos_tl
+\tl_new:N \l__chemnum_psfrag_local_pspos_tl
+\tl_set:Nn \l__chemnum_psfrag_pspos_tl { b }
-% set style
-\cs_new_protected:Npn \__chemnum_cmpd_set_style:n #1
- { \cs_set:Npn \chemnum_cmpd_style:n { #1 } }
+\bool_new:N \l__chemnum_compound_local_bool
+\bool_new:N \g__chemnum_initiate_bool
+\bool_new:N \g__chemnum_initiate_strict_bool
+\bool_new:N \g__chemnum_initiate_sub_bool
+\bool_new:N \l__chemnum_log_bool
+\bool_set_true:N \l__chemnum_log_bool
+\bool_new:N \l__chemnum_log_verbose_bool
+\bool_new:N \l__chemnum_compress_subcompounds_bool
+\bool_set_true:N \l__chemnum_compress_subcompounds_bool
+\bool_new:N \l__chemnum_merge_list_bool
+\bool_new:N \l__chemnum_sub_only_bool
+\bool_new:N \l__chemnum_sub_all_bool
+\bool_new:N \l__chemnum_show_def_bool
+\bool_new:N \l__chemnum_show_ref_bool
+\bool_new:N \l__chemnum_compound_replace_auto_bool
+\bool_set_true:N \l__chemnum_compound_replace_auto_bool
+\bool_new:N \l__chemnum_compound_replace_auto_this_bool
+\bool_set_true:N \l__chemnum_compound_replace_auto_this_bool
+\bool_new:N \l__chemnum_replace_local_bool
+
+% ----------------------------------------------------------------------------
+% label formats:
+
+% #1: name
+% #2: function with 1 n-type argument that takes an integer
+\cs_new_protected:Npn \chemnum_add_label_format:nn #1#2
+ {
+ \cs_if_exist:cTF { __chemnum_#1_label_format:n }
+ { \cs_set:cpn { __chemnum_#1_label_format:n } ##1 { #2 { ##1 } } }
+ { \cs_new:cpn { __chemnum_#1_label_format:n } ##1 { #2 { ##1 } } }
+ \prop_put:Nnx \l__chemnum_label_formats_prop {#1}
+ { \exp_not:c { __chemnum_#1_label_format:n } }
+ }
-% use style
-\bool_new:N \l__chemnum_cmpd_bold_bool
-\bool_set_true:N \l__chemnum_cmpd_bold_bool
+% a user level command to add new formats
+\NewDocumentCommand \newcmpdcounterformat { mm }
+ { \chemnum_add_label_format:nn {#1} {#2} }
+
+\newcmpdcounterformat {arabic} { \int_to_arabic:n }
+\newcmpdcounterformat {alph } { \int_to_alph:n }
+\newcmpdcounterformat {Alph } { \int_to_Alph:n }
+\newcmpdcounterformat {roman } { \int_to_roman:n }
+\newcmpdcounterformat {Roman } { \int_to_Roman:n }
+\newcmpdcounterformat {greek } { \chemgreek_int_to_greek:n }
+\newcmpdcounterformat {Greek } { \chemgreek_int_to_Greek:n }
+
+% ----------------------------------------------------------------------------
+%%% options
+% options assigned to group `compound' are only setable with the \cmpd command
+% except they're _also_ asigned to the `general' group; likewise options that
+% are assigned to the group `general' can only be set with \setchemnum except
+% they're also assigned to the `compound' group.
+\keys_define:nn {chemnum}
+ {
+ local .bool_set:N = \l__chemnum_compound_local_bool ,
+ local .groups:n = {compound} ,
+ % counter:
+ counter-within .code:n = \@addtoreset{cmpdmain}{#1} ,
+ counter-within .groups:n = {general} ,
+ counter-format .code:n =
+ \prop_if_in:NnTF \l__chemnum_label_formats_prop {#1}
+ {
+ \tl_set:Nn
+ \l__chemnum_default_counter_representation_tl
+ {#1}
+ }
+ {
+ \msg_warning:nnn {chemnum} {unknown-counter-format} {#1}
+ \tl_set:Nn
+ \l__chemnum_default_counter_representation_tl
+ {arabic}
+ } ,
+ counter-format .groups:n = {compound,general} ,
+ sub-counter-format .code:n =
+ \prop_if_in:NnTF \l__chemnum_label_formats_prop {#1}
+ {
+ \tl_set:Nn
+ \l__chemnum_default_subcounter_representation_tl
+ {#1}
+ }
+ {
+ \msg_warning:nnn {chemnum} {unknown-counter-format} {#1}
+ \tl_set:Nn
+ \l__chemnum_default_subcounter_representation_tl
+ {arabic}
+ } ,
+ sub-counter-format .groups:n = {compound,general} ,
+ % label:
+ pre-label-code .tl_set:N = \l__chemnum_pre_label_default_tl ,
+ pre-label-code .groups:n = {compound} ,
+ post-label-code .tl_set:N = \l__chemnum_post_label_default_tl ,
+ post-label-code .groups:n = {compound} ,
+ pre-main-label-code .tl_set:N = \l__chemnum_pre_main_label_default_tl ,
+ pre-main-label-code .groups:n = {compound} ,
+ post-main-label-code .tl_set:N = \l__chemnum_post_main_label_default_tl ,
+ post-main-label-code .groups:n = {compound} ,
+ main-sub-sep .tl_set:N = \l__chemnum_compound_separator_tl ,
+ main-sub-sep .groups:n = {general,list} ,
+ list-label-sep .tl_set:N = \l__chemnum_main_separator_tl ,
+ list-label-sep .groups:n = {general,list} ,
+ sub-list-label-sep .tl_set:N = \l__chemnum_sub_separator_tl ,
+ sub-list-label-sep .groups:n = {general,list} ,
+ format .code:n =
+ \tl_set:Nn \l__chemnum_local_label_format_tl {#1}
+ \bool_if:NF \l__chemnum_compound_local_bool
+ { \tl_set:Nn \l__chemnum_label_format_tl {#1} } ,
+ format .groups:n = {compound,general} ,
+ sub-only .bool_set:N = \l__chemnum_sub_only_bool ,
+ sub-only .groups:n = {compound,sub-only} ,
+ sub-all .bool_set:N = \l__chemnum_sub_all_bool ,
+ sub-all .groups:n = {compound} ,
+ compress .bool_set:N =
+ \l__chemnum_compress_subcompounds_bool ,
+ compress .groups:n = {compound,general} ,
+ merge .bool_set:N =
+ \l__chemnum_merge_list_bool ,
+ merge .groups:n = {general,list} ,
+ % initiation:
+ init .choice: ,
+ init / true .code:n =
+ \bool_set_true:N \g__chemnum_initiate_bool
+ \bool_set_true:N \g__chemnum_initiate_sub_bool
+ \bool_set_false:N \g__chemnum_initiate_strict_bool ,
+ init / main .code:n =
+ \bool_set_true:N \g__chemnum_initiate_bool
+ \bool_set_false:N \g__chemnum_initiate_sub_bool
+ \bool_set_false:N \g__chemnum_initiate_strict_bool ,
+ init / false .code:n =
+ \bool_set_false:N \g__chemnum_initiate_bool
+ \bool_set_false:N \g__chemnum_initiate_sub_bool
+ \bool_set_false:N \g__chemnum_initiate_strict_bool ,
+ init / strict .code:n =
+ \bool_set_true:N \g__chemnum_initiate_bool
+ \bool_set_true:N \g__chemnum_initiate_sub_bool
+ \bool_set_true:N \g__chemnum_initiate_strict_bool ,
+ init / main-strict .code:n =
+ \bool_set_true:N \g__chemnum_initiate_bool
+ \bool_set_false:N \g__chemnum_initiate_sub_bool
+ \bool_set_true:N \g__chemnum_initiate_strict_bool ,
+ init .default:n = true ,
+ init .groups:n = {general} ,
+ % list processing:
+ list-sep-two .tl_set:N = \l__chemnum_sep_list_two_tl ,
+ list-sep-two .groups:n = {general,list} ,
+ list-sep-more .tl_set:N = \l__chemnum_sep_list_more_tl ,
+ list-sep-more .groups:n = {general,list} ,
+ list-sep-last-two .tl_set:N = \l__chemnum_sep_list_last_two_tl ,
+ list-sep-last-two .groups:n = {general,list} ,
+ sub-list-sep-two .tl_set:N = \l__chemnum_sep_sublist_two_tl ,
+ sub-list-sep-two .groups:n = {compound,general} ,
+ sub-list-sep-more .tl_set:N = \l__chemnum_sep_sublist_more_tl ,
+ sub-list-sep-more .groups:n = {compound,general} ,
+ sub-list-sep-last-two .tl_set:N = \l__chemnum_sep_sublist_last_two_tl ,
+ sub-list-sep-last-two .groups:n = {compound,general} ,
+ sub-list-sep-range .tl_set:N = \l__chemnum_sep_sublist_range_tl ,
+ sub-list-sep-range .groups:n = {compound,general} ,
+ % logging and other information:
+ log .choice: ,
+ log / true .code:n =
+ \bool_set_true:N \l__chemnum_log_bool
+ \bool_set_false:N \l__chemnum_log_verbose_bool ,
+ log / silent .code:n =
+ \bool_set_true:N \l__chemnum_log_bool
+ \bool_set_false:N \l__chemnum_log_verbose_bool ,
+ log / false .code:n =
+ \bool_set_false:N \l__chemnum_log_bool
+ \bool_set_false:N \l__chemnum_log_verbose_bool ,
+ log / verbose .code:n =
+ \bool_set_true:N \l__chemnum_log_bool
+ \bool_set_true:N \l__chemnum_log_verbose_bool ,
+ log .default:n = true ,
+ log .groups:n = {general} ,
+ show-keys .choice: ,
+ show-keys / true .code:n =
+ \bool_set_true:N \l__chemnum_show_def_bool
+ \bool_set_true:N \l__chemnum_show_ref_bool ,
+ show-keys / false .code:n =
+ \bool_set_false:N \l__chemnum_show_def_bool
+ \bool_set_false:N \l__chemnum_show_ref_bool ,
+ show-keys / def .code:n =
+ \bool_set_true:N \l__chemnum_show_def_bool
+ \bool_set_false:N \l__chemnum_show_ref_bool ,
+ show-keys / ref .code:n =
+ \bool_set_false:N \l__chemnum_show_def_bool
+ \bool_set_true:N \l__chemnum_show_ref_bool ,
+ show-keys .default:n = true ,
+ show-keys .groups:n = {general} ,
+ replace .bool_set:N = \l__chemnum_replace_local_bool ,
+ replace .groups:n = {replace} ,
+ replace-auto .bool_set:N = \l__chemnum_compound_replace_auto_bool ,
+ replace-tag .tl_set:N = \l__chemnum_compound_replace_tag_tl ,
+ replace-tag .groups:n = {general} ,
+ tag .code:n =
+ \tl_set:Nn \l__chemnum_compound_replace_tag_tl {#1}
+ \bool_set_false:N \l__chemnum_compound_replace_auto_this_bool ,
+ tag .groups:n = {replace} ,
+ replace-style .tl_set:N = \l__chemnum_compound_replace_format_tl ,
+ replace-style .groups:n = {general} ,
+ style .code:n =
+ \tl_set:Nn \l__chemnum_compound_replace_local_format_tl {#1}
+ \bool_set_true:N \l__chemnum_replace_local_bool ,
+ style .groups:n = {replace} ,
+ replace-pos .code:n = \__chemnum_set_psfrag_pos:nn #1 ,
+ replace-pos .groups:n = {general} ,
+ pos .code:n =
+ \bool_set_true:N \l__chemnum_replace_local_bool
+ \__chemnum_set_psfrag_local_pos:nn #1 ,
+ pos .groups:n = {replace}
+ }
-\cs_new_protected:Npn \__chemnum_cmpd_use_style:n #1
+% ----------------------------------------------------------------------------
+% #1: int variable that holds the value
+% #2: the chosen format
+% this command is expandable
+\cs_new:Npn \__chemnum_label_format:Nn #1#2
{
- \group_begin:
- \bool_if:NT \l__chemnum_cmpd_bold_bool
- { \bfseries }
- \chemnum_cmpd_style:n { #1 }
- \group_end:
+ \prop_if_in:NnTF \l__chemnum_label_formats_prop {#2}
+ { \use:c { __chemnum_#2_label_format:n } {#1} }
+ { \__chemnum_arabic_label_format:n {#1} }
}
+\cs_generate_variant:Nn \__chemnum_label_format:Nn { NV , cV }
-%-----------------------------------------------------------------------------%
-% prefix, suffix, delimiters, format and separator of compound label
-\tl_new:N \l__chemnum_cmpd_prefix_tl
-\tl_new:N \l__chemnum_cmpd_suffix_tl
+% ----------------------------------------------------------------------------
+% auxiliary file -- we'll use the .aux file
+% first let's add dummy definitions so we can hopefully avoid error messages
+% if the `chemnum' package is removed from the preamble
+\AtBeginDocument
+ {
+ \if@filesw
+ \iow_now:Nn \@auxout
+ {
+ \providecommand\chemnum@cmpd[8]{} ^^J
+ \providecommand\chemnum@subcmpd[4]{} ^^J
+ \providecommand\chemnum@check{}
+ }
+ \fi
+ }
-\tl_new:N \l__chemnum_cmpd_space_tl
-\tl_set:Nn \l__chemnum_cmpd_space_tl { \penalty\@m\ }
+% we use this one to trigger a LaTeX rerun warning -- to be precise the
+% ``Label(s) may have changed'' warning:
+\cs_new_protected:Npn \__chemnum_rerun:
+ { \AtEndDocument { \def \chemnum@check { \@tempswatrue } } }
+
+% add the rerun check at the end:
+\AtEndDocument { \if@filesw \iow_now:Nn \@auxout { \chemnum@check } \fi }
+
+% ----------------------------------------------------------------------------
+% initiating new compounds
+% - property list that holds
+% - ID
+% - counter value
+% - counter represetation
+% - pre-counter-code
+% - post-counter-code
+% - pre-label-code
+% - post-label-code
+% - formatting code
+% - add to list of initiated compounds
+
+\cs_new_protected:Npn \chemnum_initiate_compound:n #1
+ {
+ \chemnum_compound_if_initiated:nF {#1}
+ { \seq_gput_right:Nn \g__chemnum_initiated_compounds_seq {#1} }
+ }
-\tl_new:N \l__chemnum_cmpd_separator_tl
+% #1: ID
+\cs_new_protected:Npn \chemnum_define_compound:n #1
+ {
+ \chemnum_initialize_compound:n {#1}
+ \chemnum_compound_declare_properties:nn {#1}
+ {
+ ID ,
+ number ,
+ counter-representation ,
+ pre-label-code ,
+ post-label-code ,
+ pre-main-label-code ,
+ post-main-label-code ,
+ label-format
+ }
+ \chemnum_compound_set_property:nnn {#1} {ID} {#1}
+ \chemnum_compound_set_property:nnx {#1} {number}
+ { \int_use:N \c@cmpdmain }
+ \chemnum_compound_set_property:nnx {#1} {counter-representation}
+ {
+ \tl_use:N \l__chemnum_pre_counter_default_tl
+ \__chemnum_label_format:NV
+ \c@cmpdmain % \g__chemnum_main_int
+ \l__chemnum_default_counter_representation_tl
+ \tl_use:N \l__chemnum_post_counter_default_tl
+ }
+ \chemnum_compound_set_property:nnV {#1} {pre-label-code}
+ \l__chemnum_pre_label_default_tl
+ \chemnum_compound_set_property:nnV {#1} {post-label-code}
+ \l__chemnum_post_label_default_tl
+ \chemnum_compound_set_property:nnV {#1} {pre-main-label-code}
+ \l__chemnum_pre_main_label_default_tl
+ \chemnum_compound_set_property:nnV {#1} {post-main-label-code}
+ \l__chemnum_post_main_label_default_tl
+ \chemnum_compound_set_property:nnV {#1} {label-format}
+ \l__chemnum_label_format_tl
+ \__chemnum_write_compound_to_auxfile:nnnVVVVV {#1}
+ { \int_use:N \g__chemnum_main_int }
+ {
+ \tl_use:N \l__chemnum_pre_counter_default_tl
+ \__chemnum_label_format:NV
+ \c@cmpdmain % \g__chemnum_main_int
+ \l__chemnum_default_counter_representation_tl
+ \tl_use:N \l__chemnum_post_counter_default_tl
+ }
+ \l__chemnum_pre_label_default_tl
+ \l__chemnum_post_label_default_tl
+ \l__chemnum_pre_main_label_default_tl
+ \l__chemnum_post_main_label_default_tl
+ \l__chemnum_label_format_tl
+ \chemnum_compound_update_properties:n {#1}
+ \chemnum_log_main:n {#1}
+ }
-\tl_new:N \l__chemnum_cmpd_odelim_tl
-\tl_new:N \l__chemnum_cmpd_cdelim_tl
+% TODO: keep? and if: what should it set?
+\cs_new_protected:Npn \chemnum_set_compound:n #1
+ {
+ % those should be done: however, they overwrite existing options in any
+ % case... this would overwrite options that really should stay set.
+
+ % \chemnum_compound_set_property:nnV {#1} {pre-label-code}
+ % \l__chemnum_pre_label_default_tl
+ % \chemnum_compound_set_property:nnV {#1} {post-label-code}
+ % \l__chemnum_post_label_default_tl
+ % \chemnum_compound_set_property:nnV {#1} {post-main-label-code}
+ % \l__chemnum_post_main_label_default_tl
+ % \chemnum_compound_set_property:nnV {#1} {label-format}
+ % \l__chemnum_label_format_tl
+ % \__chemnum_write_compound_to_auxfile:nnnVVVV {#1}
+ % { \int_use:N \g__chemnum_main_int }
+ % {
+ % \tl_use:N \l__chemnum_pre_counter_default_tl
+ % \__chemnum_label_format:NV
+ % \c@cmpdmain % \g__chemnum_main_int
+ % \l__chemnum_default_counter_representation_tl
+ % \tl_use:N \l__chemnum_post_counter_default_tl
+ % }
+ % \l__chemnum_pre_label_default_tl
+ % \l__chemnum_post_label_default_tl
+ % \l__chemnum_post_main_label_default_tl
+ % \l__chemnum_label_format_tl
+ % \chemnum_compound_update_properties:n {#1}
+ }
-% error message for wrong argument length of delim-keys
-\msg_set:nnn { chemnum } { delimiters }
+\cs_new_protected:Npn \chemnum_initialize_compound:n #1
{
- "#1-delim~=~<odelim><cdelim>"~needs~two~tokens~or~token~groups~as~a~value~
- \msg_line_context: .
+ \seq_gput_right:Nn \g__chemnum_defined_compounds_seq {#1}
+ \int_gincr:N \g__chemnum_main_int
+ \stepcounter{cmpdmain}
+ \seq_new:c { g__chemnum_#1_initiated_subcompounds_seq }
}
-% set compound delimiters
-\cs_new_protected:Npn \__chemnum_cmpd_delim:n #1
+% #1: main ID
+% #2: sub ID
+\cs_new_protected:Npn \chemnum_define_subcompound:nn #1#2
{
- \tl_if_blank:nTF { #1 }
+ \chemnum_initialize_subcompound:nn {#1} {#2}
+ \chemnum_subcompound_declare_properties:nnn {#1} {#2}
{
- \tl_clear:N \l__chemnum_cmpd_odelim_tl
- \tl_clear:N \l__chemnum_cmpd_cdelim_tl
+ ID ,
+ main-compound ,
+ number ,
+ counter-representation
}
+ \chemnum_subcompound_set_property:nnnn {#1} {#2} {ID} {#2}
+ \chemnum_subcompound_set_property:nnnn {#1} {#2} {main-compound} {#1}
+ \chemnum_subcompound_set_property:nnnx {#1} {#2} {number}
+ { \int_use:c { g__chemnum_compound_#1_subcompound_int } }
+ \chemnum_subcompound_set_property:nnnx {#1} {#2} {counter-representation}
{
- \int_compare:nNnTF { \tl_count:n { #1 } } = 2
- {
- \tl_set:Nx \l__chemnum_cmpd_odelim_tl { \tl_head:n { #1 } }
- \tl_set:Nx \l__chemnum_cmpd_cdelim_tl { \tl_tail:n { #1 } }
- }
- { \msg_error:nnx { chemnum } { delimiters } { cmpd } }
+ \__chemnum_label_format:cV
+ { g__chemnum_compound_#1_subcompound_int }
+ \l__chemnum_default_subcounter_representation_tl
}
- }
-
-% format of numbering
-\cs_new:Npn \__chemnum_cmpd_kind:nn #1#2
- { \cs:w int_to_#1:n \cs_end: #2 }
-
-% default format
-\tl_new:N \l__chemnum_cmpd_kind_value_tl
-\tl_set:Nn \l__chemnum_cmpd_kind_value_tl { arabic }
-
-% format of sub-numbering
-\cs_new:Npn \__chemnum_cmpd_sub_kind:nn #1#2
- { \cs:w int_to_ #1 :n \cs_end: #2 }
-\cs_generate_variant:Nn \__chemnum_cmpd_sub_kind:nn { Nc }
-
-% default format
-\tl_new:N \l__chemnum_cmpd_sub_kind_value_tl
-\tl_set:Nn \l__chemnum_cmpd_sub_kind_value_tl { alph }
-
-%-----------------------------------------------------------------------------%
-% add greek letters and symbols as numbering format
-% define \int_to_greek function
-\cs_new:Npn \int_to_greek:n { }
-% \bool_if:NTF \l__chemnum_textgreek_bool
-% {
- \cs_set:Npn \int_to_greek:n #1
+ \__chemnum_write_subcompound_to_auxfile:nnnn {#1} {#2}
+ { \int_use:c { g__chemnum_compound_#1_subcompound_int } }
{
- \int_to_symbols:nnn {#1} { 24 }
- {
- { 1 } { \exp_not:o \__chemnum_alpha: }
- { 2 } { \exp_not:o \__chemnum_beta: }
- { 3 } { \exp_not:o \__chemnum_gamma: }
- { 4 } { \exp_not:o \__chemnum_delta: }
- { 5 } { \exp_not:o \__chemnum_epsilon: }
- { 6 } { \exp_not:o \__chemnum_zeta: }
- { 7 } { \exp_not:o \__chemnum_eta: }
- { 8 } { \exp_not:o \__chemnum_theta: }
- { 9 } { \exp_not:o \__chemnum_iota: }
- { 10 } { \exp_not:o \__chemnum_kappa: }
- { 11 } { \exp_not:o \__chemnum_lambda: }
- { 12 } { \exp_not:o \__chemnum_mu: }
- { 13 } { \exp_not:o \__chemnum_nu: }
- { 14 } { \exp_not:o \__chemnum_xi: }
- { 15 } { \exp_not:o \__chemnum_omikron: }
- { 16 } { \exp_not:o \__chemnum_pi: }
- { 17 } { \exp_not:o \__chemnum_rho: }
- { 18 } { \exp_not:o \__chemnum_sigma: }
- { 19 } { \exp_not:o \__chemnum_tau: }
- { 20 } { \exp_not:o \__chemnum_upsilon: }
- { 21 } { \exp_not:o \__chemnum_phi: }
- { 22 } { \exp_not:o \__chemnum_chi: }
- { 23 } { \exp_not:o \__chemnum_psi: }
- { 24 } { \exp_not:o \__chemnum_omega: }
- }
+ \__chemnum_label_format:cV
+ { g__chemnum_compound_#1_subcompound_int }
+ \l__chemnum_default_subcounter_representation_tl
}
-% }
-% {
-% \cs_set_eq:NN \int_to_greek:n \int_to_alph:n
-% }
+ \chemnum_subcompound_update_properties:nn {#1} {#2}
+ \chemnum_log_sub:nn {#1} {#2}
+ }
-% define \int_to_Greek function
-\cs_new:Npn \int_to_Greek:n { }
-\bool_if:NTF \l__chemnum_textgreek_bool
+\cs_new_protected:Npn \chemnum_initialize_subcompound:nn #1#2
{
- \cs_set_protected:Npn \int_to_Greek:n #1
+ \int_if_exist:cF { g__chemnum_compound_#1_subcompound_int }
+ { \int_new:c { g__chemnum_compound_#1_subcompound_int } }
+ \int_gincr:c { g__chemnum_compound_#1_subcompound_int }
+ \seq_if_exist:cF { g__chemnum_compound_#1_subcompounds_seq }
+ { \seq_new:c { g__chemnum_compound_#1_subcompounds_seq } }
+ \prop_if_exist:cF { g__chemnum_compound_#1_subcompounds_prop }
+ { \prop_new:c { g__chemnum_compound_#1_subcompounds_prop } }
+ \seq_gput_right:cn { g__chemnum_compound_#1_subcompounds_seq } {#2}
+ \prop_gput:cnx { g__chemnum_compound_#1_subcompounds_prop } {#2}
{
- \int_to_symbols:nnn { #1 } { 24 }
- {
- { 1 } { \exp_not:o \__chemnum_Alpha: }
- { 2 } { \exp_not:o \__chemnum_Beta: }
- { 3 } { \exp_not:o \__chemnum_Gamma: }
- { 4 } { \exp_not:o \__chemnum_Delta: }
- { 5 } { \exp_not:o \__chemnum_Epsilon: }
- { 6 } { \exp_not:o \__chemnum_Zeta: }
- { 7 } { \exp_not:o \__chemnum_Eta: }
- { 8 } { \exp_not:o \__chemnum_Theta: }
- { 9 } { \exp_not:o \__chemnum_Iota: }
- { 10 } { \exp_not:o \__chemnum_Kappa: }
- { 11 } { \exp_not:o \__chemnum_Lambda: }
- { 12 } { \exp_not:o \__chemnum_Mu: }
- { 13 } { \exp_not:o \__chemnum_Nu: }
- { 14 } { \exp_not:o \__chemnum_Xi: }
- { 15 } { \exp_not:o \__chemnum_Omikron: }
- { 16 } { \exp_not:o \__chemnum_Pi: }
- { 17 } { \exp_not:o \__chemnum_Rho: }
- { 18 } { \exp_not:o \__chemnum_Sigma: }
- { 19 } { \exp_not:o \__chemnum_Tau: }
- { 20 } { \exp_not:o \__chemnum_Upsilon: }
- { 21 } { \exp_not:o \__chemnum_Phi: }
- { 22 } { \exp_not:o \__chemnum_Chi: }
- { 23 } { \exp_not:o \__chemnum_Psi: }
- { 24 } { \exp_not:o \__chemnum_Omega: }
- }
+ \int_use:c { g__chemnum_compound_#1_subcompound_int } :
+ \__chemnum_label_format:cV
+ { g__chemnum_compound_#1_subcompound_int }
+ \l__chemnum_default_subcounter_representation_tl
}
}
+
+% ----------------------------------------------------------------------------
+\cs_new_protected:Npn \chemnum_log_main:n #1
{
- \cs_set_eq:NN \int_to_Greek:n \int_to_Alph:n
+ \bool_if:NT \l__chemnum_log_bool
+ {
+ \bool_if:NTF \l__chemnum_log_verbose_bool
+ { \msg_log:nnn {chemnum} {log-compound-verbose} {#1} }
+ { \msg_log:nnn {chemnum} {log-compound-silent} {#1} }
+ }
}
-% define \int_to_Symbol function
-\cs_new_protected:Npn \int_to_Symbol:n #1
+\cs_new_protected:Npn \chemnum_log_sub:nn #1#2
{
- \int_to_symbols:nnn { #1 } { 9 }
+ \bool_if:NT \l__chemnum_log_bool
{
- { 1 } {\exp_not:o \textasteriskcentered }
- { 2 } {\exp_not:o \textdagger}
- { 3 } {\exp_not:o \textdaggerdbl}
- { 4 } {\exp_not:o \textsection}
- { 5 } {\exp_not:o \textparagraph}
- { 6 } {\exp_not:o \textbardbl}
- { 7 } {\exp_not:o \textasteriskcentered \textasteriskcentered}
- { 8 } {\exp_not:o \textdagger \textdagger}
- { 9 } {\exp_not:o \textdaggerdbl \textdaggerdbl}
+ \bool_if:NTF \l__chemnum_log_verbose_bool
+ { \msg_log:nnnn {chemnum} {log-subcompound-verbose} {#1} {#2} }
+ { \msg_log:nnnn {chemnum} {log-subcompound-silent} {#1} {#2} }
}
}
-%-----------------------------------------------------------------------------%
-% lists of sublabels
-\clist_new:N \l__chemnum_sublabel_clist
-\tl_new:N \l__chemnum_sublabel_list_sep_tl
-\tl_set:Nn \l__chemnum_sublabel_list_sep_tl { , }
-\tl_new:N \l__chemnum_cmpd_sublabel_list_tl
-\int_new:N \l__chemnum_sublabel_list_current_int
-\int_new:N \l__chemnum_sublabel_list_length_int
-\bool_new:N \l__chemnum_sublabel_list_bool
+% ----------------------------------------------------------------------------
+% #1: ID
+\prg_new_protected_conditional:Npnn \chemnum_compound_if_initiated:n #1
+ { T,F,TF }
+ {
+ \seq_if_in:NnTF \g__chemnum_initiated_compounds_seq {#1}
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+
+% #1: main ID
+% #2: sub ID
+\prg_new_protected_conditional:Npnn \chemnum_subcompound_if_initiated:nn #1#2
+ { T,F,TF }
+ {
+ \seq_if_in:cnTF { g__chemnum_#1_initiated_subcompounds_seq } {#2}
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+
+% #1: ID
+\prg_new_protected_conditional:Npnn \chemnum_compound_if_defined:n #1
+ { T,F,TF }
+ {
+ \seq_if_in:NnTF \g__chemnum_defined_compounds_seq {#1}
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+
+% #1: main ID
+% #2: sub ID
+\prg_new_protected_conditional:Npnn \chemnum_subcompound_if_defined:nn #1#2
+ { T,F,TF }
+ {
+ \seq_if_in:cnTF { g__chemnum_compound_#1_subcompounds_seq } {#2}
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+
+% ----------------------------------------------------------------------------
+% #1: ID
+% #2: property to be defined
+\cs_new_protected:Npn \chemnum_compound_declare_property:nn #1#2
+ {
+ \seq_if_in:cnF { g__chemnum_compound_#1_properties_seq } {#2}
+ { \seq_gput_right:cn { g__chemnum_compound_#1_properties_seq } {#2} }
+ }
+
+% #1: ID
+% #2: properties to be defined
+\cs_new_protected:Npn \chemnum_compound_declare_properties:nn #1#2
+ {
+ \seq_if_exist:cF { g__chemnum_compound_#1_properties_seq }
+ { \seq_new:c { g__chemnum_compound_#1_properties_seq } }
+ \prop_if_exist:cF { g__chemnum_compound_#1_prop }
+ { \prop_new:c { g__chemnum_compound_#1_prop } }
+ \clist_map_inline:nn { #2 }
+ { \chemnum_compound_declare_property:nn {#1} {##1} }
+ }
+
+% #1: ID
+% #2: property to be set
+% #3: value of property
+\cs_new_protected:Npn \chemnum_compound_set_property:nnn #1#2#3
+ {
+ \seq_if_in:cnTF { g__chemnum_compound_#1_properties_seq } {#2}
+ { \prop_gput:cnn { g__chemnum_compound_#1_prop } {#2} {#3} }
+ { \ERROR }
+ }
+\cs_generate_variant:Nn \chemnum_compound_set_property:nnn { nnV , nnx }
-\cs_new_protected:Npn \__chemnum_cmpd_sublabel_list:nn #1#2
+% #1: ID
+% #2: property to be updated
+\cs_new_protected:Npn \chemnum_compound_update_property:nn #1#2
{
- \clist_clear:N \l__chemnum_sublabel_clist
- \clist_set_eq:NN \l__chemnum_sublabel_clist #2
- \int_set:Nn \l__chemnum_sublabel_list_length_int
- { \clist_count:N \l__chemnum_sublabel_clist }
- \clist_map_variable:NNn \l__chemnum_sublabel_clist \l__chemnum_tmpb_tl
+ \seq_if_in:cnTF { g__chemnum_compound_#1_properties_seq } {#2}
{
- \int_incr:N \l__chemnum_sublabel_list_current_int
- \exp_after:wN \__chemnum_cmpd_sublabelsep:n \l__chemnum_tmpb_tl \q_stop
- \use:c { chemnum_cmpd_#1_ \l__chemnum_cmpd_sub_one_label_tl _ref: }
- \tl_if_blank:VF \l__chemnum_cmpd_sub_two_label_tl
+ \prop_get:cnN { g__chemnum_compound_#1_prop } {previous-#2}
+ \l__chemnum_tmpa_tl
+ \prop_get:cnN { g__chemnum_compound_#1_prop } {#2}
+ \l__chemnum_tmpb_tl
+ \tl_if_eq:NNF \l__chemnum_tmpb_tl \l__chemnum_tmpa_tl
{
- \tl_use:N \l__chemnum_sub_range_sep_tl
- \use:c { chemnum_cmpd_#1_ \l__chemnum_cmpd_sub_two_label_tl _ref: }
+ \prop_gput:cnV { g__chemnum_compound_#1_prop }
+ {previous-#2}
+ \l__chemnum_tmpb_tl
}
- \int_compare:nT
+ }
+ { \ERROR }
+ }
+
+% #1: ID
+\cs_new_protected:Npn \chemnum_compound_update_properties:n #1
+ {
+ \seq_map_inline:cn { g__chemnum_compound_#1_properties_seq }
+ { \chemnum_compound_update_property:nn {#1} {##1} }
+ }
+
+% #1: main ID
+% #2. sub ID
+% #3: property to be defined
+\cs_new_protected:Npn \chemnum_subcompound_declare_property:nnn #1#2#3
+ {
+ \seq_if_in:cnF { g__chemnum_compound_#1_#2_properties_seq } {#3}
+ { \seq_gput_right:cn { g__chemnum_compound_#1_#2_properties_seq } {#3} }
+ }
+
+% #1: main ID
+% #2. sub ID
+% #3: properties to be defined
+\cs_new_protected:Npn \chemnum_subcompound_declare_properties:nnn #1#2#3
+ {
+ \seq_if_exist:cF { g__chemnum_compound_#1_#2_properties_seq }
+ { \seq_new:c { g__chemnum_compound_#1_#2_properties_seq } }
+ \prop_if_exist:cF { g__chemnum_compound_#1_#2_properties_prop }
+ { \prop_new:c { g__chemnum_compound_#1_#2_properties_prop } }
+ \clist_map_inline:nn { #3 }
+ { \chemnum_subcompound_declare_property:nnn {#1} {#2} {##1} }
+ }
+
+% #1: main ID
+% #2: sub ID
+% #3: property to be set
+% #4: value of property
+\cs_new_protected:Npn \chemnum_subcompound_set_property:nnnn #1#2#3#4
+ {
+ \seq_if_in:cnTF { g__chemnum_compound_#1_#2_properties_seq } {#3}
+ { \prop_gput:cnn { g__chemnum_compound_#1_#2_properties_prop } {#3} {#4} }
+ { \ERROR }
+ }
+\cs_generate_variant:Nn \chemnum_subcompound_set_property:nnnn { nnnV , nnnx }
+
+% #1: main ID
+% #2. sub ID
+% #3: property to be updated
+\cs_new_protected:Npn \chemnum_subcompound_update_property:nnn #1#2#3
+ {
+ \seq_if_in:cnTF { g__chemnum_compound_#1_#2_properties_seq }
+ {
+ \prop_get:cnN { g__chemnum_compound_#1_#2_properties_prop } {previous-#3}
+ \l__chemnum_tmpa_tl
+ \prop_get:cnN { g__chemnum_compound_#1_#2_properties_prop } {#3}
+ \l__chemnum_tmpb_tl
+ \tl_if_eq:NNF \l__chemnum_tmpb_tl \l__chemnum_tmpa_tl
{
- \l__chemnum_sublabel_list_current_int
- <
- \l__chemnum_sublabel_list_length_int
+ \prop_gput:cnV { g__chemnum_compound_#1_#2_properties_prop }
+ {previous-#3}
+ \l__chemnum_tmpb_tl
}
- { \tl_use:N \l__chemnum_sublabel_list_sep_tl }
}
+ { \ERROR }
}
-%-----------------------------------------------------------------------------%
-% variables
-\bool_new:N \l__chemnum_cmpd_name_bool
-\bool_set_false:N \l__chemnum_cmpd_name_bool
-\bool_new:N \l__chemnum_cmpd_all_bool
-\bool_set_false:N \l__chemnum_cmpd_all_bool
-\bool_new:N \l__chemnum_cmpd_range_bool
-\bool_set_false:N \l__chemnum_cmpd_range_bool
-\bool_new:N \l__chemnum_sub_label_only_bool
-\bool_set_false:N \l__chemnum_sub_label_only_bool
-
-\tl_new:N \l__chemnum_cmpd_name_tl
-\tl_new:N \l__chemnum_cmpd_labelsep_tl
-\tl_set:Nn \l__chemnum_cmpd_labelsep_tl { . }
-\tl_new:N \l__chemnum_sublist_input_separator_tl
-\tl_set:Nn \l__chemnum_sublist_input_separator_tl { , }
-\tl_new:N \l__chemnum_sublist_output_separator_tl
-\tl_set:Nn \l__chemnum_sublist_output_separator_tl { , }
-\tl_new:N \l__chemnum_sublabel_range_marker_tl
-\tl_set:Nn \l__chemnum_sublabel_range_marker_tl { .. }
-\tl_new:N \l__chemnum_sub_range_sep_tl
-\tl_set:Nn \l__chemnum_sub_range_sep_tl { -- }
-
-%-----------------------------------------------------------------------------%
-% hyperref support
-\tl_new:N \l__chemnum_cmpd_hyper_name_tl
-
-\bool_new:N \l__chemnum_use_hyperref_bool
-\bool_new:N \l__chemnum_hypertarget_bool
-\bool_new:N \l__chemnum_hyperlink_bool
-
-\cs_new_eq:NN \__chemnum_make_hyper:nn \use_ii:nn
-
-% #1: main label, #2: sub labels, #3: invisible
-\cs_new_protected:Npn \__chemnum_hyperref:nnn #1#2#3
- {
- \bool_if:nF { #3 || !\l__chemnum_use_hyperref_bool }
- {
- \bool_if:NT \l__chemnum_hypertarget_bool
- {
- \cs_set:Npn \__chemnum_make_hyper:nn ##1##2
- {
- \raisebox { 3ex } [ 0pt ]
- { \hypertarget { ##1 } { } } ##2
- }
- }
- \bool_if:NT \l__chemnum_hyperlink_bool
- { \cs_set_eq:NN \__chemnum_make_hyper:nn \hyperlink }
- \bool_if:nT
- { !\l__chemnum_hypertarget_bool && !\l__chemnum_hyperlink_bool }
- {
- \tl_if_blank:nTF { #2 }
- { % no sublabel
- \tl_set:Nn \l__chemnum_cmpd_hyper_name_tl
- { chemnum_cmpd_#1 }
- \cs_if_exist:cTF { chemnum_cmpd_#1_hyper: }
- {
- \bool_set_false:N \l__chemnum_hypertarget_bool
- \cs_set_eq:NN \__chemnum_make_hyper:nn \hyperlink
- }
- {
- \bool_set_true:N \l__chemnum_hypertarget_bool
- \cs_set:Npn \__chemnum_make_hyper:nn ##1##2
- {
- \raisebox { 3ex } [ 0pt ]
- { \hypertarget { ##1 } { } } ##2
- }
- \cs_new:cpn { chemnum_cmpd_#1_hyper: } { }
- }
- }
- {
- \__chemnum_cmpd_sublist:n { #2 }
- \int_compare:nT { \l__chemnum_cmpd_sublist_length_int < 2 }
- { % no sublabel list
- \__chemnum_cmpd_subrange_separate:n { #2 }
- \tl_if_blank:VT \l__chemnum_tmpc_tl
- { % no sublabel range
- \tl_set:Nn \l__chemnum_cmpd_hyper_name_tl
- { chemnum_cmpd_#1_ \l__chemnum_tmpb_tl }
- \cs_if_exist:cTF
- { chemnum_cmpd_#1_ \l__chemnum_tmpb_tl _hyper: }
- {
- \bool_set_false:N \l__chemnum_hypertarget_bool
- \cs_set_eq:NN \__chemnum_make_hyper:nn \hyperlink
- }
- {
- \bool_set_true:N \l__chemnum_hypertarget_bool
- \cs_set:Npn \__chemnum_make_hyper:nn ##1##2
- {
- \raisebox { 3ex } [ 0pt ]
- { \hypertarget { ##1 } { } } ##2
- }
- \cs_new:cpn
- { chemnum_cmpd_#1_ \l__chemnum_tmpb_tl _hyper: } { }
- }
- }
- }
- }
- }
- }
- }
-
-%-----------------------------------------------------------------------------%
-% property keys for compounds
-\keys_define:nn { chemnum } {
- cmpd-style .code:n = \__chemnum_cmpd_set_style:n { #1 } ,
- cmpd-weight .choice: ,
- cmpd-weight / bold .code:n =
- \bool_set_true:N \l__chemnum_cmpd_bold_bool ,
- cmpd-weight / normal .code:n =
- \bool_set_false:N \l__chemnum_cmpd_bold_bool ,
- cmpd-label .code:n =
- {
- \bool_set_true:N \l__chemnum_cmpd_name_bool
- \tl_set:Nn \l__chemnum_cmpd_name_tl { #1 }
- } ,
- cmpd-prefix .tl_set:N = \l__chemnum_cmpd_prefix_tl ,
- cmpd-prefix .default:n = { } ,
- cmpd-suffix .tl_set:N = \l__chemnum_cmpd_suffix_tl ,
- cmpd-suffix .default:n = { } ,
- cmpd-space .tl_set:N = \l__chemnum_cmpd_space_tl ,
- cmpd-space .default:n = { \penalty\@m\ },
- cmpd-delim .code:n = \__chemnum_cmpd_delim:n { #1 },
- cmpd-delim .default:n = { ( } { ) } ,
- cmpd-odelim .tl_set:N = \l__chemnum_cmpd_odelim_tl ,
- cmpd-odelim .default:n = { } ,
- cmpd-cdelim .tl_set:N = \l__chemnum_cmpd_cdelim_tl ,
- cmpd-cdelim .default:n = { } ,
- cmpd-all .bool_set:N = \l__chemnum_cmpd_all_bool ,
- cmpd-all .default:n = true ,
- cmpd-counter .choice: ,
- cmpd-counter .choice_code:n =
- \tl_set_eq:NN \l__chemnum_cmpd_kind_value_tl \l_keys_choice_tl ,
- cmpd-counter .generate_choices:n =
- { arabic , alph , Alph , greek, Greek , roman , Roman , Symbol } ,
- cmpd-counter .default:n = arabic ,
- hyper-use .choice: ,
- hyper-use / true .code:n =
- {
- \bool_set_true:N \l__chemnum_use_hyperref_bool
- \bool_set_false:N \l__chemnum_hypertarget_bool
- \bool_set_false:N \l__chemnum_hyperlink_bool
- } ,
- hyper-use / false .code:n =
- {
- \bool_set_false:N \l__chemnum_use_hyperref_bool
- \bool_set_false:N \l__chemnum_hypertarget_bool
- \bool_set_false:N \l__chemnum_hyperlink_bool
- } ,
- hyper-use .default:n = true ,
- hyper-target .code:n =
- {
- \tl_set:Nn \l__chemnum_cmpd_hyper_name_tl { #1 }
- \bool_set_true:N \l__chemnum_use_hyperref_bool
- \bool_set_true:N \l__chemnum_hypertarget_bool
- \bool_set_false:N \l__chemnum_hyperlink_bool
- } ,
- hyper-link .code:n =
- {
- \tl_set:Nn \l__chemnum_cmpd_hyper_name_tl { #1 }
- \bool_set_true:N \l__chemnum_use_hyperref_bool
- \bool_set_false:N \l__chemnum_hypertarget_bool
- \bool_set_true:N \l__chemnum_hyperlink_bool
- } ,
- sub-counter .choice: ,
- sub-counter .choice_code:n =
- \tl_set_eq:NN \l__chemnum_cmpd_sub_kind_value_tl \l_keys_choice_tl ,
- sub-counter .generate_choices:n =
- { arabic , alph , Alph , greek , Greek , roman , Roman , Symbol } ,
- sub-counter .default:n = alph ,
- sub-input-sep .code:n = \__chemnum_subcmpdsep:n { #1 } ,
- sub-input-sep .default:n = . ,
- sub-output-sep .tl_set:N = \l__chemnum_cmpd_separator_tl ,
- sub-output-sep .default:n = { } ,
- sublist-input-sep .tl_set:N =
- \l__chemnum_sublist_input_separator_tl ,
- sublist-input-sep .default:n = { , } ,
- sublist-output-sep .tl_set:N =
- \l__chemnum_sublist_output_separator_tl ,
- sublist-output-sep .default:n = { , } ,
- sub-only .bool_set:N = \l__chemnum_sub_label_only_bool ,
- sub-only .default:n = true ,
- subrange-output-sep .tl_set:N = \l__chemnum_sub_range_sep_tl ,
- subrange-output-sep .default:n = { -- } ,
- subrange-input-sep .code:n =
- \__chemnum_sublabel_range_marker:n { #1 } ,
- subrange-input-sep .default:n = { .. }
-}
-
-%-----------------------------------------------------------------------------%
-% list separators, delimiters, prefix and suffix
-\bool_new:N \l__chemnum_no_serial_comma_bool
-\bool_set_false:N \l__chemnum_no_serial_comma_bool
-
-\tl_new:N \l__chemnum_list_input_separator_tl
-\tl_set:Nn \l__chemnum_list_input_separator_tl { , }
-\tl_new:N \l__chemnum_list_separator_tl
-\tl_set:Nn \l__chemnum_list_separator_tl { , }
-\tl_new:N \l__chemnum_list_space_tl
-\tl_set:Nn \l__chemnum_list_space_tl { \penalty\@m\ }
-\tl_new:N \l__chemnum_list_last_separator_lang_tl
-\tl_set:Nn \l__chemnum_list_last_separator_lang_tl { and }
-\tl_new:N \l__chemnum_list_last_separator_tl
-\tl_set:Nn \l__chemnum_list_last_separator_tl
- { \tl_use:N \l__chemnum_list_last_separator_lang_tl }
-\tl_new:N \l__chemnum_list_prefix_tl { }
-\tl_set:Nn \l__chemnum_list_prefix_tl { }
-\tl_new:N \l__chemnum_list_suffix_tl { }
-\tl_set:Nn \l__chemnum_list_suffix_tl { }
-\tl_new:N \l__chemnum_list_odelim_tl { }
-\tl_new:N \l__chemnum_list_cdelim_tl { }
-
-\cs_new_protected:Npn \__chemnum_list_delim:n #1 {
- \tl_if_blank:nTF { #1 } {
- \tl_clear:N \l__chemnum_list_odelim_tl
- \tl_clear:N \l__chemnum_list_cdelim_tl
- }{
- \int_compare:nNnTF { \tl_count:n { #1 } } = 2 {
- \tl_set:Nx \l__chemnum_list_odelim_tl { \tl_head:n { #1 } }
- \tl_set:Nx \l__chemnum_list_cdelim_tl { \tl_tail:n { #1 } }
- }{ \msg_error:nnx { chemnum } { delimiters } { list } }
- }
-}
-
-%-----------------------------------------------------------------------------%
-% property keys for lists
-\keys_define:nn { chemnum } {
- list-prefix .tl_set:N = \l__chemnum_list_prefix_tl ,
- list-prefix .default:n = { } ,
- list-suffix .tl_set:N = \l__chemnum_list_suffix_tl ,
- list-suffix .default:n = { } ,
- list-delim .code:n = \__chemnum_list_delim:n { #1 } ,
- list-delim .default:n = { ( } { ) } ,
- list-odelim .tl_set:N = \l__chemnum_list_odelim_tl ,
- list-odelim .default:n = { } ,
- list-cdelim .tl_set:N = \l__chemnum_list_cdelim_tl ,
- list-cdelim .default:n = { } ,
- list-space .tl_set:N = \l__chemnum_list_space_tl ,
- list-space .default:n = { \penalty\@m\ } ,
- list-input-sep .tl_set:N = \l__chemnum_list_input_separator_tl ,
- list-input-sep .default:n = { , } ,
- list-output-sep .tl_set:N = \l__chemnum_list_separator_tl ,
- list-output-sep .default:n = { , } ,
- list-last-sep .tl_set:N = \l__chemnum_list_last_separator_tl ,
- list-last-sep .default:n = \l__chemnum_list_last_separator_lang_tl ,
- list-serial-comma .choice: ,
- list-serial-comma / true .code:n =
- \bool_set_false:N \l__chemnum_no_serial_comma_bool ,
- list-serial-comma / false .code:n =
- \bool_set_true:N \l__chemnum_no_serial_comma_bool ,
- list-serial-comma .default:n = true ,
- list-lang .choice: ,
- list-lang / US .code:n =
- {
- \bool_set_false:N \l__chemnum_no_serial_comma_bool
- \tl_set:Nn \l__chemnum_list_last_separator_lang_tl { and }
- } ,
- list-lang / GB .code:n =
- {
- \bool_set_true:N \l__chemnum_no_serial_comma_bool
- \tl_set:Nn \l__chemnum_list_last_separator_lang_tl { and }
- } ,
- list-lang / DE .code:n =
- {
- \bool_set_true:N \l__chemnum_no_serial_comma_bool
- \tl_set:Nn \l__chemnum_list_last_separator_lang_tl { und }
- } ,
- list-lang / FR .code:n =
- {
- \bool_set_true:N \l__chemnum_no_serial_comma_bool
- \tl_set:Nn \l__chemnum_list_last_separator_lang_tl { et }
- } ,
- list-lang / IT .code:n =
- {
- \bool_set_true:N \l__chemnum_no_serial_comma_bool
- \tl_set:Nn \l__chemnum_list_last_separator_lang_tl { e }
- } ,
- list-lang / ES .code:n =
- {
- \bool_set_true:N \l__chemnum_no_serial_comma_bool
- \tl_set:Nn \l__chemnum_list_last_separator_lang_tl { y }
- } ,
- list-lang .default:n = US
-}
-
-%-----------------------------------------------------------------------------%
-% label and sublabel declaration
-\cs_new_protected:Npn \__chemnum_cmpd_declare:n #1
- {
- \cs_if_exist:cF { chemnum_cmpd_#1: }
- {
- \int_gincr:N \g__chemnum_cmpd_main_int
- \prop_gput:Nnx \g__chemnum_label_prop
- { #1 }
- { \int_use:N \g__chemnum_cmpd_main_int }
- \chemnum_cmpd_save:n { #1 }
- \bool_if:NF \l__chemnum_cmpd_name_bool
- { \int_gincr:N \g__chemnum_cmpd_int }
- \cs_new:cpx { chemnum_cmpd_#1: } {
- \bool_if:NTF \l__chemnum_cmpd_name_bool
- { \l__chemnum_cmpd_name_tl }
+% #1: main ID
+% #2: sub ID
+\cs_new_protected:Npn \chemnum_subcompound_update_properties:nn #1#2
+ {
+ \seq_map_inline:cn { g__chemnum_compound_#1_#2_properties_seq }
+ { \chemnum_subcompound_update_property:nnn {#1} {#2} {##1} }
+ }
+
+% #1: ID
+% #2: property
+\cs_new_protected:Npn \chemnum_get_compound_property:nn #1#2
+ { \chemnum_get_compound_property_or:nnn {#1} {#2} { } }
+
+\cs_new_protected:Npn \chemnum_get_compound_property_or:nnn #1#2#3
+ {
+ \prop_get:cnNTF { g__chemnum_compound_#1_prop } {#2}
+ \l__chemnum_tmpa_tl
+ { \tl_use:N \l__chemnum_tmpa_tl }
+ {#3}
+ }
+
+\cs_new:Npn \chemnum_expandable_get_compound_property:nn #1#2
+ { \prop_get:cn { g__chemnum_compound_#1_prop } {#2} }
+\cs_generate_variant:Nn \chemnum_expandable_get_compound_property:nn { V }
+
+% #1: main ID
+% #2: sub ID
+% #3: property
+\cs_new_protected:Npn \chemnum_get_subcompound_property:nnn #1#2#3
+ { \chemnum_get_subcompound_property_or:nnnn {#1} {#2} {#3} { } }
+
+\cs_new_protected:Npn \chemnum_get_subcompound_property_or:nnnn #1#2#3#4
+ {
+ \prop_get:cnNTF { g__chemnum_compound_#1_#2_properties_prop } {#3}
+ \l__chemnum_tmpa_tl
+ { \tl_use:N \l__chemnum_tmpa_tl }
+ {#4}
+ }
+
+\cs_new:Npn \chemnum_expandable_get_subcompound_property:nnn #1#2#3
+ { \prop_get:cn { g__chemnum_compound_#1_#2_properties_prop } {#3} }
+
+% ----------------------------------------------------------------------------
+\DeclareExpandableDocumentCommand \cmpdproperty { mm }
+ { \chemnum_expandable_get_compound_property:nn {#1} {#2} }
+
+\DeclareExpandableDocumentCommand \subcmpdproperty { mmm }
+ { \chemnum_expandable_get_subcompound_property:nnn {#1} {#2} {#3} }
+
+% ----------------------------------------------------------------------------
+% initiating subcompounds:
+
+% #1: main ID
+% #2: sub ID
+\cs_new_protected:Npn \chemnum_initiate_subcompound:nn #1#2
+ {
+ \chemnum_subcompound_if_initiated:nnF {#1} {#2}
+ { \seq_gput_right:cn { g__chemnum_#1_initiated_subcompounds_seq } {#2} }
+ }
+
+% ----------------------------------------------------------------------------
+
+% saving compounds to the auxilliary file:
+% #1: ID
+% #2: counter value
+% #3: counter representation
+% #4: pre label
+% #5: post label
+% #6: pre main label
+% #7: post main label
+% #8: label format
+\cs_new_protected:Npn \__chemnum_write_compound_to_auxfile:nnnnnnnn #1#2#3#4#5#6#7#8
+ {
+ \if@filesw
+ \token_if_eq_meaning:NNT \@nodocument \relax
+ {
+ \iow_now:Nx \@auxout
{
- \__chemnum_cmpd_kind:nn
- \l__chemnum_cmpd_kind_value_tl
- \g__chemnum_cmpd_int
+ \exp_not:N \chemnum@cmpd{#1}{#2}{#3}
+ \exp_not:n { {#4}{#5}{#6}{#7}{#8} }
}
}
- }
+ \fi
}
+\cs_generate_variant:Nn \__chemnum_write_compound_to_auxfile:nnnnnnnn { nnnVVVVV }
-\cs_new_protected:Npn \__chemnum_cmpd_sub_declare:nn #1#2
+% #1: main ID
+% #2: sub ID
+% #2: counter value
+% #3: counter representation
+\cs_new_protected:Npn \__chemnum_write_subcompound_to_auxfile:nnnn #1#2#3#4
{
- \cs_if_exist:cF { chemnum_cmpd_#1_#2: }
- {
- \chemnum_cmpd_save:n { #1 _ #2 }
- \cs_new:cpx { chemnum_cmpd_#1_#2: } { }
- \int_gincr:c { g_chemnum_cmpd_#1_int }
- % why is the next line working when \cs_gset:cpx doesn't?
- % (in case ":" is part of #1)
- \exp_after:wN \cs_gset:Npx \cs:w chemnum_cmpd_#1_#2: \cs_end:
- {
- \__chemnum_cmpd_sub_kind:Nc
- \l__chemnum_cmpd_sub_kind_value_tl
- { g_chemnum_cmpd_#1_int }
- }
- \int_compare:nT { \int_use:c { g_chemnum_cmpd_#1_int } = 1 }
- {
- \cs_gset_eq:cc { chemnum_cmpd_#1_min: } { chemnum_cmpd_#1_#2: }
- }
- \cs_gset_eq:cc { chemnum_cmpd_#1_max: } { chemnum_cmpd_#1_#2: }
- }
+ \if@filesw
+ \token_if_eq_meaning:NNT \@nodocument \relax
+ {
+ \iow_now:Nx \@auxout
+ { \exp_not:N \chemnum@subcmpd{#1}{#2}{#3}{#4} }
+ }
+ \fi
+ }
+
+% ----------------------------------------------------------------------------
+% #1: ID
+% #2: counter value
+% #3: counter representation
+% #4: pre label
+% #5: post label
+% #6: pre main label
+% #7: post main label
+% #8: label format
+\cs_new_protected:Npn \chemnum@cmpd #1#2#3#4#5#6#7#8
+ {
+ \prop_if_exist:cF { g__chemnum_compound_#1_prop }
+ { \prop_new:c { g__chemnum_compound_#1_prop } }
+ \prop_gput:cnn { g__chemnum_compound_#1_prop }
+ {previous-number} {#2}
+ \prop_gput:cnn { g__chemnum_compound_#1_prop }
+ {previous-counter-representation} {#3}
+ \prop_gput:cnn { g__chemnum_compound_#1_prop }
+ {previous-pre-label-code} {#4}
+ \prop_gput:cnn { g__chemnum_compound_#1_prop }
+ {previous-post-label-code} {#5}
+ \prop_gput:cnn { g__chemnum_compound_#1_prop }
+ {previous-pre-main-label-code} {#6}
+ \prop_gput:cnn { g__chemnum_compound_#1_prop }
+ {previous-post-main-label-code} {#7}
+ \prop_gput:cnn { g__chemnum_compound_#1_prop }
+ {previous-label-format} {#8}
+ }
+
+% #1: main ID
+% #2: sub ID
+% #3: counter value
+% #4: counter representation
+\cs_new_protected:Npn \chemnum@subcmpd #1#2#3#4
+ {
+ \prop_if_exist:cF { g__chemnum_compound_#1_#2_properties_prop }
+ { \prop_new:c { g__chemnum_compound_#1_#2_properties_prop } }
+ \prop_gput:cnn { g__chemnum_compound_#1_#2_properties_prop }
+ {previous-number} {#3}
+ \prop_gput:cnn { g__chemnum_compound_#1_#2_properties_prop }
+ {previous-counter-representation} {#4}
}
-\cs_generate_variant:Nn \__chemnum_cmpd_sub_declare:nn { no }
-\cs_new_protected:Npn \__chemnum_cmpd_sub_initiate:nn #1#2
+% ----------------------------------------------------------------------------
+% declaring and writing compounds:
+
+% #1: options
+% #2: ID
+\cs_new_protected:Npn \chemnum_declare_compound:nn #1#2
{
- \cs_if_exist:cF { chemnum_cmpd_ #1 _ #2 _init: }
+ \tl_if_blank:nF {#1}
+ { \keys_set_groups:nnn {chemnum} {compound} { local=true , #1 } }
+ \chemnum_compound_if_initiated:nF {#2}
{
- \bool_if:NTF \l__chemnum_cmpd_init_strict_bool
- {
- \msg_error:nnx { chemnum } { cmpd-init-sub }
- { #1 \l__chemnum_cmpd_labelsep_tl #2 }
- }
+ \bool_if:NT \g__chemnum_initiate_bool
{
- \msg_warning:nnx { chemnum } { cmpd-init-sub }
- { #1 \l__chemnum_cmpd_labelsep_tl #2 }
+ \bool_if:NTF \g__chemnum_initiate_strict_bool
+ { \msg_error:nnn {chemnum} {compound-not-initiated} {#2} }
+ { \msg_warning:nnn {chemnum} {compound-not-initiated} {#2} }
}
+ \bool_if:NT \l__chemnum_show_def_bool
+ { \cmpdshowdef { #2 } }
+ \bool_set_false:N \l__chemnum_show_ref_bool
+ \chemnum_initiate_compound:n {#2}
}
+ \chemnum_compound_if_defined:nTF {#2}
+ { \chemnum_set_compound:n {#2} }
+ { \chemnum_define_compound:n {#2} }
}
-%-----------------------------------------------------------------------------%
-% label and sublabel initiation
-\cs_new_protected:Npn \__chemnum_cmpd_initiate:nn #1#2
+% #1: options
+% #2: main ID
+% #3: sub ID
+\cs_new_protected:Npn \chemnum_declare_subcompound:nnn #1#2#3
{
- \cs_if_exist:cTF { chemnum_cmpd_#1_init: }
+ % \keys_set:nn {chemnum} {#1}
+ \chemnum_subcompound_if_initiated:nnF {#2} {#3}
{
- \bool_if:NT \l__chemnum_cmpd_sub_init_bool
+ \bool_if:NT \g__chemnum_initiate_sub_bool
{
- \tl_if_blank:nF { #2 }
+ \bool_if:NTF \g__chemnum_initiate_strict_bool
{
- \__chemnum_cmpd_sublist:n { #2 }
- \tl_map_inline:Nn \l__chemnum_cmpd_sublist_tl
- {
- \__chemnum_cmpd_subrange_separate:n { ##1 }
- \__chemnum_cmpd_sub_initiate:nn { #1 } { \l__chemnum_tmpb_tl }
- \tl_if_blank:VF \l__chemnum_tmpc_tl
- { \__chemnum_cmpd_sub_initiate:nn { #1 } { \l__chemnum_tmpc_tl } }
- }
+ \msg_error:nnnn {chemnum} {subcompound-not-initiated}
+ {#2} {#3}
+ }
+ {
+ \msg_warning:nnnn {chemnum} {subcompound-not-initiated}
+ {#2} {#3}
}
}
+ \bool_if:NT \l__chemnum_show_def_bool
+ { \subcmpdshowdef { #2 } { #3 } }
+ \bool_set_false:N \l__chemnum_show_ref_bool
+ \chemnum_initiate_subcompound:nn {#2} {#3}
}
+ \chemnum_subcompound_if_defined:nnF {#2} {#3}
+ { \chemnum_define_subcompound:nn {#2} {#3} }
+ }
+
+\cs_new_protected:Npn \chemnum_compound_start:n #1
+ {
+ \bool_if:NF \l__chemnum_sub_only_bool
+ { \chemnum_get_compound_property:nn {#1} {pre-label-code} }
+ }
+
+\cs_new:Npn \chemnum_expandable_compound_start:n #1
+ {
+ \bool_if:NF \l__chemnum_sub_only_bool
{
- \bool_if:NTF \l__chemnum_cmpd_init_strict_bool
- { \msg_error:nnx { chemnum } { cmpd-init } { #1 } }
- { \msg_warning:nnx { chemnum } { cmpd-init } { #1 } }
+ \chemnum_expandable_get_compound_property:nn {#1}
+ {previous-pre-label-code}
}
}
-%-----------------------------------------------------------------------------%
-% sub label separator
-% error message if no separator is chosen
-\msg_set:nnnn { chemnum } { sub-label-separator }
+\cs_new_protected:Npn \chemnum_compound_finish:n #1
{
- Missing~separator~token~as~value~for~the~key~sub-cmpd-sep \c_space_tl
- \msg_line_context: !
+ \bool_if:NF \l__chemnum_sub_only_bool
+ { \chemnum_get_compound_property:nn {#1} {post-label-code} }
}
+
+\cs_new:Npn \chemnum_expandable_compound_finish:n #1
{
- You~used~the~key~sub-cmpd-sep \c_space_tl \msg_line_context: ~but~left~the~
- argument~empty.\\
- This~can't~work.~Please~select~a~token~as~separator.
+ \bool_if:NF \l__chemnum_sub_only_bool
+ {
+ \chemnum_expandable_get_compound_property:nn {#1}
+ {previous-post-label-code}
+ }
}
-%-----------------------------------------------------------------------------%
-% variables
-
-\tl_new:N \l__chemnum_cmpd_main_label_tl
-\tl_new:N \l__chemnum_cmpd_sub_label_tl
-\tl_new:N \l__chemnum_labelsep_tmp_tl
+% actively write a compound:
+% #1: ID
+\cs_new_protected:Npn \chemnum_compound_write:n #1
+ {
+ \chemnum_get_compound_property:nn {#1} {pre-main-label-code}
+ \group_begin:
+ \bool_if:NTF \l__chemnum_compound_local_bool
+ { \l__chemnum_local_label_format_tl }
+ { \chemnum_get_compound_property:nn {#1} {label-format} }
+ { \chemnum_get_compound_property:nn {#1} {counter-representation} }
+ \group_end:
+ \chemnum_get_compound_property:nn {#1} {post-main-label-code}
+ }
-% set sublabel-separator
-\cs_new_protected:Npn \__chemnum_subcmpdsep:n #1 {
- \tl_if_blank:nTF { #1 }
- { \msg_error:nn { chemnum } { sub-label-separator } }
- { \tl_set:Nn \l__chemnum_cmpd_labelsep_tl { #1 } }
-}
+% actively write a subcompound:
+% #1: main ID
+% #2: sub ID
+\cs_new_protected:Npn \chemnum_subcompound_write:nn #1#2
+ {
+ \group_begin:
+ \bool_if:NTF \l__chemnum_compound_local_bool
+ { \l__chemnum_local_label_format_tl }
+ { \chemnum_get_compound_property:nn {#1} {label-format} }
+ {
+ \chemnum_get_subcompound_property:nnn {#1} {#2}
+ {counter-representation}
+ }
+ \group_end:
+ }
-\cs_new_protected:Npn \__chemnum_sublabel_range_marker:n #1 {
- \tl_if_blank:nTF { #1 }
- { \msg_error:nn { chemnum } { sub-label-range_sep } }
- { \tl_set:Nn \l__chemnum_sublabel_range_marker_tl { #1 } }
-}
+% this is only provided for use in PDF strings:
+\cs_new:Npn \chemnum_expandable_compound_write:n #1
+ {
+ \chemnum_expandable_get_compound_property:nn {#1} {pre-main-label-code}
+ \chemnum_expandable_get_compound_property:nn {#1} {counter-representation}
+ \chemnum_expandable_get_compound_property:nn {#1} {post-main-label-code}
+ }
-% actual separating
-\cs_new_protected:Npn \__chemnum_cmpd_labelsep:n #1 \q_stop {
- \tl_clear:N \l__chemnum_labelsep_tmp_tl
- \tl_if_in:oVTF { #1 } \l__chemnum_cmpd_labelsep_tl
- {
- \tl_set:Nn \l__chemnum_labelsep_tmp_tl { #1 }
- \tl_replace_once:NVn \l__chemnum_labelsep_tmp_tl
- \l__chemnum_cmpd_labelsep_tl
- { \q_nil }
- \exp_after:wN \__chemnum_cmpd_labelsep_aux_ii:n
- \l__chemnum_labelsep_tmp_tl \q_stop
- }
- { \__chemnum_cmpd_labelsep_aux_i:n { #1 } }
-}
-\cs_generate_variant:Nn \tl_if_in:nnTF { oV }
-\cs_generate_variant:Nn \tl_replace_once:Nnn { NV }
+\cs_new:Npn \chemnum_expandable_subcompound_write:nn #1#2
+ {
+ \chemnum_expandable_get_subcompound_property:nnn {#1} {#2}
+ {counter-representation}
+ }
-\cs_new_protected:Npn \__chemnum_cmpd_labelsep_aux_i:n #1
+% read and write saved values:
+% #1: ID
+\cs_new_protected:Npn \chemnum_compound_read:n #1
{
- \tl_set:Nn \l__chemnum_cmpd_main_label_tl { #1 }
- \tl_clear:N \l__chemnum_cmpd_sub_label_tl
+ \chemnum_get_compound_property:nn {#1} {previous-pre-main-label-code}
+ \group_begin:
+ \chemnum_get_compound_property:nn {#1} {previous-label-format}
+ {
+ \chemnum_get_compound_property_or:nnn {#1}
+ { previous-counter-representation }
+ { ?? \__chemnum_rerun: }
+ }
+ \group_end:
+ \chemnum_get_compound_property:nn {#1} {previous-post-main-label-code}
+
}
-\cs_new_protected:Npn \__chemnum_cmpd_labelsep_aux_ii:n #1 \q_nil #2 \q_stop
+% #1: main ID
+% #2: sub ID
+\cs_new_protected:Npn \chemnum_subcompound_read:nn #1#2
{
- \tl_set:Nn \l__chemnum_cmpd_main_label_tl { #1 }
- \tl_set:Nn \l__chemnum_cmpd_sub_label_tl { #2 }
+ \group_begin:
+ \bool_if:NTF \l__chemnum_compound_local_bool
+ { \l__chemnum_local_label_format_tl }
+ { \chemnum_get_compound_property:nn {#1} {previous-label-format} }
+ {
+ \chemnum_get_subcompound_property_or:nnnn {#1} {#2}
+ {previous-counter-representation}
+ { ?? \__chemnum_rerun: }
+ }
+ \group_end:
}
-% sublabel separating to display a list and/or range
-\tl_new:N \l__chemnum_cmpd_sublist_tl
-\int_new:N \l__chemnum_cmpd_sublist_length_int
+% this is only provided for use in PDF strings:
+\cs_new:Npn \chemnum_expandable_compound_read:n #1
+ {
+ \chemnum_expandable_get_compound_property:nn {#1} {previous-pre-main-label-code}
+ \chemnum_expandable_get_compound_property:nn {#1} {previous-counter-representation}
+ \chemnum_expandable_get_compound_property:nn {#1} {previous-post-main-label-code}
+ }
-\NewDocumentCommand \__chemnum_cmpd_sublist:n
- { > { \exp_args:No \SplitList { \l__chemnum_sublist_input_separator_tl } } m }
+\cs_new:Npn \chemnum_expandable_subcompound_read:nn #1#2
{
- \tl_set:Nn \l__chemnum_cmpd_sublist_tl { #1 }
- \int_zero:N \l__chemnum_cmpd_sublist_length_int
- \tl_map_inline:Nn \l__chemnum_cmpd_sublist_tl
- { \int_incr:N \l__chemnum_cmpd_sublist_length_int }
+ \chemnum_expandable_get_subcompound_property:nnn {#1} {#2}
+ {previous-counter-representation}
}
-\cs_new_protected:Npn \__chemnum_cmpd_subrange_separate:n #1
+% #1: boolean: if true register compound but don't write the label
+% #2: boolean: if true only read compound
+% #3: write == true and read == false
+% #4: write == true and read == true
+\cs_new:Npn \chemnum_if_write_and_or_read:NNTF #1#2
{
- \tl_clear:N \l__chemnum_tmpb_tl
- \tl_clear:N \l__chemnum_tmpc_tl
- \tl_if_in:noTF { #1 } { \l__chemnum_sublabel_range_marker_tl }
+ \bool_if:NTF #1
+ { \use_none:nn }
{
- \tl_set:Nn \l__chemnum_tmpb_tl { #1 }
- \tl_replace_once:NVn \l__chemnum_tmpb_tl
- \l__chemnum_sublabel_range_marker_tl
- { \q_nil }
- \exp_after:wN \__chemnum_cmpd_subrange_separate_aux:w \l__chemnum_tmpb_tl \q_stop
+ \bool_if:NTF #2
+ { \use_ii:nn }
+ { \use_i:nn }
}
- { \tl_set:Nn \l__chemnum_tmpb_tl { #1 } }
}
-\cs_new_protected:Npn \__chemnum_cmpd_subrange_separate_aux:w #1 \q_nil #2 \q_stop
+% write a label from the entries of \cmpd:
+% #1: boolean: if true register compound but don't write the label
+% #2: boolean: if true only read compound
+% #3: options
+% #4: label specifications
+\cs_new_protected:Npn \chemnum_single_compound:NNnn #1#2#3#4
{
- \tl_set:Nn \l__chemnum_tmpb_tl { #1 }
- \tl_set:Nn \l__chemnum_tmpc_tl { #2 }
+ \bool_if:NT #1 { \@bsphack }
+ \group_begin:
+ \chemnum_split_sub_from_main:VNNnn
+ \l__chemnum_compound_separator_tl
+ #1 #2 {#3} {#4}
+ \group_end:
+ \bool_if:NT {#1} { \@esphack }
}
-%-----------------------------------------------------------------------------%
-% print compound label
-\cs_new_protected:Npn \__chemnum_cmpd_print:n #1
+% #1: label separator
+% #2: boolean: if true register compound but don't write the label
+% #3: boolean: if true only read compound
+% #4: options
+% #5: label spec
+\cs_new_protected:Npn \chemnum_split_sub_from_main:nNNnn #1#2#3#4#5
+ {
+ \cs_set:Npn \__chemnum_split_sub_from_main_aux:nnnw ##1##2##3##4#1##5#1##6 \q_stop
+ {
+ \bool_if:NF ##2 { \chemnum_declare_compound:nn {##3} {##4} }
+ \keys_set_groups:nnn {chemnum} {sub-only} {#4}
+ \chemnum_if_write_and_or_read:NNTF #2 #3
+ { \chemnum_compound_start:n {##4} }
+ { \chemnum_expandable_compound_start:n {##4} }
+ % shis is in the compound_write command:
+ \chemnum_write_main:nnnn {##1} {##2} {##3} {##4}
+ \bool_if:nT
+ {
+ !\l__chemnum_sub_all_bool &&
+ !\tl_if_blank_p:n {##5}
+ }
+ { \chemnum_write_sublist:NNnnn ##1 ##2 {##3} {##4} {##5} }
+ \bool_if:NT \l__chemnum_sub_all_bool
+ {
+ \tl_clear:N \l__chemnum_tmpa_tl
+ \tl_set:Nx \l__chemnum_tmpa_tl
+ { \seq_use:cn { g__chemnum_compound_##4_subcompounds_seq } { , } }
+ \tl_if_blank:VF \l__chemnum_tmpa_tl
+ {
+ \chemnum_write_sublist:NNnnV ##1 ##2 {##3} {##4}
+ \l__chemnum_tmpa_tl
+ }
+ }
+ \chemnum_if_write_and_or_read:NNTF #2 #3
+ { \chemnum_compound_finish:n {##4} }
+ { \chemnum_expandable_compound_finish:n {##4} }
+ }
+ \__chemnum_split_sub_from_main_aux:nnnw {#2} {#3} {#4} #5#1#1 \q_stop
+ }
+\cs_generate_variant:Nn \chemnum_split_sub_from_main:nNNnn { V }
+
+\cs_new:Npn \__chemnum_split_sub_from_main_aux:nnnw #1#2#3#4.#5.#6 \q_stop {}
+
+% \chemnum_write_main:nnnn will write the main label, either with saved
+% values (+ variant, boolean #2=true), or only register it (* variant, boolean
+% #1=true)
+%
+% #1: boolean: if true register compound but don't write the label
+% #2: boolean: if true only read compound
+% #3: options
+% #4: label spec
+\cs_new_protected:Npn \chemnum_write_main:nnnn #1#2#3#4
{
- \tl_if_blank:VF \l__chemnum_cmpd_prefix_tl
+ \bool_if:NTF #2
{
- \tl_use:N \l__chemnum_cmpd_prefix_tl
- \tl_use:N \l__chemnum_cmpd_space_tl
+ \chemnum_compound_read:n {#4}
+ \bool_if:NT #1
+ { \msg_error:nn {chemnum} { erroneous-argument-combination } }
}
- \tl_use:N \l__chemnum_cmpd_odelim_tl
- \__chemnum_cmpd_use_style:n { #1 }
- \tl_use:N \l__chemnum_cmpd_cdelim_tl
- \tl_if_blank:VF \l__chemnum_cmpd_suffix_tl
{
- \tl_use:N \l__chemnum_cmpd_space_tl
- \tl_use:N \l__chemnum_cmpd_suffix_tl
+ \bool_if:NT \l__chemnum_show_ref_bool
+ { \cmpdshowref { #4 } }
+ \bool_if:nF
+ { #1 || \l__chemnum_sub_only_bool }
+ { \chemnum_compound_write:n {#4} }
}
}
-%-----------------------------------------------------------------------------%
-% main internal compound label command
-% #1: <main label> #2: <sub label> #3: <invisible> #4: <no delim>
-% #2 may be a list of sublabels
-\cs_new_protected:Npn \__chemnum_cmpd_aux:nnnn #1#2#3#4
+% ----------------------------------------------------------------------------
+\cs_set_protected:Npn \chemnum_show_key_def:n #1
+ { \marginpar { \fbox { \normalfont \ttfamily #1 } } }
+
+\cs_set_protected:Npn \chemnum_show_key_ref:n #1
+ {
+ \group_begin:
+ \hbox_unpack:N \c_empty_box % this is \leavevmode
+ \vbox_to_zero:n
+ {
+ \tex_vss:D
+ \hbox_overlap_right:n
+ {
+ \tex_vrule:D \tex_raise:D .75em
+ \hbox:n
+ { \underbar { \normalfont \footnotesize \ttfamily #1 } }
+ }
+ }
+ \group_end:
+ }
+
+% ----------------------------------------------------------------------------
+\NewDocumentCommand \chemnumshowdef { m }
+ { \chemnum_show_key_def:n { #1 } }
+\NewDocumentCommand \chemnumshowref { m }
+ { \chemnum_show_key_ref:n { #1 } }
+
+\NewDocumentCommand \cmpdshowdef { m } { \chemnumshowdef { #1 } }
+\NewDocumentCommand \cmpdshowref { m } { \chemnumshowref { #1 } }
+\NewDocumentCommand \subcmpdshowdef { mm } { \chemnumshowdef { #2~(#1) } }
+\NewDocumentCommand \subcmpdshowref { mm } { \chemnumshowref { #2 } }
+
+% ----------------------------------------------------------------------------
+% #1: boolean: if true register compound but don't write the label
+% #2: boolean: if true only read compound
+% #3: options
+% #4: main label id
+% #5: sublabel list
+\cs_new_protected:Npn \chemnum_write_sublist:NNnnn #1#2#3#4#5
+ {
+ \seq_set_split:NVn
+ \l__chemnum_tmpc_seq
+ \l__chemnum_sub_separator_tl
+ {#5}
+ \seq_remove_duplicates:N \l__chemnum_tmpc_seq
+ \seq_map_inline:Nn \l__chemnum_tmpc_seq
+ {
+ \bool_if:NF #2
+ { \chemnum_declare_subcompound:nnn {#3} {#4} {##1} }
+ }
+ \seq_clear:N \l__chemnum_tmpd_seq
+ % puts the subcompounds ready to be printed in \l__chemnum_tmpd_seq :
+ \chemnum_sort_subcompounds:NNNnnNN #1#2
+ \l__chemnum_tmpc_seq
+ {#3}
+ {#4}
+ \l__chemnum_tmpd_seq % to write the uncompressed list
+ \l__chemnum_tmpe_seq % for compressing the list, holds the numbers
+ \bool_if:nTF
+ {
+ \l__chemnum_compress_subcompounds_bool
+ &&
+ \int_compare_p:n { \seq_count:N \l__chemnum_tmpe_seq > 2 }
+ }
+ {
+ % needs a seq with the associated /numbers/!
+ \chemnum_compress_subcompounds:NNN
+ \l__chemnum_tmpd_seq % holds the IDs
+ \l__chemnum_tmpe_seq % holds the numbers
+ \l__chemnum_tmpc_seq % the new sequence
+ \seq_use:Nn \l__chemnum_tmpc_seq {}
+ }
+ {
+ \seq_use:NVVV \l__chemnum_tmpd_seq
+ \l__chemnum_sep_sublist_two_tl
+ \l__chemnum_sep_sublist_more_tl
+ \l__chemnum_sep_sublist_last_two_tl
+ }
+ }
+\cs_generate_variant:Nn \chemnum_write_sublist:NNnnn { NNnnV }
+
+% #1: boolean: if true register compound but don't write the label
+% #2: boolean: if true only read compound
+% #3: options
+% #4: main ID
+% #5: sub ID
+\cs_new_protected:Npn \chemnum_write_subcompound:NNnnn #1#2#3#4#5
+ {
+ \bool_if:NTF #2
+ { \chemnum_subcompound_read:nn {#4} {#5} }
+ {
+ \chemnum_declare_subcompound:nnn {#3} {#4} {#5}
+ \bool_if:NT \l__chemnum_show_ref_bool
+ { \subcmpdshowref { #4 } { #5 } }
+ \bool_if:NF #1
+ { \chemnum_subcompound_write:nn {#4} {#5} }
+ }
+ }
+\cs_generate_variant:Nn \chemnum_write_subcompound:NNnnn { NNnnV }
+
+%%% The following command sorts the sequence according to the order in which
+%%% they've been declared
+% #1: boolean: if true register compound but don't write the label
+% #2: boolean: if true only read compound
+% #3: sub ID sequence
+% #4: options
+% #5: main ID
+% #6: seq variable
+% #7: seq variable
+\cs_new_protected:Npn \chemnum_sort_subcompounds:NNNnnNN #1#2#3#4#5#6#7
{
- \bool_if:NT \l__chemnum_cmpd_initiated_bool
- { \__chemnum_cmpd_initiate:nn { #1 } { #2 } }
- \bool_if:NF \l__chemnum_cmpd_ref_bool
- { \__chemnum_cmpd_declare:n { #1 } }
- \__chemnum_hyperref:nnn { #1 } { #2 } { #3 }
- \tl_if_blank:nF { #2 }
+ \seq_clear:N #6
+ \seq_clear:N #7
+ \bool_if:NF #1
{
- \cs_if_exist:cF { g_chemnum_cmpd_#1_int }
- { \int_new:c { g_chemnum_cmpd_#1_int } }
- \__chemnum_cmpd_sublist:n { #2 }
- \bool_if:NF \l__chemnum_cmpd_ref_bool
+ \seq_map_inline:cn { g__chemnum_compound_#5_subcompounds_seq }
{
- \tl_map_inline:Nn \l__chemnum_cmpd_sublist_tl
+ \seq_if_in:NnT #3 {##1}
{
- \__chemnum_cmpd_subrange_separate:n { ##1 }
- \__chemnum_cmpd_sub_declare:no { #1 } { \l__chemnum_tmpb_tl }
- \tl_if_blank:VF \l__chemnum_tmpc_tl
- { \__chemnum_cmpd_sub_declare:no { #1 } { \l__chemnum_tmpc_tl } }
+ \seq_put_right:Nn #6
+ { \chemnum_write_subcompound:NNnnn #1 #2 {#4} {#5} {##1} }
+ \seq_put_right:Nx #7
+ {
+ \chemnum_expandable_get_subcompound_property:nnn
+ { #5 } { ##1 } { number }
+ }
}
}
}
- \bool_if:NTF #3
- { \mode_if_horizontal:T { \tex_unskip:D } }
- {
- \bool_if:NT #4
+ }
+
+% #1: sub ID sequence
+% #2: sub ID sequence that holds the numbers rather than the IDs
+% #3: seq variable
+\cs_new_protected:Npn \chemnum_compress_subcompounds:NNN #1#2#3
+ {
+ \int_zero:N \l__chemnum_tmpa_int
+ \int_zero:N \l__chemnum_tmpb_int
+ \seq_clear:N \l__chemnum_tmpa_seq
+ \seq_clear:N #3
+ \seq_map_inline:Nn #2
+ {
+ \int_incr:N \l__chemnum_tmpa_int
+ \int_compare:nTF { \l__chemnum_tmpa_int = 1 }
+ { \seq_put_right:Nn \l__chemnum_tmpa_seq { 1 } }
+ {
+ \seq_put_right:Nx \l__chemnum_tmpa_seq
+ { \int_eval:n { ##1 - \l__chemnum_tmpb_int } }
+ }
+ \int_set:Nn \l__chemnum_tmpb_int { ##1 }
+ }
+ \int_zero:N \l__chemnum_tmpa_int
+ \int_set:Nn \l__chemnum_tmpb_int { \seq_count:N #2 }
+ \int_zero:N \l__chemnum_tmpc_int
+ \seq_map_inline:Nn \l__chemnum_tmpa_seq
+ {
+ \int_incr:N \l__chemnum_tmpa_int
+ \int_compare:nTF { \l__chemnum_tmpa_int = 1 }
{
- \tl_clear:N \l__chemnum_cmpd_odelim_tl
- \tl_clear:N \l__chemnum_cmpd_cdelim_tl
+ \int_add:Nn \l__chemnum_tmpc_int { ##1 }
+ \seq_put_right:Nx #3 { \seq_item:Nn #1 { 1 } }
}
- \__chemnum_make_hyper:nn { \l__chemnum_cmpd_hyper_name_tl }
{
- \__chemnum_cmpd_print:n
+ \int_compare:nTF { ##1 = 1 }
+ { \int_add:Nn \l__chemnum_tmpc_int { ##1 } }
{
- \bool_if:NF \l__chemnum_sub_label_only_bool
+ \int_compare:nTF { \l__chemnum_tmpc_int > 2 }
{
- \bool_if:NTF \l__chemnum_cmpd_ref_bool
- { \use:c { chemnum_cmpd_ #1 _ref: } }
- { \use:c { chemnum_cmpd_ #1 : } }
+ \seq_put_right:NV #3 \l__chemnum_sep_sublist_range_tl
+ \seq_put_right:Nx #3
+ { \seq_item:Nn #1 { \l__chemnum_tmpa_int - 1 } }
+ \seq_put_right:NV #3 \l__chemnum_sep_sublist_two_tl
+ \seq_put_right:Nx #3
+ { \seq_item:Nn #1 { \l__chemnum_tmpa_int } }
}
- \bool_if:NTF \l__chemnum_cmpd_all_bool
{
- \tl_use:N \l__chemnum_cmpd_separator_tl
- \use:c { chemnum_cmpd_ #1 _min_ref: }
- \cs_if_eq:ccF
- { chemnum_cmpd_ #1 _min_ref: }
- { chemnum_cmpd_ #1 _max_ref: }
+ \seq_get_right:NN #3 \l__chemnum_tmpa_tl
+ \tl_if_eq:VxF
+ \l__chemnum_tmpa_tl
+ { \seq_item:Nn #1 { \l__chemnum_tmpa_int - 1 } }
{
- \tl_use:N \l__chemnum_sub_range_sep_tl
- \use:c { chemnum_cmpd_ #1 _max_ref: }
+ \seq_put_right:NV #3 \l__chemnum_sep_sublist_two_tl
+ \seq_put_right:Nx #3
+ { \seq_item:Nn #1 { \l__chemnum_tmpa_int - 1 } }
}
+ \seq_put_right:NV #3 \l__chemnum_sep_sublist_two_tl
+ \seq_put_right:Nx #3
+ { \seq_item:Nn #1 { \l__chemnum_tmpa_int } }
}
+ \int_set:Nn \l__chemnum_tmpc_int { 1 }
+ }
+ \int_compare:nT { \l__chemnum_tmpa_int = \l__chemnum_tmpb_int }
+ {
+ \seq_get_right:NN #3 \l__chemnum_tmpa_tl
+ \tl_if_eq:VxF
+ \l__chemnum_tmpa_tl
+ { \seq_item:Nn #1 { \l__chemnum_tmpa_int } }
{
- \bool_if:NTF \l__chemnum_sublabel_list_bool
- {
- \__chemnum_cmpd_sublabel_list:nn { #1 }
- { \l__chemnum_cmpd_sublabel_list_tl }
- }
- {
- \tl_if_blank:nF { #2 }
- {
- \tl_use:N \l__chemnum_cmpd_separator_tl
- \int_zero:N \l__chemnum_tmpa_int
- \tl_map_inline:Nn \l__chemnum_cmpd_sublist_tl
- {
- \int_incr:N \l__chemnum_tmpa_int
- \__chemnum_cmpd_subrange_separate:n { ##1 }
- \bool_if:NTF \l__chemnum_cmpd_ref_bool
- { \use:c { chemnum_cmpd_ #1 _ \l__chemnum_tmpb_tl _ref: } }
- { \use:c { chemnum_cmpd_ #1 _ \l__chemnum_tmpb_tl : } }
- \tl_if_blank:VF \l__chemnum_tmpc_tl
- {
- \tl_use:N \l__chemnum_sub_range_sep_tl
- \bool_if:NTF \l__chemnum_cmpd_ref_bool
- { \use:c { chemnum_cmpd_ #1 _ \l__chemnum_tmpc_tl _ref: } }
- { \use:c { chemnum_cmpd_ #1 _ \l__chemnum_tmpc_tl : } }
- }
- \int_compare:nF
- { \l__chemnum_tmpa_int = \l__chemnum_cmpd_sublist_length_int }
- { \l__chemnum_sublist_output_separator_tl }
- }
- }
- }
+ \int_compare:nTF { \l__chemnum_tmpc_int > 2 }
+ { \seq_put_right:NV #3 \l__chemnum_sep_sublist_range_tl }
+ { \seq_put_right:NV #3 \l__chemnum_sep_sublist_last_two_tl }
+ \seq_put_right:Nx #3
+ { \seq_item:Nn #1 { \l__chemnum_tmpa_int } }
}
}
}
}
}
-\cs_generate_variant:Nn \__chemnum_cmpd_aux:nnnn { VV }
-
-%-----------------------------------------------------------------------------%
-% create compound label
-% #1: label name #2: star (invisible) #3: minus (no delimiters)
-\cs_new_protected:Npn \__chemnum_cmpd:nnn #1#2#3 {
- \group_begin:
- \tl_clear:N \l__chemnum_cmpd_main_label_tl
- \tl_clear:N \l__chemnum_cmpd_sub_label_tl
- \__chemnum_cmpd_labelsep:n #1 \q_stop
- \tl_remove_all:Nn \l__chemnum_cmpd_sub_label_tl { ~ }
- \__chemnum_cmpd_aux:VVnn
- \l__chemnum_cmpd_main_label_tl
- \l__chemnum_cmpd_sub_label_tl
- { #2 }
- { #3 }
- \group_end:
-}
-
-\cs_generate_variant:Nn \__chemnum_cmpd:nnn { V }
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% DOCUMENT COMMANDS
-% variables:
-\int_new:N \l__chemnum_list_items_int
-\int_new:N \l__chemnum_list_separate_int
-
-\tl_new:N \l__chemnum_list_last_sep_empty_tl
-\tl_set:Nn \l__chemnum_list_last_sep_empty_tl { empty }
-
-\bool_new:N \l__chemnum_cmpd_ref_bool
-
-\msg_set:nnnn { chemnum } { fatal-combination }
- {
- You~can't~use \c_space_tl \token_to_str:N \cmpd \c_space_tl
- with~star~and~#1 \c_space_tl \msg_line_context: .
- }
- {
- You~used \c_space_tl \token_to_str:N \cmpd \c_space_tl
- with~both~star~and~#1 \c_space_tl \msg_line_context: .\\
- ~This~is~not~possible~since~it~doesn't~make~any~sense.
- }
-
-%-----------------------------------------------------------------------------%
-% MAIN COMMAND
-% \cmpd*+-[<key-value-list>]{<(possibly comma separated list of) compound
-% label(s)>}
-\NewDocumentCommand \__chemnum_input_separator:n
- { > { \exp_args:No \SplitList { \l__chemnum_list_input_separator_tl } } m }
- { \tl_set:Nn \l__chemnum_tmpb_tl { #1 } }
-
-\NewDocumentCommand \cmpd { s t+ t- o m }
- { \cmpd_main:nnnnn { #1 } { #2 } { #3 } { #4 } { #5 } }
-
-\cs_new_protected:Npn \cmpd_main:nnnnn #1#2#3#4#5
+% ----------------------------------------------------------------------------
+% the code level version of the main command:
+% #1: boolean: if true register compound but don't write the label
+% #2: boolean: if true only read compound
+% #3: options
+% #4: list of IDs
+\cs_new_protected:Npn \chemnum_cmpd:nnnn #1#2#3#4
{
- \IfBooleanT #2
- {
- \bool_set_true:N \l__chemnum_cmpd_ref_bool
- \IfBooleanT #1
- { \msg_error:nnx { chemnum } { fatal-combination } { plus } }
- }
- \tl_clear:N \l__chemnum_tmpa_tl
\group_begin:
- \int_zero:N \l__chemnum_list_items_int
- \int_zero:N \l__chemnum_list_separate_int
- \IfNoValueF { #4 }
- { \keys_set:nn { chemnum } { #4 } }
- \__chemnum_input_separator:n { #5 }
- \tl_map_variable:NNn \l__chemnum_tmpb_tl \l__chemnum_tmpa_tl
+ \keys_set_groups:nnn {chemnum} {list} {#3}
+ \seq_set_split:NVn
+ \l__chemnum_tmpa_seq
+ \l__chemnum_main_separator_tl
+ {#4}
+ \seq_remove_duplicates:N \l__chemnum_tmpa_seq
+ \chemnum_sort_main_labels:N \l__chemnum_tmpa_seq
+ \seq_clear:N \l__chemnum_tmpb_seq
+ \seq_map_inline:Nn \l__chemnum_tmpa_seq
{
- \tl_if_blank:VF \l__chemnum_tmpa_tl
- { \int_incr:N \l__chemnum_list_items_int }
+ \seq_put_right:Nn \l__chemnum_tmpb_seq
+ { \chemnum_single_compound:NNnn #1 #2 {#3} {##1} }
}
- \tl_map_variable:NNn \l__chemnum_tmpb_tl \l__chemnum_tmpa_tl
+ \bool_if:NTF #1 % starred call of \cmpd
+ { \seq_use:Nn \l__chemnum_tmpb_seq {} }
{
- \tl_remove_all:Nn \l__chemnum_tmpa_tl { ~ }
- \tl_if_blank:VF \l__chemnum_tmpa_tl
- {
- \int_incr:N \l__chemnum_list_separate_int
- \IfBooleanF #1
- {
- \if_int_compare:w \l__chemnum_list_separate_int = 1
- \if_int_compare:w \l__chemnum_list_items_int = 1
- \else:
- \tl_use:N \l__chemnum_list_prefix_tl
- \tl_if_blank:VF { \l__chemnum_list_prefix_tl }
- { \l__chemnum_list_space_tl }
- \tl_use:N \l__chemnum_list_odelim_tl
- \fi:
- \fi:
- }
- \IfBooleanTF #1
- {
- \__chemnum_cmpd:Vnn
- \l__chemnum_tmpa_tl
- { \BooleanTrue }
- { \BooleanFalse }
- \IfBooleanT #3
- {
- \msg_error:nnx { chemnum }
- { fatal-combination } { minus }
- }
- }
- {
- \IfBooleanTF #3
- {
- \__chemnum_cmpd:Vnn
- \l__chemnum_tmpa_tl
- { \BooleanFalse }
- { \BooleanTrue }
- }
- {
- \__chemnum_cmpd:Vnn
- \l__chemnum_tmpa_tl
- { \BooleanFalse }
- { \BooleanFalse }
- }
- \int_compare:nTF
- { \l__chemnum_list_separate_int = \l__chemnum_list_items_int }
- {
- \int_compare:nNnF { \l__chemnum_list_items_int } = { 1 }
- {
- \tl_use:N \l__chemnum_list_cdelim_tl
- \tl_if_blank:VF
- { \l__chemnum_list_suffix_tl }
- { \l__chemnum_list_space_tl }
- \tl_use:N \l__chemnum_list_suffix_tl
- }
- }
- {
- \int_compare:nTF
- {
- \l__chemnum_list_separate_int
- =
- \int_eval:n { \l__chemnum_list_items_int - 1 }
- }
- {
- \tl_if_eq:NNTF
- \l__chemnum_list_last_separator_tl
- \l__chemnum_list_last_sep_empty_tl
- {
- \tl_use:N \l__chemnum_list_separator_tl
- \l__chemnum_list_space_tl
- }
- {
- \int_compare:nNnF
- { \l__chemnum_list_separate_int } = { 1 }
- {
- \bool_if:NF \l__chemnum_no_serial_comma_bool
- { \l__chemnum_list_separator_tl }
- }
- \tl_if_blank:VF \l__chemnum_list_last_separator_tl
- { \l__chemnum_list_space_tl }
- \tl_use:N \l__chemnum_list_last_separator_tl
- \l__chemnum_list_space_tl
- }
- }
- {
- \tl_use:N \l__chemnum_list_separator_tl
- \l__chemnum_list_space_tl
- }
- }
- }
- }
+ \seq_use:NVVV \l__chemnum_tmpb_seq
+ \l__chemnum_sep_list_two_tl
+ \l__chemnum_sep_list_more_tl
+ \l__chemnum_sep_list_last_two_tl
}
\group_end:
- \bool_set_false:N \l__chemnum_cmpd_ref_bool
- }
-
-%-----------------------------------------------------------------------------%
-% INITIALISING LABELS
-\bool_new:N \l__chemnum_cmpd_initiated_bool
-\bool_new:N \l__chemnum_cmpd_init_strict_bool
-\bool_new:N \l__chemnum_cmpd_sub_init_bool
-\bool_new:N \l__chemnum_cmpd_init_declare_bool
-
-\tl_new:N \l__chemnum_cmpd_init_separator_tl
-\tl_set:Nn \l__chemnum_cmpd_init_separator_tl { , }
-
-% property keys for \cmpdinit command
-% strict=true will produce an error instead of a warning
-\keys_define:nn { chemnum } {
- init-strict .bool_set:N = \l__chemnum_cmpd_init_strict_bool ,
- init-strict .default:n = true ,
- init-sub .bool_set:N = \l__chemnum_cmpd_sub_init_bool ,
- init-sub .default:n = true ,
- init-input-sep .tl_set:N = \l__chemnum_cmpd_init_separator_tl ,
- init-input-sep .default:n = { , }
-}
-
-% warning/error messages
-\msg_set:nnn { chemnum } { cmpd-init }
- {
- You~used~\token_to_str:N \cmpdinit \c_space_tl but~didn't~initiate~
- compound~"#1"~\msg_line_context: .
}
-\msg_set:nnn { chemnum } { cmpd-init-sub }
+% #1: first variable
+% #2: second variable
+% #3: main/sub separator
+% #4: complete label
+\cs_new_protected:Npn \chemnum_separate_main_sub:NNnn #1#2#3#4
{
- You~used~\token_to_str:N \cmpdinit \c_space_tl and~"init-sub~=~true"~
- but~didn't~initiate~sub-compound~"#1"~\msg_line_context: .
+ \cs_set:Npn \__chemnum_remove_sub:w ##1#3##2 \q_stop
+ { \exp_not:n { ##1 } }
+ \cs_set:Npn \__chemnum_get_sub:w ##1#3##2#3##3 \q_stop
+ {
+ \tl_if_blank:nF {##2} { \exp_not:n { ##2 } }
+ }
+ \tl_set:Nx #1 { \__chemnum_remove_sub:w #4#3 \q_stop }
+ \tl_set:Nx #2 { \__chemnum_get_sub:w #4#3#3 \q_stop }
}
+\cs_generate_variant:Nn \chemnum_separate_main_sub:NNnn { NNV }
-% initialize (and maybe declare) labels
-\cs_new_protected:Npn \__chemnum_cmpd_init:n #1
+% sorting and merging of the main label list:
+% #1: seq that holds the label list
+\cs_new_protected:Npn \chemnum_sort_main_labels:N #1
{
- \tl_clear:N \l__chemnum_tmpa_tl
- \tl_set:Nn \l__chemnum_tmpa_tl { #1 }
- \tl_remove_all:Nn \l__chemnum_tmpa_tl { ~ }
- \tl_clear:N \l__chemnum_cmpd_main_label_tl
- \tl_clear:N \l__chemnum_cmpd_sub_label_tl
- \exp_after:wN \__chemnum_cmpd_labelsep:n \l__chemnum_tmpa_tl \q_stop
- \cs_if_exist:cF { chemnum_cmpd_ \l__chemnum_cmpd_main_label_tl _init: }
+ \prop_clear:N \l__chemnum_tmpa_prop
+ \seq_clear:N \l__chemnum_tmpb_seq
+ \seq_clear:N \l__chemnum_tmpc_seq
+ % build property list that holds entries of #1:
+ \seq_map_inline:Nn #1
{
- \cs_new_protected:cpn
- { chemnum_cmpd_ \l__chemnum_cmpd_main_label_tl _init: }
- { }
+ \chemnum_separate_main_sub:NNVn
+ \l__chemnum_tmpa_tl % main part
+ \l__chemnum_tmpb_tl % sub part
+ \l__chemnum_compound_separator_tl
+ {##1}
+ \bool_if:NTF \l__chemnum_merge_list_bool
+ {
+ \prop_get:NVNTF \l__chemnum_tmpa_prop
+ \l__chemnum_tmpa_tl
+ \l__chemnum_tmpc_tl
+ {
+ \prop_put:NVx \l__chemnum_tmpa_prop
+ \l__chemnum_tmpa_tl
+ {
+ \exp_not:V \l__chemnum_tmpc_tl
+ \exp_not:V \l__chemnum_sub_separator_tl
+ \exp_not:V \l__chemnum_tmpb_tl
+ }
+ }
+ {
+ \prop_put:NVV \l__chemnum_tmpa_prop
+ \l__chemnum_tmpa_tl
+ \l__chemnum_tmpb_tl
+ }
+ }
+ {
+ \prop_get:NVNTF \l__chemnum_tmpa_prop
+ \l__chemnum_tmpa_tl
+ \l__chemnum_tmpc_tl
+ {
+ \prop_put:NVx \l__chemnum_tmpa_prop
+ \l__chemnum_tmpa_tl
+ {
+ \exp_not:V \l__chemnum_tmpc_tl
+ \exp_not:V \l__chemnum_main_separator_tl
+ \exp_not:n {##1}
+ }
+ }
+ {
+ \prop_put:NVn \l__chemnum_tmpa_prop
+ \l__chemnum_tmpa_tl
+ {##1}
+ }
+ }
}
- \bool_if:NT \l__chemnum_cmpd_sub_init_bool
+ % merge = true:
+ % \l__chemnum_tmpa_prop now holds all main labels with possible sublabel
+ % lists
+ % merge = false
+ % \l__chemnum_tmpa_prop now holds all main labels with all occurences of
+ % the respective main label as property
+ %
+ % build sequence that holds entries of #1 in order of already defined
+ % labels:
+ \seq_map_inline:Nn \g__chemnum_defined_compounds_seq
{
- \tl_if_blank:VF \l__chemnum_cmpd_sub_label_tl
+ \bool_if:NTF \l__chemnum_merge_list_bool
{
- \__chemnum_cmpd_sublist:V \l__chemnum_cmpd_sub_label_tl
- \tl_map_inline:Nn \l__chemnum_cmpd_sublist_tl
+ \prop_get:NnNT \l__chemnum_tmpa_prop {##1} \l__chemnum_tmpa_tl
{
- \cs_if_exist:cF
+ \tl_if_in:VVTF
+ \l__chemnum_tmpa_tl
+ \l__chemnum_sub_separator_tl
{
- chemnum_cmpd_
- \l__chemnum_cmpd_main_label_tl
- _
- ##1
- _init:
+ \seq_put_right:Nx \l__chemnum_tmpb_seq
+ {
+ \exp_not:n { ##1 }
+ \tl_if_blank:VF \l__chemnum_tmpa_tl
+ {
+ \exp_not:V \l__chemnum_compound_separator_tl
+ { \exp_not:V \l__chemnum_tmpa_tl }
+ }
+ }
}
{
- \cs_new_protected:cpn
+ \seq_put_right:Nx \l__chemnum_tmpb_seq
{
- chemnum_cmpd_
- \l__chemnum_cmpd_main_label_tl
- _
- ##1
- _init:
+ \exp_not:n { ##1 }
+ \tl_if_blank:VF \l__chemnum_tmpa_tl
+ {
+ \exp_not:V \l__chemnum_compound_separator_tl
+ \exp_not:V \l__chemnum_tmpa_tl
+ }
}
- { }
}
+ \seq_if_in:NnF \l__chemnum_tmpc_seq {##1}
+ { \seq_put_right:Nn \l__chemnum_tmpc_seq {##1} }
+ }
+ }
+ {
+ \prop_get:NnNT \l__chemnum_tmpa_prop {##1} \l__chemnum_tmpa_tl
+ {
+ \tl_if_in:VVTF
+ \l__chemnum_tmpa_tl
+ \l__chemnum_main_separator_tl
+ {
+ \seq_set_split:NVV \l__chemnum_tmpc_seq
+ \l__chemnum_main_separator_tl
+ \l__chemnum_tmpa_tl
+ \seq_map_inline:Nn \l__chemnum_tmpc_seq
+ { \seq_put_right:Nn \l__chemnum_tmpb_seq {####1} }
+ }
+ { \seq_put_right:NV \l__chemnum_tmpb_seq \l__chemnum_tmpa_tl }
}
}
}
- \bool_if:NT \l__chemnum_cmpd_init_declare_bool
+ % \l__chemnum_tmpb_seq now holds all labels that are already defined
+ % merge = true :
+ % the same \l__chemnum_tmpc_seq which only holds the /main/ labels
+ \bool_if:NTF \l__chemnum_merge_list_bool
{
- \__chemnum_cmpd:Vnn
- \l__chemnum_tmpa_tl
- { \BooleanTrue }
- { \BooleanFalse }
+ \seq_map_inline:Nn #1
+ {
+ \chemnum_separate_main_sub:NNVn
+ \l__chemnum_tmpa_tl % main part
+ \l__chemnum_tmpb_tl % sub part
+ \l__chemnum_compound_separator_tl
+ {##1}
+ % check if existing main label is present, otherwise add entry
+ \seq_if_in:NVF \l__chemnum_tmpc_seq \l__chemnum_tmpa_tl
+ {
+ \prop_get:NVNT \l__chemnum_tmpa_prop
+ \l__chemnum_tmpa_tl
+ \l__chemnum_tmpc_tl
+ {
+ \seq_put_right:Nx \l__chemnum_tmpb_seq
+ {
+ \exp_not:V \l__chemnum_tmpa_tl
+ \tl_if_blank:VF \l__chemnum_tmpc_tl
+ {
+ \exp_not:V \l__chemnum_compound_separator_tl
+ \exp_not:V \l__chemnum_tmpc_tl
+ }
+ }
+ \seq_put_right:NV \l__chemnum_tmpc_seq \l__chemnum_tmpa_tl
+ }
+ }
+ }
+ }
+ {
+ \seq_map_inline:Nn #1
+ {
+ \seq_if_in:NnF \l__chemnum_tmpb_seq {##1}
+ { \seq_put_right:Nn \l__chemnum_tmpb_seq {##1} }
+ }
}
+ \seq_set_eq:NN #1 \l__chemnum_tmpb_seq
}
-\cs_generate_variant:Nn \__chemnum_cmpd_sublist:n { V }
-
-% \cmpdinit*[strict=<bool>]{<comma separated list of label names>}
-\NewDocumentCommand \cmpdinit { s o m }
- {
- \bool_set_true:N \l__chemnum_cmpd_initiated_bool
- \IfBooleanTF #1
- { \bool_set_false:N \l__chemnum_cmpd_init_declare_bool }
- { \bool_set_true:N \l__chemnum_cmpd_init_declare_bool }
- \IfNoValueF { #2 } { \keys_set:nn { chemnum } { #2 } }
- \__chemnum_input_separator:n { #3 }
- \tl_map_function:NN \l__chemnum_tmpb_tl \__chemnum_cmpd_init:n
- }
-
-%-----------------------------------------------------------------------------%
-% RESET LABEL NUMBERS
-% \cmpdreset[<number>]
-\NewDocumentCommand \cmpdreset { o }
- {
- \IfNoValueTF { #1 }
- { \int_zero:N \g__chemnum_cmpd_int }
- { \int_set:Nn \g__chemnum_cmpd_int { #1 - 1 } }
- }
-
-%-----------------------------------------------------------------------------%
-% CHEMNUM SETUP COMMAND
-% \cmpdsetup{<key-value-list>}
-\NewDocumentCommand \cmpdsetup { m }
- { \keys_set:nn { chemnum } { #1 } \tex_ignorespaces:D }
-
-%-----------------------------------------------------------------------------%
-% REPLACE TAG IN EPS PICTURE WITH LABEL
-% works similar to \schemeref command of the chemscheme package
-% \cmpdref-[<keyval>][<tag>]{<label name>}
-\tl_new:N \l__chemnum_cmpdref_tl
-\tl_new:N \l__chemnum_cmpdref_style_tl
-\tl_set:Nn \l__chemnum_cmpdref_style_tl { \sffamily }
-\tl_new:N \l__chemnum_cmpdref_marker_tl
-\tl_set:Nn \l__chemnum_cmpdref_marker_tl { TMP }
-\tl_new:N \l__chemnum_psfrag_texpos_tl
-\tl_new:N \l__chemnum_psfrag_texpos_current_tl
-\tl_set:Nn \l__chemnum_psfrag_texpos_tl { b }
-\tl_new:N \l__chemnum_psfrag_pspos_tl
-\tl_new:N \l__chemnum_psfrag_pspos_current_tl
-\tl_set:Nn \l__chemnum_psfrag_pspos_tl { b }
-\int_new:N \l__chemnum_cmpdref_int
+% %-----------------------------------------------------------------------------%
+% % REPLACE TAG IN EPS PICTURE WITH LABEL
+% % works similar to \schemeref command of the chemscheme package
+% % \cmpdref-[<keyval>][<tag>]{<label name>}
\cs_new_protected:Npn \__chemnum_set_psfrag_pos:nn #1#2
{
@@ -1391,240 +1671,213 @@
\tl_set:Nn \l__chemnum_psfrag_pspos_tl { #2 }
}
+\cs_new_protected:Npn \__chemnum_set_psfrag_local_pos:nn #1#2
+ {
+ \tl_set:Nn \l__chemnum_psfrag_local_texpos_tl { #1 }
+ \tl_set:Nn \l__chemnum_psfrag_local_pspos_tl { #2 }
+ }
+\cs_generate_variant:Nn \__chemnum_set_psfrag_local_pos:nn { VV }
+
\cs_new_protected:Npn \__chemnum_psfrag:nnnn #1#2#3#4
{ \psfrag { #1 } [ #2 ] [ #3 ] { #4 } }
-\cs_generate_variant:Nn \__chemnum_psfrag:nnnn { VVVn }
+\cs_generate_variant:Nn \__chemnum_psfrag:nnnn { VVVx }
-\cs_new_protected:Npn \__chemnum_set_psfrag_pos_local:w #1 ref-pos #2 = #3#4 , #5 \q_stop
+% #1: boolean: if true only read label
+% #2: options
+% #3: label spec
+\cs_new_protected:Npn \chemnum_cmpd_replace:nnn #1#2#3
{
- \tl_set_eq:NN \l__chemnum_psfrag_texpos_current_tl \l__chemnum_psfrag_texpos_tl
- \tl_set_eq:NN \l__chemnum_psfrag_pspos_current_tl \l__chemnum_psfrag_pspos_tl
- \tl_set:Nn \l__chemnum_psfrag_texpos_tl { #3 }
- \tl_set:Nn \l__chemnum_psfrag_pspos_tl { #4 }
+ % place the label
+ % just in case it hasn't been declared:
+ \labelcmpd[{#2}]{#3}
+ % set specific replacement options
+ \keys_set_groups:nnn {chemnum} {replace} { replace=false, #2 }
+ \bool_if:nTF
+ {
+ \l__chemnum_compound_replace_auto_bool &&
+ \l__chemnum_compound_replace_auto_this_bool
+ }
+ {
+ \int_incr:N \l__chemnum_compound_replace_int
+ \tl_set:Nx \l__chemnum_compound_replace_tl
+ {
+ \exp_not:V \l__chemnum_compound_replace_tag_tl
+ \exp_not:V \l__chemnum_compound_replace_int
+ }
+ }
+ {
+ \tl_set_eq:NN
+ \l__chemnum_compound_replace_tl
+ \l__chemnum_compound_replace_tag_tl
+ \bool_set_true:N \l__chemnum_compound_replace_auto_this_bool
+ }
+ % replace in EPS, this must not be in a group:
+ \bool_if:NTF \l__chemnum_replace_local_bool
+ {
+ \__chemnum_psfrag:VVVx
+ \l__chemnum_compound_replace_tl
+ \l__chemnum_psfrag_local_texpos_tl
+ \l__chemnum_psfrag_local_pspos_tl
+ {
+ \group_begin:
+ \exp_not:V \l__chemnum_compound_replace_local_format_tl
+ \exp_not:n
+ { \chemnum_cmpd:nnnn { \c_false_bool } { #1 } { #2 } { #3 } }
+ \group_end:
+ }
+ }
+ {
+ \__chemnum_psfrag:VVVx
+ \l__chemnum_compound_replace_tl
+ \l__chemnum_psfrag_texpos_tl
+ \l__chemnum_psfrag_pspos_tl
+ {
+ \group_begin:
+ \exp_not:V \l__chemnum_compound_replace_format_tl
+ \exp_not:n
+ { \chemnum_cmpd:nnnn { \c_false_bool } { #1 } { #2 } { #3 } }
+ \group_end:
+ }
+ }
+ % clean up local options:
+ \keys_set_groups:nnn {chemnum} {replace} { replace=false }
+ \__chemnum_set_psfrag_local_pos:VV
+ \l__chemnum_psfrag_texpos_tl
+ \l__chemnum_psfrag_pspos_tl
+ \tl_set_eq:NN
+ \l__chemnum_compound_replace_local_format_tl
+ \l__chemnum_compound_replace_format_tl
}
-\keys_define:nn { chemnum }
+\NewDocumentCommand \replacecmpd { t+ o m }
+ { \chemnum_cmpd_replace:nnn { #1 } { #2 } { #3 } }
+
+\chemnum_deprecated_command:NN \cmpdref \replacecmpd
+
+% ----------------------------------------------------------------------------
+% the user level version of the main command:
+\NewDocumentCommand \cmpd { st+O{}m }
+ { \chemnum_cmpd:nnnn {#1} {#2} {#3} {#4} }
+
+\NewDocumentCommand \refcmpd { O{}m }
+ { \chemnum_cmpd:nnnn { \c_false_bool } { \c_true_bool } {#1} {#2} }
+
+\NewDocumentCommand \labelcmpd { O{}m }
+ { \chemnum_cmpd:nnnn { \c_true_bool } { \c_false_bool } {#1} {#2} }
+
+\DeclareExpandableDocumentCommand \cmpdplain { m }
{
- ref-tag .tl_set:N = \l__chemnum_cmpdref_marker_tl ,
- ref-tag .default:n = { TMP } ,
- ref-style .tl_set:N = \l__chemnum_cmpdref_style_tl ,
- ref-style .default:n = { } ,
- ref-pos .code:n = \__chemnum_set_psfrag_pos:nn #1 ,
- ref-pos .default:n = bb
+ \chemnum_expandable_compound_start:n {#1}
+ \chemnum_expandable_compound_read:n {#1}
+ \chemnum_expandable_compound_finish:n {#1}
}
-\NewDocumentCommand \cmpdref { t- t+ o o m }
- { \cmpd_ref:nnnnn { #1 } { #2 } { #3 } { #4 } { #5 } }
+\DeclareExpandableDocumentCommand \subcmpdplain { mm }
+ { \chemnum_expandable_subcompound_read:nn {#1} {#2} }
-\cs_new_protected:Npn \cmpd_ref:nnnnn #1#2#3#4#5
+\DeclareExpandableDocumentCommand \submaincmpdplain { mm }
{
- \IfBooleanT { #1 }
- { \keys_set:nn { chemnum } { cmpd-delim = } }
- \IfNoValueTF { #3 }
- {
- \int_incr:N \l__chemnum_cmpdref_int
- \tl_set:No \l__chemnum_cmpdref_tl
- {
- \tl_use:N \l__chemnum_cmpdref_marker_tl
- \int_use:N \l__chemnum_cmpdref_int
- }
- }
- {
- \tl_if_blank:nTF { #3 }
- {
- \int_incr:N \l__chemnum_cmpdref_int
- \tl_set:No \l__chemnum_cmpdref_tl
- {
- \tl_use:N \l__chemnum_cmpdref_marker_tl
- \int_use:N \l__chemnum_cmpdref_int
- }
- }
- { \tl_set:Nn \l__chemnum_cmpdref_tl { #3 } }
- }
- \IfNoValueTF { #4 }
- {
- % need to call it once invisible in case it's the first time the label
- % is called. Somehow it otherwise “vanishes” inside \psfrag
- \IfBooleanF { #2 }
- { \cmpd * { #5 } }
- \__chemnum_psfrag:VVVn
- \l__chemnum_cmpdref_tl
- \l__chemnum_psfrag_texpos_tl
- \l__chemnum_psfrag_pspos_tl
- {
- \group_begin:
- \keys_set:nn { chemnum }
- { cmpd-style = \l__chemnum_cmpdref_style_tl }
- \IfBooleanTF { #2 }
- { \cmpd + { #5 } }
- { \cmpd { #5 } }
- \group_end:
- }
- }
- {
- % TODO: set psfrag positions before \__chemnum_psfrag is called
- % ?? hat sich erledigt, oder?
- \IfBooleanF { #2 }
- { \cmpd * [ #4 ] { #5 } }
- \tl_if_in:nnT { #4 } { ref-pos }
- { \__chemnum_set_psfrag_pos_local:w #4 , \q_stop }
- \__chemnum_psfrag:VVVn
- \l__chemnum_cmpdref_tl
- \l__chemnum_psfrag_texpos_tl
- \l__chemnum_psfrag_pspos_tl
- {
- \group_begin:
- \keys_set:nn { chemnum }
- { cmpd-style = \l__chemnum_cmpdref_style_tl }
- \IfBooleanTF { #2 }
- { \cmpd + [ #4 ] { #5 } }
- { \cmpd [ #4 ] { #5 } }
- \group_end:
- }
- \tl_if_in:nnT { #4 } { ref-pos }
- {
- \tl_set_eq:NN
- \l__chemnum_psfrag_texpos_tl \l__chemnum_psfrag_texpos_current_tl
- \tl_set_eq:NN
- \l__chemnum_psfrag_pspos_tl \l__chemnum_psfrag_pspos_current_tl
- }
- }
+ \chemnum_expandable_compound_start:n {#1}
+ \chemnum_expandable_compound_read:n {#1}
+ \chemnum_expandable_subcompound_read:nn {#1} {#2}
+ \chemnum_expandable_compound_finish:n {#1}
}
-% --------------------------------------------------------------------------- %
-% one for the hackers: get the label numbers in an expandable way:
-\cs_new:Npn \cmpd@main #1 { \use:c { chemnum_cmpd_#1: } }
-\cs_new:Npn \cmpd@sub #1#2 { \use:c { chemnum_cmpd_#1_#2: } }
+% ----------------------------------------------------------------------------
+\cs_new_protected:Npn \chemnum_init:nn #1#2
+ {
+ \group_begin:
+ % this is semantically wrong! The conflict: either I allow initiation
+ % to be set locally (which does not make sense, really) or I use wrong
+ % semantics at this very point in the package code...
+ \bool_set_false:N \g__chemnum_initiate_bool
+ \bool_set_false:N \g__chemnum_initiate_sub_bool
+ \chemnum_cmpd:nnnn { \c_true_bool } { \c_false_bool } {#1} {#2}
+ \group_end:
+ }
-% usage - main label of \cmpd{<label>.<sub>} => \cmpd@main{<label>}
-% - sublabel of \cmpd{<label>.<sub>} => \cmpd@aub{<label>}{<sub>}
-% Please be aware that this will _not_ be expandable when you use greek labels
+\NewDocumentCommand \initcmpd { O{}m }
+ { \chemnum_init:nn {#1} {#2} }
+\@onlypreamble\cmpdinit
-% --------------------------------------------------------------------------- %
-% language support:
+\chemnum_deprecated_command:NN \cmpdinit \initcmpd
-\RequirePackage { translations }
-\DeclareTranslationFallback { and~(list~seperator) } { and }
-\DeclareTranslation { English } { and~(list~seperator) } { and }
-\DeclareTranslation { French } { and~(list~seperator) } { et }
-\DeclareTranslation { German } { and~(list~seperator) } { und }
-\DeclareTranslation { Italian } { and~(list~seperator) } { e }
-\DeclareTranslation { Spanish } { and~(list~seperator) } { y }
-\tl_set:Nn \l__chemnum_list_last_separator_lang_tl
- { \GetTranslation { and~(list~seperator) } }
+% ----------------------------------------------------------------------------
+% resetting compound numbering
+\cs_new_protected:Npn \chemnum_reset_compounds:n #1
+ { \setcounter {cmpdmain} { \int_eval:n { #1 - 1 } } }
-\AtBeginDocument
+\NewDocumentCommand \resetcmpd { O{1} }
+ { \chemnum_reset_compounds:n {#1} }
+
+\chemnum_deprecated_command:NN \cmpdreset \resetcmpd
+
+% ----------------------------------------------------------------------------
+% language support:
+\DeclareTranslationFallback {chemnum-sep-two} {~and~}
+\DeclareTranslation {English} {chemnum-sep-two} {~and~}
+\DeclareTranslation {German} {chemnum-sep-two} {~und~}
+\DeclareTranslation {French} {chemnum-sep-two} {~et~}
+\DeclareTranslation {Spanish} {chemnum-sep-two} {~y~}
+\DeclareTranslation {Italian} {chemnum-sep-two} {~e~}
+\DeclareTranslation {Catalan} {chemnum-sep-two} {~i~}
+\DeclareTranslation {Portuguese} {chemnum-sep-two} {~e~}
+\DeclareTranslation {Dutch} {chemnum-sep-two} {~en~}
+\DeclareTranslation {Danish} {chemnum-sep-two} {~og~}
+\DeclareTranslation {Swedish} {chemnum-sep-two} {~och~}
+\DeclareTranslation {Finnish} {chemnum-sep-two} {~ja~}
+\DeclareTranslation {Norwegian} {chemnum-sep-two} {~og~}
+
+\DeclareTranslationFallback {chemnum-sep-last-two} {~and~}
+\DeclareTranslation {English} {chemnum-sep-last-two} {~and~}
+\DeclareTranslation {American} {chemnum-sep-last-two} {,~and~}
+\DeclareTranslation {British} {chemnum-sep-last-two} {~and~}
+\DeclareTranslation {German} {chemnum-sep-last-two} {~und~}
+\DeclareTranslation {French} {chemnum-sep-last-two} {~et~}
+\DeclareTranslation {Spanish} {chemnum-sep-last-two} {~y~}
+\DeclareTranslation {Italian} {chemnum-sep-last-two} {~e~}
+\DeclareTranslation {Catalan} {chemnum-sep-last-two} {~i~}
+\DeclareTranslation {Portuguese} {chemnum-sep-last-two} {~e~}
+\DeclareTranslation {Dutch} {chemnum-sep-last-two} {~en~}
+\DeclareTranslation {Danish} {chemnum-sep-last-two} {~og~}
+\DeclareTranslation {Swedish} {chemnum-sep-last-two} {~och~}
+\DeclareTranslation {Finnish} {chemnum-sep-last-two} {~ja~}
+\DeclareTranslation {Norwegian} {chemnum-sep-last-two} {~og~}
+
+% ----------------------------------------------------------------------------
+% TODO: add a warning for those options that can't be set with the setup
+% command, i.e., those belonging to the `compound' group
+\cs_new_protected:Npn \chemnum_setup:n #1
{
- \@ifpackageloaded { babel }
- {
- \iflanguage { american }
- { \bool_set_false:N \l__chemnum_no_serial_comma_bool }
- { \bool_set_true:N \l__chemnum_no_serial_comma_bool }
- \cs_new_eq:NN \__chemnum_selectlanguage:n \selectlanguage
- \cs_set:Npn \selectlanguage #1
- {
- \__chemnum_selectlanguage:n { #1 }
- \iflanguage { american }
- { \bool_set_false:N \l__chemnum_no_serial_comma_bool }
- { \bool_set_true:N \l__chemnum_no_serial_comma_bool }
- }
- }
- {}
+ \keys_set_filter:nnn {chemnum} {compound,general} {#1}
+ \keys_set_groups:nnn {chemnum} {general} {#1}
}
+\NewDocumentCommand \setchemnum { m }
+ { \chemnum_setup:n {#1} }
+
+\chemnum_deprecated_command:NN \cmpdsetup \setchemnum
+
\tex_endinput:D
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% ----------------------------------------------------------------------------
+TODO:
+
+% ----------------------------------------------------------------------------
+new features in chemnum v1.0:
+- \cmpdplain{<id>} => reads label and writes it expandably without
+ formatting. It is not able to parse a list. Its sole purpose is usage in
+ pdfstrings (cf. \texorpdfstring{<tex>}{<pdfstring>}).
+- \refcmpd[<options>]{<id>} only reference a label, similar to \cmpdplain but
+ unexpandable and able to parse a list. The same as \cmpd+
+- \cmpdproperty, \subcmpdproperty
+- \newcmpdcounterformat
+- logging messages
+- \cmpdshowdef, \cmpdshowref, \subcmpdshowdef, \subcmpdshowref
+- some options are grouped `compound': only those can be set with \cmpd
+- sub label list is sorted
+- sub label list is compressed when option `compress=true' is used
+
+% ----------------------------------------------------------------------------
HISTORY:
- 2011/06/27 version 0.1
- 2011/06/29 version 0.1a - bugfixes
- 2011/07/17 version 0.2 - instead of two commands (\cmpd and \cmpdlist ) only
- one (\cmpd) for both tasks
- - setup with a keyval system
- - possibility to initiate sublabels
- - choices "greek" and "Greek" for the cmpd-counter
- keys, choice "symbol" changed to "Symbol"
- - package option "textgreek = <value>" to control
- usage of the `textgreek' package
- - former \cmpd+ is now \cmpd-
- - new \cmpd+ added which reads label from
- <jobname>.cmpd
- - bugfix: wrong declaration in \cmpdinit and \cmpd
- when used with line break fixed
- - bugfix: error when \cmpd was used in vertical mode
- fixed
- - bugfix: corrected up to date support test
- - bugfix: wrong output in \cmpd* list removed
- - commented and cleaned up code
- 2011/08/02 version 0.3 - keys "cmpd-all", "sub-list", "sub-range-sep" and
- "sub-range-marker" added, key "cmpd-sub-counter"
- renamed into "sub-counter", key "sub-cmpd-sep"
- renamed into "sub-marker"
- - \cmpdref-[<keyval>][<tag>]{<label name>} added
- - key "ref-tag" added
- - cleaned up code
- 2011/09/03 version 0.3a - it is now impossible to use the (conflicting or
- better: senseless) \cmpd*+ and \cmpd*- command
- versions. An error message is produced.
- - made sure code has no more than 80 tokens per line
- to improve readability on small screens
- - bug (unwanted whitespace) in \cmpdsetup fixed
- 2011/11/03 version 0.3b - key "sub-only" added, see schema 23 at
- http://www.arkat-usa.org/get-file/29257/ or scheme 4
- at http://www.arkat-usa.org/get-file/27301/ for
- reasons, why
- 2011/11/08 version 0.3c - localization via `babel' is now supported with the
- help of the `translator' package
- - key "list-serial-comma" added
- 2011/12/01 version 0.3d - greek letters without `textgreek' package
- - new key cmpd-weight = bold/normal
- - bugfix: sublabels are now possible, when main label
- name contains a colon
- - it is now possible to change the list input
- separator; this means the comma may be part of the
- label name
- 2011/12/01 version 0.3e - bugfix: labels have been saved in a wrong way, when
- "list-input-sep" had been changed. this is fixed
- 2011/12/09 version 0.4 - new input of sublabel lists and ranges
- - new key: "sublist-input-sep"
- - new key: "sublist-output-sep"
- - new key: "init-input-sep"
- - "sub-marker" => "sub-input-sep"
- - "cmpd-sep" => "sub-output-sep"
- - "sub-range-sep" => "subrange-output-sep"
- - "sub-range-marker" => "subrange-input-sep"
- - "strict" => "init-strict"
- - "sub-init" => "init-sub"
- - key removed: "sub-list"
- - it is now possible, to mark the labels with
- \hypertarget and \hyperlink if `hyperref' is loaded
- - new key: "hyper-use"
- - new key: "hyper-target"
- - new key: "hyper-link"
- - new key: "ref-style"
- - documentation got an index
- 2012/02/22 version 0.4a - corrected outdated expl3 function
- 2012/04/15 version 0.4b - bugfix in \cmpdref
- 2012/04/20 version 0.5 - new option "ref-pos"
- - switched order of optional arguments of \cmpdref
- 2012/05/03 version 0.5a - corrected stupid typos in documentation
- 2012/05/17 version 0.5b - retrieve label numbers in an expandable (LaTeX2e) way
- see
- https://groups.google.com/d/topic/de.comp.text.tex/LF0knPIuqrM/discussio
- for possible reasons why
- 2012/07/24 version 0.5c - adapted to changes in l3kernel
- 2012/08/15 version 0.5d - fixed bug in \cmpdref
- 2012/09/17 version 0.5e - fixed bug in \cmpdinit
- 2012/12/29 version 0.5f - added Italian documentation, minor adjustment of `ref-pos'
- 2013/01/20 version 0.6 - added + argument to \cmpdref
- - changed internal syntax
- 2013/04/17 version 0.6a - adapted to deprecated l3 functions
- - protected functions that needed to be
- 2013/06/05 version 0.6b - internal changes to the code
-
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% TODO:
- - add a possibility to \ref{} the compounds
- - (rudimentäre) Unterstützung für hyperref und pdfstrings
- - provide expandable makro which gives the label and/or sublabel without any
- formatting
+