From 4dded0aef4bd1be26e84ab78afebf87cc7ecce0a Mon Sep 17 00:00:00 2001 From: Clemens Niederberger Date: Sun, 23 Jan 2022 12:27:54 +0100 Subject: [PATCH] version 4.17 --- HISTORY | 6 +- README | 13 ++- chemformula-manual.cls | 28 +++++- chemformula-manual.tex | 65 ++++++------ chemformula.sty | 219 ++++++++++++++++++++++++++++++++--------- 5 files changed, 238 insertions(+), 93 deletions(-) diff --git a/HISTORY b/HISTORY index 6cf576e..0cc66d3 100644 --- a/HISTORY +++ b/HISTORY @@ -241,10 +241,12 @@ VERSION HISTORY 2020/12/22 - version 4.16 - new option `math-scripts' - use LaTeX's new hooks - get rid of unnecessary package dependencies -2022/??/?? - version 4.17 - adjust options `stoich-print' and `frac-math-cmd' +2022/01/23 - version 4.17 - adjust options `stoich-print' and `frac-math-cmd' and correct bug in `stoich-print' - - lazy boolean evaluation + - deprecate `stoich-print' and introduce `stoich-format' + - lazy boolean evaluation where possible - fix deprecated file hook - implement issue #17 - fix issue #18 - fix issue #19 + - fix typos in code diff --git a/README b/README index 05e609e..fd87280 100644 --- a/README +++ b/README @@ -1,5 +1,5 @@ -------------------------------------------------------------------------- -the CHEMFORMULA package v4.17 2022/??/?? +the CHEMFORMULA package v4.17 2022/01/23 typeset chemical compounds and reactions @@ -23,9 +23,14 @@ This work has the LPPL maintenance status `maintained'. The Current Maintainer of this work is Clemens Niederberger. -------------------------------------------------------------------------- The chemformula package consists of the following files - - chemformula.sty, - - chemformula-manual.cls, chemformula-manual.tex, chemformula-manual.pdf, - - README + == STYLE FILES == + chemformula.sty + == DOCUMENTATION FILES == + chemformula-manual.tex + chemformula-manual.pdf + chemformula-manual.cls + README + HISTORY -------------------------------------------------------------------------- If you have any ideas, questions, suggestions or bugs to report, please feel free to contact me. diff --git a/chemformula-manual.cls b/chemformula-manual.cls index ec88f15..0c0061d 100644 --- a/chemformula-manual.cls +++ b/chemformula-manual.cls @@ -26,7 +26,7 @@ % % The Current Maintainer of this work is Clemens Niederberger. % -------------------------------------------------------------------------- -\ProvidesClass{chemformula-manual}[2022/01/07] +\ProvidesClass{chemformula-manual}[2022/01/23] \LoadClass[load-preamble,add-index]{cnltx-doc} \RequirePackage{imakeidx} @@ -301,6 +301,30 @@ \itemize\let\change\item }{\enditemize} +\chemsetup{ + greek = newtx , + formula = chemformula , + chemformula/format = \libertineLF +} + +\usepackage{acro} +\acsetup{ + format/long = \scshape , + format/short = \scshape +} +\DeclareAcronym{iupac}{ + short = iupac , + long = International Union of Pure and Applied Chemistry , + pdfstring = IUPAC , + short-acc = IUPAC +} + +\sisetup{ + detect-mode=false, + mode=text, + text-font-command=\libertineLF +} + \chemformula@add@version{2012-01-28}{3.0} \chemformula@add@version{2012-01-30}{3.0a} \chemformula@add@version{2012-02-03}{3.0b} @@ -360,6 +384,6 @@ \chemformula@add@version{2020-03-07}{4.15j} \chemformula@add@version{2020-03-15}{4.15k} \chemformula@add@version{2020-12-22}{4.16} -\chemformula@add@version{2022-01-07}{4.17} +\chemformula@add@version{2022-01-23}{4.17} \endinput diff --git a/chemformula-manual.tex b/chemformula-manual.tex index 9b3ee78..e1d592a 100644 --- a/chemformula-manual.tex +++ b/chemformula-manual.tex @@ -1,5 +1,5 @@ -% !arara: pdflatex -% !arara: biber +% arara: pdflatex +% arara: biber % arara: pdflatex % arara: pdflatex % -------------------------------------------------------------------------- @@ -33,31 +33,6 @@ \documentclass{chemformula-manual} \addbibresource{cnltx.bib} - -\chemsetup{ - greek = newtx , - formula = chemformula , - chemformula/format = \libertineLF -} - -\usepackage{acro} -\acsetup{ - format/long = \scshape , - format/short = \scshape -} -\DeclareAcronym{iupac}{ - short = iupac , - long = International Union of Pure and Applied Chemistry , - pdfstring = IUPAC , - short-acc = IUPAC -} - -\sisetup{ - detect-mode=false, - mode=text, - text-font-command=\libertineLF -} - \addbibresource{\jobname.bib} \begin{filecontents*}{\jobname.bib} @book{iupac:greenbook, @@ -231,7 +206,7 @@ \section{Stoichiometric Factors} (1/5) K "\ox{7,Mn}" O4 + (8/5) HCl == (1/5) "\ox{2,Mn}" Cl2 + (1/2) Cl2 + (1/5) KCl + (4/5) H2O \end{reaction*} -There are a few possibilities to customize the output. +There are a few possibilities to customize the output: \begin{options} \keyval{decimal-marker}{marker}\Default{.} The symbol to indicate the decimal. @@ -246,9 +221,14 @@ \section{Stoichiometric Factors} \keybool{stoich-paren-parse}\Default{false} If set to true stoichiometric factors enclosed by parentheses also are parsed. + \keyval{stoich-format}{code}\Default + \sinceversion{4.17}Allows formatting of the stoichiometric factors. The + last macro given may take an argument. \keyval{stoich-print}{code containing \#1}\Default{\#1} - \changedversion{4.17}This option allows to adjust how stoichiometric - factors are printed. + \changedversion{4.17}This option allows to use specify a macro for + printing the stoichiometric factors where \code{\#1} represents the + factor. \emph{This option is depecated and will be removed some time in + the future. Use \option{stoich-format} instead.} \end{options} \begin{example} @@ -356,11 +336,6 @@ \subsection{Commands} \end{sourcecode} See section~\ref{ssec:text} for a way around this. -Please also note that formulas are placed inside a group! -\begin{example}[side-by-side] - \ch{A2\color{red}B3 C4} -\end{example} - \subsection{Charges and Other Superscripts} \paragraph{Basics} If a compound \emph{ends} with a plus or minus sign it will be treated as @@ -1016,6 +991,16 @@ \subsection{Labels} \ch{A ->[ "\chemfig{-[:30]-[:-30]OH}" ] B} \par \end{example} +The\sinceversion{4.17} labels are typeset inside of a \env*{tabular}\Marg{c} +environment. This means you can get several lines: +\begin{example}[side-by-side] + \ch{A ->[{a\\b}] B} \par + \ch{A ->[a \newline b] B} +\end{example} +The command \cs*{\textbackslash} must be hidden in order to +work. \cs*{tabularnewline} does work, of course. For convenience \chemformula\ +also allows \cs*{newline} here. + \subsection{Customization} These are the options which enable you to customize the arrows: \begin{options} @@ -1188,7 +1173,8 @@ \subsection{Customization} \chemformula\ provides two options to customize the output of the names: \begin{options} \keyval{name-format}{commands}\Default{\cs*{scriptsize}\cs*{centering}} - The format of the name. This can be arbitrary input. + \changedversion{4.15d}The format of the name. This can be arbitrary input + and the last macro may receive the name as an argument. \keychoice{name-width}{\meta{dim},auto}\Default{auto} The width of the box where the label is put into. \code{auto} will detect the width of the name and set the box to this width. @@ -1574,6 +1560,13 @@ \section{History Since Version~4.0} and code. \end{changes} +\begin{changes}{4.17} + \change Various bug fixes. + \change Lazy boolean evaluation where possible. + \change Place arrow's arguments in a tabular. This allows for multiple + lines. +\end{changes} + \printbibliography \end{document} diff --git a/chemformula.sty b/chemformula.sty index e1896b0..3a7b1d9 100644 --- a/chemformula.sty +++ b/chemformula.sty @@ -30,7 +30,7 @@ \usetikzlibrary{arrows.meta} \ExplSyntaxOn -\tl_const:Nn \c_chemformula_date_tl {2022/01/08} +\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 @@ -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 @@ -266,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 @@ -366,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: @@ -1149,7 +1270,7 @@ \l__chemformula_input_tl \l__chemformula_catcodes_tl \chemformula_write:V \l__chemformula_input_tl - \tl_show:N \l__chemformula_input_tl + \__chemformula_if_debug:T { \tl_show:N \l__chemformula_input_tl } } \group_end: } @@ -1161,11 +1282,11 @@ \cs_new_protected:Npn \__chemformula_read_input:w #1 ~ #2 \q_stop { \__chemformula_input:n {#1} - \tl_set:Nn \l__chemmacros_tmpa_tl {#2} - \tl_if_blank:VF \l__chemmacros_tmpa_tl + \tl_set:Nn \l__chemformula_tmpa_tl {#2} + \tl_if_blank:VF \l__chemformula_tmpa_tl { - \tl_trim_spaces:N \l__chemmacros_tmpa_tl - \__chemformula_read_input:V \l__chemmacros_tmpa_tl + \tl_trim_spaces:N \l__chemformula_tmpa_tl + \__chemformula_read_input:V \l__chemformula_tmpa_tl } } @@ -1367,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 @@ -1392,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} @@ -2141,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 @@ -2155,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 } } @@ -2184,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 { @@ -2195,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 @@ -2219,13 +2341,19 @@ { \chemformula_parse_stoich:n {#1} } \cs_generate_variant:Nn \chemformula_print_stoich:n {V} -\cs_new_protected:Npn \__chemformula_print_stoich:n #1 {#1} +\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_print_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 { @@ -2290,7 +2418,7 @@ { \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 {\__chemformula_print_stoich:n {#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 @@ -2348,7 +2476,7 @@ \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 @@ -2530,12 +2658,6 @@ \__chemformula_if_only_parens:nTF {#2} { \tl_put_right:Nn #1 {#2} } { - % start with formatting: - % \tl_put_right:Nn #1 - % { - % \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: @@ -2576,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 @@ -3004,8 +3124,9 @@ 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-print .cs_set_protected:Np = \__chemformula_print_stoich:n #1 , - stoich-print .initial:n = #1 , + stoich-format .tl_set:N = \l__chemformula_stoich_format_tl , + stoich-print .code:n = + \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 ,