summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/chemformula/chemformula.sty
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/chemformula/chemformula.sty')
-rw-r--r--macros/latex/contrib/chemformula/chemformula.sty598
1 files changed, 268 insertions, 330 deletions
diff --git a/macros/latex/contrib/chemformula/chemformula.sty b/macros/latex/contrib/chemformula/chemformula.sty
index 4ba76f16b5..3a7b1d94a1 100644
--- a/macros/latex/contrib/chemformula/chemformula.sty
+++ b/macros/latex/contrib/chemformula/chemformula.sty
@@ -12,7 +12,7 @@
% If you have any ideas, questions, suggestions or bugs to report, please
% feel free to contact me.
% --------------------------------------------------------------------------
-% Copyright 2011--2020 Clemens Niederberger
+% Copyright 2011--2022 Clemens Niederberger
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3
@@ -30,8 +30,8 @@
\usetikzlibrary{arrows.meta}
\ExplSyntaxOn
-\tl_const:Nn \c_chemformula_date_tl {2020/12/22}
-\tl_const:Nn \c_chemformula_version_number_tl {4.16}
+\tl_const:Nn \c_chemformula_date_tl {2022/01/23}
+\tl_const:Nn \c_chemformula_version_number_tl {4.17}
\tl_const:Nn \c_chemformula_version_suffix_tl {}
\tl_const:Nx \c_chemformula_version_tl
{ \c_chemformula_version_number_tl \c_chemformula_version_suffix_tl }
@@ -128,14 +128,50 @@
\NewChemSymbol \c_space_tl but~ a~ symbol~ `#1'~ doesn't~ exist.
}
+\msg_new:nnn {chemformula} {deprecated}
+ {
+ On~ line~ \msg_line_number: : \\
+ The~ #1~ `#2'~ is~ deprecated.~ Use~ #1~ `#3'~ instead .
+ }
+
+\msg_new:nnn {chemformula} {deprecated-function}
+ { The~ command~ #1~ is~ deprecated.~ Use~ #2 instead . }
+
+\msg_new:nnn {chemformula} {removed-function}
+ { The~ command~ #1~ has~ been~ removed. }
+
+\msg_new:nnn {chemformula} {removed}
+ {
+ On~ line~ \msg_line_number: : \\
+ The~ #1~ `#2'~ has~ been~ removed~ from~ chemformula. \\
+ If~ you~ need~ it~ back~ please~ open~ an~ issue~ on~ \\
+ https://github.com/cgnieder/chemformula/issues
+ \tl_if_blank:nF {#3} { \\ #3 }
+ }
+
+\msg_new:nnn {chemformula} {load-time-option}
+ {
+ `#1'~ is~ a~ load-time~ option! \\
+ You~ cannot~ set~ it~ with~ \token_to_str:N \setchemformula ! \\
+ You~ need~ to~ use~ \token_to_str:N \usepackage [#1] {chemformula} .
+ }
+
+\msg_new:nnn {chemformula} {unknown-option}
+ {
+ Unknown~ option~ `#1' \\
+ I~ dont'~ know~ the~ option~ `#1'.~ Please~ make~ sure~ there~ is~ no~
+ typo.~ Check~ the~ manual~ for~ help.
+ }
+
% --------------------------------------------------------------------------
% variants of kernel functions:
\cs_generate_variant:Nn \keys_set:nn {nV}
\cs_generate_variant:Nn \tl_if_blank:nF {V}
\cs_generate_variant:Nn \tl_if_in:nnT {x,nV}
\cs_generate_variant:Nn \tl_if_eq:nnT {V,x}
-\cs_generate_variant:Nn \tl_if_eq:nnTF {o}
-\cs_generate_variant:Nn \tl_set:Nn {cV}
+\cs_generate_variant:Nn \tl_if_eq:nnTF {o,V}
+\cs_generate_variant:Nn \tl_set:Nn {cV,Ne}
+\cs_generate_variant:Nn \tl_put_right:Nn {Ne}
\cs_generate_variant:Nn \tl_replace_all:Nnn {NV,Nnx}
\cs_generate_variant:Nn \tl_replace_once:Nnn {Nxx}
\cs_generate_variant:Nn \tl_set_rescan:Nnn {NnV}
@@ -168,6 +204,7 @@
\bool_new:N \l__chemformula_tmpa_bool
% booleans
+\bool_new:N \l__chemformula_debug_bool
\bool_new:N \l_chemformula_inside_ch_bool
\bool_new:N \l_chemformula_formal_charges_bool
\bool_new:N \l_chemformula_formal_chem_bool
@@ -178,6 +215,7 @@
\bool_new:N \l__chemformula_is_addition_symbol_bool
\bool_new:N \l__chemformula_is_symbol_bool
\bool_new:N \l__chemformula_is_arrow_bool
+\bool_new:N \l__chemformula_arrow_has_options_bool
\bool_new:N \l__chemformula_is_name_bool
\bool_new:N \l__chemformula_stoich_is_iupac_bool
\bool_new:N \l__chemformula_stoich_parse_iupac_bool
@@ -265,6 +303,7 @@
\tl_new:N \g__chemformula_output_tl
\tl_new:N \l__chemformula_input_tl
\tl_new:N \l__chemformula_stoich_tl
+\tl_new:N \l__chemformula_stoich_format_tl
\tl_new:N \l__chemformula_decimal_output_tl
\tl_new:N \l__chemformula_font_family_tl
\tl_new:N \l__chemformula_font_series_tl
@@ -365,6 +404,89 @@
\skip_set:Nn \l__chemformula_stoich_space_skip { .1667em plus .0333em minus .0117em }
\skip_set:Nn \l__chemformula_math_space_skip { .1667em plus .0333em minus .0117em }
+% ----------------------------------------------------------------------------
+% debugging
+\prg_new_conditional:Npnn \__chemformula_if_debug: {T,F,TF}
+ {
+ \bool_if:NTF \l__chemformula_debug_bool
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+
+% ----------------------------------------------------------------------------
+% deprecation & removal:
+% #1: type
+% #2: old
+% #3: new
+\cs_new_protected:Npn \__chemformula_deprecation_warning:nnn #1#2#3
+ { \msg_warning:nnnnn {chemformula} {deprecated} {#1} {#2} {#3} }
+\cs_generate_variant:Nn \__chemformula_deprecation_warning:nnn {nne,nV}
+
+% #1: type
+% #2: old
+% #3: additional text
+\cs_new_protected:Npn \chemformula_removal_warning:nnn #1#2#3
+ { \msg_warning:nnnnn {chemformula} {removed} {#1} {#2} {#3} }
+\cs_generate_variant:Nn \chemformula_removal_warning:nnn {nV}
+
+% #1: type
+% #2: old
+\cs_new_protected:Npn \chemformula_removal_warning:nn #1#2
+ { \msg_warning:nnnn {chemformula} {removed} {#1} {#2} }
+\cs_generate_variant:Nn \chemformula_removal_warning:nn {nV}
+
+% #1: new
+\cs_new_protected:Npn \chemformula_deprecate_option:n #1
+ { \__chemformula_deprecation_warning:nVn {option} \l_keys_key_str {#1} }
+
+% #1: additional text
+\cs_new_protected:Npn \chemformula_remove_option:n #1
+ { \chemformula_removal_warning:nVn {option} \l_keys_key_str {#1} }
+
+\cs_new_protected:Npn \chemformula_remove_option:
+ { \chemformula_removal_warning:nV {option} \l_keys_key_str }
+
+% #1: old
+% #2: new
+\cs_new_protected:Npn \chemformula_deprecate_function:NN #1#2
+ {
+ \cs_set_protected:Npn #1
+ {
+ \msg_error:nnnn {chemformula} {deprecated-function} {#1} {#2}
+ #2
+ }
+ }
+
+% #1: old
+\cs_new_protected:Npn \chemformula_remove_function:N #1
+ {
+ \cs_set_protected:Npn #1
+ { \msg_error:nnn {chemformula} {removed-function} {#1} }
+ }
+
+% --------------------------------------------------------------------------
+% load-time options:
+\cs_new_protected:Npn \__chemformula_loadtime_error:n #1
+ { \msg_error:nnV {chemformula} {#1} \l_keys_key_str }
+
+\cs_new_protected:Npn \__chemformula_loadtime_warning:n #1
+ { \msg_warning:nnV {chemformula} {#1} \l_keys_key_str }
+
+\keys_define:nn {chemformula/load-time}
+ {
+ debug .bool_set:N = \l__chemformula_debug_bool ,
+ debug .initial:n = false
+ }
+
+\ProcessKeysPackageOptions {chemformula/load-time}
+
+\keys_define:nn {chemformula}
+ {
+ debug .code:n = \__chemformula_loadtime_error:n {load-time-option} ,
+ unknown .code:n = \__chemformula_loadtime_warning:n {unknown-option} ,
+ load-time / debug .meta:nn = {chemformula} {debug}
+ }
+
% --------------------------------------------------------------------------
% catcode stuff
\cs_new_protected:Npn \__chemformula_save_catcodes:
@@ -413,8 +535,8 @@
{
\__chemformula_basic_catcodes:
% disable some of the specials (needed for sub- and superscripts):
- \char_set_catcode_letter:N \{
- \char_set_catcode_letter:N \}
+ \char_set_catcode_other:N \{
+ \char_set_catcode_other:N \}
}
{#2}
}
@@ -891,9 +1013,17 @@
{ \__chemformula_basic_catcodes: } {#1}
% determine length of the arrow
\hbox_set:Nn \l__chemformula_arrow_arg_i_box
- { \tl_use:N \l__chemformula_arrow_label_style_tl #2 }
+ {
+ \tl_use:N \l__chemformula_arrow_label_style_tl
+ \cs_set:Npn \newline { \tabularnewline }
+ \begin {tabular} {c} #2 \end {tabular}
+ }
\hbox_set:Nn \l__chemformula_arrow_arg_ii_box
- { \tl_use:N \l__chemformula_arrow_label_style_tl #3 }
+ {
+ \tl_use:N \l__chemformula_arrow_label_style_tl
+ \cs_set:Npn \newline { \tabularnewline }
+ \begin {tabular} {c} #3 \end {tabular}
+ }
\__chemformula_determine_arrow_length:NN
\l__chemformula_arrow_arg_i_box
\l__chemformula_arrow_arg_ii_box
@@ -1124,37 +1254,42 @@
% --------------------------------------------------------------------------
% MAIN COMMAND
-\cs_new_protected:Npn \__chemformula_ch_main:n #1
+\cs_set_protected:Npn \__chemformula_ch_main:n #1
{
\group_begin:
% abort if `#1' is blank:
\tl_if_blank:nF {#1}
{
- \tl_set:Nn \l__chemmacros_tmpa_tl {#1}
- \tl_trim_spaces:N \l__chemmacros_tmpa_tl
- \seq_set_split:NnV \l__chemformula_input_seq {~} \l__chemmacros_tmpa_tl
- % remove empty items in order to avoid unnecessary processing:
- \seq_remove_all:Nn \l__chemformula_input_seq {}
% disable \xspace:
\cs_set_eq:NN \xspace \scan_stop:
\bool_set_true:N \l_chemformula_inside_ch_bool
\tl_if_blank:VF \g__chemformula_options_tl
- {
- \keys_set:nV
- {chemformula}
- \g__chemformula_options_tl
- }
- \seq_map_function:NN
- \l__chemformula_input_seq
- \__chemformula_input:n
+ { \keys_set:nV {chemformula} \g__chemformula_options_tl }
+ \__chemformula_read_input:n {#1}
\__chemformula_prepare_output:NV
\l__chemformula_input_tl
\l__chemformula_catcodes_tl
\chemformula_write:V \l__chemformula_input_tl
+ \__chemformula_if_debug:T { \tl_show:N \l__chemformula_input_tl }
}
\group_end:
}
+\cs_new_protected:Npn \__chemformula_read_input:n #1
+ { \__chemformula_read_input:w #1 ~ \q_stop }
+\cs_generate_variant:Nn \__chemformula_read_input:n {V}
+
+\cs_new_protected:Npn \__chemformula_read_input:w #1 ~ #2 \q_stop
+ {
+ \__chemformula_input:n {#1}
+ \tl_set:Nn \l__chemformula_tmpa_tl {#2}
+ \tl_if_blank:VF \l__chemformula_tmpa_tl
+ {
+ \tl_trim_spaces:N \l__chemformula_tmpa_tl
+ \__chemformula_read_input:V \l__chemformula_tmpa_tl
+ }
+ }
+
\cs_new_protected:Npn \chemformula_write:n #1
{
\mode_if_math:TF
@@ -1171,7 +1306,7 @@
\tl_if_blank:nTF {#1}
{ \tl_gclear:N \g__chemformula_options_tl }
{ \tl_gset:Nn \g__chemformula_options_tl {#1} }
- \__chemformula_ch_newline:w #2 \\ \q_no_value \q_stop
+ \__chemformula_ch_newline:w #2 \\ \q_nil \q_stop
\group_align_safe_end:
\tl_use:N \g__chemformula_output_tl
\tl_gclear:N \g__chemformula_output_tl
@@ -1182,8 +1317,8 @@
% bypass \\:
\cs_new_protected:Npn \__chemformula_ch_newline:w #1 \\ #2 \q_stop
{
- \__chemformula_ch_align:w #1 & \q_no_value \q_stop
- \quark_if_no_value:nF {#2}
+ \__chemformula_ch_align:w #1 & \q_nil \q_stop
+ \quark_if_nil:nF {#2}
{
\tl_gput_right:Nn \g__chemformula_output_tl { \\ }
% look for optional argument:
@@ -1203,8 +1338,8 @@
% bypass &:
\cs_new_protected:Npn \__chemformula_ch_align:w #1 & #2 \q_stop
{
- \__chemformula_ch_intertext:w #1 \intertext{} \q_no_value \q_stop
- \quark_if_no_value:nF {#2}
+ \__chemformula_ch_intertext:w #1 \intertext{} \q_nil \q_stop
+ \quark_if_nil:nF {#2}
{
\tl_gput_right:Nn \g__chemformula_output_tl {&}
\__chemformula_ch_align:w #2 \q_stop
@@ -1214,8 +1349,8 @@
% bypass \intertext:
\cs_new_protected:Npn \__chemformula_ch_intertext:w #1 \intertext#2 #3 \q_stop
{
- \__chemformula_ch_shortintertext:w #1 \shortintertext{} \q_no_value \q_stop
- \quark_if_no_value:nF {#3}
+ \__chemformula_ch_shortintertext:w #1 \shortintertext{} \q_nil \q_stop
+ \quark_if_nil:nF {#3}
{
\tl_gput_right:Nn \g__chemformula_output_tl { \intertext {#2} }
\__chemformula_ch_intertext:w #3 \q_stop
@@ -1227,7 +1362,7 @@
{
\tl_gput_right:Nn \g__chemformula_output_tl
{ \__chemformula_ch_main:n {#1} }
- \quark_if_no_value:nF {#3}
+ \quark_if_nil:nF {#3}
{
\tl_gput_right:Nn \g__chemformula_output_tl { \shortintertext {#2} }
\__chemformula_ch_shortintertext:w #3 \q_stop
@@ -1330,6 +1465,11 @@
\prop_map_break:
}
}
+ \bool_if:NT \l__chemformula_is_arrow_bool
+ {
+ \tl_if_in:nnT {#1} {[}
+ { \bool_set_true:N \l__chemformula_arrow_has_options_bool }
+ }
}
% --------------------------------------------------------------------------
@@ -1348,19 +1488,11 @@
\bool_if:NF \l__chemformula_name_width_bool
{
\chemformula_dim_to_width:Nn \l__chemformula_name_dim
- {
- \group_begin:
- \l__chemformula_name_format_tl {#1}
- \group_end:
- }
+ { \chemformula_name_write:n {#1} }
}
\parbox
{ \dim_use:N \l__chemformula_name_dim }
- {
- \group_begin:
- \l__chemformula_name_format_tl {#1}
- \group_end:
- }
+ { \chemformula_name_write:n {#1} }
}
{
\text
@@ -1373,6 +1505,13 @@
\c_math_toggle_token
}
+\cs_new_protected:Npn \chemformula_name_write:n #1
+ {
+ \group_begin:
+ \l__chemformula_name_format_tl {#1}
+ \group_end:
+ }
+
\cs_new_protected:Npn \__chemformula_generate_name:Nn #1#2
{
\__chemformula_sanitize:Nn \l__chemformula_tmpa_tl {#2}
@@ -1716,7 +1855,7 @@
{
\bool_if:NTF \l__chemformula_number_style_math_bool
{ \ensuremath {#1} }
- { \ensuremath { \text {#1} } }
+ { \ensuremath { \text { { \chemformula_atom: #1 } } } }
}
\cs_generate_variant:Nn \__chemformula_number_style:n {V}
@@ -1724,7 +1863,7 @@
{
\bool_if:NTF \l__chemformula_charge_style_math_bool
{ \ensuremath {#1} }
- { \ensuremath { \text {#1} } }
+ { \ensuremath { \text { { \chemformula_atom: #1 } } } }
}
\cs_generate_variant:Nn \chemformula_charge_style:n {V}
@@ -1769,6 +1908,7 @@
}
\cs_generate_variant:Nn \__chemformula_subscript:n {V}
+
\cs_new_protected:Npn \chemformula_add_subscript_cleanup:nn #1#2
{
\seq_put_right:Nn \l__chemformula_clean_subscript_seq {#1}
@@ -2121,7 +2261,7 @@
\__chemformula_input_escape_text:V \l__chemformula_chemformula_tmpa_tl
\__chemformula_input_escape_math:n {#1}
\__chemformula_input_stoich:n {#1}
- \__chemformula_clean_chemmacros:V \l__chemformula_chemformula_tmpa_tl
+ \__chemformula_clean_chemformula:V \l__chemformula_chemformula_tmpa_tl
\__chemformula_input_compound:NV
\l__chemformula_input_tl
\l__chemformula_chemformula_tmpa_tl
@@ -2135,19 +2275,15 @@
% set options for next compound:
\cs_new_protected:Npn \__chemformula_input_options:n #1
{
- % \makeatother
- \char_set_catcode_other:N \@
- \tl_set_rescan:Nnn \l__chemformula_tmpa_tl
- { \char_set_catcode_letter:N \@ }
- {#1}
- \tl_if_in:VnTF \l__chemformula_tmpa_tl { @ }
+ \tl_set_rescan:Nnn \l__chemformula_tmpa_tl {} {#1}
+ \tl_set:Ne \l__chemformula_tmpb_tl { \tl_tail:V \l__chemformula_tmpa_tl }
+ \tl_set:Ne \l__chemformula_tmpa_tl { \tl_head:V \l__chemformula_tmpa_tl }
+ \str_if_eq:VnTF \l__chemformula_tmpa_tl {@}
{
\bool_set_false:N \l__chemformula_options_bool
\bool_set_true:N \l__chemformula_is_option_bool
- \tl_remove_all:Nn \l__chemformula_tmpa_tl { @ }
\exp_last_unbraced:Nno
- \tl_set:Nn \l__chemformula_internal_options_tl
- { \l__chemformula_tmpa_tl }
+ \tl_set:Nn \l__chemformula_internal_options_tl { \l__chemformula_tmpb_tl }
}
{ \bool_set_false:N \l__chemformula_is_option_bool }
}
@@ -2164,7 +2300,10 @@
\tl_map_inline:nn {#1}
{
\prop_if_in:NnF \l__chemformula_no_stoich_prop {##1}
- { \bool_set_false:N \l__chemformula_no_stoich_bool }
+ {
+ \bool_set_false:N \l__chemformula_no_stoich_bool
+ \tl_map_break:
+ }
}
\bool_if:NF \l__chemformula_no_stoich_bool
{
@@ -2175,7 +2314,10 @@
\bool_if:NT \l__chemformula_stoich_bool
{ \tl_put_right:NV \l__chemformula_stoich_tl \l__chemformula_tmpa_tl }
}
- { \bool_set_false:N \l__chemformula_stoich_bool }
+ {
+ \bool_set_false:N \l__chemformula_stoich_bool
+ \tl_map_break:
+ }
}
}
\bool_if:NTF \l__chemformula_stoich_bool
@@ -2186,7 +2328,7 @@
\__chemformula_sanitize:NV
\l__chemformula_stoich_tl
\l__chemformula_stoich_tl
- \__chemformula_print_stoich:V
+ \chemformula_print_stoich:V
\l__chemformula_stoich_tl
}
}
@@ -2195,15 +2337,23 @@
\cs_new_protected:Npn \chemformula_bm:n #1 {#1}
-\cs_new_protected:Npn \__chemformula_print_stoich:n #1
+\cs_new_protected:Npn \chemformula_print_stoich:n #1
{ \chemformula_parse_stoich:n {#1} }
-\cs_generate_variant:Nn \__chemformula_print_stoich:n {V}
+\cs_generate_variant:Nn \chemformula_print_stoich:n {V}
+
+\cs_new_protected:Npn \__chemformula_print_stoich:n #1
+ { { \l__chemformula_stoich_format_tl {#1} } }
\cs_new_protected:Npn \chemformula_parse_stoich:n #1
{ \__chemformula_parse_stoich:w #1 \q_nil }
\NewDocumentCommand \chstoich {m}
- { \chemformula_parse_stoich:n {#1} }
+ {
+ \group_begin:
+ \__chemformula_input_stoich:n {#1}
+ \l__chemformula_input_tl
+ \group_end:
+ }
\cs_new_protected:Npn \__chemformula_parse_stoich:w \q_mark #1 \q_nil
{
@@ -2235,8 +2385,14 @@
\tl_set:Nn \l__chemformula_tmpb_tl { \chemformula_decimal: }
% check if stoich starts with decimal-marker and add leading 0 if so:
\tl_if_eq:NNTF \l__chemformula_tmpa_tl \l__chemformula_tmpb_tl
- { \tl_put_right:Nn \l__chemformula_input_tl { 0#1 } }
- { \tl_put_right:Nn \l__chemformula_input_tl {#1} }
+ {
+ \tl_put_right:Nn \l__chemformula_input_tl
+ { \__chemformula_print_stoich:n {0#1} }
+ }
+ {
+ \tl_put_right:Nn \l__chemformula_input_tl
+ { \__chemformula_print_stoich:n {#1} }
+ }
}
\cs_new_protected:Npn \__chemformula_parse_stoich_frac:n #1
@@ -2249,20 +2405,20 @@
\cs_new_protected:Npn \__chemformula_parse_stoich_frac:w #1/#2 \q_nil
{
\tl_put_right:Nn \l__chemformula_input_tl
- { \__chemformula_frac:nn {#1} {#2} }
+ { \__chemformula_print_stoich:n { \__chemformula_frac:nn {#1} {#2} } }
}
\cs_new_protected: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} }
+ { \__chemformula_print_stoich:n { \__chemformula_misc_frac:nnn {#1} {#2} {#3} } }
}
\cs_new_protected:Npn \__chemformula_parse_stoich_iupac:n #1
{
\bool_if:NTF \l__chemformula_stoich_parse_iupac_bool
{ \__chemformula_parse_stoich_iupac:w #1 \q_nil }
- { \tl_put_right:Nn \l__chemformula_input_tl {#1} }
+ { \tl_put_right:Nn \l__chemformula_input_tl { \__chemformula_print_stoich:n {#1} } }
}
\cs_new_protected:Npn \__chemformula_parse_stoich_iupac:w (#1) \q_nil
@@ -2304,6 +2460,9 @@
}
% --------------------------------------------------------------------------
+\cs_new_protected:Npn \chemformula_atom:
+ { \mode_if_math:F { \l__chemformula_atom_format_tl } }
+
% input compounds
\cs_new_protected:Npn \__chemformula_input_compound:Nn #1#2
{
@@ -2317,26 +2476,29 @@
\bool_if:NT \l__chemformula_is_option_bool
{
\bool_set_true:N \l__chemformula_options_bool
- \tl_put_right:Nx #1
+ \tl_put_right:Ne #1
{
\group_begin:
% open group
\keys_set:nn
{chemformula}
{ \exp_not:V \l__chemformula_internal_options_tl }
+ \chemformula_atom:
}
+ \tl_clear:N \l__chemformula_internal_options_tl
}
- \bool_if:nT
+ \bool_lazy_any:nF
{
- !\l__chemformula_is_option_bool &&
- !\l__chemformula_is_addition_symbol_bool &&
- !\l__chemformula_is_symbol_bool &&
- !\l__chemformula_is_arrow_bool &&
- !\l__chemformula_is_name_bool &&
- !\l__chemformula_first_last_text_bool &&
- !\l__chemformula_first_last_math_bool
+ { \l__chemformula_is_option_bool }
+ { \l__chemformula_is_addition_symbol_bool }
+ { \l__chemformula_is_symbol_bool }
+ { \l__chemformula_is_arrow_bool }
+ { \l__chemformula_is_name_bool }
+ { \l__chemformula_first_last_text_bool }
+ { \l__chemformula_first_last_math_bool }
}
{
+ \chemformula_atom:
\__chemformula_input_compound_no_check:Nn #1 {#2}
\bool_if:NT \l__chemformula_options_bool
{
@@ -2344,7 +2506,6 @@
{
% end group
\group_end:
- \tl_clear:N \l__chemformula_internal_options_tl
}
\bool_set_false:N \l__chemformula_options_bool
}
@@ -2497,13 +2658,6 @@
\__chemformula_if_only_parens:nTF {#2}
{ \tl_put_right:Nn #1 {#2} }
{
- % start with formatting:
- \tl_put_right:Nn #1
- {
- \tl_use:N \l__chemformula_format_tl
- \group_begin:
- \l__chemformula_atom_format_tl
- }
\__chemformula_sanitize:Nn \l__chemformula_tmpa_tl {#2}
% let's see if the compound starts with a sub- or superscript - if yes
% this is an isotope:
@@ -2526,8 +2680,15 @@
\prop_get:NnNTF \l__chemformula_compound_prop
{##1}
\l__chemformula_tmpb_tl
- { \tl_put_right:NV #1 \l__chemformula_tmpb_tl }
- { \tl_put_right:Nn #1 {##1} }
+ {
+ \tl_put_right:NV #1
+ \l__chemformula_tmpb_tl
+ }
+ {
+ \token_if_letter:NTF ##1
+ { \tl_put_right:Nn #1 { ##1 } }
+ { \tl_put_right:Nn #1 {##1} }
+ }
}
}
% if Kroeger-Vink notation is active:
@@ -2537,22 +2698,20 @@
{ \chemformula_prime: }
{ \chemformula_superscript:n { \chemformula_prime: } }
}
- % finish formatting:
- \tl_put_right:Nn #1 { \group_end: }
}
\tl_clear:N \l__chemformula_tmpa_tl
}
\cs_generate_variant:Nn \__chemformula_input_compound_no_check:Nn {NV}
% --------------------------------------------------------------------------
-% clean up chemmacros commands:
-\cs_new_protected:Npn \__chemformula_clean_chemmacros:n #1
+% clean up chemformula commands:
+\cs_new_protected:Npn \__chemformula_clean_chemformula:n #1
{
- \cs_set:Nn \chemmacros_text:n
+ \cs_set:Nn \chemformula_text:n
{ \mode_if_math:TF { \text {##1} } {##1} }
- \cs_set:Npn \chemmacros_xspace: {}
+ \cs_set:Npn \chemformula_xspace: {}
}
-\cs_generate_variant:Nn \__chemformula_clean_chemmacros:n {V}
+\cs_generate_variant:Nn \__chemformula_clean_chemformula:n {V}
% --------------------------------------------------------------------------
% input "and" sign
@@ -2733,11 +2892,11 @@
% input arrow
\cs_new_protected:Npn \__chemformula_input_arrow:n #1
{
- \bool_if:nT
+ \bool_lazy_all:nT
{
- \l__chemformula_is_arrow_bool &&
- !\l__chemformula_first_last_text_bool &&
- !\l__chemformula_first_last_math_bool
+ { \l__chemformula_is_arrow_bool }
+ { !\l__chemformula_first_last_text_bool }
+ { !\l__chemformula_first_last_math_bool }
}
{
\__chemformula_generate_arrows:Nn \l__chemformula_tmpa_tl {#1}
@@ -2751,11 +2910,11 @@
% input compound name
\cs_new_protected:Npn \__chemformula_input_name:n #1
{
- \bool_if:nT
+ \bool_lazy_all:nT
{
- \l__chemformula_is_name_bool &&
- !\l__chemformula_first_last_text_bool &&
- !\l__chemformula_first_last_math_bool
+ { \l__chemformula_is_name_bool }
+ { !\l__chemformula_first_last_text_bool }
+ { !\l__chemformula_first_last_math_bool }
}
{
\__chemformula_generate_name:Nn \l__chemformula_tmpa_tl {#1}
@@ -2961,25 +3120,24 @@
\bool_set_false:N \l__chemformula_xfrac_bool
\bool_set_true:N \l__chemformula_nicefrac_bool
\bool_set_false:N \l__chemformula_mathfrac_bool ,
- frac-math-cmd .code:n =
- { \cs_set_eq:NN \chemformula_math_frac:nn #1 } ,
+ frac-math-cmd .cs_set_protected:Np = \chemformula_math_frac:nn #1#2 ,
+ frac-math-cmd .initial:n = \frac {#1} {#2} ,
stoich-paren-parse .bool_set:N = \l__chemformula_stoich_parse_iupac_bool ,
stoich-space .skip_set:N = \l__chemformula_stoich_space_skip ,
+ stoich-format .tl_set:N = \l__chemformula_stoich_format_tl ,
stoich-print .code:n =
- \cs_set_eq:NN \chemformula_print_stoich:n #1 ,
+ \chemformula_remove_option:n {Use~ the~ option~ `stoich-format'~ instead.} ,
adduct-space .dim_set:N = \l__chemformula_adduct_space_dim ,
adduct-penalty .tl_set:N = \l__chemformula_adduct_penalty_tl ,
math-space .skip_set:N = \l__chemformula_math_space_skip ,
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}
- }
- } ,
+ \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 ,
bond-offset .dim_set:N = \l__chemformula_bond_space_dim ,
bond-style .code:n =
@@ -3282,7 +3440,7 @@
% --------------------------------------------------------------------------
% hyperref support
-\hook_gput_code:nnn {package/after/hyperref} {chemformula}
+\hook_gput_code:nnn {package/hyperref/after} {chemformula}
{
\pdfstringdefDisableCommands
{
@@ -3295,224 +3453,4 @@
}
\file_input_stop:
-
-% --------------------------------------------------------------------------
-VERSION HISTORY
-2012/01/28 - version 3.0 - bundled with packages `chemmacros' and `ghs'
-2012/01/30 - version 3.0a - bugfix
- - renamed formula => chemformula
- (following a request by Karl Berry for TeXlive)
-2012/02/03 - version 3.0b - stepped number with `chemmacros'
-2012/02/05 - version 3.0c - stepped number with `chemmacros'
-2012/02/10 - version 3.0d - several bugfixes
- - new arrow type <>
-2012/02/19 - version 3.1 - new arrow types -/>, </- and <o>
- - new commands \DeclareChemArrow, \RenewChemArrow and
- \ShowChemArrow
-2012/02/26 - version 3.1a - stepped number with `chemmacros'
-2012/03/03 - version 3.1b - arrow types are stored in a sequence to automate the
- search and replace in the right order
- - new arrow type ==
- - IUPAC compliance for stoichiometric factors
- - new handling of super- and subscripts to correct
- various flaws: clear distinction between isotope and
- formula
- - new option charge-vshift
-2012/03/14 - version 3.1c - improved arrow labels
-2012/03/20 - version 3.2 - new: option input via @{<options>}
-2012/05/07 - version 3.3 - \ch now bypasses \ref{}, \label{}, and \intertext{}
-2012/05/13 - version 3.3a - stepped number with `chemmacros'
-2012/05/18 - version 3.3b - stepped number with `chemmacros'
-2012/05/18 - version 3.3c - stepped number with `chemmacros'
-2012/07/24 - version 3.3d - stepped number with `chemmacros'
- - default bond length set to 1.1667ex
- - bug fix in the bonds
-2012/08/21 - version 3.3e - stepped number with `chemmacros'
-2012/09/11 - version 3.4 - cleaned a little, minor bug fixes
- - switched to internal scratch variables
- - new command \bond, more bond types
- - new commands \DeclareChemBond, \DeclareChemBondAlias,
- \RenewChemBond and \ShowChemBond
- - radical point thicker, new options `radical-style'
- and `radical-radius'
-2012/10/03 - version 3.4a - stepped number with `chemmacros'
-2013/01/04 - version 3.4b - bug fix in the sub- and superscript handling
-2013/01/28 - version 3.5 - disallow breaks at bonds
- - allow breaks after arrows
- - made some spaces in chemformulas stretch- and
- shrinkable
- - various internal code improvements
- - changed defaults for horizontal spaces that have in
- set in ex into corresponding values in em.
- - improvements to the placement of sub- and superscripts
-2013/02/19 - version 3.5a - stepped number with `chemmacros'
-2013/02/26 - version 3.6 - support for use with the `breqn' package
- - math escaping also via \(\)
- - internal: clearer escaping macros
- - new options: `radical-vshift', `radical-hshift'
- and `radical-space'
- - bug fix: `radical-...' options are now correctly set
- - stoichiometric factors: add leading 0 if missing
- - new option: `stoich-paren-parse'
- - internal changes: be way more rigid about protected
- and expandable macros
- - internal changes: clearer distinction between
- private macros and accessable module macros
- - internal changes: clearer distinction between
- document commands and module level commands
- - !()() syntax now also works with babel's French
-2013/02/27 - version 3.6a - bug fix: escaped text and math stays escaped, i.e.
- also arrow code like `<=>'
-2013/04/19 - version 3.6b - new option `arrow-min-length'
- - bug fix: stoichiometric fractions correctly displayed
-2013/07/06 - version 4.0 - don't need `chemmacros' package any more,
- `chemformula' can be used stand-alone;
- this has lead to a few definitions that previously
- were done by chemmacros; chemmacros will get them
- now from chemformula when needed
- - bug fix: allow braces in subscripts and superscripts
- by disabling superfluous \chemformula_subscript:n
- and \chemformula_superscript:n in the scripts write
- commands
- - remove superfluous rescanning at the begin of the
- formula input; this is handled by the sanitize
- command later anyway
- - changed internal mathshifts from $ ... $ to \( ... \)
- - removed superfluous \textstyle from math-frac
- definition
- - new command \charrow{}[][] that allows direct
- access to chemformula's arrows
- - new command \chname()() that allows direct access
- to chemformula's naming
- - new command \chcpd[]{} that allows typesetting a
- simple single formula - also not nestable with \ch
- - new command \setchemformula
- - package option: `strict'
- - don't allow a line break before a plus
- (`chem-and')
- - don't allow a line break between a stoichiometric
- factor and a compound
- - changed formal charges to match ``plain'' charges
-2013/07/26 - version 4.0a - added options `arrow-penalty' (0), `plus-penalty'
- (700) and `bond-penalty' (10000) that determine if
- there may be a break after an arrow, a bond or the
- plus
-2013/08/24 - version 4.1 - changed `0' values in TikZ coordinates into `0pt'
- see http://tex.stackexchange.com/q/128792/5049 and
- http://tex.stackexchange.com/q/118467/5049 for
- reference
- - new option `tikz-external-disable'
- - new option `frac-math-cmd'
-2013/10/24 - version 4.2 - \chemformula_font_inner: is only applied /once/ to
- a formula, and at the beginning, fixes
- https://bitbucket.org/cgnieder/chemmacros/issue/23
- - fixed wrong setting of the TikZ bond style
- - new option `arrow-style'
- - new command \chlewis
-2013/11/04 - version 4.2a - bug fix in \chcpd,
- - change sanitizing/restoring of category codes
-2014/01/24 - version 4.3 - changed behaviour of \DeclareChem to match
- \DeclareRobustCommand, i.e., no check if command
- is defined; added a \NewChem variant to each that
- /does/ check; use \NewChem instead of \DeclareChem
- for definitions
- - new option stoich-print
- - new command \chstoich
-2014/01/29 - version 4.4 - treat a single `-' as a minus sign
-2014/04/07 - version 4.5 - make sure that < and > have catcode 12 when read
- as parts of arrows
- - new arrow types `>=<', `>=<<', `>>=<' and `<==>'
- - arrow lengths and compound offset now correctly
- adapts to new fontsize if relative lengths (em,ex)
- are used
- - allow optional arguments to \\ in equation
- environments
- - allow optional arguments to \label in equation
- environments
- (credits: http://tex.stackexchange.com/a/166661/5049)
- - support for Kröger-Vink notation
-2014/06/30 - version 4.6 - fix: a comma in a superscript is typeset according
- to `decimal-marker' again
- - fix charge type behaviour: option `circled' and
- `circletype' are now obeyed if the option is
- changed mid-document
- - new option `chemformula/circled' similar to
- `chemmacros/circled'
- - new option `chemformula/circletype' similar to
- `chemmacros/circletype'
-2014/08/04 - version 4.7 - change dependency: pgf library `arrows.meta'
- instead of `arrows'
- - new arrow tip definition allows redeclaration to
- other existing tips by \pgfkeys{cf/.tip=<tip>}
-2014/08/08 - version 4.8 - fix bug introduced in last update: `butt cap' now
- needs to be `Butt Cap' with the new `arrows.meta'
- library
- - split from `chemmacros' bundle as independent
- package
-2014/10/07 - version 4.9 - new options: `minus-space', `minus-penalty',
- `plus-output-symbol' and `minus-output-symbol'
-2015/03/16 - version 4.10 - new macros \NewChemCompoundProperty,
- \RenewChemCompoundProperty,
- \DeclareChemCompoundProperty,
- \RemoveChemCompoundProperty
-2015/04/03 - version 4.10a - bug fix in \__chemformula_input_stoich:n
-2015/06/30 - version 4.11 - small changes in \chcpd
- - remove unnecessary \mathchoice => noticable speed
- improvement
- - \NewChemAdditionSymbol
- - \NewChemSymbol
-2015/08/12 - version 4.12 - remove chemmacros' `circletype' and `circled'
- options. They really belong to chemmacros
- - change requirement amsmath -> amstext
- - shorten definition of double and triple bonds
-2015/08/29 - version 4.12a - \chemformula_formal_plus: ,
- \chemformula_formal_minus:
- \ProvideChem... equivalents to all \NewChem...
- macros
-2015/09/08 - version 4.12b - trim spaces of \ch input -- due to a change in
- l3kernel
-2015/01/01 - version 4.13 - clean up code
- - check for blank input
- - drop support for \[ and \]
- - new option `atom-format'
-2015/10/21 - version 4.14 - fix issue
- https://github.com/cgnieder/chemformula/issues/2
- - new option `adduct-penalty'
-2016/01/07 - version 4.14a - \prop_get:Nn => \prop_item:Nn
-2016/05/03 - version 4.14b - local options now are correctly working again
- - `atom-format' is only applied to formulas
-2016/05/11 - version 4.15 - arrow definitions don't have to be made in a
- certain order any more
- - new quasi equilibria arrows
- - bug fix in \RenewChemArrow
- - meaningful error if \charrow if used with an
- unknown arrow type
-2016/06/08 - version 4.15a - change requirement amstext -> amsmath; \chname
- uses \underset which needs amsmath
-2016/06/08 - version 4.15b - add missing variant of kernel function
-2016/08/21 - version 4.15c - corrected redundant definition of
- \chemformula_single_bond:
- - fix problem with TikZ externalization and
- Kroeger-Vink notation
-2017/02/02 - version 4.15d - allow `name-format' to end with a macro that
- takes an argument
-2017/03/23 - version 4.15e - small bug fix (issue #5)
- - implement \shortintertext bypass
-2019/09/23 - version 4.15f - add missing definition for temporary variable
-2019/09/27 - version 4.15g - bug fix in fontspec option
-2019/10/13 - version 4.15h - new (undocumented) option `set-catcodes'
- - fix behaviour with category codes
- (https://tex.stackexchange.com/q/511592/)
- - fix bug: local format changes are now applied
- again
-2020/02/01 - version 4.15i - fix issue #12
-2020/03/07 - version 4.15j - make sure that < and > have catcode 12 when read
- as arrows -- again...
-2020/03/15 - version 4.15k - fix https://tex.stackexchange.com/questions/532674/
-2020/12/22 - version 4.16 - new option `math-scripts'
- - use LaTeX's new hooks
- - get rid of unnecessary package dependencies
-
% --------------------------------------------------------------------------
-% IDEAS:
-- Addukte: Zahlen nach * und . automatisch erkennen?