summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/chemmacros
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/tex/latex/chemmacros')
-rw-r--r--Master/texmf-dist/tex/latex/chemmacros/chemformula.sty1488
-rw-r--r--Master/texmf-dist/tex/latex/chemmacros/chemmacros-version1.cfg11
-rw-r--r--Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty1005
-rw-r--r--Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty436
4 files changed, 2691 insertions, 249 deletions
diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
new file mode 100644
index 00000000000..c6f338ecbd6
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/chemmacros/chemformula.sty
@@ -0,0 +1,1488 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% --------------------------------------------------------------------------- %
+% - the CHEMMACROS bundle - %
+% - chemformula.sty - %
+% - macros and commands for chemists - %
+% --------------------------------------------------------------------------- %
+% - Clemens Niederberger - %
+% - 2012/01/30 - %
+% --------------------------------------------------------------------------- %
+% - http://www.mychemistry.eu/ - %
+% - contact@mychemistry.eu - %
+% --------------------------------------------------------------------------- %
+% - If you have any ideas, questions, suggestions or bugs to report, please - %
+% - feel free to contact me. - %
+% --------------------------------------------------------------------------- %
+% - Copyright 2011-2012 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. - %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\RequirePackage{ expl3 }
+\ProvidesExplPackage {chemformula} {2012/01/30} {3.0a} {typeset chemical compounds and reactions}
+
+%-----------------------------------------------------------------------------%
+% WARNING AND ERROR MESSAGES
+\msg_set:nnnn { chemformula } { missing-argument }
+ {
+ Wrong~name~input~ \msg_line_context: .
+ }
+ {
+ Maybe~you've~forgotten~to~add~the~second~argument~to~name~syntax?~
+ "!(<name>)(<chemformula>)".\\
+ Or~you~have~forgotten~to~add~a~group~between~an~exclamation~mark~and~
+ the~following~parenthesis?~"!~{}()"\\
+ Either~way~-~I~don't~know~what~to~do~ \msg_line_context: .
+ }
+
+\msg_set:nnnn { chemformula } { explicit }
+ { It~seems~you've~loaded~`chemformula'~explicitly. }
+ {
+ It~seems~you've loaded~`chemformula'~explicitly.~This~should~work~but~the~
+ recommended~way~is~to~load~it~via~the~bundle,~i.e.~by~using~
+ \token_to_str:N \usepackage \{ chemmacros \}.
+ }
+
+%-----------------------------------------------------------------------------%
+% test, if we are loaded without the `chemmacros' package
+\cs_if_exist:cF { ver@chemmacros.sty }
+ { \msg_warning:nn { chemformula } { explicit } }
+
+% pass options to the `chemmacros' package
+\DeclareOption*
+ { \PassOptionsToPackage { \CurrentOption } { chemmacros } }
+\ProcessOptions\relax
+
+\RequirePackage { chemmacros , nicefrac }
+
+%-----------------------------------------------------------------------------%
+% HELPER FUNCTIONS
+\cs_new:Npn \chemformula_tikz:nn #1#2
+ { \tikz [ #1 ] { #2 } }
+\cs_generate_variant:Nn \chemformula_tikz:nn { xn,nf }
+
+\cs_new:Npn \chemformula_draw:nn #1#2
+ { \draw [ #1 ] #2 ; }
+\cs_generate_variant:Nn \chemformula_draw:nn { xn,nx,xx,xf }
+
+%-----------------------------------------------------------------------------%
+% Some basic internal commands:
+\cs_new:Nn \chemformula_plus:
+ {
+ \bool_if:nTF { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool }
+ {
+ \bool_if:NTF \l_chemmacros_circled_chem_bool
+ { \chemmacros_fplus: }
+ { \mode_if_math:TF { \oplus } { $ \oplus $ } }
+ }
+ {
+ \bool_if:NTF \l_chemformula_charge_style_math_bool
+ { \ensuremath { + } }
+ { \mode_if_math:TF { \text { + } } { + } }
+ }
+ }
+
+\cs_new:Nn \chemformula_minus:
+ {
+ \bool_if:nTF { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool }
+ {
+ \bool_if:NTF \l_chemmacros_circled_chem_bool
+ { \chemmacros_fminus: }
+ { \mode_if_math:TF { \ominus } { $ \ominus $ } }
+ }
+ {
+ \bool_if:NTF \l_chemformula_charge_style_math_bool
+ { \ensuremath { - } }
+ { \mode_if_math:TF { \text { \textendash } } { \textendash } }
+ }
+ }
+
+\cs_new:Nn \chemformula_radical: { \textperiodcentered }
+\cs_new:Nn \chemformula_adduct:
+ {
+ \skip_horizontal:N \l_chemformula_cdot_space_dim
+ \textperiodcentered
+ \skip_horizontal:N \l_chemformula_cdot_space_dim
+ }
+
+%-----------------------------------------------------------------------------%
+% ARROW DEFINITION
+% arrow heads:
+\dim_new:N \l_chemformula_arrow_head_dim
+
+% full tip for pairs
+\pgfarrowsdeclare { cf } { cf }
+{
+ \dim_set:Nn \l_chemformula_arrow_head_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfarrowsleftextend { -\l_chemformula_arrow_head_dim }
+ \pgfarrowsrightextend { .5\pgflinewidth }
+}
+{
+ \dim_set:Nn \l_chemformula_arrow_head_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfsetdash {} { 0pt }
+ \pgfsetroundjoin
+ \pgfsetroundcap
+ \pgfpathmoveto { \pgfpoint { 0pt } { 0pt } }
+ \pgfpathlineto
+ {
+ \pgfpoint
+ { -\l_chemformula_arrow_head_dim }
+ { .3\l_chemformula_arrow_head_dim }
+ }
+ \pgfpathlineto
+ { \pgfpoint { -.5\l_chemformula_arrow_head_dim } { 0pt } }
+ \pgfpathlineto
+ {
+ \pgfpoint
+ { -\l_chemformula_arrow_head_dim }
+ { -.3\l_chemformula_arrow_head_dim }
+ }
+ \pgfpathlineto { \pgfpoint { 0pt } { 0pt } }
+ \pgfusepathqfillstroke
+}
+
+% half tip on the left
+\pgfarrowsdeclare { left~cf } { left~cf }
+{
+ \dim_set:Nn \l_chemformula_arrow_head_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfarrowsleftextend { -\l_chemformula_arrow_head_dim }
+ \pgfarrowsrightextend { .5\pgflinewidth }
+}
+{
+ \dim_set:Nn \l_chemformula_arrow_head_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfsetdash {} { 0pt }
+ \pgfsetroundjoin
+ \pgfsetroundcap
+ \pgfpathmoveto { \pgfpoint { 0pt } { 0pt } }
+ \pgfpathlineto
+ {
+ \pgfpoint
+ { -\l_chemformula_arrow_head_dim }
+ { .3\l_chemformula_arrow_head_dim }
+ }
+ \pgfpathlineto { \pgfpoint { -.5\l_chemformula_arrow_head_dim } { 0pt } }
+ \pgfpathlineto { \pgfpoint { 0pt } { 0pt } }
+ \pgfusepathqfillstroke
+}
+
+% half tip in the right
+\pgfarrowsdeclare { right~cf } { right~cf }
+{
+ \dim_set:Nn \l_chemformula_arrow_head_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfarrowsleftextend { -\l_chemformula_arrow_head_dim }
+ \pgfarrowsrightextend { .5\pgflinewidth }
+}
+{
+ \dim_set:Nn \l_chemformula_arrow_head_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfsetdash {} { 0pt }
+ \pgfsetroundjoin
+ \pgfsetroundcap
+ \pgfpathmoveto { \pgfpoint { 0pt } { 0pt } }
+ \pgfpathlineto
+ {
+ \pgfpoint
+ { -\l_chemformula_arrow_head_dim }
+ { -.3\l_chemformula_arrow_head_dim }
+ }
+ \pgfpathlineto { \pgfpoint { -.5\l_chemformula_arrow_head_dim } { 0pt } }
+ \pgfpathlineto { \pgfpoint { 0pt } { 0pt } }
+ \pgfusepathqfillstroke
+}
+
+%-----------------------------------------------------------------------------%
+% dimension variables
+\dim_new:N \l_chemformula_arrow_length_dim
+
+\dim_new:N \l_chemformula_arrow_label_offset_dim
+\dim_set:Nn \l_chemformula_arrow_label_offset_dim { 2pt }
+
+\dim_new:N \l_chemformula_arrow_shortage_dim
+\tl_new:N \l_chemformula_arrow_ratio_tl
+\tl_set:Nn \l_chemformula_arrow_ratio_tl { .6 }
+
+\dim_new:N \l_chemformula_arrow_offset_dim
+\dim_set:Nn \l_chemformula_arrow_offset_dim { 1.5ex }
+
+\dim_new:N \l_chemformula_compound_sep_dim
+\dim_set:Nn \l_chemformula_compound_sep_dim { \medskipamount }
+
+\dim_new:N \l_chemformula_arrow_yshift_dim
+\dim_set:Nn \l_chemformula_arrow_yshift_dim { 0pt }
+
+% determine length in dependency of labels
+\cs_new:Npn \chemformula_determine_arrow_length:nn #1#2
+ {
+ \hbox_set:Nn \l_tmpa_box { { #1 } }
+ \dim_set:Nn \l_tmpa_dim { \box_wd:N \l_tmpa_box }
+ \hbox_set:Nn \l_tmpa_box { { #2 } }
+ \dim_set:Nn \l_tmpb_dim { \box_wd:N \l_tmpa_box }
+ \box_clear:N \l_tmpa_box
+ \dim_compare:nTF { \l_tmpa_dim >= \l_tmpb_dim }
+ { \dim_set_eq:NN \l_chemformula_arrow_length_dim \l_tmpa_dim }
+ { \dim_set_eq:NN \l_chemformula_arrow_length_dim \l_tmpb_dim }
+ \dim_add:Nn \l_chemformula_arrow_length_dim
+ { \l_chemformula_arrow_offset_dim }
+ \dim_add:Nn \l_chemformula_arrow_length_dim
+ { \l_chemformula_arrow_offset_dim }
+ \dim_set:Nn \l_chemformula_arrow_shortage_dim
+ {
+ \l_chemformula_arrow_length_dim *
+ \dim_ratio:nn { \l_chemformula_arrow_ratio_tl pt } { 1pt }
+ }
+ \dim_set:Nn \l_chemformula_arrow_shortage_dim
+ { \l_chemformula_arrow_length_dim - \l_chemformula_arrow_shortage_dim }
+ \dim_set:Nn \l_chemformula_arrow_shortage_dim
+ {
+ \l_chemformula_arrow_shortage_dim *
+ \dim_ratio:nn { 1pt } { 2pt }
+ }
+ }
+
+%-----------------------------------------------------------------------------%
+% define arrow types
+\tl_new:N \l_chemformula_arrow_head_tl
+\tl_set:Nn \l_chemformula_arrow_head_tl { cf }
+\tl_new:N \l_chemformula_upper_label_tl
+\tl_new:N \l_chemformula_lower_label_tl
+\tl_new:N \l_chemformula_arrow_style_tl
+\tl_new:N \l_chemformula_arrow_label_style_tl
+\tl_set:Nn \l_chemformula_arrow_label_style_tl { \footnotesize }
+
+% <->
+\NewDocumentCommand \chemformula_arrow_mesomeric:w { O{}O{} }
+ {
+ \chemformula_determine_arrow_length:nn { #1 } { #2 }
+ \chemformula_tikz:nf { inner~sep=0, baseline=(chemformula_arrow_start.base) }
+ {
+ \chemformula_draw:xn
+ { \l_chemformula_arrow_head_tl-\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl }
+ {
+ coordinate (chemformula_arrow_start) (0,0)
+ ++ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++
+ ( \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ node[pos=.5,above=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #1 }
+ node[pos=.5,below=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #2 }
+ }
+ \chemformula_draw:nn {}
+ {
+ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++
+ ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ }
+ }
+ }
+
+% ->
+\NewDocumentCommand \chemformula_arrow_right:w { O{}O{} }
+ {
+ \chemformula_determine_arrow_length:nn { #1 } { #2 }
+ \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) }
+ {
+ \chemformula_draw:xn { -\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl }
+ {
+ coordinate (chemformula_arrow_start) (0,0)
+ ++ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++
+ ( \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ node[pos=.5,above=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #1 }
+ node[pos=.5,below=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #2 }
+ }
+ \chemformula_draw:nn {}
+ {
+ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++
+ ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ }
+ }
+ }
+
+% <-
+\NewDocumentCommand \chemformula_arrow_left:w { O{}O{} }
+ {
+ \chemformula_determine_arrow_length:nn { #1 } { #2 }
+ \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) }
+ {
+ \chemformula_draw:xn { \l_chemformula_arrow_head_tl- , \l_chemformula_arrow_style_tl }
+ {
+ coordinate (chemformula_arrow_start) (0,0)
+ ++ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++
+ ( \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ node[pos=.5,above=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #1 }
+ node[pos=.5,below=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #2 }
+ }
+ \chemformula_draw:nn {}
+ {
+ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim)++
+ ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ }
+ }
+ }
+
+% <=>
+\NewDocumentCommand \chemformula_arrow_equilibrium:w { O{}O{} }
+ {
+ \chemformula_determine_arrow_length:nn { #1 } { #2 }
+ \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) }
+ {
+ \chemformula_draw:xn { -left~\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl }
+ {
+ coordinate (chemformula_arrow_start) (0,0)
+ ++ (\l_chemformula_compound_sep_dim,.429em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++
+ ( \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ node[pos=.5,above=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #1 }
+ }
+ \chemformula_draw:xn { left~\l_chemformula_arrow_head_tl- , \l_chemformula_arrow_style_tl }
+ {
+ (chemformula_arrow_start) ++
+ (\l_chemformula_compound_sep_dim,.2574em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++
+ ( \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ node[pos=.5,below=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #2 }
+ }
+ \chemformula_draw:nn {}
+ {
+ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++
+ ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ }
+ }
+ }
+
+% <=>>
+\NewDocumentCommand \chemformula_arrow_equilibrium_right:w { O{}O{} }
+ {
+ \chemformula_determine_arrow_length:nn { #1 } { #2 }
+ \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) }
+ {
+ \chemformula_draw:xn { -left~\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl }
+ {
+ coordinate (chemformula_arrow_start) (0,0)
+ ++ (\l_chemformula_compound_sep_dim,.429em) ++ (0,\dim_use:N \l_chemformula_arrow_yshift_dim) -- ++
+ ( \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ node[pos=.5,above=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #1 }
+ }
+ \chemformula_draw:xn { left~\l_chemformula_arrow_head_tl- , \l_chemformula_arrow_style_tl }
+ {
+ (chemformula_arrow_start) ++
+ (\l_chemformula_compound_sep_dim + \l_chemformula_arrow_shortage_dim,.2574em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++
+ ( \dim_use:N \l_chemformula_arrow_length_dim -2*\l_chemformula_arrow_shortage_dim , 0)
+ node[pos=.5,below=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #2 }
+ }
+ \chemformula_draw:nn {}
+ {
+ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++
+ ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ }
+ }
+ }
+
+% <<=>
+\NewDocumentCommand \chemformula_arrow_equilibrium_left:w { O{}O{} }
+ {
+ \chemformula_determine_arrow_length:nn { #1 } { #2 }
+ \chemformula_tikz:nn { inner~sep=0, baseline=(chemformula_arrow_start.base) }
+ {
+ \chemformula_draw:xn { -left~\l_chemformula_arrow_head_tl , \l_chemformula_arrow_style_tl }
+ {
+ coordinate (chemformula_arrow_start) (0,0)
+ ++ (\l_chemformula_compound_sep_dim + \l_chemformula_arrow_shortage_dim,.429em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++
+ ( \dim_use:N \l_chemformula_arrow_length_dim - 2*\l_chemformula_arrow_shortage_dim , 0)
+ node[pos=.5,above=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #1 }
+ }
+ \chemformula_draw:xn { left~\l_chemformula_arrow_head_tl- , \l_chemformula_arrow_style_tl }
+ {
+ (chemformula_arrow_start) ++ (\l_chemformula_compound_sep_dim,.2574em) ++ (0,\l_chemformula_arrow_yshift_dim) -- ++
+ ( \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ node[pos=.5,below=\l_chemformula_arrow_label_offset_dim,font=\l_chemformula_arrow_label_style_tl,butt~cap-butt~cap] { #2 }
+ }
+ \chemformula_draw:nn {}
+ {
+ (\l_chemformula_compound_sep_dim,.3432em) ++ (0,\l_chemformula_arrow_yshift_dim) ++
+ ( \l_chemformula_compound_sep_dim + \dim_use:N \l_chemformula_arrow_length_dim , 0)
+ }
+ }
+ }
+
+%-----------------------------------------------------------------------------%
+% arrow customization
+\keys_define:nn { chemmacros / chemformula }
+ {
+ arrow-offset .dim_set:N = \l_chemformula_arrow_offset_dim ,
+ arrow-yshift .dim_set:N = \l_chemformula_arrow_yshift_dim ,
+ arrow-ratio .tl_set:N = \l_chemformula_arrow_ratio_tl ,
+ label-offset .dim_set:N = \l_chemformula_arrow_label_offset_dim ,
+ compound-sep .dim_set:N = \l_chemformula_compound_sep_dim ,
+ arrow-tips .tl_set:N = \l_chemformula_arrow_head_tl ,
+ arrow-style .tl_set:N = \l_chemformula_arrow_style_tl ,
+ label-style .tl_set:N = \l_chemformula_arrow_label_style_tl
+ }
+
+%-----------------------------------------------------------------------------%
+% MAIN COMMAND
+\NewDocumentCommand \chemformula_ch_aux_iii:w { > { \SplitList { ~ } } m }
+ {
+ \group_begin:
+ \tl_if_blank:oF { \g_chemformula_options_tl }
+ { \keys_set:no { chemmacros / chemformula } { \g_chemformula_options_tl } }
+ \tl_map_function:nN { #1 } \chemformula_input:n
+ \chemformula_generate_arrows:N \l_chemformula_input_tl
+ \chemformula_generate_name:N \l_chemformula_output_tl
+ \tl_set_rescan:Nno \l_chemformula_output_tl
+ { \ExplSyntaxOn }
+ { \l_chemformula_output_tl }
+ \chemformula_write:n { \l_chemformula_output_tl }
+ \group_end:
+ }
+
+\cs_new:Nn \chemformula_ch:nn
+ {
+ \group_align_safe_begin:
+ \IfNoValueTF { #1 }
+ { \tl_gclear:N \g_chemformula_options_tl }
+ { \tl_gset:Nn \g_chemformula_options_tl { #1 } }
+ \chemformula_ch_aux_i:w #2 \\ \q_no_value \q_stop
+ \group_align_safe_end:
+ \tl_use:N \g_chemformula_output_tl
+ \tl_gclear:N \g_chemformula_output_tl
+ }
+
+\cs_new:Npn \chemformula_ch_aux_i:w #1 \\ #2 \q_stop
+ {
+ \chemformula_ch_aux_ii:w #1 & \q_no_value \q_stop
+ \quark_if_no_value:nF { #2 }
+ {
+ \tl_gput_right:Nn \g_chemformula_output_tl { \\ }
+ \chemformula_ch_aux_i:w #2 \q_stop
+ }
+ }
+
+\cs_new:Npn \chemformula_ch_aux_ii:w #1 & #2 \q_stop
+ {
+ \tl_gput_right:Nn \g_chemformula_output_tl { \chemformula_ch_aux_iii:w { #1 } }
+ \quark_if_no_value:nF { #2 }
+ {
+ \tl_gput_right:Nn \g_chemformula_output_tl { & }
+ \chemformula_ch_aux_ii:w #2 \q_stop
+ }
+ }
+
+% user command:
+\NewDocumentCommand \ch { om }
+ { \chemformula_ch:nn { #1 } { #2 } }
+
+\cs_new:Npn \chemformula_write:n #1
+ {
+ \mode_if_math:TF
+ {
+ \mathchoice
+ { \hbox:n { #1 } }
+ { \hbox:n { #1 } }
+ { \hbox:n { \scriptsize #1 } }
+ { \hbox:n { \tiny #1 } }
+ }
+ { #1 }
+ }
+
+%-----------------------------------------------------------------------------%
+% arrow generation & detection
+\cs_new:Npn \chemformula_generate_arrows:n #1
+ {
+ \tl_set:No \l_tmpa_tl { #1 }
+ \tl_if_in:onT { \l_tmpa_tl } { <-> }
+ { \tl_replace_all:Nnn \l_tmpa_tl { <-> } { \chemformula_arrow_mesomeric:w } }
+ \tl_if_in:onT { \l_tmpa_tl } { -> }
+ { \tl_replace_all:Nnn \l_tmpa_tl { -> } { \chemformula_arrow_right:w } }
+ \tl_if_in:onT { \l_tmpa_tl } { <- }
+ { \tl_replace_all:Nnn \l_tmpa_tl { <- } { \chemformula_arrow_left:w } }
+ \tl_if_in:onT { \l_tmpa_tl } { glgw_l }
+ { \tl_replace_all:Nnn \l_tmpa_tl { glgw_l } { \chemformula_arrow_equilibrium_left:w } }
+ \tl_if_in:onT { \l_tmpa_tl } { <=>> }
+ { \tl_replace_all:Nnn \l_tmpa_tl { <=>> } { \chemformula_arrow_equilibrium_right:w } }
+ \tl_if_in:onT { \l_tmpa_tl } { <=> }
+ { \tl_replace_all:Nnn \l_tmpa_tl { <=> } { \chemformula_arrow_equilibrium:w } }
+ \tl_set_eq:NN \l_chemformula_output_tl \l_tmpa_tl
+ }
+\cs_generate_variant:Nn \chemformula_generate_arrows:n { N }
+
+\cs_new:Npn \chemformula_detect_arrows:n #1
+ {
+ \bool_set_false:N \l_chemformula_is_arrow_bool
+ \tl_set:No \l_tmpa_tl { #1 }
+ \tl_if_in:onT { \l_tmpa_tl } { <-> }
+ { \bool_set_true:N \l_chemformula_is_arrow_bool }
+ \tl_if_in:onT { \l_tmpa_tl } { -> }
+ { \bool_set_true:N \l_chemformula_is_arrow_bool }
+ \tl_if_in:onT { \l_tmpa_tl } { <- }
+ { \bool_set_true:N \l_chemformula_is_arrow_bool }
+ \tl_if_in:onT { \l_tmpa_tl } { <=>> }
+ { \bool_set_true:N \l_chemformula_is_arrow_bool }
+ \tl_if_in:onT { \l_tmpa_tl } { glgw_l }
+ { \bool_set_true:N \l_chemformula_is_arrow_bool }
+ \tl_if_in:onT { \l_tmpa_tl } { <=> }
+ { \bool_set_true:N \l_chemformula_is_arrow_bool }
+ }
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% compound names
+\dim_new:N \l_chemformula_name_dim
+
+\cs_new:Npn \chemformula_name_cmpd:w
+ { \peek_meaning:NTF { ( } { \chemformula_name_cmpd_aux:w } { ! } }
+
+\cs_new:Npn \chemformula_name_cmpd_aux:w (#1)(#2)
+ {
+ \(
+ \underset
+ {
+ \bool_if:NF \l_chemformula_name_width_bool
+ {
+ \width_to_dim:Nn \l_chemformula_name_dim
+ { \l_chemformula_name_format_tl #1 }
+ }
+ \parbox
+ { \dim_use:N \l_chemformula_name_dim }
+ { \l_chemformula_name_format_tl #1 }
+ }
+ { \text { \vphantom{\gas} #2 } }
+ \)
+ }
+
+\cs_new:Npn \width_to_dim:nn #1#2
+ {
+ \hbox_set:Nn \l_tmpa_box { #2 }
+ \dim_set:Nn #1 { \box_wd:N \l_tmpa_box }
+ \box_clear:N \l_tmpa_box
+ }
+\cs_generate_variant:Nn \width_to_dim:nn { Nn }
+
+\cs_new:Npn \chemformula_generate_name:n #1
+ {
+ \tl_set:No \l_tmpa_tl { #1 }
+ \tl_if_in:onT { \l_tmpa_tl } { ! }
+ { \tl_replace_all:Nnn \l_tmpa_tl { ! } { \chemformula_name_cmpd:w } }
+ \tl_set_eq:NN \l_chemformula_output_tl \l_tmpa_tl
+ }
+\cs_generate_variant:Nn \chemformula_generate_name:n { N }
+
+\cs_new:Npn \chemformula_detect_name:n #1
+ {
+ \bool_set_false:N \l_chemformula_is_name_bool
+ \tl_set:No \l_tmpa_tl { #1 }
+ \tl_if_in:onT { \l_tmpa_tl } { ! }
+ { \bool_set_true:N \l_chemformula_is_name_bool }
+ }
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% parsing input
+% booleans:
+\bool_new:N \l_chemformula_stoich_bool
+\bool_new:N \l_chemformula_is_plus_bool
+\bool_new:N \l_chemformula_is_up_bool
+\bool_new:N \l_chemformula_is_down_bool
+\bool_new:N \l_chemformula_is_arrow_bool
+\bool_new:N \l_chemformula_is_name_bool
+\bool_new:N \l_chemformula_first_last_text_bool
+\bool_new:N \l_chemformula_first_last_double_bool
+\bool_new:N \l_chemformula_first_last_single_bool
+\bool_new:N \l_chemformula_first_last_math_bool
+\bool_new:N \l_chemformula_number_style_math_bool
+\bool_new:N \l_chemformula_charge_style_math_bool
+\bool_new:N \l_chemformula_sub_bool
+\bool_new:N \l_chemformula_sup_bool
+\bool_new:N \l_chemformula_xfrac_bool
+\bool_new:N \l_chemformula_nicefrac_bool
+\bool_new:N \l_chemformula_mathfrac_bool
+ \bool_set_true:N \l_chemformula_mathfrac_bool
+\bool_new:N \l_chemformula_fss_bool
+\bool_new:N \l_chemformula_fontspec_bool
+\bool_new:N \l_chemformula_fss_family_bool
+\bool_new:N \l_chemformula_fss_series_bool
+\bool_new:N \l_chemformula_fss_shape_bool
+\bool_new:N \l_chemformula_name_width_bool
+\bool_new:N \l_chemformula_charge_shift_bool
+
+% token lists:
+\tl_new:N \l_chemformula_tmpa_tl
+\tl_new:N \g_chemformula_options_tl
+\tl_new:N \g_chemformula_output_tl
+\tl_new:N \l_chemformula_output_tl
+\tl_new:N \l_chemformula_input_tl
+\tl_new:N \l_chemformula_stoich_tl
+\tl_new:N \l_chemformula_decimal_output_tl
+ \tl_set:Nn \l_chemformula_decimal_output_tl { . }
+\tl_new:N \l_chemformula_font_family_tl
+ \tl_set_eq:NN \l_chemformula_font_family_tl \f@family
+\tl_new:N \l_chemformula_font_series_tl
+ \tl_set_eq:NN \l_chemformula_font_series_tl \f@series
+\tl_new:N \l_chemformula_font_shape_tl
+ \tl_set_eq:NN \l_chemformula_font_shape_tl \f@shape
+\tl_new:N \l_chemformula_format_tl
+\tl_new:N \l_chemformula_fontspec_options_tl
+\tl_new:N \l_chemformula_fontspec_argument_tl
+\tl_new:N \l_chemformula_name_format_tl
+ \tl_set:Nn \l_chemformula_name_format_tl { \scriptsize\centering }
+
+% dimensions:
+\dim_new:N \l_chemformula_stoich_space_dim
+ \dim_set:Nn \l_chemformula_stoich_space_dim { .1667em }
+\dim_new:N \l_chemformula_math_space_dim
+ \dim_set:Nn \l_chemformula_math_space_dim { .1667em }
+\dim_new:N \l_chemformula_plus_space_dim
+ \dim_set:Nn \l_chemformula_plus_space_dim { .3em }
+\dim_new:N \l_chemformula_cdot_space_dim
+ \dim_set:Nn \l_chemformula_cdot_space_dim { .1333em }
+\dim_new:N \l_chemformula_charge_shift_dim
+ \dim_set:Nn \l_chemformula_charge_shift_dim { .3ex }
+\dim_new:N \l_chemformula_subscript_shift_default_dim
+ \dim_set:Nn \l_chemformula_subscript_shift_default_dim { -.6ex }
+\dim_new:N \l_chemformula_subscript_shift_dim
+ \dim_set_eq:NN
+ \l_chemformula_subscript_shift_dim
+ \l_chemformula_subscript_shift_default_dim
+\dim_new:N \l_chemformula_subscript_shift_additional_dim
+\dim_new:N \l_chemformula_subscript_dim
+ \dim_zero:N \l_chemformula_subscript_dim
+\dim_new:N \l_chemformula_supscript_dim
+ \dim_zero:N \l_chemformula_supscript_dim
+\dim_new:N \l_chemformula_bond_dim
+ \hbox_set:Nn \l_tmpa_box { \textendash }
+ \dim_set:Nn \l_chemformula_bond_dim { \box_wd:N \l_tmpa_box }
+ \box_clear:N \l_tmpa_box
+
+% integers:
+\int_new:N \l_chemformula_count_tokens_int
+
+% property lists:
+% behaviour in a compound
+\prop_new:N \l_chemformula_cmpd_prop
+\prop_put:Nnn \l_chemformula_cmpd_prop { 0 } { \chemformula_subscript:n { 0 } }
+\prop_put:Nnn \l_chemformula_cmpd_prop { 1 } { \chemformula_subscript:n { 1 } }
+\prop_put:Nnn \l_chemformula_cmpd_prop { 2 } { \chemformula_subscript:n { 2 } }
+\prop_put:Nnn \l_chemformula_cmpd_prop { 3 } { \chemformula_subscript:n { 3 } }
+\prop_put:Nnn \l_chemformula_cmpd_prop { 4 } { \chemformula_subscript:n { 4 } }
+\prop_put:Nnn \l_chemformula_cmpd_prop { 5 } { \chemformula_subscript:n { 5 } }
+\prop_put:Nnn \l_chemformula_cmpd_prop { 6 } { \chemformula_subscript:n { 6 } }
+\prop_put:Nnn \l_chemformula_cmpd_prop { 7 } { \chemformula_subscript:n { 7 } }
+\prop_put:Nnn \l_chemformula_cmpd_prop { 8 } { \chemformula_subscript:n { 8 } }
+\prop_put:Nnn \l_chemformula_cmpd_prop { 9 } { \chemformula_subscript:n { 9 } }
+\prop_put:Nnn \l_chemformula_cmpd_prop { * } { \chemformula_adduct: }
+\prop_put:Nnn \l_chemformula_cmpd_prop { . } { \chemformula_adduct: }
+\prop_put:Nnn \l_chemformula_cmpd_prop { - } { \chemformula_single_bond: }
+\prop_put:Nnn \l_chemformula_cmpd_prop { = } { \chemformula_double_bond: }
+\prop_put:Nnn \l_chemformula_cmpd_prop { + } { \chemformula_triple_bond: }
+
+% numbers
+\prop_new:N \l_chemformula_numbers_prop
+\prop_put:Nnn \l_chemformula_numbers_prop { 0 } { 0 }
+\prop_put:Nnn \l_chemformula_numbers_prop { 1 } { 1 }
+\prop_put:Nnn \l_chemformula_numbers_prop { 2 } { 2 }
+\prop_put:Nnn \l_chemformula_numbers_prop { 3 } { 3 }
+\prop_put:Nnn \l_chemformula_numbers_prop { 4 } { 4 }
+\prop_put:Nnn \l_chemformula_numbers_prop { 5 } { 5 }
+\prop_put:Nnn \l_chemformula_numbers_prop { 6 } { 6 }
+\prop_put:Nnn \l_chemformula_numbers_prop { 7 } { 7 }
+\prop_put:Nnn \l_chemformula_numbers_prop { 8 } { 8 }
+\prop_put:Nnn \l_chemformula_numbers_prop { 9 } { 9 }
+
+% behaviour in a charge
+\prop_new:N \l_chemformula_charge_prop
+\prop_put:Nnn \l_chemformula_charge_prop { 0 } { \chemformula_charge_style:n { 0 } }
+\prop_put:Nnn \l_chemformula_charge_prop { 1 } { \chemformula_charge_style:n { 1 } }
+\prop_put:Nnn \l_chemformula_charge_prop { 2 } { \chemformula_charge_style:n { 2 } }
+\prop_put:Nnn \l_chemformula_charge_prop { 3 } { \chemformula_charge_style:n { 3 } }
+\prop_put:Nnn \l_chemformula_charge_prop { 4 } { \chemformula_charge_style:n { 4 } }
+\prop_put:Nnn \l_chemformula_charge_prop { 5 } { \chemformula_charge_style:n { 5 } }
+\prop_put:Nnn \l_chemformula_charge_prop { 6 } { \chemformula_charge_style:n { 6 } }
+\prop_put:Nnn \l_chemformula_charge_prop { 7 } { \chemformula_charge_style:n { 7 } }
+\prop_put:Nnn \l_chemformula_charge_prop { 8 } { \chemformula_charge_style:n { 8 } }
+\prop_put:Nnn \l_chemformula_charge_prop { 9 } { \chemformula_charge_style:n { 9 } }
+\prop_put:Nnn \l_chemformula_charge_prop { + } { \chemformula_plus: }
+\prop_put:Nnn \l_chemformula_charge_prop { - } { \chemformula_minus: }
+\prop_put:Nnn \l_chemformula_charge_prop { . } { \chemformula_radical: }
+
+% stoichiometric factors
+\prop_new:N \l_chemformula_stoich_prop
+\prop_put:Nnn \l_chemformula_stoich_prop { 0 } { 0 }
+\prop_put:Nnn \l_chemformula_stoich_prop { 1 } { 1 }
+\prop_put:Nnn \l_chemformula_stoich_prop { 2 } { 2 }
+\prop_put:Nnn \l_chemformula_stoich_prop { 3 } { 3 }
+\prop_put:Nnn \l_chemformula_stoich_prop { 4 } { 4 }
+\prop_put:Nnn \l_chemformula_stoich_prop { 5 } { 5 }
+\prop_put:Nnn \l_chemformula_stoich_prop { 6 } { 6 }
+\prop_put:Nnn \l_chemformula_stoich_prop { 7 } { 7 }
+\prop_put:Nnn \l_chemformula_stoich_prop { 8 } { 8 }
+\prop_put:Nnn \l_chemformula_stoich_prop { 9 } { 9 }
+\prop_put:Nnn \l_chemformula_stoich_prop { . } { { \l_chemformula_decimal_output_tl } }
+\prop_put:Nnn \l_chemformula_stoich_prop { , } { { \l_chemformula_decimal_output_tl } }
+\prop_put:Nnn \l_chemformula_stoich_prop { / } { / }
+\prop_put:Nnn \l_chemformula_stoich_prop { _ } { _ }
+
+%-----------------------------------------------------------------------------%
+% bonds:
+\cs_new:Npn \chemformula_single_bond:
+ {
+ \bool_if:NTF \l_chemformula_sup_bool
+ { \chemformula_minus: }
+ {
+ \chemformula_tikz:nn { inner~sep=0, outer~sep=0 }
+ {
+ \draw node[draw=none,minimum~height=1em,minimum~width=0]
+ (chemformula-single-bond) at (0,0) {} ;
+ \draw[butt~cap-butt~cap] (chemformula-single-bond) ++ (0,-.1716em)
+ -- ++( \l_chemformula_bond_dim ,0) ;
+ }
+ }
+ }
+
+\cs_new:Npn \chemformula_double_bond:
+ {
+ \chemformula_tikz:nn { inner~sep=0, outer~sep=0 }
+ {
+ \draw node[draw=none,minimum~height=1em,minimum~width=0] (chemformula-double-bond) at (0,0) {} ;
+ \draw[butt~cap-butt~cap] (chemformula-double-bond) ++ (0,-.0858em) -- ++( \l_chemformula_bond_dim ,0) ;
+ \draw[butt~cap-butt~cap] (chemformula-double-bond) ++ (0,-.2574em) -- ++( \l_chemformula_bond_dim ,0) ;
+ }
+ }
+
+\cs_new:Npn \chemformula_triple_bond:
+ {
+ \chemformula_tikz:nn { inner~sep=0, outer~sep=0 }
+ {
+ \draw node[draw=none,minimum~height=1em,minimum~width=0] (chemformula-triple-bond) at (0,0) {} ;
+ \draw[butt~cap-butt~cap] (chemformula-triple-bond) ++ (0,-.0429em) -- ++( \l_chemformula_bond_dim ,0) ;
+ \draw[butt~cap-butt~cap] (chemformula-triple-bond) ++ (0,-.1716em) -- ++( \l_chemformula_bond_dim ,0) ;
+ \draw[butt~cap-butt~cap](chemformula-triple-bond) ++ (0,-.3003em) -- ++( \l_chemformula_bond_dim ,0) ;
+ }
+ }
+
+%-----------------------------------------------------------------------------%
+% sub- and superscripts
+\cs_new:Nn \chemformula_number_style:n
+ {
+ \bool_if:NTF \l_chemformula_number_style_math_bool
+ { \ensuremath { #1 } }
+ { \ensuremath { \text { #1 } } }
+ }
+
+\cs_new:Nn \chemformula_charge_style:n
+ {
+ \bool_if:NTF \l_chemformula_charge_style_math_bool
+ { \ensuremath { #1 } }
+ { \ensuremath { \text { #1 } } }
+ }
+
+\cs_new:Npn \chemformula_subscript:n #1
+ {
+ \bool_set_true:N \l_chemformula_sub_bool
+ % clean up wrong input
+ \tl_set:Nn \l_tmpc_tl { #1 }
+ \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_single_bond: } { \chemformula_minus: }
+ \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_triple_bond: } {\chemformula_plus: }
+ \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_adduct: } { . }
+ % measure width and save it
+ \hbox_set:Nn \l_tmpa_box
+ {
+ $\mathchoice
+ { \scriptstyle }
+ { \scriptstyle }
+ { \scriptscriptstyle }
+ { \scriptscriptstyle }
+ \prop_get:NnNTF \l_chemformula_numbers_prop { #1 } \l_tmpa_tl
+ { \chemformula_number_style:n { \l_tmpa_tl } }
+ { \chemformula_number_style:n { \l_tmpc_tl } }$
+ }
+ \dim_set:Nn \l_chemformula_subscript_dim { -\box_wd:N \l_tmpa_box }
+ \box_clear:N \l_tmpa_box
+ \bool_if:NT \l_chemformula_sup_bool
+ {
+ \chemformula_sub_or_supscript_skip:
+ \bool_if:NT \l_chemformula_charge_shift_bool
+ {
+ \skip_horizontal:n { \l_chemformula_charge_shift_dim +1pt }
+ \bool_set_false:N \l_chemformula_charge_shift_bool
+ }
+ \dim_zero:N \l_chemformula_supscript_dim
+ }
+ % typeset subscript
+ \tex_raise:D \l_chemformula_subscript_shift_dim
+ \hbox:n
+ {
+ $\mathchoice
+ { \scriptstyle }
+ { \scriptstyle }
+ { \scriptscriptstyle }
+ { \scriptscriptstyle }
+ \prop_get:NnNTF \l_chemformula_numbers_prop { #1 } \l_tmpa_tl
+ { \chemformula_number_style:n { \l_tmpa_tl } }
+ { \chemformula_number_style:n { \l_tmpc_tl } }$
+ }
+ % look ahead what's coming next and set boolean accordingly
+ \peek_meaning:NTF \chemformula_supscript:n
+ { \bool_set_true:N \l_chemformula_sub_bool }
+ {
+ \peek_meaning:NTF \chemformula_chief_supscript:n
+ { \bool_set_true:N \l_chemformula_sub_bool }
+ { \bool_set_false:N \l_chemformula_sub_bool }
+ }
+ }
+\cs_new:Npn \chemformula_supscript:n #1
+ {
+ \bool_set_true:N \l_chemformula_sup_bool
+ % clean up wrong input
+ \tl_set:Nn \l_tmpc_tl { #1 }
+ \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_single_bond: } { \chemformula_minus: }
+ \tl_replace_all:Nnn \l_tmpc_tl { - } { \chemformula_minus: }
+ \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_triple_bond: } { \chemformula_plus: }
+ \tl_replace_all:Nnn \l_tmpc_tl { + } { \chemformula_plus: }
+ \tl_replace_all:Nnn \l_tmpc_tl { \chemformula_adduct: } { \chemformula_radical: }
+ \tl_replace_all:Nnn \l_tmpc_tl { . } { \chemformula_radical: }
+ % measure width and save it
+ \prop_get:NnNTF \l_chemformula_charge_prop { #1 } \l_tmpa_tl
+ { \exp_args:NNo \hbox_set:Nn \l_tmpa_box { $ ^ { \chemformula_charge_style:n { \l_tmpa_tl } } $ } }
+ { \exp_args:NNo \hbox_set:Nn \l_tmpa_box { $ ^ { \chemformula_charge_style:n { \l_tmpc_tl } } $ } }
+ \dim_set:Nn \l_chemformula_supscript_dim
+ { -\box_wd:N \l_tmpa_box }
+ \box_clear:N \l_tmpa_box
+ \bool_if:NT \l_chemformula_sub_bool
+ {
+ \chemformula_sub_or_supscript_skip:
+ \skip_horizontal:N \l_chemformula_charge_shift_dim
+ \bool_set_true:N \l_chemformula_charge_shift_bool
+ \dim_zero:N \l_chemformula_subscript_dim
+ }
+ % typeset superscript
+ \prop_get:NnNTF \l_chemformula_charge_prop { #1 } \l_tmpa_tl
+ { $ ^ { \chemformula_charge_style:n { \l_tmpa_tl } } $ }
+ { $ ^ { \chemformula_charge_style:n { \l_tmpc_tl } } $ }
+ % look ahead what's coming next and set boolean accordingly
+ \peek_meaning:NTF \chemformula_subscript:n
+ { \bool_set_true:N \l_chemformula_sup_bool }
+ {
+ \peek_meaning:NTF \chemformula_chief_subscript:n
+ { \bool_set_true:N \l_chemformula_sup_bool }
+ { \bool_set_false:N \l_chemformula_sup_bool }
+ }
+ }
+
+\cs_new:Npn \chemformula_sub_or_supscript_skip:
+ {
+ \dim_compare:nTF
+ {
+ \dim_abs:n { \l_chemformula_subscript_dim }
+ <=
+ \dim_abs:n { \l_chemformula_supscript_dim }
+ }
+ { \skip_horizontal:N \l_chemformula_subscript_dim }
+ { \skip_horizontal:N \l_chemformula_supscript_dim }
+ \bool_set_false:N \l_chemformula_sup_bool
+ \bool_set_false:N \l_chemformula_sub_bool
+ }
+
+% handle sub- in superscripts and vice versa
+\cs_new:Npn \chemformula_chief_supscript:n #1
+ {
+ \tl_if_eq:nnTF { #1 } { \chemformula_supscript:n }
+ { \chemformula_supscript:n }
+ {
+ \tl_if_eq:nnTF { #1 } { \chemformula_subscript:n }
+ { \chemformula_supscript:n }
+ {
+ \tl_set:Nn \l_tmpc_tl { #1 }
+ \tl_if_in:nnT { #1 } { \chemformula_subscript:n }
+ { \tl_remove_all:Nn \l_tmpc_tl { \chemformula_subscript:n } }
+ \tl_if_in:nnT { #1 } { \chemformula_supscript:n }
+ { \tl_remove_all:Nn \l_tmpc_tl { \chemformula_supscript:n } }
+ \exp_args:No \chemformula_supscript:n { \l_tmpc_tl }
+ }
+ }
+ }
+
+\cs_new:Npn \chemformula_chief_subscript:n #1
+ {
+ \tl_if_eq:nnTF { #1 }{ \chemformula_supscript:n }
+ { \chemformula_subscript:n }
+ {
+ \tl_if_eq:nnTF { #1 }{ \chemformula_subscript:n }
+ { \chemformula_subscript:n }
+ {
+ \tl_set:Nn \l_tmpc_tl { #1 }
+ \tl_if_in:nnT { #1 } { \chemformula_subscript:n }
+ { \tl_remove_all:Nn \l_tmpc_tl { \chemformula_subscript:n } }
+ \tl_if_in:nnT { #1 } { \chemformula_supscript:n }
+ { \tl_remove_all:Nn \l_tmpc_tl { \chemformula_supscript:n } }
+ \exp_args:No \chemformula_subscript:n { \l_tmpc_tl }
+ }
+ }
+ }
+
+\cs_new:Npn \chemformula_test_for_subscript:n #1
+ {
+ \peek_meaning:NT \chemformula_subscript:n
+ {
+ \bool_if:NT \l_chemformula_sup_bool
+ { \skip_horizontal:N #1 }
+ \bool_set_false:N \l_chemformula_sup_bool
+ }
+ }
+
+\cs_new:Npn \chemformula_test_for_supscript:n #1
+ {
+ \peek_meaning:NT \chemformula_subscript:n
+ {
+ \bool_if:NT \l_chemformula_sup_bool
+ { \skip_horizontal:N #1 }
+ \bool_set_false:N \l_chemformula_sup_bool
+ }
+ }
+
+%-----------------------------------------------------------------------------%
+% read the input
+\cs_new:Npn \chemformula_input:n #1
+ {
+ \tl_set_rescan:Nnn \l_chemformula_tmpa_tl
+ {
+% \char_set_catcode_letter:N \_
+ \char_set_catcode_letter:N \{
+ \char_set_catcode_letter:N \}
+ \char_set_catcode_letter:N \\
+ \char_set_catcode_other:N \"
+ }
+ { #1 }
+ \chemformula_input_escape_text:o { \l_chemformula_tmpa_tl }
+ \chemformula_input_escape_math:n { #1 }
+ \chemformula_input_stoich:n { #1 }
+ % need to take care of <<=> arrow
+ \tl_if_in:onT { \l_chemformula_tmpa_tl } { <<=> }
+ { \tl_replace_all:Nnn \l_chemformula_tmpa_tl { <<=> } { glgw_l } }
+ \chemformula_clean_chem_macros:o { \l_chemformula_tmpa_tl }
+ \chemformula_input_cmpd:oN { \l_chemformula_tmpa_tl } \l_chemformula_input_tl
+ \chemformula_input_arrow:o { \l_chemformula_tmpa_tl }
+ \chemformula_input_name:n { #1 }
+ \chemformula_input_plus:n { #1 }
+ \chemformula_input_up:n { #1 }
+ \chemformula_input_down:n { #1 }
+ }
+
+%-----------------------------------------------------------------------------%
+% input stoichiometric factors
+\cs_new:Npn \chemformula_input_stoich:n #1
+ {
+ \bool_set_true:N \l_chemformula_stoich_bool
+ \tl_put_right:Nn \l_chemformula_stoich_tl { \chemformula_font_inner: }
+ \tl_map_inline:nn { #1 }
+ {
+ \prop_get:NnNTF \l_chemformula_stoich_prop { ##1 } \l_tmpa_tl
+ {
+ \bool_if:NT \l_chemformula_stoich_bool
+ { \tl_put_right:Nx \l_chemformula_stoich_tl { \l_tmpa_tl } }
+ }
+ { \bool_set_false:N \l_chemformula_stoich_bool }
+ }
+ \bool_if:NTF \l_chemformula_stoich_bool
+ {
+ \tl_if_blank:VF \l_chemformula_stoich_tl
+ {
+ \tl_set_rescan:Nno \l_chemformula_stoich_tl
+ { \ExplSyntaxOn }
+ { \l_chemformula_stoich_tl }
+ \exp_args:No \chemformula_parse_stoich:n { \l_chemformula_stoich_tl }
+ }
+ }
+ { \tl_clear:N \l_chemformula_stoich_tl }
+ }
+
+\cs_new:Nn \chemformula_bm:n { #1 }
+
+\cs_new:Npn \chemformula_parse_stoich:n #1
+ {
+ \tl_if_in:nnTF { #1 } { _ }
+ { \chemformula_parse_stoich_misc_frac:w #1 \q_nil }
+ {
+ \tl_if_in:nnTF { #1 } { / }
+ { \chemformula_parse_stoich_frac:w #1 \q_nil }
+ { \tl_put_right:Nn \l_chemformula_input_tl { #1 } }
+ }
+ }
+
+\DeclareInstance { xfrac } { chemformula-text-frac } { text }
+ {
+ slash-left-kern = -.15em ,
+ slash-right-kern = -.15em
+ }
+
+\cs_new:Npn \chemformula_parse_stoich_frac:w #1/#2 \q_nil
+ { \tl_put_right:Nn \l_chemformula_input_tl { \chemformula_frac:nn { #1 } { #2 } } }
+
+\cs_new:Npn \chemformula_parse_stoich_misc_frac:w #1_#2/#3 \q_nil
+ {
+ \tl_put_right:Nn \l_chemformula_input_tl
+ { \chemformula_misc_frac:nnn { #1 } { #2 } { #3 } }
+ }
+
+\cs_new:Npn \chemformula_frac:nn #1#2
+ {
+ \bool_if:NT \l_chemformula_xfrac_bool
+ { \sfrac[chemformula-text-frac]{#1}{#2} }
+ \bool_if:NT \l_chemformula_nicefrac_bool
+ { \nicefrac{#1}{#2} }
+ \bool_if:NT \l_chemformula_mathfrac_bool
+ { $ \frac{ \text { #1 } } { \text { #2 } } $ }
+ }
+
+\cs_new:Npn \chemformula_misc_frac:nnn #1#2#3
+ {
+ \bool_if:NT \l_chemformula_xfrac_bool
+ { #1\sfrac[chemformula-text-frac]{#2}{#3} }
+ \bool_if:NT \l_chemformula_nicefrac_bool
+ { #1\nicefrac{#2}{#3} }
+ \bool_if:NT \l_chemformula_mathfrac_bool
+ { #1 $ \frac{ \text { #2 } } { \text { #3 } } $ }
+ }
+
+%-----------------------------------------------------------------------------%
+% input compounds
+\cs_new:Nn \chemformula_input_cmpd:nN
+ {
+ \tl_if_blank:VTF \l_chemformula_stoich_tl
+ {
+ \tl_if_eq:nnT { #1 } { + }
+ { \bool_set_true:N \l_chemformula_is_plus_bool }
+ \tl_if_eq:nnT { #1 } { v }
+ { \bool_set_true:N \l_chemformula_is_down_bool }
+ \tl_if_eq:nnT { #1 } { ^ }
+ { \bool_set_true:N \l_chemformula_is_up_bool }
+ \chemformula_detect_arrows:n { #1 }
+ \chemformula_detect_name:n { #1 }
+ \bool_if:nT
+ {
+ !\l_chemformula_is_plus_bool &&
+ !\l_chemformula_is_down_bool &&
+ !\l_chemformula_is_up_bool &&
+ !\l_chemformula_is_arrow_bool &&
+ !\l_chemformula_is_name_bool &&
+ !\l_chemformula_first_last_text_bool &&
+ !\l_chemformula_first_last_math_bool
+ }
+ {
+ \tl_put_right:Nn #2
+ { \chemformula_font_inner: }
+ \chemformula_handle_sub_and_supscripts:nN { #1 } #2
+ }
+ }
+ {
+ \tl_put_right:Nn #2 { \skip_horizontal:N \l_chemformula_stoich_space_dim }
+ \tl_clear:N \l_chemformula_stoich_tl
+ }
+ }
+\cs_generate_variant:Nn \chemformula_input_cmpd:nN { oN }
+
+\cs_new:Nn \chemformula_font_inner:
+ {
+ \bool_if:NT \l_chemformula_fss_bool
+ {
+ \bool_if:NT \l_chemformula_fss_family_bool
+ { \fontfamily { \l_chemformula_font_family_tl } }
+ \bool_if:NT \l_chemformula_fss_series_bool
+ { \fontseries { \l_chemformula_font_series_tl } }
+ \bool_if:NT \l_chemformula_fss_shape_bool
+ { \fontshape { \l_chemformula_font_shape_tl } }
+ \selectfont
+ }
+ \bool_if:NT \l_chemformula_fontspec_bool
+ { \chemformula_font: }
+ \tl_use:N \l_chemformula_format_tl
+ \exp_args:No \tl_if_eq:nnTF { \f@series } { bx }
+ { \cs_set_eq:NN \chemformula_bm:n \bm }
+ { \cs_set:Nn \chemformula_bm:n { ##1 } }
+ }
+
+\cs_new:Nn \chemformula_font: {}
+\cs_new:Nn \chemformula_fontspec:n
+ {
+ \tl_if_in:nnTF { #1 } { [ }
+ { \chemformula_fontspec_aux:w #1 \q_stop }
+ { \chemformula_fontspec_aux:w [] #1 \q_stop }
+ }
+
+\cs_new:Npn \chemformula_fontspec_aux:w [#1]#2 \q_stop
+ { \newfontfamily \chemformula_font: [ #1 ] { #2 } }
+
+\cs_new:Nn \chemformula_handle_sub_and_supscripts:nN
+ {
+ \tl_set_rescan:Nnn \l_tmpa_tl
+ {
+ \char_set_catcode_letter:N \_
+ \char_set_catcode_letter:N \{
+ \char_set_catcode_letter:N \}
+ \char_set_catcode_letter:N \\
+ }
+ { #1 }
+ \tl_if_in:VnT \l_tmpa_tl { ^ }
+ { \tl_replace_all:Nnn \l_tmpa_tl { ^ } { \chemformula_chief_supscript:n } }
+ \tl_if_in:VnT \l_tmpa_tl { _ }
+ { \tl_replace_all:Nnn \l_tmpa_tl { _ } { \chemformula_chief_subscript:n } }
+ \int_zero:N \l_chemformula_count_tokens_int
+ \tl_map_inline:Nn \l_tmpa_tl
+ {
+ \int_incr:N \l_chemformula_count_tokens_int
+ \int_compare:nTF { \l_chemformula_count_tokens_int = \tl_length:N \l_tmpa_tl }
+ {
+ \tl_if_eq:nnTF { ##1 } { + }
+ {
+ \tl_put_right:Nn #2
+ { \chemformula_supscript:n { \chemformula_plus: } }
+ }
+ {
+ \tl_if_eq:nnTF { ##1 } { - }
+ {
+ \tl_put_right:Nn #2
+ { \chemformula_supscript:n { \chemformula_minus: } }
+ }
+ {
+ \prop_get:NnNTF \l_chemformula_cmpd_prop { ##1 } \l_tmpb_tl
+ { \tl_put_right:No #2 { \l_tmpb_tl } }
+ { \tl_put_right:Nn #2 { ##1 } }
+ }
+ }
+ }
+ {
+ \prop_get:NnNTF \l_chemformula_cmpd_prop { ##1 } \l_tmpb_tl
+ { \tl_put_right:No #2 { \l_tmpb_tl } }
+ { \tl_put_right:Nn #2 { ##1 } }
+ }
+ }
+ }
+
+%-----------------------------------------------------------------------------%
+% clean up chemmacros commands:
+\cs_new:Nn \chemformula_clean_chem_macros:n
+ {
+ \cs_set:Nn \chemmacros_text:n
+ {
+ \mode_if_math:TF
+ { \text { \chemformula_font_inner: ##1 } }
+ { \chemformula_font_inner: ##1 }
+ }
+ \cs_set:Npn \chemmacros_xspace: {}
+ \tl_set:Nn \l_tmpa_tl { #1 }
+ \exp_args:NNo \tl_replace_all:Nnn \l_tmpa_tl { \l_chemformula_aq_tl } { _{(aq)} }
+ \bool_if:NTF \l_chemmacros_german_bool
+ { \exp_args:NNo \tl_replace_all:Nnn \l_tmpa_tl { \l_chemformula_sld_tl } { _{(f)} } }
+ { \exp_args:NNo \tl_replace_all:Nnn \l_tmpa_tl { \l_chemformula_sld_tl } { _{(s)} } }
+ \bool_if:NTF \l_chemmacros_german_bool
+ { \exp_args:NNo \tl_replace_all:Nnn \l_tmpa_tl { \l_chemformula_lqd_tl } { _{(f\/l)} } }
+ { \exp_args:NNo \tl_replace_all:Nnn \l_tmpa_tl { \l_chemformula_lqd_tl } { _{(l)} } }
+ \exp_args:NNo \tl_replace_all:Nnn \l_tmpa_tl { \l_chemformula_gas_tl } { _{(g)} }
+ \tl_set_eq:NN \l_chemformula_tmpa_tl \l_tmpa_tl
+ }
+\cs_generate_variant:Nn \chemformula_clean_chem_macros:n { o }
+
+\tl_new:N \l_chemformula_aq_tl
+\tl_set_rescan:Nnn \l_chemformula_aq_tl { \char_set_catcode_letter:N \\ } { \aq }
+\tl_set_rescan:Nnn \l_chemformula_sld_tl { \char_set_catcode_letter:N \\ } { \sld }
+\tl_set_rescan:Nnn \l_chemformula_lqd_tl { \char_set_catcode_letter:N \\ } { \lqd }
+\tl_set_rescan:Nnn \l_chemformula_gas_tl { \char_set_catcode_letter:N \\ } { \gas }
+
+%-----------------------------------------------------------------------------%
+% input "and" sign
+\cs_new:Nn \chemformula_input_plus:n
+ {
+ \tl_if_eq:nnT { #1 } { + }
+ {
+ \tl_put_right:Nn \l_chemformula_input_tl
+ {
+ \skip_horizontal:N \l_chemformula_plus_space_dim
+ +
+ \skip_horizontal:N \l_chemformula_plus_space_dim
+ }
+ }
+ \bool_set_false:N \l_chemformula_is_plus_bool
+ }
+
+%-----------------------------------------------------------------------------%
+% input escaping gas
+\cs_new:Nn \chemformula_input_up:n
+ {
+ \tl_if_eq:nnT { #1 } { ^ }
+ { \tl_put_right:Nn \l_chemformula_input_tl { $\uparrow$ } }
+ \bool_set_false:N \l_chemformula_is_up_bool
+ }
+
+%-----------------------------------------------------------------------------%
+% input precipitate
+\cs_new:Nn \chemformula_input_down:n
+ {
+ \tl_if_eq:nnT { #1 } { v }
+ { \tl_put_right:Nn \l_chemformula_input_tl { $\downarrow$ } }
+ \bool_set_false:N \l_chemformula_is_down_bool
+ }
+
+%-----------------------------------------------------------------------------%
+% input arrow
+\cs_new:Nn \chemformula_input_arrow:n
+ {
+ \bool_if:nT
+ {
+ \l_chemformula_is_arrow_bool &&
+ !\l_chemformula_first_last_text_bool &&
+ !\l_chemformula_first_last_math_bool
+ }
+ { \tl_put_right:Nn \l_chemformula_input_tl { #1 } }
+ \bool_set_false:N \l_chemformula_is_arrow_bool
+ }
+\cs_generate_variant:Nn \chemformula_input_arrow:n { o }
+
+%-----------------------------------------------------------------------------%
+% input compound name
+\cs_new:Nn \chemformula_input_name:n
+ {
+ \bool_if:nT
+ {
+ \l_chemformula_is_name_bool &&
+ !\l_chemformula_first_last_text_bool &&
+ !\l_chemformula_first_last_math_bool
+ }
+ { \tl_put_right:Nn \l_chemformula_input_tl { #1 } }
+ \bool_set_false:N \l_chemformula_is_name_bool
+ }
+
+%-----------------------------------------------------------------------------%
+% input escaped text
+\cs_new:Nn \chemformula_input_escape_text:n
+ {
+ \chemformula_first_last_text:n { #1 }
+ \bool_if:NT \l_chemformula_first_last_double_bool
+ {
+ \bool_set_true:N \l_chemformula_first_last_text_bool
+ \chemformula_read_escape_double:w #1 \q_nil
+ }
+ \bool_if:NT \l_chemformula_first_last_single_bool
+ {
+ \bool_set_true:N \l_chemformula_first_last_text_bool
+ \chemformula_read_escape_single:w #1 \q_nil
+ }
+ }
+\cs_generate_variant:Nn \chemformula_input_escape_text:n { o }
+
+\cs_new:Npn \chemformula_read_escape_double:w "#1" \q_nil
+ {
+ \tl_set_rescan:Nnn \l_tmpa_tl
+ { \ExplSyntaxOn \char_set_catcode_other:N \: }
+ { #1 }
+ \tl_replace_all:Nnn \l_tmpa_tl { \_ } { chemformulaplaceholder }
+ \tl_replace_all:Nnn \l_tmpa_tl { _ } { \sb }
+ \tl_replace_all:Nnn \l_tmpa_tl { chemformulaplaceholder } { \_ }
+ \tl_set_rescan:Nno \l_tmpa_tl { \ExplSyntaxOff } { \l_tmpa_tl }
+ \tl_put_right:NV \l_chemformula_input_tl \l_tmpa_tl
+ }
+
+\cs_new:Npn \chemformula_read_escape_single:w '#1' \q_nil
+ {
+ \tl_set_rescan:Nnn \l_tmpa_tl
+ { \ExplSyntaxOn \char_set_catcode_other:N \: }
+ { { #1 } }
+ \tl_replace_all:Nnn \l_tmpa_tl { \_ } { chemformulaplaceholder }
+ \tl_replace_all:Nnn \l_tmpa_tl { _ } { \sb }
+ \tl_replace_all:Nnn \l_tmpa_tl { chemformulaplaceholder } { \_ }
+ \tl_set_rescan:Nno \l_tmpa_tl { \ExplSyntaxOff } { \l_tmpa_tl }
+ \tl_put_right:NV \l_chemformula_input_tl \l_tmpa_tl
+ }
+
+\cs_new:Nn \chemformula_first_last_text:n
+ {
+ \bool_set_false:N \l_chemformula_first_last_double_bool
+ \bool_set_false:N \l_chemformula_first_last_single_bool
+ \bool_set_false:N \l_chemformula_first_last_text_bool
+ \int_zero:N \l_tmpa_int
+ \int_zero:N \l_tmpb_int
+ \tl_map_inline:nn { #1 } { \int_incr:N \l_tmpa_int }
+ \tl_map_inline:nn { #1 }
+ {
+ \int_incr:N \l_tmpb_int
+ \int_compare:nT { \l_tmpb_int = 1 }
+ {
+ \tl_if_eq:nnT { ##1 } { " }
+ { \bool_set_true:N \l_chemformula_first_last_double_bool }
+ }
+ \int_compare:nT { \l_tmpb_int = \l_tmpa_int }
+ {
+ \tl_if_eq:nnF { ##1 } { " }
+ { \bool_set_false:N \l_chemformula_first_last_double_bool }
+ }
+ }
+ \bool_if:NF \l_chemformula_first_last_double_bool
+ {
+ \int_zero:N \l_tmpb_int
+ \tl_map_inline:nn { #1 }
+ {
+ \int_incr:N \l_tmpb_int
+ \int_compare:nT { \l_tmpb_int = 1 }
+ {
+ \tl_if_eq:nnT { ##1 } { ' }
+ { \bool_set_true:N \l_chemformula_first_last_single_bool }
+ }
+ \int_compare:nT { \l_tmpb_int = \l_tmpa_int }
+ {
+ \tl_if_eq:nnF { ##1 } { ' }
+ { \bool_set_false:N \l_chemformula_first_last_single_bool }
+ }
+ }
+ }
+ }
+
+%-----------------------------------------------------------------------------%
+% input escaped math
+\cs_new:Nn \chemformula_input_escape_math:n
+ {
+ \chemformula_first_last_math:n { #1 }
+ \bool_if:NT \l_chemformula_first_last_math_bool
+ { \chemformula_read_escape_math:w #1 \q_nil }
+ }
+
+\cs_new:Npn \chemformula_read_escape_math:w $#1$ \q_nil
+ {
+ \tl_set_rescan:Nnn \l_tmpa_tl
+ {
+ \ExplSyntaxOn \char_set_catcode_letter:N \{
+ \char_set_catcode_letter:N \}
+ }
+ { \mbox { \( #1 \) } }
+ \tl_replace_all:Nnn \l_tmpa_tl { \_ } { chemformulaplaceholder }
+ \tl_replace_all:Nnn \l_tmpa_tl { _ } { \sb }
+ \tl_replace_all:Nnn \l_tmpa_tl { chemformulaplaceholder } { \_ }
+ \tl_set_rescan:Nno \l_tmpa_tl { \ExplSyntaxOff } { \l_tmpa_tl }
+ \tl_put_right:NV \l_chemformula_input_tl \l_tmpa_tl
+ \tl_put_right:Nn \l_chemformula_input_tl
+ { \skip_horizontal:N \l_chemformula_math_space_dim }
+ }
+
+\cs_new:Nn \chemformula_first_last_math:n
+ {
+ \bool_set_false:N \l_chemformula_first_last_math_bool
+ \int_zero:N \l_tmpa_int
+ \int_zero:N \l_tmpb_int
+ \tl_map_inline:nn { #1 } { \int_incr:N \l_tmpa_int }
+ \tl_map_inline:nn { #1 }
+ {
+ \int_incr:N \l_tmpb_int
+ \int_compare:nT { \l_tmpb_int = 1 }
+ {
+ \tl_if_eq:nnT { ##1 } { $ }
+ { \bool_set_true:N \l_chemformula_first_last_math_bool }
+ }
+ \int_compare:nT { \l_tmpb_int = \l_tmpa_int }
+ {
+ \tl_if_eq:nnF { ##1 } { $ }
+ { \bool_set_false:N \l_chemformula_first_last_math_bool }
+ }
+ }
+ }
+
+%-----------------------------------------------------------------------------%
+% customization of output other than arrows
+\keys_define:nn { chemmacros / chemformula }
+ {
+ charge-hshift .dim_set:N = \l_chemformula_charge_shift_dim ,
+ charge-hshift .default:n = .3ex ,
+ charge-style .choice: ,
+ charge-style / text .code:n =
+ \bool_set_false:N \l_chemformula_charge_style_math_bool ,
+ charge-style / math .code:n =
+ \bool_set_true:N \l_chemformula_charge_style_math_bool ,
+ subscript-vshift .code:n =
+ {
+ \dim_set:Nn \l_chemformula_subscript_shift_additional_dim { #1 }
+ \dim_set:Nn \l_chemformula_subscript_shift_dim
+ { \l_chemformula_subscript_shift_default_dim + \l_chemformula_subscript_shift_additional_dim }
+ } ,
+ subscript-vshift .default:n = 0pt ,
+ subscript-style .choice: ,
+ subscript-style / text .code:n =
+ \bool_set_false:N \l_chemformula_number_style_math_bool ,
+ subscript-style / math .code:n =
+ \bool_set_true:N \l_chemformula_number_style_math_bool ,
+ decimal-marker .tl_set:N = \l_chemformula_decimal_output_tl ,
+ frac-style .choice: ,
+ frac-style / math .code:n =
+ \bool_set_false:N \l_chemformula_xfrac_bool
+ \bool_set_false:N \l_chemformula_nicefrac_bool
+ \bool_set_true:N \l_chemformula_mathfrac_bool ,
+ frac-style / xfrac .code:n =
+ \bool_set_true:N \l_chemformula_xfrac_bool
+ \bool_set_false:N \l_chemformula_nicefrac_bool
+ \bool_set_false:N \l_chemformula_mathfrac_bool ,
+ frac-style / nicefrac .code:n =
+ \bool_set_false:N \l_chemformula_xfrac_bool
+ \bool_set_true:N \l_chemformula_nicefrac_bool
+ \bool_set_false:N \l_chemformula_mathfrac_bool ,
+ stoich-space .dim_set:N = \l_chemformula_stoich_space_dim ,
+ adduct-space .dim_set:N = \l_chemformula_cdot_space_dim ,
+ plus-space .dim_set:N = \l_chemformula_plus_space_dim ,
+ math-space .dim_set:N = \l_chemformula_math_space_dim ,
+ name-format .tl_set:N = \l_chemformula_name_format_tl ,
+ name-width .code:n =
+ {
+ \tl_if_eq:nnTF { #1 } { auto }
+ { \bool_set_false:N \l_chemformula_name_width_bool }
+ {
+ \bool_set_true:N \l_chemformula_name_width_bool
+ \dim_set:Nn \l_chemformula_name_dim { #1 }
+ }
+ } ,
+ bond-length .dim_set:N = \l_chemformula_bond_dim ,
+ font-family .code:n =
+ \bool_set_true:N \l_chemformula_fss_bool
+ \bool_set_false:N \l_chemformula_fontspec_bool
+ \bool_set_true:N \l_chemformula_fss_family_bool
+ \tl_set:Nn \l_chemformula_font_family_tl { #1 } ,
+ font-series .code:n =
+ \bool_set_true:N \l_chemformula_fss_bool
+ \bool_set_false:N \l_chemformula_fontspec_bool
+ \bool_set_true:N \l_chemformula_fss_series_bool
+ \tl_set:Nn \l_chemformula_font_series_tl { #1 } ,
+ font-shape .code:n =
+ \bool_set_true:N \l_chemformula_fss_bool
+ \bool_set_false:N \l_chemformula_fontspec_bool
+ \bool_set_true:N \l_chemformula_fss_shape_bool
+ \tl_set:Nn \l_chemformula_font_shape_tl { #1 } ,
+ font-spec .code:n =
+ \bool_set_false:N \l_chemformula_fss_bool
+ \bool_set_true:N \l_chemformula_fontspec_bool
+ \chemformula_fontspec:n { #1 } ,
+ format .code:n =
+ \bool_set_false:N \l_chemformula_fss_bool
+ \bool_set_false:N \l_chemformula_fontspec_bool
+ \tl_set:Nn \l_chemformula_format_tl { #1 }
+ }
+
+%-----------------------------------------------------------------------------%
+% hyperref support
+\AfterPackage* { hyperref }
+ { \pdfstringdefDisableCommands { \cs_set:Npn \cn #1 { #1 } } }
+
+\tex_endinput:D
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+VERSION HISTORY
+2012/01/28 - version 3.0 - first published to CTAN with the chemmacros bundle
+2012/01/30 - version 3.0a - bugfix: subscripts in escaped inputs failed,
+ renamed formula => chemformula
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% TODO
+- Addukte: Zahlen nach * und . automatisch erkennen?
+- allow fractions in subscripts: _{$\frac{1}{2}$} ?
+- optionale argumente von \\ nach außen weiterreichen?
+- vertikaler shift für superskripte?
+- the explicit definition of each arrow on its own is inefficient.
+ also these definitions abuse the `xparse' command \NewDocumentCommand
+ for internal commands => needs to be taken care of \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemmacros-version1.cfg b/Master/texmf-dist/tex/latex/chemmacros/chemmacros-version1.cfg
index a7dd522d55f..ae8adb9f968 100644
--- a/Master/texmf-dist/tex/latex/chemmacros/chemmacros-version1.cfg
+++ b/Master/texmf-dist/tex/latex/chemmacros/chemmacros-version1.cfg
@@ -1,10 +1,11 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --------------------------------------------------------------------------- %
-% - chemmacros - chemmacros-version1.cfg - %
+% - the CHEMMACROS bundle - %
+% - chemmacros-version1.cfg - %
% - macros and commands for chemists - %
% --------------------------------------------------------------------------- %
% - Clemens Niederberger - %
-% - 2011/11/03 - %
+% - 2012/01/28 - %
% --------------------------------------------------------------------------- %
% - http://www.mychemistry.eu/ - %
% - contact@mychemistry.eu - %
@@ -12,7 +13,7 @@
% - If you have any ideas, questions, suggestions or bugs to report, please - %
% - feel free to contact me. - %
% --------------------------------------------------------------------------- %
-% - Copyright 2011 Clemens Niederberger - %
+% - Copyright 2011-2012 Clemens Niederberger - %
% - - %
% - This work may be distributed and/or modified under the - %
% - conditions of the LaTeX Project Public License, either version 1.3 - %
@@ -25,10 +26,6 @@
% - This work has the LPPL maintenance status `maintained'. - %
% - - %
% - The Current Maintainer of this work is Clemens Niederberger. - %
-% - - %
-% - This work consists of the files chemmacros.sty, chemmacros-version1.cfg,- %
-% - chemmacros_doc_de.tex, chemmacros_doc_de.tex, README and the derived - %
-% - files chemmacros_doc_de.pdf and chemmacros_doc_en.pdf - %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% old definitions of some commands, deprecated commands
\RequirePackage { ifthen }
diff --git a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty
index 0aeffae3755..3adb8505858 100644
--- a/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty
+++ b/Master/texmf-dist/tex/latex/chemmacros/chemmacros.sty
@@ -1,10 +1,11 @@
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% --------------------------------------------------------------------------- %
-% - chemmacros - chemmacros.sty - %
+% - the CHEMMACROS bundle - %
+% - chemmacros.sty - %
% - macros and commands for chemists - %
% --------------------------------------------------------------------------- %
% - Clemens Niederberger - %
-% - 2011/11/03 - %
+% - 2012/02/01 - %
% --------------------------------------------------------------------------- %
% - http://www.mychemistry.eu/ - %
% - contact@mychemistry.eu - %
@@ -12,7 +13,7 @@
% - If you have any ideas, questions, suggestions or bugs to report, please - %
% - feel free to contact me. - %
% --------------------------------------------------------------------------- %
-% - Copyright 2011 Clemens Niederberger - %
+% - Copyright 2011-2012 Clemens Niederberger - %
% - - %
% - This work may be distributed and/or modified under the - %
% - conditions of the LaTeX Project Public License, either version 1.3 - %
@@ -25,18 +26,13 @@
% - This work has the LPPL maintenance status `maintained'. - %
% - - %
% - The Current Maintainer of this work is Clemens Niederberger. - %
-% - - %
-% - This work consists of the files chemmacros.sty, chemmacros-version1.cfg - %
-% - chemmacros_doc_de.tex, chemmacros_doc_de.tex, README and the derived - %
-% - files chemmacros_doc_de.pdf and chemmacros_doc_en.pdf - %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-\RequirePackage{ expl3 , xparse , l3keys2e , xfrac , siunitx , tikz , mathtools , cancel , environ }
+\RequirePackage{ expl3 , xparse , l3keys2e , xfrac , siunitx , tikz , mathtools , environ , scrlfile , etoolbox , bm }
\usetikzlibrary{calc,arrows}
-\AtBeginDocument
- {
- \@ifpackageloaded{mhchem}{} { \RequirePackage[ version=3 ]{ mhchem } }
- }
-\ProvidesExplPackage {chemmacros} {2011/11/03} {2.0a} {macros and commands for chemists}
+
+\ProvidesExplPackage {chemmacros} {2012/02/01} {3.0a} {macros and commands for chemists}
+
+\@ifpackageloaded { chemformula } {} { \RequirePackage { chemformula } }
\bool_new:N \l_chemmacros_version_one_bool
\bool_set_false:N \l_chemmacros_version_one_bool
@@ -62,10 +58,15 @@
\bool_new:N \l_chemmacros_EZ_cool_bool
\bool_set_false:N \l_chemmacros_EZ_cool_bool
+\bool_new:N \l_chemmacros_use_mhchem_bool
+\bool_set_false:N \l_chemmacros_use_mhchem_bool
+
\bool_new:N \l_chemmacros_chemstyle_bool
\bool_new:N \l_chemmacros_hyperref_bool
\bool_new:N \l_chemmacros_varioref_bool
\bool_new:N \l_chemmacros_chemfig_bool
+\bool_new:N \l_chemmacros_ghsystem_bool
+\bool_set_true:N \l_chemmacros_ghsystem_bool
\AtBeginDocument
{
@@ -85,65 +86,102 @@
% --------------------------------------------------------------------------- %
% package options
-% german => change pKA => pKS etc
-% xspace => add an \xspace after a whole bunch of macros
-% bpchem => use \IUPAC inside for \NMR command
-% circled => circle charges
-% EZ => cool or chemmacros version of \E
-% version=1 => compatibility for documents set with v1.*
+% xspace => add an \xspace after a whole bunch of macros
+% bpchem => use \IUPAC inside for \NMR command
+% circled => circle charges
+% detect-bold => behaviour when font series bold
+% EZ => cool or chemmacros version of \E
+% german => change pKA => pKS etc
+% ngerman => an alias :)
+% ghsystem => load ghsystem or don't
+% method => use `chemformula' or `mhchem'
+% strict => errors or warnings
+% synchronize => let particles et.al. adapt chemformula's font selection
+% version=1 => compatibility for documents set with v1.*
+
+\bool_new:N \l_chemmacros_strict_bool
+\bool_new:N \l_chemmacros_detect_bold_bool
+\bool_set_false:N \l_chemmacros_detect_bold_bool
+
+\cs_new:Nn \chemmacros_inner_font: {}
\keys_define:nn { chemmacros / option }
{
- bpchem .bool_set:N = \l_chemmacros_bpchem_bool ,
- bpchem .default:n = true ,
- circletype .choice: ,
+ bpchem .bool_set:N = \l_chemmacros_bpchem_bool ,
+ bpchem .default:n = true ,
+ circletype .choice: ,
circletype / math .code:n =
{ \bool_set_false:N \l_chemmacros_circled_chem_bool } ,
circletype / chem .code:n =
{ \bool_set_true:N \l_chemmacros_circled_chem_bool } ,
- circletype .default:n = chem ,
- circled .choice: ,
- circled / none .code:n =
+ circletype .default:n = chem ,
+ circled .choice: ,
+ circled / none .code:n =
{
\bool_set_false:N \l_chemmacros_circled_bool
\bool_set_false:N \l_chemmacros_circled_formal_bool
} ,
- circled / formal .code:n =
+ circled / formal .code:n =
{
\bool_set_true:N \l_chemmacros_circled_bool
\bool_set_true:N \l_chemmacros_circled_formal_bool
} ,
- circled / all .code:n =
+ circled / all .code:n =
{
\bool_set_true:N \l_chemmacros_circled_bool
\bool_set_false:N \l_chemmacros_circled_formal_bool
} ,
- circled .default:n = formal ,
- EZ .choice: ,
- EZ / cool .code:n =
+ circled .default:n = formal ,
+ detect-bold .bool_set:N = \l_chemmacros_detect_bold_bool ,
+ detect-bold .default:n = true ,
+ EZ .choice: ,
+ EZ / cool .code:n =
{ \bool_set_true:N \l_chemmacros_EZ_cool_bool } ,
- EZ / chemmacros .code:n =
+ EZ / chemmacros .code:n =
{ \bool_set_false:N \l_chemmacros_EZ_cool_bool } ,
- EZ .default:n = chemmacros ,
- german .bool_set:N = \l_chemmacros_german_bool ,
- german .default:n = true ,
- xspace .bool_set:N = \l_chemmacros_xspace_bool ,
- xspace .default:n = true ,
- version .choice: ,
- version / 1 .code:n =
+ EZ .default:n = chemmacros ,
+ german .bool_set:N = \l_chemmacros_german_bool ,
+ german .default:n = true ,
+ ghsystem .bool_set:N = \l_chemmacros_ghsystem_bool ,
+ ghsystem .default:n = true ,
+ ngerman .bool_set:N = \l_chemmacros_german_bool ,
+ ngerman .default:n = true ,
+ method .choice: ,
+ method / chemformula .code:n =
+ \bool_set_false:N \l_chemmacros_use_mhchem_bool ,
+ method / mhchem .code:n =
+ \bool_set_true:N \l_chemmacros_use_mhchem_bool ,
+ method .default:n = chemformula ,
+ strict .bool_set:N = \l_chemmacros_strict_bool ,
+ strict .default:n = true ,
+ synchronize .choice: ,
+ synchronize / true .code:n =
+ \cs_set_eq:NN \chemmacros_inner_font: \chemformula_font_inner: ,
+ synchronize / false .code:n = \cs_set:Nn \chemmacros_inner_font: {} ,
+ synchronize .default:n = true ,
+ xspace .bool_set:N = \l_chemmacros_xspace_bool ,
+ xspace .default:n = true ,
+ version .choice: ,
+ version / 1 .code:n =
{ \bool_set_true:N \l_chemmacros_version_one_bool } ,
- version / 2 .code:n =
+ version / 2 .code:n =
+ { \bool_set_false:N \l_chemmacros_version_one_bool } ,
+ version / bundle .code:n =
{ \bool_set_false:N \l_chemmacros_version_one_bool }
}
\ProcessKeysOptions { chemmacros / option }
-\AtBeginDocument
+\AtEndPreamble
{
+ \bool_if:NT \l_chemmacros_ghsystem_bool
+ { \RequirePackage { ghsystem } }
\bool_if:NT \l_chemmacros_bpchem_bool
{ \RequirePackage { bpchem } }
\bool_if:NT \l_chemmacros_xspace_bool
{ \RequirePackage { xspace } }
+ \bool_if:NT \l_chemmacros_use_mhchem_bool
+ { \RequirePackage[ version=3 ]{ mhchem } }
}
\cs_new_nopar:Npn \chemmacros_xspace:
@@ -154,6 +192,13 @@
% --------------------------------------------------------------------------- %
% warning / error messages
+\cs_new:Npn \chemmacros_msg:nnxx #1#2#3#4
+ {
+ \bool_if:NTF \l_chemmacros_strict_bool
+ { \msg_error:nnxx { #1 } { #2 } { #3 } { #4 } }
+ { \msg_warning:nnxx { #1 } { #2 } { #3 } { #4 } }
+ }
+
\msg_set:nnnn { chemmacros } { already-defined }
{
The~command~#1~has~also~been~defined~by~another~package.
@@ -228,18 +273,6 @@
% --------------------------------------------------------------------------- %
% circled charge signs
-% Definition inspired by chemstyle's definition of \standarsstate
-% \cs_new_nopar:Npn \chemmacros_fplus_aux:
-% {
-% \raise.1ex\hbox{\scalebox{.65}{\textcircled{\lower.1ex\hbox{$+$}}}}
-% }
-% \cs_new_nopar:Npn \chemmacros_fplus:
-% {
-% \mode_if_math:TF
-% { \text { \chemmacros_fplus_aux: } }
-% { \chemmacros_fplus_aux: }
-% }
-
\cs_new_nopar:Npn \chemmacros_fplus:
{ \ensuremath { \chemmacros_fplus_aux_i: } }
\cs_new_nopar:Npn \chemmacros_fplus_aux_i:
@@ -259,17 +292,6 @@
}
}
-% \cs_new_nopar:Npn \chemmacros_fminus_aux:
-% {
-% \raise.1ex\hbox{\scalebox{.65}{\textcircled{\lower.1ex\hbox{$-$}}}}
-% }
-% \cs_new_nopar:Npn \chemmacros_fminus:
-% {
-% \mode_if_math:TF
-% { \text { \chemmacros_fminus_aux: } }
-% { \chemmacros_fminus_aux: }
-% }
-
\cs_new_nopar:Npn \chemmacros_fminus:
{ \ensuremath { \chemmacros_fminus_aux_i: } }
\cs_new_nopar:Npn \chemmacros_fminus_aux_i:
@@ -296,7 +318,8 @@
% change output depending on circled-option
\cs_new_nopar:Npn \chemmacros_plus:
{
- \bool_if:nTF { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool }
+ \bool_if:nTF
+ { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool }
{
\bool_if:NTF \l_chemmacros_circled_chem_bool
{ \chemmacros_fplus: }
@@ -307,7 +330,8 @@
\cs_new_nopar:Npn \chemmacros_minus:
{
- \bool_if:nTF { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool }
+ \bool_if:nTF
+ { \l_chemmacros_circled_bool && !\l_chemmacros_circled_formal_bool }
{
\bool_if:NTF \l_chemmacros_circled_chem_bool
{ \chemmacros_fminus: }
@@ -367,24 +391,75 @@
}
}
-\cs_new_nopar:Npn \chemmacros_atom:n #1
- { \ce { #1 } }
+\cs_new:Nn \chemmacros_atom:n
+ {
+ \mode_if_math:TF
+ { \text { \chemmacros_inner_font: #1 } }
+ { \group_begin: \chemmacros_inner_font: #1 \group_end: }
+ }
\cs_generate_variant:Nn \chemmacros_atom:n { o,f,x }
+\cs_new:Nn \chemmacros_text:n
+ { \mode_if_math:TF { \text { #1 } } { #1 } }
+
+% add a possibility to let chemformula use the chemformula with method=chemformula, too
+\tl_new:N \l_chemmacros_chemformula_tl
+\cs_new:Nn \chemmacros_chemformula:n
+ {
+ \bool_if:NTF \l_chemmacros_use_mhchem_bool
+ { \ce { #1 } }
+ {
+ \group_begin:
+ \cs_set_eq:NN \chemformula_font_inner: \chemmacros_inner_font:
+ \chemformula_input_cmpd:nN { #1 } \l_chemmacros_chemformula_tl
+ \mode_if_math:TF
+ { \text { \l_chemmacros_chemformula_tl } }
+ { { \l_chemmacros_chemformula_tl } }
+ \group_end:
+ }
+ }
+
% --------------------------------------------------------------------------- %
% particles, charges
% electron
\bool_new:N \l_chemmacros_charge_append_bool
\bool_set_false:N \l_chemmacros_charge_append_bool
-\cs_new_nopar:Npn \el
- { \chemmacros_atom:n { e } \mch \chemmacros_xspace: }
-% proton
-\cs_new_nopar:Npn \prt
- { \chemmacros_atom:n { p } \pch \chemmacros_xspace: }
-% neutron
-\cs_new_nopar:Npn \ntr
- { \chemmacros_atom:n { n^0 } \chemmacros_xspace: }
+\bool_if:NTF \l_chemmacros_use_mhchem_bool
+ {
+ \cs_new_nopar:Npn \el { \chemmacros_atom:n { e } \mch \chemmacros_xspace: }
+ \cs_new_nopar:Npn \prt { \chemmacros_atom:n { p } \pch \chemmacros_xspace: }
+ }
+ {
+ \cs_new_nopar:Npn \el { \chemmacros_chemformula:n { e- } \chemmacros_xspace: }
+ \cs_new_nopar:Npn \prt { \chemmacros_chemformula:n { p+ } \chemmacros_xspace: }
+ }
+\cs_new_nopar:Npn \ntr { \chemmacros_chemformula:n { n^0 } \chemmacros_xspace: }
+
+\cs_new_nopar:Npn \chemmacros_bm:n #1
+ {
+ \bool_if:NTF \l_chemmacros_detect_bold_bool
+ { \bm { #1 } }
+ { #1 }
+ }
+
+\cs_new_nopar:Npn \chemmacros_bf:n #1
+ {
+ \bool_if:NTF \l_chemmacros_detect_bold_bool
+ { { \normalfont \bfseries #1 } }
+ { { \normalfont #1 } }
+ }
+
+\cs_new_nopar:Npn \chemmacros_detect_bold:n #1
+ {
+ \chemmacros_if_bold:TF
+ {
+ \mode_if_math:TF
+ { \chemmacros_bm:n { #1 } }
+ { \chemmacros_bf:n { #1 } }
+ }
+ { #1 }
+ }
% charges
\cs_new_nopar:Npn \chemmacros_charge:n #1
@@ -392,13 +467,13 @@
\bool_if:NTF \l_chemmacros_charge_append_bool
{
\mode_if_math:TF
- { {}^ { #1 } }
- { $ {}^ { #1 } $ }
+ { {}^ { \chemmacros_detect_bold:n { #1 } } }
+ { $ {}^ { \chemmacros_detect_bold:n { #1 } } $ }
}
{
\mode_if_math:TF
- { ^ { #1 } }
- { $ ^ { #1 } $ }
+ { ^ { \chemmacros_detect_bold:n { #1 } } }
+ { $ ^ { \chemmacros_detect_bold:n { #1 } } $ }
}
}
@@ -460,34 +535,47 @@
% --------------------------------------------------------------------------- %
% ions, molecules
% proton, hydroxide, hydronium/oxonium, water, nucleophile, electrophile
-\cs_new_nopar:Npn \Hpl
- { \chemmacros_atom:n { H } \pch \chemmacros_xspace: }
-\cs_new_nopar:Npn \Hyd
- { \chemmacros_atom:n { OH } \mch \chemmacros_xspace: }
-\cs_new_nopar:Npn \HtO
- { \chemmacros_atom:n { H3O } \pch \chemmacros_xspace: }
+\bool_if:NTF \l_chemmacros_use_mhchem_bool
+ {
+ \cs_new_nopar:Npn \Hpl { \chemmacros_atom:n { H } \pch \chemmacros_xspace: }
+ \cs_new_nopar:Npn \Hyd { \chemmacros_atom:n { OH } \mch \chemmacros_xspace: }
+ \cs_new_nopar:Npn \HtO { \chemmacros_chemformula:n { H3O } \pch \chemmacros_xspace: }
+ \cs_new_nopar:Npn \El { \chemmacros_atom:n { E } \pch \chemmacros_xspace: }
+ }
+ {
+ \cs_new_nopar:Npn \Hpl { \chemmacros_chemformula:n { H+ } \chemmacros_xspace: }
+ \cs_new_nopar:Npn \Hyd { \chemmacros_chemformula:n { OH- } \chemmacros_xspace: }
+ \cs_new_nopar:Npn \HtO { \chemmacros_chemformula:n { H3O+ } \chemmacros_xspace: }
+ \cs_new_nopar:Npn \El { \chemmacros_chemformula:n { E+ } \chemmacros_xspace: }
+ }
\cs_new_nopar:Npn \water
- { \chemmacros_atom:n { H2O } \chemmacros_xspace: }
+ { \chemmacros_chemformula:n { H2O } \chemmacros_xspace: }
+% TODO: \Nu konflikt mit `mathspec'
\NewDocumentCommand \Nu { o }
{
\IfNoValueF { #1 } { \keys_set:nn { chemmacros / particle } { #1 } }
\bool_if:NTF \l_chemmacros_particle_elpair_bool
- { \chemmacros_elpair:n { Nu } }
- { \chemmacros_atom:n { Nu } }
- \mch \chemmacros_xspace:
+ { \chemmacros_elpair:n { Nu } \mch }
+ {
+ \bool_if:NTF \l_chemmacros_use_mhchem_bool
+ { \chemmacros_atom:n { Nu } \mch }
+ { \chemmacros_chemformula:n { Nu- } }
+ }
+ \chemmacros_xspace:
}
-\cs_new_nopar:Npn \El
- { \chemmacros_atom:n { E } \pch \chemmacros_xspace: }
-
\NewDocumentCommand \ba { o }
{
\IfNoValueF { #1 } { \keys_set:nn { chemmacros / particle } { #1 } }
\bool_if:NTF \l_chemmacros_particle_elpair_bool
- { \chemmacros_elpair:n { ba } }
- { \chemmacros_atom:n { ba } }
- \mch \chemmacros_xspace:
+ { \chemmacros_elpair:n { ba } \mch }
+ {
+ \bool_if:NTF \l_chemmacros_use_mhchem_bool
+ { \chemmacros_atom:n { ba } \mch }
+ { \chemmacros_chemformula:n { ba- } }
+ }
+ \chemmacros_xspace:
}
\cs_new_nopar:Npn \chemmacros_elpair:n #1
@@ -495,11 +583,11 @@
\bool_if:NTF \l_chemmacros_chemfig_bool
{
\bool_if:NTF \l_chemmacros_elpair_dots_bool
- { \Lewis { 0: , #1 } }
- { \Lewis { 0 , #1 } }
+ { { \chemmacros_inner_font: #1 \Lewis { 0: , { \vphantom { #1 } } } } }
+ { { \chemmacros_inner_font: #1 \Lewis { 0 , \vphantom { #1 } } } }
}
{
- \msg_warning:nnx { chemmacros } { chemfig } { #1 }
+ \chemmacros_msg:nnxx { chemmacros } { chemfig } { #1 } {}
\chemmacros_atom:n { #1 }
}
}
@@ -526,11 +614,13 @@
}
% --------------------------------------------------------------------------- %
-% stereo descriptors and sim.
+% stereo descriptors and other nomenclature commands
% Cahn-Ingold-Prelog
-\cs_new_nopar:Npn \Rcip { \textit { (R) } }
-\cs_new_nopar:Npn \Scip { \textit { (S) } }
-\cs_new_nopar:Npn \cip #1 { \textit { (#1) } }
+\cs_new_protected_nopar:Npn \Rcip { \textit { (R) } }
+\cs_new_protected_nopar:Npn \Scip { \textit { (S) } }
+\cs_new_protected_nopar:Npn \cip #1 { \textit { (#1) } }
+
+% TikZ needs : to be other
\ExplSyntaxOff
\NewDocumentCommand\Sconf { O { S } }%
{%
@@ -550,48 +640,81 @@
}%
}%
\ExplSyntaxOn
+
% E(ntgegen)/Z(usammen)
\AtBeginDocument
{
\bool_if:NTF \l_chemmacros_EZ_cool_bool
{
- \cs_new_nopar:Npn \Ent { \textit { (E) } }
- \cs_new_nopar:Npn \Zus { \textit { (Z) } }
+ \cs_new_protected_nopar:Npn \Ent { \textit { (E) } }
+ \cs_new_protected_nopar:Npn \Zus { \textit { (Z) } }
}
{
\cs_if_free:NTF \E
- { \cs_new_nopar:Npn \E { \textit { (E) } } }
- { \cs_set_nopar:Npn \E { \textit { (E) } } }
- \cs_new_nopar:Npn \Z { \textit { (Z) } }
+ { \cs_new_protected_nopar:Npn \E { \textit { (E) } } }
+ { \cs_set_protected_nopar:Npn \E { \textit { (E) } } }
+ \cs_new_protected_nopar:Npn \Z { \textit { (Z) } }
}
}
+% cis/trans & tert
\AtBeginDocument
{
\cs_if_free:NTF \cis
- {
- \cs_new_nopar:Npn \cis { \textit { cis } \chemmacros_xspace: }
- }
- {
- \cs_set_nopar:Npn \cis { \textit { cis } \chemmacros_xspace: }
- }
+ { \cs_new_protected_nopar:Npn \cis { \textit { cis } } }
+ { \cs_set_protected_nopar:Npn \cis { \textit { cis } } }
\cs_if_free:NTF \trans
- {
- \cs_new_nopar:Npn \trans { \textit { trans } \chemmacros_xspace: }
- }
- {
- \cs_set_nopar:Npn \trans { \textit { trans } \chemmacros_xspace: }
- }
+ { \cs_new_protected_nopar:Npn \trans { \textit { trans } } }
+ { \cs_set_protected_nopar:Npn \trans { \textit { trans } } }
}
+\cs_new_protected_nopar:Npn \tert { \textit { tert } }
-\cs_new_nopar:Npn \tert { \textit { tert } \chemmacros_xspace: }
% Fischer
-\cs_new_nopar:Npn \Dfi { \textsc { d } }
-\cs_new_nopar:Npn \Lfi { \textsc { l } }
+\cs_new_protected_nopar:Npn \Dfi { \textsc { d } }
+\cs_new_protected_nopar:Npn \Lfi { \textsc { l } }
+
% ortho/meta/para
-\cs_new_nopar:Npn \ortho { \textsl { o } }
-\cs_new_nopar:Npn \meta { \textsl { m } }
-\cs_new_nopar:Npn \para { \textsl { p } }
+\cs_new_protected_nopar:Npn \ortho { \textsl { o } }
+\cs_new_protected_nopar:Npn \meta { \textsl { m } }
+\cs_new_protected_nopar:Npn \para { \textsl { p } }
+
+% syn/anti
+\cs_new_protected_nopar:Npn \syn { \textit { syn } }
+\cs_new_protected_nopar:Npn \anti { \textit { anti } }
+
+% \iupac (basically the same as bpchem's \IUPAC)
+% - allows multiple breaking points as compound names can get really long and
+% especially in multicolumn documents can span more than two lines
+% - add a (very) little space after the hyphen
+\cs_new_protected:Nn \chemmacros_allow_hyphens:
+ { \tex_penalty:D \c_ten_thousand \skip_horizontal:n { \c_zero_dim } }
+\cs_new_protected:Nn \chemmacros_break_point_hyphen:
+ { \tex_penalty:D \c_ten_thousand - \chemmacros_allow_hyphens: }
+\cs_new_protected:Nn \chemmacros_break_point:
+ {
+ \tex_penalty:D \c_ten_thousand
+ \tex_discretionary:D { - } { } { \tex_kern:D .03em }
+ \chemmacros_allow_hyphens:
+ }
+
+\cs_new_protected:Nn \chemmacros_iupac:n
+ {
+ \group_begin:
+ \tex_ignorespaces:D
+ \cs_set_eq:NN \- \chemmacros_break_point_hyphen:
+ \cs_set_eq:NN \| \chemmacros_break_point:
+ \cs_set_eq:NN \^ \chemformula_supscript:n
+ #1
+ \group_end:
+ }
+
+% Thanks to Joseph Wright and Enrico Gregorio for the help on the curious
+% redefinition of \- and the end of the compilation
+\cs_set_protected_nopar:Npx \| { \exp_not:o { \| } }
+\cs_set_protected_nopar:Npx \- { \exp_not:o { \- } }
+\cs_set_eq:NN \@dischyph \-
+
+\cs_set_eq:NN \iupac \chemmacros_iupac:n
% latin phrases
\AtBeginDocument
@@ -610,26 +733,98 @@
% --------------------------------------------------------------------------- %
% acid/base
\cs_new_nopar:Npn \pH
- { \mbox { \textsl { p } H } \chemmacros_xspace: }
+ { \mbox { \chemmacros_detect_bold:n { \textsl { p } H } } \chemmacros_xspace: }
\cs_new_nopar:Npn \pOH
- { \mbox { \textsl { p } OH } \chemmacros_xspace: }
+ { \mbox { \chemmacros_detect_bold:n { \textsl { p } OH } } \chemmacros_xspace: }
\NewDocumentCommand \p { m }
- { \mbox { \textsl { p } \ensuremath { #1 } } \chemmacros_xspace: }
+ {
+ \mbox
+ {
+ \chemmacros_detect_bold:n { \textsl { p } }
+ \ensuremath
+ { \chemmacros_detect_bold:n { #1 } }
+ }
+ \chemmacros_xspace:
+ }
+
+\cs_new_nopar:Npn \chemmacros_if_bold:TF #1#2
+ {
+ \ifx\f@series\l_chemmacros_if_bf_tl
+ \expandafter\@firstoftwo
+ \else
+ \expandafter\@secondoftwo
+ \fi
+ { #1 }{ #2 }
+ }
+\tl_new:N \l_chemmacros_if_bf_tl
+\tl_set:Nn \l_chemmacros_if_bf_tl { bx }
\char_set_catcode_math_subscript:N \@
+\cs_new_nopar:Npn \Ka
+ {
+ \mbox
+ {\(
+ \chemmacros_if_bold:TF
+ {
+ \chemmacros_bm:n
+ {
+ K @ \mathrm
+ {
+ \bool_if:NTF \l_chemmacros_german_bool
+ { S }
+ { A }
+ }
+ }
+ }
+ {
+ K @ \mathrm
+ {
+ \bool_if:NTF \l_chemmacros_german_bool
+ { S }
+ { A }
+ }
+ }
+ \)}
+ \chemmacros_xspace:
+ }
+
+\cs_new_nopar:Npn \Kb
+ {
+ \mbox
+ {\(
+ \chemmacros_if_bold:TF
+ {
+ \chemmacros_bm:n { K @ \mathrm { B } }
+ }
+ {
+ K @ \mathrm { B }
+ }
+ \)}
+ \chemmacros_xspace:
+ }
+
+\cs_new_nopar:Npn \Kw
+ {
+ \mbox
+ {\(
+ \chemmacros_if_bold:TF
+ {
+ \chemmacros_bm:n { K @ \mathrm { W } }
+ }
+ {
+ K @ \mathrm { W }
+ }
+ \)}
+ \chemmacros_xspace:
+ }
+
\NewDocumentCommand \pKa { o }
{
\mbox
{
- \textsl { p }
+ \chemmacros_detect_bold:n { \textsl { p } }
\(
- K @ \mathrm
- {
- \bool_if:NTF \l_chemmacros_german_bool
- { S }
- { A }
- \IfNoValueF{ #1 } { #1 }
- }
+ \Ka \IfNoValueF { #1 } { @ #1 }
\)
}
\chemmacros_xspace:
@@ -639,13 +834,9 @@
{
\mbox
{
- \textsl { p }
+ \chemmacros_detect_bold:n { \textsl { p } }
\(
- K @ \mathrm
- {
- B
- \IfNoValueF{ #1 } { #1 }
- }
+ \Kb \IfNoValueF { #1 } { @ #1 }
\)
}
\chemmacros_xspace:
@@ -804,12 +995,12 @@
\DeclareInstance { xfrac } { chemmacros-ox-frac } { text }
{
- scale-factor = 1.5 ,
+ scale-factor = 1.2 ,
denominator-bot-sep = -.5ex ,
numerator-top-sep = -.3ex ,
- slash-left-kern = -.05em ,
- slash-right-kern = -.05em ,
- slash-symbol-font = ptm
+ slash-left-kern = -.2em ,
+ slash-right-kern = -.2em ,
+ slash-symbol-font = lmr
}
\cs_new_nopar:Npn \chemmacros_ox_fraction:n #1/#2
@@ -913,18 +1104,28 @@
{
\bool_if:NT \l_chemmacros_ox_super_bool
{
- \chemmacros_atom:n
- { #2 ^ { \text { \tiny \chemmacros_ox_process_number:n { #1 } } } }
+ \chemmacros_text:n
+ {
+ #2
+ $ ^ { \text { \tiny \chemmacros_ox_process_number:n { #1 } } } $
+ }
}
\bool_if:NT \l_chemmacros_ox_side_bool
{
- \chemmacros_atom:n { #2 ( \text { \chemmacros_ox_process_number:n { #1 } } ) }
+ \chemmacros_text:n
+ { #2 ( \text { \chemmacros_ox_process_number:n { #1 } } ) }
}
\bool_if:NT \l_chemmacros_ox_top_bool
{
\overset
- { \mbox { \tiny \chemmacros_ox_process_number:n { #1 } } }
- { \chemmacros_atom:n { #2 } }
+ {
+ \rlap
+ {
+ \chemmacros_text:n
+ { \tiny \chemmacros_ox_process_number:n { #1 } }
+ }
+ }
+ { \chemmacros_text:n { #2 } }
}
}
}
@@ -1020,7 +1221,7 @@
}
\tikz[baseline=(#1.base),remember~picture]
{
- \node [inner~sep=0] (#1) { \chemmacros_atom:n {#2} } ;
+ \node [inner~sep=0] (#1) { #2 } ;
}
}
@@ -1034,7 +1235,8 @@
{
\IfNoValueT { #1 }
{
- \msg_error:nnx { chemmacros } { redox } { You~need~to~specify~coordinates }
+ \msg_error:nnx { chemmacros } { redox }
+ { You~need~to~specify~coordinates }
}
\tl_clear:N \l_chemmacros_redox_begin_tl
\tl_clear:N \l_chemmacros_redox_end_tl
@@ -1047,19 +1249,24 @@
\fp_set:Nn \l_chemmacros_redox_shift_fp { 1 }
\tl_set:Nn \l_chemmacros_redox_anchor_tl { above }
\tl_set:Nn \l_chemmacros_redox_side_tl { north }
- \dim_set_eq:NN \l_chemmacros_redox_sep_dim \l_chemmacros_redox_sep_default_dim
+ \dim_set_eq:NN
+ \l_chemmacros_redox_sep_dim
+ \l_chemmacros_redox_sep_default_dim
}
{
\fp_compare:nNnTF { #3 } < { 0 }
{
\tl_set:Nn \l_chemmacros_redox_anchor_tl { below }
\tl_set:Nn \l_chemmacros_redox_side_tl { south }
- \exp_args:NNo \dim_set:Nn \l_chemmacros_redox_sep_dim { - \l_chemmacros_redox_sep_default_dim }
+ \exp_args:NNo \dim_set:Nn \l_chemmacros_redox_sep_dim
+ { - \l_chemmacros_redox_sep_default_dim }
}
{
\tl_set:Nn \l_chemmacros_redox_anchor_tl { above }
\tl_set:Nn \l_chemmacros_redox_side_tl { north }
- \dim_set_eq:NN \l_chemmacros_redox_sep_dim \l_chemmacros_redox_sep_default_dim
+ \dim_set_eq:NN
+ \l_chemmacros_redox_sep_dim
+ \l_chemmacros_redox_sep_default_dim
}
\fp_set:Nn \l_chemmacros_redox_shift_fp { #3 }
}
@@ -1071,7 +1278,7 @@
($(\l_chemmacros_redox_begin_tl . \l_chemmacros_redox_side_tl)+(0,\l_chemmacros_redox_sep_dim)$)
--
++(0,\l_chemmacros_redox_shift_tl * \l_chemmacros_redox_dist_dim) -|
- node [pos=.25,\l_chemmacros_redox_anchor_tl] { #4 }
+ node [pos=.25,\l_chemmacros_redox_anchor_tl] { { #4 } }
($(\l_chemmacros_redox_end_tl . \l_chemmacros_redox_side_tl)+(0,\l_chemmacros_redox_sep_dim)$) ;
}
}
@@ -1217,7 +1424,7 @@
\bool_if:NT \l_chemmacros_nmr_comma_bool
{ , ~ }
\bool_if:NT \l_chemmacros_nmr_solvent_bool
- { \chemmacros_atom:n { #4 } }
+ { \chemmacros_chemformula:n { #4 } }
\bool_if:NT \l_chemmacros_nmr_delimiters_bool
{ ) }
\IfBooleanF { #1 }
@@ -1242,14 +1449,14 @@
\tl_new:N \l_chemmacros_mhname_align_tl
\tl_set:Nn \l_chemmacros_mhname_align_tl { \centering }
-\tl_new:N \l_chemmacros_mhname_fontattr_tl
+\tl_new:N \l_chemmacros_mhname_format_tl
\tl_new:N \l_chemmacros_mhname_fontsize_tl
\tl_set:Nn \l_chemmacros_mhname_fontsize_tl { \tiny }
\keys_define:nn { chemmacros / mhName }
{
align .tl_set:N = \l_chemmacros_mhname_align_tl ,
- fontattr .tl_set:N = \l_chemmacros_mhname_fontattr_tl ,
+ format .tl_set:N = \l_chemmacros_mhname_format_tl ,
fontsize .tl_set:N = \l_chemmacros_mhname_fontsize_tl ,
width .code:n =
{
@@ -1262,8 +1469,8 @@
}
}
-% \mhName[<keyval>]{<formula>}{<text>}
-\bool_if:NF \l_chemmacros_version_one_bool
+% \mhName[<keyval>]{<chemformula>}{<text>}
+\bool_if:nF { \l_chemmacros_version_one_bool || \l_chemmacros_use_mhchem_bool }
{
\NewDocumentCommand \mhName { o m m }
{
@@ -1279,12 +1486,12 @@
{ \dim_use:N \l_chemmacros_mhname_width_dim }
{
\tl_use:N \l_chemmacros_mhname_align_tl
- \tl_use:N \l_chemmacros_mhname_fontattr_tl
+ \tl_use:N \l_chemmacros_mhname_format_tl
\tl_use:N \l_chemmacros_mhname_fontsize_tl
#3
}
}
- { \chemmacros_atom:n { #2 } }
+ { \ce { #2 } }
}
\group_end:
}
@@ -1296,14 +1503,14 @@
\cs_new_nopar:Npn \sld
{
\peek_meaning:NTF [
- { \chemmacros_sld_aux_i: }
- { \chemmacros_sld_aux_ii: }
+ { \chemmacros_sld_aux_i:w }
+ { \chemmacros_sld_aux_ii:w }
}
-\cs_new_nopar:Npn \chemmacros_sld_aux_i: [#1]
+\cs_new_nopar:Npn \chemmacros_sld_aux_i:w [#1]
{ \ensuremath { @ \mathrm { ( #1 ) } } }
-\cs_new_nopar:Npn \chemmacros_sld_aux_ii:
+\cs_new_nopar:Npn \chemmacros_sld_aux_ii:w
{
\ensuremath { @ \mathrm {
(
@@ -1349,23 +1556,75 @@
\char_set_catcode_letter:N \@
% --------------------------------------------------------------------------- %
+% reaction environments for mhchem
+
+% redefine mathtools' command \MT_define_tagform:nwnn to ensure we add an
+% entry to the list of reactions even if the user redefines the reaction tag
+\AfterPackage* { mathtools }
+ {
+ \cs_set_nopar:Npn \MT_define_tagform:nwnn #1[#2]#3#4
+ {
+ \@namedef{MT_tagform_#1:n}##1
+ {
+ % this is the original part:
+ \maketag@@@{#3\ignorespaces#2{##1}\unskip\@@italiccorr#4}
+ % this is added:
+ \tl_if_eq:nnT { #1 } { reaction }
+ {
+ \addcontentsline { lor } { reaction }
+ {
+ \l_chemmacros_reaction_lorname_tl #3 ##1 #4
+ \tl_use:c { l_chemmacros_reaction_ \thereaction _tl }
+ }
+ }
+ }
+ }
+ }
+
+% define \listofreactions
+\tl_new:N \l_chemmacros_reaction_lorname_tl
+\tl_new:N \reactionlistname
+\tl_set:Nn \l_chemmacros_reaction_lorname_tl
+ { \bool_if:NTF \l_chemmacros_german_bool { Reaktion ~ } { Reaction ~ } }
+
+\bool_if:NTF \l_chemmacros_german_bool
+ { \tl_set:Nn \reactionlistname { Reaktionsverzeichnis } }
+ { \tl_set:Nn \reactionlistname { List~of~reactions } }
+
+\cs_new:Npn \listofreactions
+ { \section* { \reactionlistname } \@starttoc { lor } }
+
+\cs_new:Npn \l@reaction #1#2
+ { \@dottedtocline { 1 } { 1.5em } { 2.3em } { #1 } { #2 } }
+
+% create tagform
\bool_if:NTF \l_chemmacros_version_one_bool
{ \newtagform { CMreaction } { \{ } { \} } }
{ \newtagform { reaction } { \{ } { \} } }
\newcounter { chemmacros_save_reaction }
\newcounter { reaction }
+
+% switch to reaction tags
\cs_new_nopar:Npn \chemmacros_begin_reaction:
{
- \bool_if:NT \l_chemmacros_hyperref_bool % create individual names for hyperref
- { \cs_set_nopar:Npn \theHequation { R . \theHsection . \arabic { reaction } } }
- \bool_if:NT \l_chemmacros_varioref_bool % enable labelformat reaction
+ % create individual names for `hyperref':
+ \bool_if:NT \l_chemmacros_hyperref_bool
+ {
+ \cs_set_nopar:Npn \theHequation
+ { R . \theHsection . \arabic { reaction } }
+ }
+ % enable labelformat `reaction':
+ \bool_if:NT \l_chemmacros_varioref_bool
{ \cs_set_eq:NN \p@equation \p@reaction }
\setcounter { chemmacros_save_reaction } { \value { equation } }
\setcounter { equation } { \value { reaction } }
\bool_if:NTF \l_chemmacros_version_one_bool
{ \usetagform { CMreaction } }
{ \usetagform { reaction } }
+ \tl_new:c { l_chemmacros_reaction_ \thereaction _tl }
}
+
+% switch back to equation tags
\cs_new_nopar:Npn \chemmacros_end_reaction:
{
\setcounter { reaction } { \value { equation } }
@@ -1373,28 +1632,28 @@
}
% --------------------------------------------------------------------------- %
-% reaction environments for mhchem
\bool_new:N \l_chemmacros_reactions_star_bool
\bool_new:N \l_chemmacros_reactions_args_bool
-\int_new:N \l_chemmacros_reactions_args_int
\keys_define:nn { chemmacros / reaction }
{
- star .bool_set:N = \l_chemmacros_reactions_star_bool ,
- star .default:n = true ,
- arg .bool_set:N = \l_chemmacros_reactions_args_bool ,
- arg .default:n = true
+ star .bool_set:N = \l_chemmacros_reactions_star_bool ,
+ star .default:n = true ,
+ arg .bool_set:N = \l_chemmacros_reactions_args_bool ,
+ arg .default:n = true ,
+ list-name .tl_set:N = \reactionlistname ,
+ list-entry .code:n =
+ \tl_set:Nn \l_chemmacros_reaction_lorname_tl { #1 ~ }
}
+% TODO: define new reactions with optional Argument for lor-entry
% \newreaction[<keyval>]{<name>}{<type>}
\bool_if:NF \l_chemmacros_version_one_bool
{
\NewDocumentCommand \newreaction { o m m }
{
\cs_if_exist:cTF { #2 }
- {
- \msg_error:nnx { chemmacros } { already-defined } { #2 }
- }
+ { \msg_error:nnx { chemmacros } { already-defined } { #2 } }
{
\IfNoValueTF { #1 }
{
@@ -1404,11 +1663,17 @@
{ \keys_set:nn { chemmacros / reaction } { #1 } }
\bool_if:NTF \l_chemmacros_reactions_args_bool
{
- \NewEnviron { #2 } [ 1 ]
+ \NewEnviron { #2 } [ 2 ] []
{
\chemmacros_begin_reaction:
- \begin { #3 } { ##1 }
- \chemmacros_cee:f { \BODY }
+ \tl_if_blank:nF { ##1 }
+ {
+ \tl_set:cn
+ { l_chemmacros_reaction_ \thereaction _tl }
+ { : ~ ##1 }
+ }
+ \begin { #3 } { ##2 }
+ \chemmacros_equation_chemformula:o { \BODY }
\end{ #3 }
\chemmacros_end_reaction:
}
@@ -1417,17 +1682,23 @@
\NewEnviron { #2* } [ 1 ]
{
\begin { #3* } { ##1 }
- \chemmacros_cee:f { \BODY }
+ \chemmacros_equation_chemformula:o { \BODY }
\end { #3* }
}
}
}
{
- \NewEnviron { #2 }
+ \NewEnviron { #2 } [ 1 ] []
{
\chemmacros_begin_reaction:
+ \tl_if_blank:nF { ##1 }
+ {
+ \tl_set:cn
+ { l_chemmacros_reaction_ \thereaction _tl }
+ { : ~ ##1 }
+ }
\begin { #3 }
- \chemmacros_cee:f { \BODY }
+ \chemmacros_equation_chemformula:o { \BODY }
\end { #3 }
\chemmacros_end_reaction:
}
@@ -1436,18 +1707,23 @@
\NewEnviron { #2* }
{
\begin { #3* }
- \chemmacros_cee:f { \BODY }
+ \chemmacros_equation_chemformula:o { \BODY }
\end { #3* }
}
}
}
}
+ \ignorespaces
}
}
-\cs_new:Npn \chemmacros_cee:n #1
- { \cee { #1 } }
-\cs_generate_variant:Nn \chemmacros_cee:n { f }
+\cs_new:Npn \chemmacros_equation_chemformula:n #1
+ {
+ \bool_if:NTF \l_chemmacros_use_mhchem_bool
+ { \cee { #1 } }
+ { \ch { #1 } }
+ }
+\cs_generate_variant:Nn \chemmacros_equation_chemformula:n { o }
% predefined:
\bool_if:NF \l_chemmacros_version_one_bool
@@ -1456,9 +1732,6 @@
\newreaction [ star ] { reactions } { align }
}
-\NewDocumentCommand \chcancel { m }
- { \cancel { \chemmacros_atom:f { #1 } } }
-
% --------------------------------------------------------------------------- %
% thermodynamics et.al.
% \standardstate as defined by the chemstyle package. Thanks to Joseph Wright
@@ -1754,14 +2027,16 @@
}
}
\group_end:
+ \ignorespaces
}
% predefined:
\bool_if:NF \l_chemmacros_version_one_bool
{
- \setnewstate {Enthalpy} {H} {\kilo\joule\per\mole}
- \setnewstate[delta=false,subscript-left=false] {Entropy} {S} {\joule\per\kelvin\per\mole}
- \setnewstate {Gibbs} {G} {\kilo\joule\per\mole}
+ \setnewstate {Enthalpy} {H} {\kilo\joule\per\mole}
+ \setnewstate [ delta=false, subscript-left=false ] {Entropy}
+ {S} {\joule\per\kelvin\per\mole}
+ \setnewstate {Gibbs} {G} {\kilo\joule\per\mole}
}
% --------------------------------------------------------------------------- %
@@ -1804,9 +2079,6 @@
angle .default:n = 0
}
-% old usage (v1.1):
-% \newman[<angle>,<scale>,<tikz ring>][<tikz (front) nodes>][<tikz back nodes>]{<1>,<2>,<3>,<4>,<5>,<6>}
-% new usage (v1.2):
% \newman[<keyval>](<angle>){<1>,<2>,<3>,<4>,<5>,<6>}
\bool_if:NF \l_chemmacros_version_one_bool
{
@@ -1815,7 +2087,11 @@
\group_begin:
\IfNoValueF { #1 } { \keys_set:nn { chemmacros / newman } { #1 } }
\IfNoValueTF { #2 }
- { \fp_set_eq:NN \l_chemmacros_newman_rel_angle_fp \l_chemmacros_newman_abs_angle_fp }
+ {
+ \fp_set_eq:NN
+ \l_chemmacros_newman_rel_angle_fp
+ \l_chemmacros_newman_abs_angle_fp
+ }
{ \fp_set:Nn \l_chemmacros_newman_rel_angle_fp { #2 } }
\chemmacros_newman_atoms:nnnnnn #3
\group_end:
@@ -1877,8 +2153,10 @@
\fp_mul:Nn \l_chemmacros_newman_tmp_angle_fp { \fp_use:N \c_pi_fp }
\fp_zero:N \l_chemmacros_newman_x_fp
\fp_zero:N \l_chemmacros_newman_y_fp
- \fp_cos:Nn \l_chemmacros_newman_x_fp { \fp_use:N \l_chemmacros_newman_tmp_angle_fp }
- \fp_sin:Nn \l_chemmacros_newman_y_fp { \fp_use:N \l_chemmacros_newman_tmp_angle_fp }
+ \fp_cos:Nn \l_chemmacros_newman_x_fp
+ { \fp_use:N \l_chemmacros_newman_tmp_angle_fp }
+ \fp_sin:Nn \l_chemmacros_newman_y_fp
+ { \fp_use:N \l_chemmacros_newman_tmp_angle_fp }
\fp_mul:Nn \l_chemmacros_newman_x_fp { \fp_use:N #2 }
\fp_mul:Nn \l_chemmacros_newman_y_fp { \fp_use:N #2 }
}
@@ -1894,9 +2172,15 @@
{ \l_chemmacros_newman_scale_fp }
\chemmacros_tikz_draw:f
{ \tl_use:N \l_chemmacros_newman_tikz_ring_tl }
- ( 15 * \fp_to_dim:N \l_chemmacros_newman_x_fp , 15 * \fp_to_dim:N \l_chemmacros_newman_y_fp )
+ (
+ 15 * \fp_to_dim:N \l_chemmacros_newman_x_fp ,
+ 15 * \fp_to_dim:N \l_chemmacros_newman_y_fp
+ )
--
- ( 30 * \fp_to_dim:N \l_chemmacros_newman_x_fp , 30 * \fp_to_dim:N \l_chemmacros_newman_y_fp ) ;
+ (
+ 30 * \fp_to_dim:N \l_chemmacros_newman_x_fp ,
+ 30 * \fp_to_dim:N \l_chemmacros_newman_y_fp
+ ) ;
\chemmacros_newman_coordinates:on
{ \fp_to_int:N \l_chemmacros_newman_rel_angle_fp }
{ \l_chemmacros_newman_scale_fp }
@@ -1905,7 +2189,11 @@
chemmacros_newman_atom_back,
anchor = -180 + \fp_to_int:N \l_chemmacros_newman_rel_angle_fp
}
- at ( 31 * \fp_to_dim:N \l_chemmacros_newman_x_fp , 31 * \fp_to_dim:N \l_chemmacros_newman_y_fp )
+ at
+ (
+ 31 * \fp_to_dim:N \l_chemmacros_newman_x_fp ,
+ 31 * \fp_to_dim:N \l_chemmacros_newman_y_fp
+ )
{ #2 } ;
\group_end:
}
@@ -1917,11 +2205,19 @@
\chemmacros_newman_coordinates:nn { #1 } { \l_chemmacros_newman_scale_fp }
\chemmacros_tikz_draw:f
{ \tl_use:N \l_chemmacros_newman_tikz_ring_tl }
- (0,0) -- ++ ( 30 * \fp_to_dim:N \l_chemmacros_newman_x_fp , 30 * \fp_to_dim:N \l_chemmacros_newman_y_fp ) ;
+ (0,0) -- ++
+ (
+ 30 * \fp_to_dim:N \l_chemmacros_newman_x_fp ,
+ 30 * \fp_to_dim:N \l_chemmacros_newman_y_fp
+ ) ;
\chemmacros_newman_coordinates:nn { #1 } { \l_chemmacros_newman_scale_fp }
\chemmacros_tikz_node:f
{ chemmacros_newman_atom_front, anchor = -180 + #1 }
- at ( 31 * \fp_to_dim:N \l_chemmacros_newman_x_fp , 31 * \fp_to_dim:N \l_chemmacros_newman_y_fp )
+ at
+ (
+ 31 * \fp_to_dim:N \l_chemmacros_newman_x_fp ,
+ 31 * \fp_to_dim:N \l_chemmacros_newman_y_fp
+ )
{ #2 } ;
}
\cs_generate_variant:Nn \chemmacros_newman_front_node:nn { nf }
@@ -2066,7 +2362,8 @@
}
\chemmacros_tikz_picture:xn{ \chemmacros_orbital_options: }
{
- \chemmacros_tikz_shade:f { ball~color = \l_chemmacros_orbital_s_phase_color_tl }
+ \chemmacros_tikz_shade:f
+ { ball~color = \l_chemmacros_orbital_s_phase_color_tl }
(0,0) circle (\l_chemmacros_orbital_s_scale_tl * .6em) ;
}
}
@@ -2127,17 +2424,39 @@
}
\chemmacros_tikz_picture:xn { \chemmacros_orbital_options: }
{
- \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_p_pphase_color_tl , ball~color = \l_chemmacros_orbital_p_pphase_color_tl }
- (0,0) .. controls
- ++(- \l_chemmacros_orbital_p_scale_tl * 2em,\l_chemmacros_orbital_p_scale_tl * 2em) and
- ++(\l_chemmacros_orbital_p_scale_tl * 2em,\l_chemmacros_orbital_p_scale_tl * 2em)
+ \chemmacros_tikz_shadedraw:f
+ {
+ draw = \l_chemmacros_orbital_p_pphase_color_tl ,
+ ball~color = \l_chemmacros_orbital_p_pphase_color_tl
+ }
+ (0,0) .. controls ++
+ (
+ - \l_chemmacros_orbital_p_scale_tl * 2em ,
+ \l_chemmacros_orbital_p_scale_tl * 2em
+ )
+ and ++
+ (
+ \l_chemmacros_orbital_p_scale_tl * 2em ,
+ \l_chemmacros_orbital_p_scale_tl * 2em
+ )
.. (0,0);
\bool_if:NF \l_chemmacros_orbital_p_half_bool
{
- \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_p_mphase_color_tl , ball~color = \l_chemmacros_orbital_p_mphase_color_tl }
- (0,0) .. controls
- ++(- \l_chemmacros_orbital_p_scale_tl * 2em,- \l_chemmacros_orbital_p_scale_tl * 2em) and
- ++(\l_chemmacros_orbital_p_scale_tl * 2em,- \l_chemmacros_orbital_p_scale_tl * 2em)
+ \chemmacros_tikz_shadedraw:f
+ {
+ draw = \l_chemmacros_orbital_p_mphase_color_tl ,
+ ball~color = \l_chemmacros_orbital_p_mphase_color_tl
+ }
+ (0,0) .. controls ++
+ (
+ - \l_chemmacros_orbital_p_scale_tl * 2em ,
+ - \l_chemmacros_orbital_p_scale_tl * 2em
+ )
+ and ++
+ (
+ \l_chemmacros_orbital_p_scale_tl * 2em ,
+ - \l_chemmacros_orbital_p_scale_tl * 2em
+ )
.. (0,0);
}
}
@@ -2197,15 +2516,37 @@
}
\chemmacros_tikz_picture:xn { \chemmacros_orbital_options: }
{
- \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_sp_pphase_color_tl , ball~color = \l_chemmacros_orbital_sp_pphase_color_tl }
- (0,0) .. controls
- ++(- \l_chemmacros_orbital_sp_scale_tl * 2em,\l_chemmacros_orbital_sp_scale_tl * 2em) and
- ++(\l_chemmacros_orbital_sp_scale_tl * 2em,\l_chemmacros_orbital_sp_scale_tl * 2em)
+ \chemmacros_tikz_shadedraw:f
+ {
+ draw = \l_chemmacros_orbital_sp_pphase_color_tl ,
+ ball~color = \l_chemmacros_orbital_sp_pphase_color_tl
+ }
+ (0,0) .. controls ++
+ (
+ - \l_chemmacros_orbital_sp_scale_tl * 2em ,
+ \l_chemmacros_orbital_sp_scale_tl * 2em
+ )
+ and ++
+ (
+ \l_chemmacros_orbital_sp_scale_tl * 2em ,
+ \l_chemmacros_orbital_sp_scale_tl * 2em
+ )
.. (0,0);
- \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_sp_mphase_color_tl , ball~color = \l_chemmacros_orbital_sp_mphase_color_tl }
- (0,0) .. controls
- ++(- \l_chemmacros_orbital_sp_scale_tl * .6em,- \l_chemmacros_orbital_sp_scale_tl * .6em) and
- ++(\l_chemmacros_orbital_sp_scale_tl * .6em,- \l_chemmacros_orbital_sp_scale_tl * .6em)
+ \chemmacros_tikz_shadedraw:f
+ {
+ draw = \l_chemmacros_orbital_sp_mphase_color_tl ,
+ ball~color = \l_chemmacros_orbital_sp_mphase_color_tl
+ }
+ (0,0) .. controls ++
+ (
+ - \l_chemmacros_orbital_sp_scale_tl * .6em ,
+ - \l_chemmacros_orbital_sp_scale_tl * .6em
+ )
+ and ++
+ (
+ \l_chemmacros_orbital_sp_scale_tl * .6em ,
+ - \l_chemmacros_orbital_sp_scale_tl * .6em
+ )
.. (0,0);
}
}
@@ -2264,15 +2605,37 @@
}
\chemmacros_tikz_picture:xn { \chemmacros_orbital_options: }
{
- \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_sptwo_pphase_color_tl , ball~color = \l_chemmacros_orbital_sptwo_pphase_color_tl }
- (0,0) .. controls
- ++(- \l_chemmacros_orbital_sptwo_scale_tl * 2em,\l_chemmacros_orbital_sptwo_scale_tl * 2em) and
- ++(\l_chemmacros_orbital_sptwo_scale_tl * 2em,\l_chemmacros_orbital_sptwo_scale_tl * 2em)
+ \chemmacros_tikz_shadedraw:f
+ {
+ draw = \l_chemmacros_orbital_sptwo_pphase_color_tl ,
+ ball~color = \l_chemmacros_orbital_sptwo_pphase_color_tl
+ }
+ (0,0) .. controls ++
+ (
+ - \l_chemmacros_orbital_sptwo_scale_tl * 2em ,
+ \l_chemmacros_orbital_sptwo_scale_tl * 2em
+ )
+ and ++
+ (
+ \l_chemmacros_orbital_sptwo_scale_tl * 2em ,
+ \l_chemmacros_orbital_sptwo_scale_tl * 2em
+ )
.. (0,0);
- \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_sptwo_mphase_color_tl , ball~color = \l_chemmacros_orbital_sptwo_mphase_color_tl }
- (0,0) .. controls
- ++(- \l_chemmacros_orbital_sptwo_scale_tl * .8em,- \l_chemmacros_orbital_sptwo_scale_tl * .8em) and
- ++(\l_chemmacros_orbital_sptwo_scale_tl * .8em,- \l_chemmacros_orbital_sptwo_scale_tl * .8em)
+ \chemmacros_tikz_shadedraw:f
+ {
+ draw = \l_chemmacros_orbital_sptwo_mphase_color_tl ,
+ ball~color = \l_chemmacros_orbital_sptwo_mphase_color_tl
+ }
+ (0,0) .. controls ++
+ (
+ - \l_chemmacros_orbital_sptwo_scale_tl * .8em ,
+ - \l_chemmacros_orbital_sptwo_scale_tl * .8em
+ )
+ and ++
+ (
+ \l_chemmacros_orbital_sptwo_scale_tl * .8em ,
+ - \l_chemmacros_orbital_sptwo_scale_tl * .8em
+ )
.. (0,0);
}
}
@@ -2331,15 +2694,37 @@
}
\chemmacros_tikz_picture:xn { \chemmacros_orbital_options: }
{
- \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_spthree_pphase_color_tl , ball~color = \l_chemmacros_orbital_spthree_pphase_color_tl }
- (0,0) .. controls
- ++(- \l_chemmacros_orbital_spthree_scale_tl * 2em,\l_chemmacros_orbital_spthree_scale_tl * 2em) and
- ++(\l_chemmacros_orbital_spthree_scale_tl * 2em,\l_chemmacros_orbital_spthree_scale_tl * 2em)
+ \chemmacros_tikz_shadedraw:f
+ {
+ draw = \l_chemmacros_orbital_spthree_pphase_color_tl ,
+ ball~color = \l_chemmacros_orbital_spthree_pphase_color_tl
+ }
+ (0,0) .. controls ++
+ (
+ - \l_chemmacros_orbital_spthree_scale_tl * 2em ,
+ \l_chemmacros_orbital_spthree_scale_tl * 2em
+ )
+ and ++
+ (
+ \l_chemmacros_orbital_spthree_scale_tl * 2em ,
+ \l_chemmacros_orbital_spthree_scale_tl * 2em
+ )
.. (0,0);
- \chemmacros_tikz_shadedraw:f { draw = \l_chemmacros_orbital_spthree_mphase_color_tl , ball~color = \l_chemmacros_orbital_spthree_mphase_color_tl }
- (0,0) .. controls
- ++(- \l_chemmacros_orbital_spthree_scale_tl * 1em,- \l_chemmacros_orbital_spthree_scale_tl * 1em) and
- ++(\l_chemmacros_orbital_spthree_scale_tl * 1em,- \l_chemmacros_orbital_spthree_scale_tl * 1em)
+ \chemmacros_tikz_shadedraw:f
+ {
+ draw = \l_chemmacros_orbital_spthree_mphase_color_tl ,
+ ball~color = \l_chemmacros_orbital_spthree_mphase_color_tl
+ }
+ (0,0) .. controls ++
+ (
+ - \l_chemmacros_orbital_spthree_scale_tl * 1em ,
+ - \l_chemmacros_orbital_spthree_scale_tl * 1em
+ )
+ and ++
+ (
+ \l_chemmacros_orbital_spthree_scale_tl * 1em ,
+ - \l_chemmacros_orbital_spthree_scale_tl * 1em
+ )
.. (0,0);
}
}
@@ -2386,13 +2771,102 @@
}
% --------------------------------------------------------------------------- %
+% arrow tips for electron movement
+\dim_new:N \l_chemmacros_el_length_dim
+
+% full tip for pairs
+\pgfarrowsdeclare { el } { el }
+{
+ \dim_set:Nn \l_chemmacros_el_length_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfarrowsleftextend { -\l_chemmacros_el_length_dim }
+ \pgfarrowsrightextend { .5\pgflinewidth }
+}
+{
+ \dim_set:Nn \l_chemmacros_el_length_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfsetdash {} { 0pt }
+ \pgfsetroundjoin
+ \pgfsetroundcap
+ \pgfpathmoveto { \pgfpoint { 0pt } { 0pt } }
+ \pgfpathlineto
+ {
+ \pgfpoint
+ { -\l_chemmacros_el_length_dim }
+ { .3\l_chemmacros_el_length_dim }
+ }
+ \pgfpathlineto
+ { \pgfpoint { -.5\l_chemmacros_el_length_dim } { 0pt } }
+ \pgfpathlineto
+ {
+ \pgfpoint
+ { -\l_chemmacros_el_length_dim }
+ { -.3\l_chemmacros_el_length_dim }
+ }
+ \pgfpathlineto { \pgfpoint { 0pt } { 0pt } }
+ \pgfusepathqfillstroke
+}
+
+% half tip on the left
+\pgfarrowsdeclare { left~el } { left~el }
+{
+ \dim_set:Nn \l_chemmacros_el_length_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfarrowsleftextend { -\l_chemmacros_el_length_dim }
+ \pgfarrowsrightextend { .5\pgflinewidth }
+}
+{
+ \dim_set:Nn \l_chemmacros_el_length_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfsetdash {} { 0pt }
+ \pgfsetroundjoin
+ \pgfsetroundcap
+ \pgfpathmoveto { \pgfpoint { 0pt } { 0pt } }
+ \pgfpathlineto
+ {
+ \pgfpoint
+ { -\l_chemmacros_el_length_dim }
+ { .3\l_chemmacros_el_length_dim }
+ }
+ \pgfpathlineto { \pgfpoint { -.5\l_chemmacros_el_length_dim } { 0pt } }
+ \pgfpathlineto { \pgfpoint { 0pt } { 0pt } }
+ \pgfusepathqfillstroke
+}
+
+% half tip in the right
+\pgfarrowsdeclare { right~el } { right~el }
+{
+ \dim_set:Nn \l_chemmacros_el_length_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfarrowsleftextend { -\l_chemmacros_el_length_dim }
+ \pgfarrowsrightextend { .5\pgflinewidth }
+}
+{
+ \dim_set:Nn \l_chemmacros_el_length_dim
+ { 2.5pt + 2.5\pgflinewidth }
+ \pgfsetdash {} { 0pt }
+ \pgfsetroundjoin
+ \pgfsetroundcap
+ \pgfpathmoveto { \pgfpoint { 0pt } { 0pt } }
+ \pgfpathlineto
+ {
+ \pgfpoint
+ { -\l_chemmacros_el_length_dim }
+ { -.3\l_chemmacros_el_length_dim }
+ }
+ \pgfpathlineto { \pgfpoint { -.5\l_chemmacros_el_length_dim } { 0pt } }
+ \pgfpathlineto { \pgfpoint { 0pt } { 0pt } }
+ \pgfusepathqfillstroke
+}
+
+% --------------------------------------------------------------------------- %
% setup
\NewDocumentCommand \chemsetup { o m }
{
\IfNoValueTF { #1 }
{ \keys_set:nn { chemmacros } { #2 } }
{ \keys_set:nn { chemmacros / #1 } { #2 } }
-% \tex_unskip:D
+ \ignorespaces
}
% --------------------------------------------------------------------------- %
@@ -2402,6 +2876,33 @@
\input { chemmacros-version1 . cfg }
}
+% --------------------------------------------------------------------------- %
+% hyperref support
+\AfterPackage* { hyperref }
+ {
+ \pdfstringdefDisableCommands
+ {
+ \cs_set:Npn \- { - }
+ \cs_set:Npn \| { }
+ \cs_set:Npn \iupac #1 { #1 }
+ \cs_set:Npn \ortho { o }
+ \cs_set:Npn \meta { m }
+ \cs_set:Npn \para { p }
+ \cs_set:Npn \Dfi { D }
+ \cs_set:Npn \Lfi { L }
+ \cs_set:Npn \tert { tert }
+ \cs_set:Npn \cis { cis }
+ \cs_set:Npn \trans { trans }
+ \cs_set:Npn \E { E }
+ \cs_set:Npn \Z { Z }
+ \cs_set:Npn \Ent { E }
+ \cs_set:Npn \Zus { Z }
+ \cs_set:Npn \Rcip { (R) }
+ \cs_set:Npn \Scip { (S) }
+ \cs_set:Npn \cip #1 { (#1) }
+ }
+ }
+
\tex_endinput:D
% --------------------------------------------------------------------------- %
@@ -2433,4 +2934,24 @@ Version history
2011/11/03 version 2.0a - minor bug fixes
- new feature for \Nu
- new command \ba
-% --------------------------------------------------------------------------- % \ No newline at end of file
+2012/01/28 version 3.0 - bundled with packages `formula' and `ghs'
+ - new commands \Ka, \Kb, \Kw
+ - commands can detect if font series is bold
+ - new package option "detect-bold"
+ - new package option "method" => choose between `mhchem'
+ and `formula' for internal uses.
+ - new package option "ghs" => load `ghs' or don't
+ - new package option "synchronize"
+ - new package option "strict"
+ - new command \iupac
+ - new command \listofreactions, reaction environments
+ with optional argument
+ - \cis, \trans, \tert without \xspace
+2012/01/30 version 3.0a - bugfix in formula.sty
+ - renamed formula => chemformula
+ and ghs => ghsystem to make the names unique
+ (following a request by Karl Berry)
+% --------------------------------------------------------------------------- %
+% TODO:
+- ox-option xfrac vs math?
+- Option „side“ for Phasen-Befehle? \ No newline at end of file
diff --git a/Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty b/Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty
new file mode 100644
index 00000000000..1f1be06e3cd
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/chemmacros/ghsystem.sty
@@ -0,0 +1,436 @@
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% --------------------------------------------------------------------------- %
+% - the CHEMMACROS bundle - %
+% - ghsystem.sty - %
+% - macros and commands for chemists - %
+% --------------------------------------------------------------------------- %
+% - Clemens Niederberger - %
+% - 2012/01/30 - %
+% --------------------------------------------------------------------------- %
+% - http://www.mychemistry.eu/ - %
+% - contact@mychemistry.eu - %
+% --------------------------------------------------------------------------- %
+% - If you have any ideas, questions, suggestions or bugs to report, please - %
+% - feel free to contact me. - %
+% --------------------------------------------------------------------------- %
+% - Copyright 2011-2012 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. - %
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+\RequirePackage{ expl3 }
+\ProvidesExplPackage {ghsystem} {2012/01/30} {3.0a} {globally harmonised system}
+
+% --------------------------------------------------------------------------- %
+% error and warning messages:
+\msg_set:nnnn { ghsystem } { explicit }
+ { It~seems~you've~loaded~`ghsystem'~explicitly. }
+ {
+ It~seems~you've~loaded~`ghsystem'~explicitly.~This~should~work~but~the~
+ recommended~way~is~to~load~it~via~the~bundle,~i.e.~by~using~
+ \token_to_str:N \usepackage \{ chemmacros \}.
+ }
+
+\msg_set:nnnn { ghsystem } { statements }
+ {
+ You've~tried~to~call~statement~#1#2~ \msg_line_context: \c_space_tl but~it~
+ it~is~not~defined~in~ghsystem.sty .
+ }
+ {
+ You've~tried~to~call~statement~#1#2~ \msg_line_context: \c_space_tl but~it~
+ it~is~not~defined~in~ghsystem.sty . ~ Are~you~sure~it~exists? ~ If~so~please~send
+ ~a~message~to~the~author.~Thanks.
+ }
+
+\msg_set:nnnn { ghsystem } { booktabs }
+ { Package~`booktabs'~missing~\msg_line_context: . }
+ {
+ Option~#1~of~the~\token_to_str:N \ghslistall \c_space_tl command~
+ \msg_line_context: \c_space_tl needs~the~`booktabs'~package . ~Please~make~
+ sure~to~load~it~in~your~preamble.
+ }
+
+% --------------------------------------------------------------------------- %
+% test, if we are loaded without the `chemmacros' package
+\cs_if_exist:cF { ver@chemmacros.sty }
+ { \msg_warning:nn { ghsystem } { explicit } }
+
+% pass options to the `chemmacros' package
+\DeclareOption*
+ { \PassOptionsToPackage { \CurrentOption } { chemmacros } }
+\ProcessOptions\relax
+
+% load required packages:
+\RequirePackage{ chemmacros , graphicx , tabu , longtable , ifpdf }
+
+% --------------------------------------------------------------------------- %
+% define variables:
+\prop_new:N \l_ghsystem_h_prop
+\prop_new:N \l_ghsystem_euh_prop
+\prop_new:N \l_ghsystem_p_prop
+
+\cs_new:Npn \ghsystem_exposure: {}
+\cs_new:Npn \ghsystem_effect: {}
+\cs_new:Npn \ghsystem_organs: {}
+\cs_new:Npn \ghsystem_substance: {}
+\cs_new:Npn \ghsystem_text: {}
+
+\bool_new:N \l_ghsystem_fill_in_bool
+\bool_new:N \l_ghsystem_show_number_bool
+\bool_new:N \l_ghsystem_substance_bool
+\bool_new:N \l_ghsystem_organs_bool
+\bool_new:N \l_ghsystem_hide_statement_bool
+\bool_new:N \l_ghsystem_engine_pdftex_bool
+\bool_new:N \l_ghsystem_engine_xetex_bool
+\bool_new:N \l_ghsystem_engine_luatex_bool
+
+\tl_new:N \l_ghsystem_number_space_tl
+\tl_new:N \l_ghsystem_celsius_temperature_tl
+\tl_new:N \l_ghsystem_fahrenheit_temperature_tl
+\tl_new:N \l_ghsystem_kg_mass_tl
+\tl_new:N \l_ghsystem_lbs_mass_tl
+\tl_new:N \l_ghsystem_dots_tl
+\tl_set:Nn \l_ghsystem_dots_tl { \ldots }
+\tl_new:N \l_ghsystem_picture_scale_default_tl
+\tl_set:Nn \l_ghsystem_picture_scale_default_tl { .05 }
+\tl_new:N \l_ghsystem_picture_scale_tl
+\tl_set_eq:NN \l_ghsystem_picture_scale_tl \l_ghsystem_picture_scale_default_tl
+\tl_new:N \l_ghsystem_picture_includegraphics_tl
+\tl_new:N \l_ghsystem_picture_type_tl
+\tl_new:N \l_ghsystem_identifier_tl
+\tl_new:N \l_ghsystem_table_text_tl
+\tl_new:N \l_ghsystem_table_next_page_tl
+\tl_new:N \l_ghsystem_table_head_rule_tl
+\tl_set:Nn \l_ghsystem_table_head_rule_tl { \hline }
+\tl_new:N \l_ghsystem_table_top_head_rule_tl
+\tl_set:Nn \l_ghsystem_table_top_head_rule_tl { \hline }
+\tl_new:N \l_ghsystem_table_foot_rule_tl
+\tl_set:Nn \l_ghsystem_table_foot_rule_tl { \hline }
+\tl_new:N \l_ghsystem_table_last_foot_rule_tl
+\tl_set:Nn \l_ghsystem_table_last_foot_rule_tl { \hline }
+\tl_new:N \l_ghsystem_table_caption_tl
+\tl_new:N \l_ghsystem_table_caption_short_tl
+\tl_new:N \l_ghsystem_table_label_tl
+\tl_set:Nn \l_ghsystem_table_label_tl { tab : ghs-hp-statements }
+
+\dim_new:N \l_ghsystem_table_line_sep_dim
+\dim_set:Nn \l_ghsystem_table_line_sep_dim { 3pt }
+
+\fp_new:N \l_ghsystem_picture_scale_fp
+\fp_set:Nn \l_ghsystem_picture_scale_fp { \l_ghsystem_picture_scale_tl }
+
+\DeclareSIUnit { \GHSfahrenheit } { \SIUnitSymbolDegree F }
+\DeclareSIUnit { \GHScelsius } { \SIUnitSymbolDegree C }
+\DeclareSIUnit { \GHSkilogram } { kg }
+\DeclareSIUnit { \GHSpounds } { lbs }
+
+\bool_if:NTF \l_chemmacros_german_bool
+ { \input { language / ghsystem_german.def } \ExplSyntaxOn }
+ { \input { language / ghsystem_english.def } \ExplSyntaxOn }
+
+\cs_new_nopar:Nn \ghsystem_booktabs:n
+ {
+ \cs_if_exist:cF { ver@booktabs.sty }
+ { \msg_error:nnx { ghsystem } { booktabs } { #1 } }
+ }
+
+% --------------------------------------------------------------------------- %
+% define options:
+\keys_define:nn { chemmacros / ghsystem }
+ {
+ % general options:
+ language .code:n =
+ \bool_set_true:c { l_ghsystem_#1_bool }
+ \input { language / ghsystem_#1.def } \ExplSyntaxOn ,
+ % \ghs options:
+ hide .bool_set:N = \l_ghsystem_hide_statement_bool ,
+ hide .default:n = true ,
+ fill-in .bool_set:N = \l_ghsystem_fill_in_bool ,
+ fill-in .default:n = true ,
+ exposure .code:n =
+ \cs_set:Npn \ghsystem_exposure: { ~ #1 } ,
+ effect .code:n =
+ \cs_set:Npn \ghsystem_effect: { ~ #1 } ,
+ organs .code:n =
+ \bool_set_true:N \l_ghsystem_organs_bool
+ \cs_set:Npn \ghsystem_organs: { ~ #1 } ,
+ substance .code:n =
+ \bool_set_true:N \l_ghsystem_substance_bool
+ \cs_set:Npn \ghsystem_substance: { ~ #1 } ,
+ text .code:n =
+ \cs_set:Npn \ghsystem_text: { ~ #1 } ,
+ space .tl_set:N = \l_ghsystem_number_space_tl ,
+ C-temperature .tl_set:N = \l_ghsystem_celsius_temperature_tl ,
+ F-temperature .tl_set:N =
+ \l_ghsystem_fahrenheit_temperature_tl ,
+ kg-mass .tl_set:N = \l_ghsystem_kg_mass_tl ,
+ lbs-mass .tl_set:N = \l_ghsystem_lbs_mass_tl ,
+ dots .tl_set:N = \l_ghsystem_dots_tl ,
+ % \ghspic options:
+ scale .code:n =
+ \fp_mul:Nn \l_ghsystem_picture_scale_fp { #1 } ,
+ includegraphics .code:n =
+ \tl_set:Nn \l_ghsystem_picture_includegraphics_tl { , #1 } ,
+ pic-type .choices:nn = { eps , jpg , png }
+ { \tl_set_eq:NN \l_ghsystem_picture_type_tl \l_keys_choice_tl } ,
+ % \ghslistall options:
+ table-head-number .tl_set:N = \l_ghsystem_identifier_tl ,
+ table-head-text .tl_set:N = \l_ghsystem_table_text_tl ,
+ table-next-page .tl_set:N = \l_ghsystem_table_next_page_tl ,
+ table-row-sep .dim_set:N = \l_ghsystem_table_line_sep_dim ,
+ table-head-rule .choice: ,
+ table-head-rule / default .code:n =
+ \tl_set:Nn \l_ghsystem_table_head_rule_tl { \hline } ,
+ table-head-rule / booktabs .code:n =
+ \ghsystem_booktabs:n { table-head-rule }
+ \tl_set:Nn \l_ghsystem_table_head_rule_tl { \midrule } ,
+ table-head-rule / none .code:n =
+ \tl_clear:N \l_ghsystem_table_head_rule_tl ,
+ table-top-head-rule .choice: ,
+ table-top-head-rule / default .code:n =
+ \tl_set:Nn \l_ghsystem_table_top_head_rule_tl { \hline } ,
+ table-top-head-rule / booktabs .code:n =
+ \ghsystem_booktabs:n { table-top-head-rule }
+ \tl_set:Nn \l_ghsystem_table_top_head_rule_tl { \toprule } ,
+ table-top-head-rule / none .code:n =
+ \tl_clear:N \l_ghsystem_table_top_head_rule_tl ,
+ table-foot-rule .choice: ,
+ table-foot-rule / default .code:n =
+ \tl_set:Nn \l_ghsystem_table_foot_rule_tl { \hline } ,
+ table-foot-rule / booktabs .code:n =
+ \ghsystem_booktabs:n { table-foot-rule }
+ \tl_set:Nn \l_ghsystem_table_foot_rule_tl { \midrule } ,
+ table-foot-rule / none .code:n =
+ \tl_clear:N \l_ghsystem_table_foot_rule_tl ,
+ table-last-foot-rule .choice: ,
+ table-last-foot-rule / default .code:n =
+ \tl_set:Nn \l_ghsystem_table_last_foot_rule_tl { \hline } ,
+ table-last-foot-rule / booktabs .code:n =
+ \ghsystem_booktabs:n { table-last-foot-rule }
+ \tl_set:Nn \l_ghsystem_table_last_foot_rule_tl { \bottomrule } ,
+ table-last-foot-rule / none .code:n =
+ \tl_clear:N \l_ghsystem_table_last_foot_rule_tl ,
+ table-rules .choice: ,
+ table-rules / default .code:n =
+ \tl_set:Nn \l_ghsystem_table_head_rule_tl { \hline }
+ \tl_set:Nn \l_ghsystem_table_top_head_rule_tl { \hline }
+ \tl_set:Nn \l_ghsystem_table_foot_rule_tl { \hline }
+ \tl_set:Nn \l_ghsystem_table_last_foot_rule_tl { \hline } ,
+ table-rules / booktabs .code:n =
+ \ghsystem_booktabs:n { table-rules }
+ \tl_set:Nn \l_ghsystem_table_head_rule_tl { \midrule }
+ \tl_set:Nn \l_ghsystem_table_top_head_rule_tl { \toprule }
+ \tl_set:Nn \l_ghsystem_table_foot_rule_tl { \midrule }
+ \tl_set:Nn \l_ghsystem_table_last_foot_rule_tl { \bottomrule } ,
+ table-rules / none .code:n =
+ \tl_clear:N \l_ghsystem_table_head_rule_tl
+ \tl_clear:N \l_ghsystem_table_top_head_rule_tl
+ \tl_clear:N \l_ghsystem_table_foot_rule_tl
+ \tl_clear:N \l_ghsystem_table_last_foot_rule_tl ,
+ table-caption .tl_set:N = \l_ghsystem_table_caption_tl ,
+ table-caption-short .tl_set:N = \l_ghsystem_table_caption_short_tl ,
+ table-label .tl_set:N = \l_ghsystem_table_label_tl
+ }
+
+% --------------------------------------------------------------------------- %
+% the main command for getting the H/EUH/P statements
+% \ghs{<type>}{<num>}
+% \ghs*{<type>}{<num>} : type without number
+%
+\NewDocumentCommand \ghs { somm }
+ {
+ \group_begin:
+ \IfBooleanF { #1 } { \bool_set_true:N \l_ghsystem_show_number_bool }
+ \IfNoValueF { #2 } { \keys_set:nn { chemmacros / ghsystem } { #2 } }
+ \ghsystem_read_args:nn { #3 } { #4 }
+ \group_end:
+ }
+
+\cs_new:Nn \ghsystem_read_args:nn
+ {
+ \ghsystem_get_type:nN { #1 } \l_tmpa_tl
+ \prop_get:cnNTF { l_ghsystem_ \l_tmpa_tl _prop } { #2 } \l_tmpb_tl
+ {
+ \ghsystem_is_combination:nn { #1 } { #2 }
+ \bool_if:NF \l_ghsystem_hide_statement_bool
+ { \tl_use:N \l_tmpb_tl }
+ }
+ { \chemmacros_msg:nnxx { ghsystem } { statements } { #1 } { #2 } }
+ }
+
+\cs_new:Nn \ghsystem_get_type:nN
+ {
+ \tl_if_eq:nnT { #1 } { h } { \tl_set:Nn #2 { h } }
+ \tl_if_eq:nnT { #1 } { H } { \tl_set:Nn #2 { h } }
+ \tl_if_eq:nnT { #1 } { euh } { \tl_set:Nn #2 { euh } }
+ \tl_if_eq:nnT { #1 } { Euh } { \tl_set:Nn #2 { euh } }
+ \tl_if_eq:nnT { #1 } { euH } { \tl_set:Nn #2 { euh } }
+ \tl_if_eq:nnT { #1 } { eUh } { \tl_set:Nn #2 { euh } }
+ \tl_if_eq:nnT { #1 } { EUh } { \tl_set:Nn #2 { euh } }
+ \tl_if_eq:nnT { #1 } { EuH } { \tl_set:Nn #2 { euh } }
+ \tl_if_eq:nnT { #1 } { eUH } { \tl_set:Nn #2 { euh } }
+ \tl_if_eq:nnT { #1 } { EUH } { \tl_set:Nn #2 { euh } }
+ \tl_if_eq:nnT { #1 } { p } { \tl_set:Nn #2 { p } }
+ \tl_if_eq:nnT { #1 } { P } { \tl_set:Nn #2 { p } }
+ }
+
+\cs_new:Nn \ghsystem_is_combination:nn
+ {
+ \tl_if_in:nnTF { #2 } { + }
+ { \ghsystem_is_combination_aux_i:w #1,#2 \q_stop }
+ { \ghsystem_is_combination_aux_ii:w #1,#2 \q_stop }
+ }
+
+\cs_new:Npn \ghsystem_is_combination_aux_i:w #1,#2+#3 \q_stop
+ {
+ \bool_if:NT \l_ghsystem_show_number_bool
+ {
+ \tl_to_uppercase:n { #1 }
+ \tl_use:N \l_ghsystem_number_space_tl
+ #2 ~ + ~
+ \tl_if_in:nnTF { #3 } { + }
+ { \ghsystem_is_combination_aux_iii:w #1,#3 \q_stop }
+ {
+ \tl_to_uppercase:n { #1 }
+ \tl_use:N \l_ghsystem_number_space_tl
+ #3 \bool_if:NF \l_ghsystem_hide_statement_bool { : ~ }
+ }
+ }
+ }
+
+\cs_new:Npn \ghsystem_is_combination_aux_ii:w #1,#2 \q_stop
+ {
+ \bool_if:NT \l_ghsystem_show_number_bool
+ {
+ \tl_to_uppercase:n { #1 }
+ \tl_use:N \l_ghsystem_number_space_tl
+ #2 \bool_if:NF \l_ghsystem_hide_statement_bool { : ~ }
+ }
+ }
+
+\cs_new:Npn \ghsystem_is_combination_aux_iii:w #1,#2+#3 \q_stop
+ {
+ \bool_if:NT \l_ghsystem_show_number_bool
+ {
+ \tl_to_uppercase:n { #1 }
+ \tl_use:N \l_ghsystem_number_space_tl
+ #2 ~ + ~
+ \tl_to_uppercase:n { #1 }
+ \tl_use:N \l_ghsystem_number_space_tl
+ #3 \bool_if:NF \l_ghsystem_hide_statement_bool { : ~ }
+ }
+ }
+
+% --------------------------------------------------------------------------- %
+% list all statements in a table
+%
+\NewDocumentCommand \ghslistall { o }
+ {
+ \group_begin:
+ \IfNoValueF { #1 } { \keys_set:nn { chemmacros / ghsystem } { #1 } }
+ \int_zero:N \l_tmpa_int
+ \int_zero:N \l_tmpb_int
+ \prop_map_inline:Nn \l_ghsystem_p_prop { \int_incr:N \l_tmpa_int }
+ \dim_set_eq:NN \tabulinesep \l_ghsystem_table_line_sep_dim
+% \taburowcolors [2] 2{white .. gray!15}
+ \begin { longtabu } { X[3]X[7,L] }
+ \caption [ \l_ghsystem_table_caption_short_tl ]
+ {
+ \l_ghsystem_table_caption_tl
+ \exp_args:No \label { \l_ghsystem_table_label_tl }
+ } \\
+ \l_ghsystem_table_top_head_rule_tl
+ \textbf { \l_ghsystem_identifier_tl } & \textbf { \l_ghsystem_table_text_tl } \\
+ \l_ghsystem_table_head_rule_tl
+ \endfirsthead
+ \l_ghsystem_table_top_head_rule_tl
+ \textbf { \l_ghsystem_identifier_tl } & \textbf { \l_ghsystem_table_text_tl } \\
+ \l_ghsystem_table_head_rule_tl
+ \endhead
+ \l_ghsystem_table_last_foot_rule_tl
+ \multicolumn{2}{r} { \textit { \l_ghsystem_table_next_page_tl } }
+ \endfoot
+ \l_ghsystem_table_foot_rule_tl \multicolumn{2}{r} { }
+ \endlastfoot
+ \prop_map_inline:Nn \l_ghsystem_h_prop
+ { \ghsystem_read_number:nn { H } { ##1 } & ##2 \\ }
+ \prop_map_inline:Nn \l_ghsystem_euh_prop
+ { \ghsystem_read_number:nn { EUH } { ##1 } & ##2 \\ }
+ \prop_map_inline:Nn \l_ghsystem_p_prop
+ { \ghsystem_read_number:nn { P } { ##1 } & ##2 \\ }
+ \end { longtabu }
+ \group_end:
+ }
+
+\cs_new:Nn \ghsystem_read_number:nn
+ {
+ \tl_if_in:nnTF { #2 } { + }
+ { \ghsystem_read_number_aux_i:w #1 , #2 \q_stop }
+ { #1#2 }
+ }
+
+\cs_new:Npn \ghsystem_read_number_aux_i:w #1,#2+#3\q_stop
+ {
+ #1#2 ~+~
+ \tl_if_in:nnTF { #3 } { + }
+ { \ghsystem_read_number_aux_ii:w #1,#3 \q_stop }
+ { #1#3 }
+ }
+
+\cs_new:Npn \ghsystem_read_number_aux_ii:w #1,#2+#3\q_stop { #1#2 ~+~ #1#3 }
+
+% --------------------------------------------------------------------------- %
+% the picture command
+% \ghspic[<options>]{<name>}
+%
+% test for compilation engine/mode:
+\pdftex_if_engine:T { \bool_set_true:N \l_ghsystem_engine_pdftex_bool }
+\xetex_if_engine:T { \bool_set_true:N \l_ghsystem_engine_xetex_bool }
+\luatex_if_engine:T { \bool_set_true:N \l_ghsystem_engine_luatex_bool }
+
+\bool_if:NT \l_ghsystem_engine_pdftex_bool
+ {
+ \ifpdf
+ \tl_set:Nn \l_ghsystem_picture_type_tl { png }
+ \else
+ \tl_set:Nn \l_ghsystem_picture_type_tl { eps }
+ \fi
+ }
+\bool_if:NT \l_ghsystem_engine_xetex_bool
+ { \tl_set:Nn \l_ghsystem_picture_type_tl { png } }
+\bool_if:NT \l_ghsystem_engine_luatex_bool
+ { \tl_set:Nn \l_ghsystem_picture_type_tl { png } }
+
+% the command:
+\NewDocumentCommand \ghspic { om }
+ {
+ \group_begin:
+ \IfNoValueF { #1 } { \keys_set:nn { chemmacros / ghsystem } { #1 } }
+ \ghsystem_includegraphics:xn
+ { scale=\fp_to_tl:N \l_ghsystem_picture_scale_fp \l_ghsystem_picture_includegraphics_tl }
+ { pictures / #2 . \l_ghsystem_picture_type_tl }
+ \group_end:
+ }
+
+\cs_new:Nn \ghsystem_includegraphics:nn
+ { \includegraphics[#1]{#2} }
+\cs_generate_variant:Nn \ghsystem_includegraphics:nn { xn }
+
+\tex_endinput:D
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+VERSION HISTORY
+2012/01/28 - version 3.0 - first published to CTAN with the chemmacros bundle
+2012/01/30 - version 3.0a - bugfix in chemormula.sty, renamed ghs => ghsystem
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+% TODO:
+- add option to switch between `longtable` and `supertabular` for \ghslistall \ No newline at end of file