diff options
author | Karl Berry <karl@freefriends.org> | 2018-04-30 17:05:54 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-04-30 17:05:54 +0000 |
commit | 2595862e871c121eb470cdd8f5a7a73970e9c398 (patch) | |
tree | bbba94460d3bd4f4dd2541e5a59a6e8080f20053 /Master/texmf-dist/tex/latex/cooking-units | |
parent | d628af7b1a32a21730b60108f0a4fd66434d3588 (diff) |
cooking-units (20apr18)
git-svn-id: svn://tug.org/texlive/trunk@47514 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/cooking-units')
-rw-r--r-- | Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty | 1796 |
1 files changed, 1064 insertions, 732 deletions
diff --git a/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty b/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty index 466ca5b3b63..7e53a0129f6 100644 --- a/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty +++ b/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty @@ -5,16 +5,16 @@ %% The original source files were: %% %% cooking-units.dtx (with options: `package') -%% Copyright (C) 2016--2017 by Ben Vitecek (current Maintainer) +%% Copyright (C) 2016--2018 by Ben Vitecek (current Maintainer) %% %% This file 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 1.3c 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 +%% https://ctan.org/license/lppl1.3c %% -%% and version 1.3 or later is part of all distributions of +%% and version 1.3c or later is part of all distributions of %% LaTeX version 2008-05-04 or later. %% %% This work has the LPPL maintenance status `maintained'. @@ -22,7 +22,6 @@ %% This work consists of the files README.md, cooking-units.dtx and cooking-units.ins %% and the derived file cooking-units.sty. %% -%% \@ifpackageloaded {xparse} { } { \RequirePackage {xparse} } @@ -31,10 +30,10 @@ { \RequirePackage {expl3} } \ProvidesExplPackage {cooking-units} - {2017/10/23} - {1.2} + {2018/04/20} + {1.30} {Ein Paket fuer Kocheinheiten} -\@ifpackagelater { expl3 } { 2017/09/18 } +\@ifpackagelater { expl3 } { 2018/02/21 } { } { \PackageError { cooking-units } { Support~package~expl3~too~old } @@ -75,17 +74,20 @@ } \cs_generate_variant:Nn \tl_replace_all:Nnn { NVn } \cs_generate_variant:Nn \tl_replace_once:Nnn { NnV, NVn } -\cs_generate_variant:Nn \tl_if_in:nnTF { nVTF } +\cs_generate_variant:Nn \tl_if_in:nnTF { nV , xn } \cs_generate_variant:Nn \tl_if_in:NnTF { NVTF } \cs_generate_variant:Nn \tl_if_in:NnT { NVT } -\cs_generate_variant:Nn \fp_compare:nNnT { cNnT } -\cs_generate_variant:Nn \fp_eval:n { c } -\cs_generate_variant:Nn \prop_get:cVN { cVc } -\cs_generate_variant:Nn \int_abs:n { c } -\cs_generate_variant:Nn \tl_show:n { x , f } +\cs_generate_variant:Nn \fp_compare:nNnT { vNnT } +\cs_generate_variant:Nn \prop_get:NnN { cVc } +\cs_generate_variant:Nn \tl_set_rescan:Nnn { NnV } +\cs_generate_variant:Nn \msg_error:nnnn { nnnV } +\cs_generate_variant:Nn \msg_error:nnn { nnV } +\cs_new:Npn \__cooking_units_dim_horizontal:N #1 { \tex_kern:D #1 } \cs_new_eq:NN \__cooking_units_frac:nn \sfrac -\cs_new:Npn \__cooking_units_print_numeral:n #1 {} -\cs_new:Npn \__cooking_units_print_Numeral:n #1 {} +\cs_new_eq:NN \__cooking_units_set_amount:Nn \tl_set:Nn +\cs_new_eq:NN \__cooking_units_set_unit:Nn \tl_set:Nn +\cs_new:Npn \__cooking_units_print_numeral:n #1 { } +\cs_new:Npn \__cooking_units_print_Numeral:n #1 { } \bool_if:NT \g__cooking_units_opt_numeral_bool { \cs_set_eq:NN \__cooking_units_print_numeral:n \numberstringnum @@ -97,6 +99,7 @@ \tl_new:N \l__cooking_units_tmpa_tl \tl_new:N \l__cooking_units_tmpb_tl \tl_new:N \l__cooking_units_mixed_fraction_tl +\tl_new:N \l__cooking_units_given_amount_tl \tl_new:N \l__cooking_units_given_unit_tl \tl_new:N \l__cooking_units_option_unit_tl \tl_new:N \l__cooking_units_language_tl @@ -109,17 +112,23 @@ \tl_new:N \l__cooking_units_input_allowed_special_signs_tl \tl_new:N \c__cooking_units_input_str_hash_one_tl \tl_new:N \l__cooking_units_input_range_sign_tl -\tl_new:N \l__cooking_units_input_times_persons_sign \tl_new:N \l__cooking_units_cutext_space_tl \tl_new:N \l__cooking_units_cuphrase_space_tl \tl_new:N \l__cooking_units_translation_tmpa_tl \tl_new:N \l__cooking_units_cutext_last_value_tl \tl_new:N \l__cooking_units_phantom_tl \tl_new:N \l__cooking_units_phrase_phrase_tl -\tl_new:N \l__cooking_units_unit_key_not_allowed_tl +\tl_new:N \l__cooking_units_unit_letter_not_allowed_tl +\tl_new:N \l__cooking_units_input_fraction_sign_tl +\tl_new:N \l__cooking_units_input_mixed_fraction_sign_tl +\tl_new:N \l__cooking_units_cunum_hook_tl +\tl_new:N \l__cooking_units_cutext_hook_tl +\tl_new:N \l__cooking_units_Cutext_hook_tl +\tl_new:N \l__cooking_units_cuam_hook_tl \tl_set:Nn \l__cooking_units_input_digits_tl { 0123456789 } -\tl_set:Nn \l__cooking_units_input_times_persons_sign { * } \tl_set:Nn \l__cooking_units_input_range_sign_tl { -- } +\tl_set:Nn \l__cooking_units_input_fraction_sign_tl { / } +\tl_set:Nn \l__cooking_units_input_mixed_fraction_sign_tl { _ } \tl_set:Nn \l__cooking_units_input_decimal_mark_tl { . , } \tl_set:Nn \l__cooking_units_input_value_signs_tl { + - } \tl_set:Nn \l__cooking_units_input_allowed_special_signs_tl { ? } @@ -130,7 +139,7 @@ \tl_set:Nn \l__cooking_units_value_unit_space_tl { \thinspace } \tl_set:Nn \l__cooking_units_cutext_space_tl { \space } \tl_set:Nn \l__cooking_units_cuphrase_space_tl { \space } -\tl_set:Nn \l__cooking_units_unit_key_not_allowed_tl { , / } +\tl_set:Nn \l__cooking_units_unit_letter_not_allowed_tl { , / } \AtBeginDocument { \cs_if_free:cT { T@TS1 } { @@ -155,27 +164,26 @@ } \dim_new:N \l__cooking_units_mixed_frac_dim \dim_set:Nn \l__cooking_units_mixed_frac_dim { 0.1 em } -\int_new:N \l__cooking_units_significant_figures_int -\int_new:N \l__cooking_units_significant_figures_plus_one_int -\int_set:Nn \l__cooking_units_significant_figures_int { 2 } -\int_set:Nn \l__cooking_units_significant_figures_plus_one_int { 2 + 1 } +\int_new:N \l__cooking_units_round_precision_int +\int_set:Nn \l__cooking_units_round_precision_int { 2 } \int_new:N \l__cooking_units_print_numerals_below_int \int_set:Nn \l__cooking_units_print_numerals_below_int { 13 } -\int_new:N \l__cooking_units_number_of_persons_tmpa_int -\int_new:N \l__cooking_units_calc_for_number_of_persons_int -\int_set:Nn \l__cooking_units_calc_for_number_of_persons_int { 4 } +\int_new:N \l__cooking_units_local_number_of_persons_int +\int_new:N \l__cooking_units_wanted_number_of_persons_int +\int_set:Nn \l__cooking_units_wanted_number_of_persons_int { 4 } \int_new:N \l__cooking_units_phrase_number_tl \seq_new:N \l__cooking_units_list_of_defined_keys_seq \seq_new:N \g__cooking_units_list_of_defined_units_seq \clist_new:N \g__cooking_units_allowed_special_keys_clist \clist_new:N \l__cooking_units_phrase_numbers_clist \seq_new:N \l__cooking_units_temperatures_to_check_seq +\seq_new:N \l__cooking_units_curef_do_not_change_seq \prop_new:N \l__cooking_units_phrase_prop \bool_new:N \l__cooking_units_minus_bool -\bool_new:N \l__cooking_units_round_decimal_part_bool +\bool_new:N \l__cooking_units_round_number_bool \bool_new:N \l__cooking_units_error_bool \bool_new:N \l__cooking_units_eval_fractions_bool -\bool_new:N \l__cooking_units_parse_input_bool +\bool_new:N \l__cooking_units_draft_bool \bool_new:N \l__cooking_units_round_to_int_bool \bool_new:N \l__cooking_units_special_sign_bool \bool_new:N \l__cooking_units_single_key_bool @@ -185,24 +193,31 @@ \bool_new:N \l__cooking_units_error_for_unknown_value_bool \bool_new:N \l__cooking_units_using_cutext_bool \bool_new:N \l__cooking_units_cuam_old_bool -\bool_new:N \l__cooking_units_calc_for_persons_bool +\bool_new:N \l__cooking_units_change_number_of_persons_bool \bool_new:N \l__cooking_units_calc_because_ref_was_given_bool -\bool_new:N \l__cooking_units_calc_persons_bool +\bool_new:N \l__cooking_units_lokal_persons_bool \bool_new:N \l__cooking_units_cutext_to_cunum_bool \bool_new:N \l__cooking_units_cutext_old_bool \bool_new:N \l__cooking_units_cutext_change_unit_bool \bool_new:N \l__cooking_units_round_commercial_bool \bool_new:N \l__cooking_units_use_phrases_bool -\bool_new:N \l__cooking_units_check_if_phrase_used_bool -\bool_new:N \l__cooking_units_local_numeral_bool +\bool_new:N \l__cooking_units_lokal_phrase_bool +\bool_new:N \l__cooking_units_print_numeral_bool +\bool_new:N \l__cooking_units_lokal_numeral_bool +\bool_new:N \l__cooking_units_round_precision_positive_bool +\bool_new:N \l__cooking_units_fourty_two_bool \bool_new:N \l__cooking_units_range_in_input_bool -\bool_new:N \l__cooking_units_fraction_in_input_bool +\bool_new:N \l__cooking_units_lokal_fraction_bool +\bool_new:N \l__cooking_units_print_fraction_bool +\bool_new:N \l__cooking_units_lokal_mixed_fraction_bool \bool_new:N \l__cooking_units_decimal_in_input_bool -\bool_set_true:N \l__cooking_units_parse_input_bool \bool_set_true:N \l__cooking_units_cutext_change_unit_bool -\bool_set_eq:NN \l__cooking_units_local_numeral_bool \g__cooking_units_opt_numeral_bool +\bool_set_eq:NN \l__cooking_units_print_numeral_bool \g__cooking_units_opt_numeral_bool \quark_new:N \q__cooking_units_range \quark_new:N \q__cooking_units_no_translation +\quark_new:N \q__cooking_units_decimal +\quark_new:N \q__cooking_units_frac +\quark_new:N \q__cooking_units_mixed_frac \fp_new:N \l__cooking_units_tmpa_fp \clist_new:N \l__cooking_units_tmpa_clist \prop_new:N \l__cooking_units_tmpa_prop @@ -212,73 +227,120 @@ \int_new:N \l__cooking_units_tmpb_int \keys_define:nn { cooking-units } { - eval-fraction .bool_set:N = \l__cooking_units_eval_fractions_bool , - eval-fraction .default:n = { false } , - round-precision .code:n = + add-unit-to-group .code:n = { - \int_set:Nn \l__cooking_units_significant_figures_int {#1} - \int_set:Nn \l__cooking_units_significant_figures_plus_one_int { #1 + \c_one } + \keyval_parse:NNn + \__cooking_units_unit_group_add_unit_error:n + \__cooking_units_unit_group_add_unit:nn + {#1} } , - round-precision .default:n = { 2 } , - round-to-int .bool_set:N = \l__cooking_units_round_to_int_bool , - round-to-int .default:n = { false } , - range-sign .meta:n = + add-unit-to-group .default:n = {} , + set-option-for .code:n = { - cunum-range-sign = {#1} , - cutext-range-sign = {#1} + \keyval_parse:NNn + \__cooking_units_set_options_for_error:n + \__cooking_units_set_options_for:nn + {#1} + }, + add-option-for .code:n = + { + \keyval_parse:NNn + \__cooking_units_add_options_for_error:n + \__cooking_units_add_options_for:nn + {#1} + }, + erase-all-options .code:n = + { + \seq_map_inline:Nn \g__cooking_units_list_of_defined_units_seq + { + \clist_clear:c { l__cooking_units_predefined_option_ ##1 _clist } + } + }, + erase-all-options .value_forbidden:n = { true } , + erase-all-options-for .code:n = + { + \keyval_parse:NNn + \__cooking_units_erase_options_for:n + \__cooking_units_erase_options_for_error:nn + {#1} + }, + erase-all-options-for .value_required:n = { true } , + cutext-to-cunum .bool_set:N = \l__cooking_units_cutext_to_cunum_bool , + cutext-to-cunum .default:n = { false } , + cutext-to-cunum .groups:n = { change-command } , + cutext-change-unit .bool_set:N = \l__cooking_units_cutext_change_unit_bool , + cutext-change-unit .default:n = { true } , + cuam-version .choices:nn = + { new , old } + { + \int_case:nn { \l_keys_choice_int } + { + { 1 } { \bool_set_false:N \l__cooking_units_cuam_old_bool } + { 2 } { \bool_set_true:N \l__cooking_units_cuam_old_bool } + } } , - range-sign .default:n = { -- } , - cunum-range-sign .tl_set:N = \l__cooking_units_cunum_range_sign_tl , - cunum-range-sign .default:n = { -- } , - cutext-range-sign .tl_set:N = \l__cooking_units_cutext_range_sign_tl , - cutext-range-sign .default:n = { -- } , - amount-unit-space .tl_set:N = \l__cooking_units_value_unit_space_tl , - amount-unit-space .default:n = { \thinspace } , - fraction-command .code:n = { \cs_set_eq:NN \__cooking_units_frac:nn #1 } , - fraction-command .default:n = { \sfrac } , - fraction-inline .code:n = { \cs_set:Npn \__cooking_units_frac:nn ##1##2 {#1} } , - fraction-inline .default:n = { \sfrac {#1} {#2} } , - mixed-fraction-space .dim_set:N = \l__cooking_units_mixed_frac_dim , - mixed-fraction-space .default:n = { 0.1 em } , - parse-number .bool_set:N = \l__cooking_units_parse_input_bool , - parse-number .default:n= { true } , - add-special-sign .code:n = + cuam-version .default:n = { new } , + cutext-version .choices:nn = + { new , old } { - \str_if_eq:nnTF {#1} { < } - { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } - { \tl_put_right:Nn \l__cooking_units_input_allowed_special_signs_tl {#1} } + \int_case:nn { \l_keys_choice_int } + { + { 1 } { \bool_set_false:N \l__cooking_units_cutext_old_bool } + { 2 } { \bool_set_true:N \l__cooking_units_cutext_old_bool } + } } , - add-special-sign .default:n = { } , + cutext-version .default:n = { new } , + expand-both .choices:nn = + { n , o , f , x } + { + \cs_set_eq:Nc \__cooking_units_set_unit:Nn { tl_set:N \l_keys_choice_tl } + \cs_set_eq:Nc \__cooking_units_set_amount:Nn { tl_set:N \l_keys_choice_tl } + } , + expand-both .default:n = { n } , + expand-amount .choices:nn = + { n , o , f , x } + { + \cs_set_eq:Nc \__cooking_units_set_amount:Nn { tl_set:N \l_keys_choice_tl } + } , + expand-amount .default:n = { n } , + expand-unit .choices:nn = + { n , o , f , x } + { + \cs_set_eq:Nc \__cooking_units_set_unit:Nn { tl_set:N \l_keys_choice_tl } + } , + expand-unit .default:n = { n } , set-special-sign .code:n = { - \str_if_eq:nnTF {#1} { < } - { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } - { \tl_set:Nn \l__cooking_units_input_allowed_special_signs_tl {#1} } + \tl_map_inline:nn {#1} + { + \str_if_eq:nnT {##1} { < } + { + \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } + \tl_map_break:n { \use_none:nn } + } + } + \use:n { \tl_set:Nn \l__cooking_units_input_allowed_special_signs_tl {#1} } } , - input-range-sign .tl_set:N = \l__cooking_units_input_range_sign_tl , - input-range-sign .default:n = { -- } , - check-temperature .bool_set:N = \l__cooking_units_check_temperature_bool , - check-temperature .default:n = { true } , - add-temperature-to-check .code:n = + add-special-sign .code:n = { - \keyval_parse:NNn - \__cooking_units_temperature_to_check_print_error:n - \__cooking_units_temperatures_to_check_define:nn - {#1} - }, - temperature-to-check .value_required:n = { true } , - convert-to-eV .bool_set:N = \l__cooking_units_convert_to_eV_bool , - convert-to-eV .default:n = { true } , - convert-to-eV .groups:n = { change-unit } , - use-numerals-below .int_set:N = \l__cooking_units_print_numerals_below_int , - use-numerals-below .default:n = { 13 } , + \tl_map_inline:nn {#1} + { + \str_if_eq:nnTF {##1} { < } + { + \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } + }{ + \tl_put_right:Nn \l__cooking_units_input_allowed_special_signs_tl {##1} + } + } + } , + add-special-sign .default:n = { } , set-unknown-message .choices:nn = { error , warning , none } { \msg_redirect_name:nnn { cooking-units } { amount-not-known } { \l_keys_choice_tl } } , - set-unknown-message .default:n = { warning } , + set-unknown-message .default:n = { set-cutext-translation-message } , set-cutext-translation-message .choices:nn = { error , warning , none } { @@ -286,13 +348,34 @@ { \l_keys_choice_tl } } , set-cutext-translation-message .default:n = { warning } , - erase-all-options .code:n = + print-numerals .bool_set:N = \l__cooking_units_print_numeral_bool , + print-numerals .default:n = { true } , + use-numerals-below .int_set:N = \l__cooking_units_print_numerals_below_int , + use-numerals-below .default:n = { 13 } , + parse-number .bool_set_inverse:N = \l__cooking_units_draft_bool , + parse-number .default:n= { true } , + range-sign .meta:n = { - \seq_map_inline:Nn \g__cooking_units_list_of_defined_units_seq - { - \clist_clear:c { l__cooking_units_predefined_option_##1_clist } - } - }, + cunum-range-sign = {#1} , + cutext-range-sign = {#1} + } , + range-sign .default:n = { -- } , + cunum-range-sign .tl_set:N = \l__cooking_units_cunum_range_sign_tl , + cunum-range-sign .default:n = { -- } , + cutext-range-sign .tl_set:N = \l__cooking_units_cutext_range_sign_tl , + cutext-range-sign .default:n = { -- } , + use-phrases .bool_set:N = \l__cooking_units_use_phrases_bool , + use-phrases .default:n = { true } , + round-precision .code:n = + { + \int_set:Nn \l__cooking_units_round_precision_int {#1} + \int_compare:nNnTF {#1} < { 0 } + { \bool_set_false:N \l__cooking_units_round_precision_positive_bool } + { \bool_set_true:N \l__cooking_units_round_precision_positive_bool } + } , + round-precision .default:n = { 2 } , + round-to-int .bool_set:N = \l__cooking_units_round_to_int_bool , + round-to-int .default:n = { false } , round-half .choices:nn = { default , commercial } { @@ -303,7 +386,23 @@ } }, round-half .default:n = { default }, - set-number-of-persons .int_set:N = \l__cooking_units_calc_for_number_of_persons_int , + eval-fraction .bool_set:N = \l__cooking_units_eval_fractions_bool , + eval-fraction .default:n = { false } , + fraction-command .code:n = { \cs_set_eq:NN \__cooking_units_frac:nn #1 } , + fraction-command .default:n = { \sfrac } , + fraction-inline .code:n = { \cs_set:Npn \__cooking_units_frac:nn ##1##2 {#1} } , + fraction-inline .default:n = { \sfrac {#1} {#2} } , + mixed-fraction-space .dim_set:N = \l__cooking_units_mixed_frac_dim , + mixed-fraction-space .default:n = { 0.1 em } , + cutext-space .tl_set:N = \l__cooking_units_cutext_space_tl , + cutext-space .default:n = { \space } , + phrase-space .tl_set:N = \l__cooking_units_cuphrase_space_tl , + phrase-space .default:n = { \space } , + amount-unit-space .tl_set:N = \l__cooking_units_value_unit_space_tl , + amount-unit-space .default:n = { \thinspace } , + recalculate-amount .bool_set:N = \l__cooking_units_change_number_of_persons_bool , + recalculate-amount .default:n = { false } , + set-number-of-persons .int_set:N = \l__cooking_units_wanted_number_of_persons_int , set-number-of-persons .default:n = { 4 } , label .code:n = { @@ -320,46 +419,48 @@ \__cooking_units_reference_label_and_persons:n {#1} } , ref .value_required:n = { true } , - cuam-version .choices:nn = - { new , old } + check-temperature .bool_set:N = \l__cooking_units_check_temperature_bool , + check-temperature .default:n = { true } , + add-temperature-to-check .code:n = { - \int_case:nn { \l_keys_choice_int } - { - { 1 } { \bool_set_false:N \l__cooking_units_cuam_old_bool } - { 2 } { \bool_set_true:N \l__cooking_units_cuam_old_bool } - } - } , - cuam-version .default:n = { new } , - cutext-version .choices:nn = - { new , old } + \keyval_parse:NNn + \__cooking_units_temperature_to_check_print_error:n + \__cooking_units_temperatures_to_check_define:nn + {#1} + }, + temperature-to-check .value_required:n = { true } , + convert-to-eV .bool_set:N = \l__cooking_units_convert_to_eV_bool , + convert-to-eV .default:n = { true } , + convert-to-eV .groups:n = { change-unit } , + add-natural-unit .code:n = { - \int_case:nn { \l_keys_choice_int } - { - { 1 } { \bool_set_false:N \l__cooking_units_cutext_old_bool } - { 2 } { \bool_set_true:N \l__cooking_units_cutext_old_bool } - } + \__cooking_units_error_if_unit_not_defined:n {#1} + \seq_set_from_clist:Nn \l__cooking_units_tmpa_seq {#1} + \seq_concat:NNN \g__cooking_units_natural_units_seq \g__cooking_units_natural_units_seq \l__cooking_units_tmpa_seq + \seq_remove_duplicates:N \g__cooking_units_natural_units_seq } , - cutext-version .default:n = { new } , - recalculate-amount .bool_set:N = \l__cooking_units_calc_for_persons_bool , - recalculate-amount .default:n = { false } , - cutext-to-cunum .bool_set:N = \l__cooking_units_cutext_to_cunum_bool , - cutext-to-cunum .default:n = { false } , - cutext-space .tl_set:N = \l__cooking_units_cutext_space_tl , - cutext-space .default:n = { \space } , - phrase-space .tl_set:N = \l__cooking_units_cuphrase_space_tl , - phrase-space .default:n = { \space } , - cutext-change-unit .bool_set:N = \l__cooking_units_cutext_change_unit_bool , - cutext-change-unit .default:n = { true } , - use-phrases .bool_set:N = \l__cooking_units_use_phrases_bool , - use-phrases .default:n = { true } , - print-numerals .bool_set:N = \l__cooking_units_local_numeral_bool , - print-numerals .default:n = { true } , + add-natural-unit .value_required:n = { true } , + 42 .bool_set:N = \l__cooking_units_fourty_two_bool , + 42 .default:n = { true } , + input-range-sign .tl_set:N = \l__cooking_units_input_range_sign_tl , + input-range-sign .default:n = { -- } , numeral-function .code:n = { \cs_set_eq:NN \__cooking_units_print_numeral:n #1 } , Numeral-function .code:n = { \cs_set_eq:NN \__cooking_units_print_Numeral:n #1 } , + commands-add-hook .meta:n = + { + cunum-add-hook = {#1} , + cutext-add-hook = {#1} , + Cutext-add-hook = {#1} , + cuam-add-hook = {#1} , + } , + cunum-add-hook .code:n = { \tl_put_right:Nn \l__cooking_units_cunum_hook_tl {#1} } , + cutext-add-hook .code:n = { \tl_put_right:Nn \l__cooking_units_cutext_hook_tl {#1} } , + Cutext-add-hook .code:n = { \tl_put_right:Nn \l__cooking_units_Cutext_hook_tl {#1} } , + cuam-add-hook .code:n = { \tl_put_right:Nn \l__cooking_units_cuam_hook_tl {#1} } , } \msg_new:nnnn { cooking-units } { fraction-not-allowed-with-range } { - 'You' \ cannot \ use \ '/' \ ( and \ '_' )\ in \ combination \ + You \ cannot \ use \ '/' \ ( and \ '_' )\ in \ combination \ with \ '\l__cooking_units_input_range_sign_tl' \ in \ '#1'. }{ You \ cannot \ use \ fractions \ with \ a \ range. @@ -368,16 +469,24 @@ \msg_new:nnnn { cooking-units } { missing-slash } { You \ cannot \ use \ '_' \ without \ - '/' in '#1'. + '/' \ in \ '#1'. }{ You \ cannot \ have \ a \ mixed \ fraction \ ('_') \ without \ a \ normal \ fraction \ ('/'). \msg_see_documentation_text:n { cooking-units } } +\msg_new:nnnn { cooking-units } { fraction-wrong-order } + { + You \ cannot \ use \ '/' \ before \ '_' \ in \ '#1'. + }{ + You \ can \ only \ use \ '_' \ before \ '/'. + \msg_see_documentation_text:n { cooking-units } + } \msg_new:nnnn { cooking-units } { unknown-unit } { The \ unit \ '#1' \ is \ not \ defined. \ Use \ - \newcookingunit \ to \ define \ new \ units. + \newcookingunit ~ (or \ one \ of \ the \ others) \ to \ + define \ new \ units. }{ Define \ units \ before \ using \ or \ check \ if \ the \ unit-key \ is \ written \ correctly. @@ -390,31 +499,52 @@ key \ for \ a \ new \ unit. \msg_see_documentation_text:n {cooking-units} } +\msg_new:nnnn { cooking-units } { character-not-allowed } + { + Unit-keys \ are \ not \ allowed \ to \ either \ contain \ ',' \ or \ '/' \ + in \ '#1'. + }{ + The \ unit-key \ is \ not \ allowed \ to \ contain \ ',' \ or \ '/'. \ + Due \ to \ internal \ reasons. + \msg_see_documentation_text:n {cooking-units} + } \msg_new:nnnn { cooking-units } { missing-argument } - { There \ is \ an \ missing \ argument. } + { There \ is \ a \ missing \ argument. } { You \ probably \ have \ forgotten \ a \ curly-brace \ pair. \msg_see_documentation_text:n {cooking-units} } \msg_new:nnnn { cooking-units } { Division-by-zero } - { Division\ by \ zero \ is \ not \ allowed. } + { Division\ by \ zero \ is \ not \ allowed \ in \ '#1'. } { See \ a \ math \ book \ of \ your \ choice \ or \ for \ example \ Wikipedia. } \msg_new:nnnn { cooking-units } { Token-not-allowed } - { The \ token \ '#1' \ is \ not \ allowed. } + { The \ token \ '#1' \ is \ not \ allowed \ in \ '#2'. } { The \ command \ accepts \ only \ a \ fixed \ number \ of \ tokens. \msg_see_documentation_text:n {cooking-units} } \msg_new:nnnn { cooking-units } { Second-decimal-sign-not-allowed } - { A \ second \ decimal \ sign \ is \ not \ allowed. } + { A \ second \ decimal \ sign \ is \ not \ allowed \ in \ '#1'. } + { + Perhaps \ you \ didn't \ type \ it \ correctly. + \msg_see_documentation_text:n {cooking-units} + } +\msg_new:nnnn { cooking-units } { Second-fraction-sign-not-allowed } + { A \ second \ fraction \ sign \ is \ not \ allowed \ in \ '#1'. } + { + Perhaps \ you \ didn't \ type \ it \ correctly. + \msg_see_documentation_text:n {cooking-units} + } +\msg_new:nnnn { cooking-units } { Second-mixed-fraction-sign-not-allowed } + { A \ second \ mixed \ fraction \ sign \ is \ not \ allowed \ in \ '#1'. } { Perhaps \ you \ didn't \ type \ it \ correctly. \msg_see_documentation_text:n {cooking-units} } \msg_new:nnnn { cooking-units } { Key-not-defined } { - The \ key \ '#1' \ is \ not \ defined. \ Use \ \cudefinekeys or \ - \cudefinesinglekey to \ define \ keys. + The \ key \ '#1' \ is \ not \ defined. \ Use \ \cudefinekeys ~ or \ + \cudefinesinglekey ~ to \ define \ keys. } { This \ key \ is \ not \ defined, \ perhaps \ you \ misspelled \ it. @@ -427,7 +557,7 @@ the \ temperatures \ '\seq_use:Nnnn \l__cooking_units_temperatures_to_check_seq { ', ~ ' } { ', ~ ' } { ' ~ and ~ ' }' \ - are \ rounded \ to \ integers. + are \ rounded \ to \ integers \ by \ default. \\\\ You \ can \ disable \ the \ option \ 'check-temperature' \ to \ disable \ this \ error. @@ -437,11 +567,19 @@ { The \ key \ '#1' \ only \ accepts \ only \ '#3' \ as \ a \ set \ of \ choices \ and \ '#2' \ is \ non \ of \ these. + }{ + The \ key \ accepts \ only \ a \ fixed \ set \ of \ choices. \ + You \ can \ add \ new \ choices \ via \ \cuaddkeys, ~ \cuaddsinglekeys ~ + and \ \cuaddtokeys. + \msg_see_documentation_text:n {cooking-units} } +\msg_new:nnnn { cooking-units } { group-choice-not-allowed } { - The \ key \ accepts \ accepts\ only \ a \ fixed \ set \ of \ choices. \ - You \ can \ add \ new \ choices \ via \ \cuaddkeys, \ \cuaddsinglekeys \ - and \ \cuaddtokeys{}. + The \ group \ key \ '#1' \ accepts \ only \ + '#3' \ as \ a \ set \ of \ choices \ and \ '#2' \ is \ non \ of \ these. + }{ + The \ key \ accepts\ only \ a \ fixed \ set \ of \ choices. \ + You \ can \ add \ new \ choices \ via \ option \ 'add-unit-to-group'. \msg_see_documentation_text:n {cooking-units} } \msg_new:nnnn { cooking-units } { amount-not-known } @@ -455,39 +593,52 @@ reminds\ you\ about\ that\ fact. \msg_see_documentation_text:n {cooking-units} } +\msg_new:nnnn { cooking-units } { group-key-unknown } + { + The \ group \ key \ '#1' \ is \ not \ defined. \ Perhaps + \ you \ misspelled \ it? + }{ + The \ group \ key \ is \ not \ defined. + \msg_see_documentation_text:n { cooking-units } + } \msg_new:nnnn { cooking-units } { load-time-option } { The \ option \ '#1' \ is \ only \ available \ as \ a \ load-time-option. \ Please \ set \ it \ as \ a \ package \ option. } { - You \ cannot \ set \ this \ option \ using \ \cusetup \ + You \ cannot \ set \ this \ option \ using \ \cusetup ~ but \ only \ as \ a \ package \ option. \msg_see_documentation_text:n { cooking-units } } \msg_new:nnnn { cooking-units } { obsolete-command } { Command \ #1 is \ obsolete. \ Please \ use \ #2 instead. - } - { + }{ Don't \ use \ this \ old \ command \ ... \msg_see_documentation_text:n { cooking-units } } \msg_new:nnnn { cooking-units } { No-Value-given } { - Please \ input \ a \ number \ to \ check \ for \ - 'check-temperature'. + Please \ input \ a \ value \ for \ the \ key-value \ list \ in \ '#1' } { - A \ minimum \ value \ is \ needed \ for \ testing \ if \ - 'check-temperature' \ is \ active. + Each \ element \ of \ the \ list \ needs \ a \ value. \msg_see_documentation_text:n { cooking-units } } -\msg_new:nnnn { cooking-units } { Minimum-already-defined } +\msg_new:nnnn { cooking-units } { Value-not-allowed } { - A \ minimum \ for \ '#1' \ has \ already \ been \ defined. + The \ key-list \ in \ '#1' \ does \ not \ take \ a \ value. } { + This \ key-list \ does \ not \ take \ a \ value. \ The \ + given \ value \ will \ be \ ignored. + \msg_see_documentation_text:n { cooking-units } + } +\msg_new:nnnn { cooking-units } { Minimum-already-defined } + { + A \ minimum \ for \ '#1' \ has \ already \ been \ defined. + }{ You \ cannot \ redefine \ it. \msg_see_documentation_text:n { cooking-units } } @@ -513,8 +664,7 @@ \msg_new:nnnn { cooking-units } { label-already-defined } { The \ label \ '#1' \ has \ already \ been \ defined. - } - { + }{ Each \ label \ must \ be \ unique. \msg_see_documentation_text:n { cooking-units } } @@ -522,41 +672,39 @@ { The \ label \ is \ not \ defined. \ Please \ note \ that \ a \ label \ has \ to \ defined \ before \ it \ is \ referenced. - } - { + }{ Define \ the \ label \ before \ using \ it. \msg_see_documentation_text:n { cooking-units } } \msg_new:nnnn { cooking-units } { redefine-unit } { - The \ unit \ '#1' \ is \ redefined \ by \ \declarecookingunit at \ \msg_line_context: . - } - { + The \ unit \ '#1' \ is \ redefined \ by \ \declarecookingunit ~ at \ + \msg_line_context: . + }{ \msg_see_documentation_text:n { cooking-units } } \msg_new:nnnn { cooking-units } { phrase-unit-not-an-integer } { A \ phrase \ must \ be \ an \ integer, \ '#1' \ is \ not \ allowed. - } - { + }{ You \ can \ only \ use \ integers. \msg_see_documentation_text:n { cooking-units } } -\msg_new:nnnn { cooking-units } { cutext-no-translation-available } %% ToDo +\msg_new:nnnn { cooking-units } { cutext-no-translation-available } { For \ the \ unit \ '#1' \ there \ exists \ no \ translation \ to \ be \ used \ - for \ \cutext and \ \Cutext{}. \ + for \ \cutext ~ and \ \Cutext. \ You \ can \ define \ new \ translations \ for \ a \ given \ language \ using \ - \cudefinename{}. + \cudefinename. } { - \cunum \ is \ used \ instead. + \cunum ~ is \ used \ instead. \msg_see_documentation_text:n { cooking-units } } -\msg_new:nnnn { cooking-units } { Translation-not-available } %% ToDo +\msg_new:nnnn { cooking-units } { Translation-not-available } { The \ translation \ for \ #1 \ does \ not \ exist. - Please \ define \ it \ using \ \cudefinename{}. + Please \ define \ it \ using \ \cudefinename. } { And \ you \ may \ send \ me \ the \ translation \ as \ it \ is \ @@ -580,13 +728,22 @@ Please \ remove \ spaces \ if \ there \ are \ some. \msg_see_documentation_text:n { cooking-units } } +\msg_new:nnnn { cooking-units } { internal-error } + { + This \ error \ shouldn't \ show. \ This \ means \ I + \ (the \ package \ author) \ screwed + \ up. + }{ + Please \ send \ me \ a \ bug \ report. + \msg_see_documentation_text:n { cooking-units } + } \cs_new:Npn \__cooking_units_error_if_unit_not_defined:n #1 { \seq_if_in:NnF \g__cooking_units_list_of_defined_units_seq {#1} { \msg_error:nnn { cooking-units } { unknown-unit } {#1} } } \cs_generate_variant:Nn \__cooking_units_error_if_unit_not_defined:n { V } -\prg_new_protected_conditional:Npnn \__cooking_units_if_integer:n #1 { TF , F , T } +\prg_new_protected_conditional:Npnn \__cooking_units_if_integer:n #1 { TF , F } { \tl_map_inline:nn {#1} { @@ -598,28 +755,35 @@ \use_i:nn \prg_return_true: \prg_return_false: } \cs_generate_variant:Nn \__cooking_units_if_integer:nTF { V } -\cs_generate_variant:Nn \__cooking_units_if_integer:nT { V } \cs_generate_variant:Nn \__cooking_units_if_integer:nF { V } -\prg_new_protected_conditional:Npnn \__cooking_units_if_parse_and_integer:n #1 { TF } +\cs_new:Npn \__cooking_units_bool_set_if_integers:NNN #1#2#3 { - \bool_if:NTF \l__cooking_units_parse_input_bool + \__cooking_units_if_integer:VTF #2 + { \bool_set_true:N #1 } + { \bool_set_false:N #1 } + \bool_lazy_and:nnT + { \l__cooking_units_range_in_input_bool } {#1} { - \__cooking_units_if_integer:nTF {#1} - { \prg_return_true: } - { \prg_return_false: } + \__cooking_units_if_integer:VF #3 + { \bool_set_false:N #1 } } - { \prg_return_false: } } -\cs_generate_variant:Nn \__cooking_units_if_parse_and_integer:nTF { V } \prg_new_conditional:Npnn \__cooking_units_fp_if_equal_one:n #1 { TF } { - \fp_compare:nNnTF {#1} = { \c_one_fp } + \fp_compare:nNnTF {#1} = { 1.0 } { \prg_return_true: } { \prg_return_false: } } \prg_new_conditional:Npnn \__cooking_units_int_if_equal_one:n #1 { TF } { - \int_compare:nNnTF {#1} = { \c_one } + \int_compare:nNnTF {#1} = { 1 } + { \prg_return_true: } + { \prg_return_false: } + } +\prg_new_conditional:Npnn \__cooking_units_change_cutext_to_cunum:n #1 { TF } + { + \keys_set_groups:nnn { cooking-units } { change-command } {#1} + \bool_if:NTF \l__cooking_units_cutext_to_cunum_bool { \prg_return_true: } { \prg_return_false: } } @@ -627,11 +791,63 @@ { \str_case:nnF {#1} { - { m } {} - { f } {} - { n } {} + { m } { } + { f } { } + { n } { } } { \msg_error:nnn { cooking-units } { unknown-gender } {#1} } } +\cs_new:Npn \__cooking_units_define_unit_group:nn #1#2 + { + \clist_new:c { l__cooking_units_group_ #1 _clist } + \clist_set:cn { l__cooking_units_group_ #1 _clist } {#2} + \keys_define:nn { cooking-units } + { + #1 .code:n = { \__cooking_units_unit_group_convert_units:nn {#1} {##1} } , + #1 .groups:n = { change-unit } + } + } +\cs_new:Npn \__cooking_units_error_if_group_not_defined:n #1 + { + \clist_if_exist:cF { l__cooking_units_group_ #1 _clist } + { \msg_error:nn { cooking-units} { group-key-unknown } } + } +\cs_new:Npn \__cooking_units_unit_group_convert_units:nn #1#2 + { + \__cooking_units_error_if_group_not_defined:n {#1} + \__cooking_units_error_if_unit_not_defined:n {#2} + \clist_if_in:cnTF { l__cooking_units_group_ #1 _clist } {#2} + { + \clist_map_inline:cn { l__cooking_units_group_ #1 _clist } + { \__cooking_units_keys_set:nnn { cooking-units } {##1} {#2} } + }{ + \msg_error:nnxxx + { cooking-units } + { group-choice-not-allowed } + {#1} + {#2} + { \clist_use:cnnn { l__cooking_units_group_ #1 _clist } { ',~ ' } { ',~ ' } { ' ~ and ~ ' } } + } + } +\__cooking_units_define_unit_group:nn { weight } { kg , dag, g, oz, lb, stick } +\__cooking_units_define_unit_group:nn { length } { m , dm , cm , mm , in } +\__cooking_units_define_unit_group:nn { volume } { l , dl , cl , ml } +\__cooking_units_define_unit_group:nn { temperature } { C , F , K , Re } +\__cooking_units_define_unit_group:nn { energy } { cal, kcal , J , kJ , eV } +\__cooking_units_define_unit_group:nn { time } { d , h , min , s } +\cs_new:Npn \__cooking_units_unit_group_add_unit_error:n #1 + { + \msg_error:nnn { cooking-units } { No-Value-given } { add-unit-to-group } + } +\cs_new:Npn \__cooking_units_unit_group_add_unit:nn #1#2 + { + \__cooking_units_error_if_group_not_defined:n {#1} + \clist_map_inline:nn {#2} + { + \__cooking_units_error_if_unit_not_defined:n {##1} + \clist_if_in:cnF { l__cooking_units_group_ #1 _clist } {##1} + { \clist_put_right:cn { l__cooking_units_group_ #1 _clist } {##1} } + } + } \seq_new:N \g__cooking_units_natural_units_seq \prop_new:N \g__cooking_units_convert_to_eV_remember_prop \seq_set_split:Nnn \g__cooking_units_natural_units_seq { , } @@ -672,12 +888,23 @@ } } } -\cs_new:Npn \__cooking_units_tl_set_fp_and_eval:Nn #1#2 - { \tl_set:Nx #1 { \fp_eval:n {#2} } } -\cs_generate_variant:Nn \__cooking_units_tl_set_fp_and_eval:Nn { Nc } +\cs_new:Npn \__cooking_units_tl_eval:Nn #1#2 { \tl_set:Nf #1 { \fp_eval:n {#2} } } +\cs_generate_variant:Nn \__cooking_units_tl_eval:Nn { Nv } +\prg_new_conditional:Npnn \__cooking_units_change_unit: { TF } + { + \bool_lazy_any:nTF + { + { \l__cooking_units_lokal_fraction_bool } + { \l__cooking_units_special_sign_bool } + { \l__cooking_units_draft_bool } + } + { \prg_return_false: } + { \prg_return_true: } + } \cs_new:Npn \__cooking_units_temperature_to_check_print_error:n #1 { - \msg_error:nn { cooking-units } { No-Value-given } + \__cooking_units_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { No-Value-given } { add-temperature-to-check } } \cs_new:Npn \__cooking_units_temperatures_to_check_define:nn #1#2 { @@ -689,18 +916,44 @@ \fp_const:cn { c__cooking_units_ #1 _min_fp } {#2} } } +\cs_new:Npn \__cooking_units_erase_options_for:n #1 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \clist_clear:c { l__cooking_units_predefined_option_ ##1 _clist } + } +\cs_new:Npn \__cooking_units_erase_options_for_error:nn #1#2 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { Value-not-allowed } { erase-all-options-for } + } +\cs_new:Npn \__cooking_units_set_options_for_error:n #1 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { No-Value-given } { set-option-for } + } +\cs_new:Npn \__cooking_units_set_options_for:nn #1#2 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \clist_set:cn { l__cooking_units_predefined_option_#1_clist } {#2} + } +\cs_new:Npn \__cooking_units_add_options_for_error:n #1 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { No-Value-given } { add-option-for } + } +\cs_new:Npn \__cooking_units_add_options_for:nn #1#2 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \clist_put_right:cn { l__cooking_units_predefined_option_ #1 _clist } {#2} + } \cs_new:Npn \__cooking_units_rounding_function:n #1 { #1 - \bool_if:NTF \l__cooking_units_round_commercial_bool - { - , - \bool_if:NTF \l__cooking_units_round_to_int_bool - { \c_zero_fp } - { \l__cooking_units_significant_figures_int } - , #1 - } - { \bool_if:NF \l__cooking_units_round_to_int_bool { , \l__cooking_units_significant_figures_int } } + \bool_if:NTF \l__cooking_units_round_to_int_bool + { , 0 } + { , \l__cooking_units_round_precision_int } + \bool_if:NT \l__cooking_units_round_commercial_bool + { , #1 } } \cs_new:Npn \__cooking_units_label_and_persons:n #1 { @@ -717,35 +970,35 @@ } \cs_new:Npn \__cooking_units_culabel:nn #1#2 { - \int_if_exist:cTF { l__cooking_units_number_of_persons_ #1 _int } + \int_if_exist:cTF { g__cooking_units_number_of_persons_ #1 _int } { \msg_error:nnn { cooking-units } { label-already-defined } {#1} }{ \__cooking_units_if_integer:nTF {#2} { - \int_new:c { l__cooking_units_number_of_persons_ #1 _int } - \int_gset:cn { l__cooking_units_number_of_persons_ #1 _int } {#2} + \int_new:c { g__cooking_units_number_of_persons_ #1 _int } + \int_gset:cn { g__cooking_units_number_of_persons_ #1 _int } {#2} } { \msg_error:nnn { cooking-units } { Number-of-persons-is-not-an-integer } {#2} } } } \cs_new:Npn \__cooking_units_reference_label_and_persons:n #1 { - \int_if_exist:cTF { l__cooking_units_number_of_persons_ #1 _int } + \int_if_exist:cTF { g__cooking_units_number_of_persons_ #1 _int } { \bool_set_true:N \l__cooking_units_calc_because_ref_was_given_bool - \int_set_eq:Nc \l__cooking_units_number_of_persons_tmpa_int - { l__cooking_units_number_of_persons_ #1 _int } + \int_set_eq:Nc \l__cooking_units_local_number_of_persons_int + { g__cooking_units_number_of_persons_ #1 _int } } { \msg_error:nnn { cooking-units } { label-not-defined } {#1} } } \cs_new:Npn \__cooking_units_curef:n #1 { - \int_if_exist:cTF { l__cooking_units_number_of_persons_ #1 _int } + \int_if_exist:cTF { g__cooking_units_number_of_persons_ #1 _int } { - \bool_if:NTF \l__cooking_units_calc_for_persons_bool - { \int_use:N \l__cooking_units_calc_for_number_of_persons_int } - { \int_use:c { l__cooking_units_number_of_persons_ #1 _int } } + \bool_if:NTF \l__cooking_units_change_number_of_persons_bool + { \int_use:N \l__cooking_units_wanted_number_of_persons_int } + { \int_use:c { g__cooking_units_number_of_persons_ #1 _int } } }{ \msg_error:nnn { cooking-units } { label-not-defined } {#1} } } \NewDocumentCommand \culabel { m m } { \__cooking_units_culabel:nn {#1} {#2} } @@ -849,28 +1102,249 @@ \__cooking_units_newtranslation_to:nnVn { German } { one (m) } \c__cooking_units_postfix_unitname_tl { ein } \__cooking_units_newtranslation_to:nnVn { German } { one (f) } \c__cooking_units_postfix_unitname_tl { eine } \__cooking_units_newtranslation_to:nnVn { German } { one (n) } \c__cooking_units_postfix_unitname_tl { ein } -\cs_new:Npn \__cooking_units_parse_input:N #1 +\cs_new_protected:Npn \__cooking_units_initialise_default:n #1 { - \bool_if:NTF \l__cooking_units_range_in_input_bool - { \__cooking_units_parse_range_in_input:ww #1 \q_stop } + \__cooking_units_set_unit:Nn \l__cooking_units_given_unit_tl {#1} + \__cooking_units_error_if_unit_not_defined:V \l__cooking_units_given_unit_tl + \bool_set_false:N \l__cooking_units_special_sign_bool + \bool_set_false:N \l__cooking_units_error_bool + \bool_set_false:N \l__cooking_units_range_in_input_bool + \bool_set_false:N \l__cooking_units_lokal_fraction_bool + \bool_set_false:N \l__cooking_units_lokal_mixed_fraction_bool + } +\cs_new_protected:Npn \__cooking_units_initialise_unit_change:n #1 + { + \tl_if_empty:nF {#1} { - \tl_if_in:nnTF {#1} { / } + \keys_set_groups:nnn { cooking-units } { change-unit } {#1} + } + \bool_if:NT \l__cooking_units_convert_to_eV_bool { \__cooking_units_convert_to_eV: } + \prop_get:NVNF \l__cooking_units_change_unit_prop \l__cooking_units_given_unit_tl \l__cooking_units_option_unit_tl + { + \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl + } + } +\cs_new_protected:Npn \__cooking_units_initialise_after_unit_change:nn #1#2 + { + \IfNoValueF {#1} + { \__cooking_units_reference_label_and_persons:n {#1} } + \clist_if_empty:cF { l__cooking_units_predefined_option_ \l__cooking_units_option_unit_tl _clist } + { + \keys_set_filter:nnv + { cooking-units } + { change-unit } + { l__cooking_units_predefined_option_ \l__cooking_units_option_unit_tl _clist } + } + \tl_if_empty:nF {#2} + { \keys_set_filter:nnn { cooking-units } { change-unit } {#2} } + \bool_lazy_and:nnTF + { \l__cooking_units_calc_because_ref_was_given_bool } { \l__cooking_units_change_number_of_persons_bool } + { \bool_set_true:N \l__cooking_units_lokal_persons_bool } + { \bool_set_false:N \l__cooking_units_lokal_persons_bool } + \bool_lazy_and:nnTF + { \g__cooking_units_opt_numeral_bool } { \l__cooking_units_print_numeral_bool } + { \bool_set_true:N \l__cooking_units_lokal_numeral_bool } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + } +\cs_new_protected:Npn \__cooking_units_print_input:N #1 { } +\cs_new_protected:Npn \__cooking_units_print_correct_unit: { } +\cs_new_protected:Npn \__cooking_units_do_not_process_input:NN #1#2 { } +\cs_new_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN +\cs_new_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_do_not_process_input:NN +\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cunum: + { + \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_print_numerical_input:N + \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cunum_print_correct_unit: + \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN + \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_do_not_process_input:NN + } +\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cutext: + { + \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_cutext_print_input:N + \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cutext_print_correct_unitname: + \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_cutext_pre_process_input:NN + \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_cutext_post_process_input:NN + } +\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cuam: + { + \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_cuam_print_numerical_input:N + \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cuam_print_correct_unitphrase: + \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN + \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_cuam_post_process_input:NN + } +\cs_new_protected:Npn \__cooking_units_print_numerical_input:N #1 + { + \tl_if_in:NnT #1 { . } + { + \__cooking_units_translate_let:Nxx \l__cooking_units_translation_tmpa_tl + { decimal-mark } \c__cooking_units_postfix_unitname_tl + \tl_replace_once:Nnn #1 { . } { \l__cooking_units_translation_tmpa_tl } + } + \tl_replace_once:Nnn #1 { - } \c__cooking_units_minus_tl + #1 + } +\cs_new:Npn \__cooking_units_print_fractions:nnn #1#2#3 + { + \bool_if:NT \l__cooking_units_minus_bool { \c__cooking_units_minus_tl } + \tl_if_empty:nF {#1} + { + #1 + \__cooking_units_dim_horizontal:N \l__cooking_units_mixed_frac_dim + } + \__cooking_units_frac:nn {#2} {#3} + } +\cs_new:Npn \__cooking_units_parse_input:n #1 + { + \bool_if:NTF \l__cooking_units_fourty_two_bool + { \tl_clear:N \l__cooking_units_given_amount_tl } + { \__cooking_units_set_amount:Nn \l__cooking_units_given_amount_tl {#1} } + \tl_set_rescan:NnV \l__cooking_units_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N \ % + \char_set_catcode_other:N ? % + } \l__cooking_units_given_amount_tl + \bool_lazy_or:nnTF + { \l__cooking_units_draft_bool } + { \tl_if_empty_p:N \l__cooking_units_tmpa_tl } + { + \bool_if:NTF \l__cooking_units_fourty_two_bool + { 42 } + { \l__cooking_units_tmpa_tl } + }{ + \tl_if_in:NVT \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { - \bool_lazy_or:nnTF - { \l__cooking_units_calc_persons_bool }{ \l__cooking_units_eval_fractions_bool } - { \bool_set_false:N \l__cooking_units_fraction_in_input_bool } - { \bool_set_true:N \l__cooking_units_fraction_in_input_bool } - \tl_if_in:nnTF {#1} { _ } - { \__cooking_units_parse_mixed_fraction_in_input:www #1 \q_stop } - { \__cooking_units_parse_fraction_in_input:ww #1 \q_stop } + \tl_replace_once:NVn \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } + \bool_set_true:N \l__cooking_units_range_in_input_bool + } + \__cooking_units_parsing_amount_input:V \l__cooking_units_tmpa_tl + \__cooking_units_split_input: + } + } +\cs_new:Npn \__cooking_units_parsing_amount_input:n #1 + { + \cs_set_eq:NN \__cooking_units_parse:N \__cooking_units_start_loop:N + \tl_map_function:nN {#1} \__cooking_units_parse:N + } +\cs_generate_variant:Nn \__cooking_units_parsing_amount_input:n { V } +\cs_new:Npn \__cooking_units_split_input: + { + \bool_if:NTF \l__cooking_units_lokal_fraction_bool + { + \tl_set_eq:NN \l__cooking_units_number_tmpb_tl \l__cooking_units_tmpa_tl + \bool_lazy_or:nnT + { \l__cooking_units_lokal_persons_bool }{ \l__cooking_units_eval_fractions_bool } + { \bool_set_false:N \l__cooking_units_lokal_fraction_bool } + \bool_if:NTF \l__cooking_units_lokal_mixed_fraction_bool + { \__cooking_units_parse_mixed_fraction_in_input: } + { \__cooking_units_parse_fraction_in_input: } + }{ + \bool_if:NT \l__cooking_units_lokal_mixed_fraction_bool + { \msg_error:nnV { cooking-units } { missing-slash } \l__cooking_units_given_amount_tl } + \bool_if:NTF \l__cooking_units_range_in_input_bool + { + \tl_set_eq:NN \l__cooking_units_number_tmpb_tl \l__cooking_units_tmpa_tl + \__cooking_units_parse_range_in_input: + }{ + \tl_set_eq:NN \l__cooking_units_number_tmpa_tl \l__cooking_units_tmpa_tl + \__cooking_units_parse_number_in_input: + } + } + } +\cs_new:Npn \__cooking_units_start_loop:N #1 + { + \tl_clear:N \l__cooking_units_tmpa_tl + \bool_set_false:N \l__cooking_units_decimal_in_input_bool + \cs_set_eq:NN \__cooking_units_parse:N \__cooking_units_parse_input_loop_aux:N + \tl_if_in:NnTF \l__cooking_units_input_value_signs_tl {#1} + { \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} } + { + \tl_map_function:nN {#1} \__cooking_units_parse:N + } + } +\cs_new:Npn \__cooking_units_parse_input_loop_aux:N #1 + { + \tl_if_in:NnTF \l__cooking_units_input_digits_tl {#1} + { \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} } + { + \tl_if_in:NnTF \l__cooking_units_input_decimal_mark_tl {#1} + { + \__cooking_units_check_repitition:NN + \q__cooking_units_decimal + \l__cooking_units_decimal_in_input_bool + \tl_put_right:Nn \l__cooking_units_tmpa_tl { . } + }{ + \tl_if_in:NnTF \l__cooking_units_input_allowed_special_signs_tl {#1} + { + \bool_set_true:N \l__cooking_units_special_sign_bool + \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} + }{ + \bool_if:NTF \l__cooking_units_range_in_input_bool + { + \tl_if_eq:nnTF \q__cooking_units_range {#1} + { + \tl_set_eq:NN \l__cooking_units_number_tmpa_tl \l__cooking_units_tmpa_tl + \cs_set_eq:NN \__cooking_units_parse:N \__cooking_units_start_loop:N + }{ + \tl_if_in:xnTF + { + \exp_not:V \l__cooking_units_input_fraction_sign_tl + \exp_not:V \l__cooking_units_input_mixed_fraction_sign_tl + } {#1} + { \msg_error:nnV { cooking-units } { fraction-not-allowed-with-range } \l__cooking_units_given_amount_tl } + { \msg_error:nnnV { cooking-units } { Token-not-allowed } {#1} \l__cooking_units_given_amount_tl } + \bool_set_true:N \l__cooking_units_error_bool + \tl_map_break: + } + }{ + \tl_if_in:NnTF \l__cooking_units_input_fraction_sign_tl {#1} + { + \__cooking_units_check_repitition:NN + \q__cooking_units_frac + \l__cooking_units_lokal_fraction_bool + \tl_set_eq:NN \l__cooking_units_number_tmpa_tl \l__cooking_units_tmpa_tl + \cs_set_eq:NN \__cooking_units_parse:N \__cooking_units_start_loop:N + }{ + \tl_if_in:NnTF \l__cooking_units_input_mixed_fraction_sign_tl {#1} + { + \__cooking_units_check_repitition:NN + \q__cooking_units_mixed_frac + \l__cooking_units_lokal_mixed_fraction_bool + \bool_if:NT \l__cooking_units_lokal_fraction_bool + { \msg_error:nnV { cooking-units } { fraction-wrong-order } \l__cooking_units_given_amount_tl } + \tl_set_eq:NN \l__cooking_units_mixed_fraction_tl \l__cooking_units_tmpa_tl + \cs_set_eq:NN \__cooking_units_parse:N \__cooking_units_start_loop:N + }{ + \msg_error:nnnV { cooking-units } { Token-not-allowed } {#1} \l__cooking_units_given_amount_tl + \bool_set_true:N \l__cooking_units_error_bool + \tl_map_break: + } + } + } + } + } + } + } +\cs_new:Npn \__cooking_units_check_repitition:NN #1#2 + { + \bool_if:NTF #2 + { + \tl_case:NnTF #1 + { + \q__cooking_units_decimal + { \msg_error:nnV { cooking-units } { Second-decimal-sign-not-allowed } \l__cooking_units_given_amount_tl } + \q__cooking_units_frac + { \msg_error:nnV { cooking-units } { Second-fraction-sign-not-allowed } \l__cooking_units_given_amount_tl } + \q__cooking_units_mixed_frac + { \msg_error:nnV { cooking-units } { Second-mixed-fraction-sign-not-allowed } \l__cooking_units_given_amount_tl } } - { \__cooking_units_parse_number_in_input:n {#1} } + { \bool_set_true:N \l__cooking_units_error_bool } + { \msg_error:nn { cooking-units } { internal-error } } } + { \bool_set_true:N #2 } } -\cs_generate_variant:Nn \__cooking_units_parse_input:N { V } -\cs_new:Npn \__cooking_units_parse_number_in_input:n #1 +\cs_new:Npn \__cooking_units_parse_number_in_input: { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_number_tmpa_tl \__cooking_units_process_and_print_number_in_input:N \l__cooking_units_number_tmpa_tl } \cs_new:Npn \__cooking_units_process_and_print_number_in_input:N #1 @@ -880,10 +1354,8 @@ \__cooking_units_post_process_input:NN #1 \q_no_value \__cooking_units_print_input:N #1 } -\cs_new:Npn \__cooking_units_parse_range_in_input:ww #1 \q__cooking_units_range #2 \q_stop +\cs_new:Npn \__cooking_units_parse_range_in_input: { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_number_tmpa_tl - \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_number_tmpb_tl \__cooking_units_pre_process_input:NN \l__cooking_units_number_tmpa_tl \l__cooking_units_number_tmpb_tl \__cooking_units_calculate_and_store_in:N \l__cooking_units_number_tmpa_tl \__cooking_units_calculate_and_store_in:N \l__cooking_units_number_tmpb_tl @@ -894,44 +1366,43 @@ { \tl_use:N \l__cooking_units_cunum_range_sign_tl } \__cooking_units_print_input:N \l__cooking_units_number_tmpb_tl } -\cs_new:Npn \__cooking_units_parse_fraction_in_input:ww #1/#2 \q_stop +\cs_new:Npn \__cooking_units_parse_fraction_in_input: { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_number_tmpa_tl - \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_number_tmpb_tl \bool_lazy_or:nnTF - { \l__cooking_units_fraction_in_input_bool } + { \l__cooking_units_lokal_fraction_bool } { \l__cooking_units_special_sign_bool } { \__cooking_units_tl_if_in_remove_and_set_bool:NnN \l__cooking_units_number_tmpa_tl { - } \l__cooking_units_minus_bool \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_number_tmpb_tl { - } \l__cooking_units_minus_bool - \__cooking_units_formatiere_fractions:nnn + \__cooking_units_print_fractions:nnn { } { \l__cooking_units_number_tmpa_tl } { \l__cooking_units_number_tmpb_tl } }{ - \__cooking_units_tl_set_fp_and_eval:Nn \l__cooking_units_number_tmpa_tl + \fp_compare:nNnT { \l__cooking_units_number_tmpb_tl } = { 0 } + { \msg_error:nnV { cooking-units } { Division-by-zero } \l__cooking_units_given_amount_tl } + \__cooking_units_tl_eval:Nn \l__cooking_units_number_tmpa_tl { \l__cooking_units_number_tmpa_tl / \l__cooking_units_number_tmpb_tl } \__cooking_units_process_and_print_number_in_input:N \l__cooking_units_number_tmpa_tl } } -\cs_new:Npn \__cooking_units_parse_mixed_fraction_in_input:www #1_#2/#3 \q_stop +\cs_new:Npn \__cooking_units_parse_mixed_fraction_in_input: { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_mixed_fraction_tl - \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_number_tmpa_tl - \__cooking_units_parse_input_and_safe_in:nN {#3} \l__cooking_units_number_tmpb_tl \__cooking_units_tl_if_in_remove_and_set_bool:NnN \l__cooking_units_mixed_fraction_tl { - } \l__cooking_units_minus_bool \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_number_tmpa_tl { - } \l__cooking_units_minus_bool \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_number_tmpb_tl { - } \l__cooking_units_minus_bool \bool_lazy_or:nnTF - { \l__cooking_units_fraction_in_input_bool } + { \l__cooking_units_lokal_fraction_bool } { \l__cooking_units_special_sign_bool } { - \__cooking_units_formatiere_fractions:nnn + \__cooking_units_print_fractions:nnn { \l__cooking_units_mixed_fraction_tl } { \l__cooking_units_number_tmpa_tl } { \l__cooking_units_number_tmpb_tl } }{ - \__cooking_units_tl_set_fp_and_eval:Nn \l__cooking_units_number_tmpa_tl + \fp_compare:nNnT { \l__cooking_units_number_tmpb_tl } = { 0 } + { \msg_error:nnV { cooking-units } { Division-by-zero } \l__cooking_units_given_amount_tl } + \__cooking_units_tl_eval:Nn \l__cooking_units_number_tmpa_tl { \bool_if:NTF \l__cooking_units_minus_bool { - \l__cooking_units_mixed_fraction_tl - } @@ -941,61 +1412,6 @@ \__cooking_units_process_and_print_number_in_input:N \l__cooking_units_number_tmpa_tl } } -\cs_new:Npn \__cooking_units_parse_input_and_safe_in:nN #1 #2 - { - \tl_clear:N \l__cooking_units_tmpa_tl - \bool_set_false:N \l__cooking_units_decimal_in_input_bool - \__cooking_units_parse_vorzeichen_and_rest:Nw #1 \q_stop - \bool_if:NTF \l__cooking_units_error_bool - { \tl_set:Nn #2 {#1} } - { \tl_set_eq:NN #2 \l__cooking_units_tmpa_tl } - } -\cs_new:Npn \__cooking_units_parse_vorzeichen_and_rest:Nw #1#2 \q_stop - { - \tl_if_in:NnTF \l__cooking_units_input_value_signs_tl {#1} - { \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} } - { - \tl_map_function:nN {#1} \__cooking_units_parse_input_for_safety_aux:N - } - \bool_if:NF \l__cooking_units_error_bool - { \tl_map_function:nN {#2} \__cooking_units_parse_input_for_safety_aux:N } - } -\cs_new:Npn \__cooking_units_parse_input_for_safety_aux:N #1 - { - \tl_if_in:NnTF \l__cooking_units_input_digits_tl {#1} - { \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} } - { - \tl_if_in:NnTF \l__cooking_units_input_decimal_mark_tl {#1} - { - \bool_if:NT \l__cooking_units_decimal_in_input_bool - { - \msg_error:nn { cooking-units } - { Second-decimal-sign-not-allowed } - } - \bool_set_true:N \l__cooking_units_decimal_in_input_bool - \tl_put_right:Nn \l__cooking_units_tmpa_tl { . } - }{ - \tl_if_in:NnTF \l__cooking_units_input_allowed_special_signs_tl {#1} - { - \bool_set_true:N \l__cooking_units_special_sign_bool - \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} - }{ - \bool_if:NTF \l__cooking_units_range_in_input_bool - { - \tl_if_in:nnTF { / _ } {#1} - { \msg_error:nnn { cooking-units } { fraction-not-allowed-with-range } {#1} } - { \msg_error:nnn { cooking-units } { Token-not-allowed } {#1} } - }{ - \tl_if_in:nnTF { _ } {#1} - { \msg_error:nnn { cooking-units } { missing-slash } {#1} } - { \msg_error:nnn { cooking-units } { Token-not-allowed } {#1} } - } - \bool_set_true:N \l__cooking_units_error_bool - \tl_map_break: - } - } - } - } \cs_new:Npn \__cooking_units_calculate_and_store_in:N #1 { \bool_if:NF \l__cooking_units_error_bool @@ -1009,8 +1425,11 @@ { \l__cooking_units_using_cutext_bool } { ! \l__cooking_units_cutext_change_unit_bool } { \tl_set_eq:NN \l__cooking_units_tmpa_tl #1 } { \__cooking_units_calculate_input_and_store_in:nN {#1} \l__cooking_units_tmpa_tl } - \bool_if:NT \l__cooking_units_calc_persons_bool - { \__cooking_units_calc_for_number_of_persons_and_store_in:NN \l__cooking_units_tmpa_tl \l__cooking_units_tmpa_tl } + \bool_if:NT \l__cooking_units_lokal_persons_bool + { + \__cooking_units_calc_for_number_of_persons_and_store_in:NN + \l__cooking_units_tmpa_tl \l__cooking_units_tmpa_tl + } \__cooking_units_round_calculated_input:NV \l__cooking_units_tmpa_tl \l__cooking_units_tmpa_tl \__cooking_units_check_temperature_limit:N \l__cooking_units_tmpa_tl } @@ -1020,112 +1439,72 @@ \cs_new:Npn \__cooking_units_calculate_input_and_store_in:nN #1#2 { \fp_set:Nn \l__cooking_units_tmpa_fp {#1} - \tl_if_in:cnTF { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } { \l__cooking_units_tmpa_fp } + \tl_if_in:cnTF { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } { \l__cooking_units_tmpa_fp } { - \__cooking_units_tl_set_fp_and_eval:Nc #2 { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } + \__cooking_units_tl_eval:Nv #2 { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } }{ - \__cooking_units_tl_set_fp_and_eval:Nn #2 + \__cooking_units_tl_eval:Nn #2 { \l__cooking_units_tmpa_fp * \tl_use:c { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } } } } \cs_new:Npn \__cooking_units_calc_for_number_of_persons_and_store_in:NN #1#2 { \int_compare:nNnF - { \l__cooking_units_calc_for_number_of_persons_int } + { \l__cooking_units_wanted_number_of_persons_int } = - { \l__cooking_units_number_of_persons_tmpa_int } + { \l__cooking_units_local_number_of_persons_int } { - \__cooking_units_tl_set_fp_and_eval:Nn #1 + \__cooking_units_tl_eval:Nn #1 { - \l__cooking_units_calc_for_number_of_persons_int / - \l__cooking_units_number_of_persons_tmpa_int * + \l__cooking_units_wanted_number_of_persons_int / + \l__cooking_units_local_number_of_persons_int * #2 } } } \cs_new:Npn \__cooking_units_check_number_for_rounding:n #1 { - \bool_set_false:N \l__cooking_units_round_decimal_part_bool - \__cooking_units_check_number_after_dot_aux:w #1 . \q_recursion_tail . + \bool_set_false:N \l__cooking_units_round_number_bool + \__cooking_units_check_number_after_dot_aux:ww #1 . \q_recursion_tail . \q_recursion_stop } -\cs_new:Npn \__cooking_units_check_number_after_dot_aux:w #1. #2 . +\cs_new:Npn \__cooking_units_check_number_after_dot_aux:ww #1 . #2 . { - \quark_if_recursion_tail_stop:n {#2} - \bool_if:NTF \l__cooking_units_round_to_int_bool - { \int_zero:N \l_tmpa_int } - { \int_set_eq:NN \l_tmpa_int \l__cooking_units_significant_figures_plus_one_int } - \int_compare:nNnF - { \tl_count:n {#2} } < { \l_tmpa_int } - { \bool_set_true:N \l__cooking_units_round_decimal_part_bool } + \quark_if_recursion_tail_stop_do:nn {#2} + { + \bool_lazy_or:nnF + { \l__cooking_units_round_precision_positive_bool } + { \l__cooking_units_round_to_int_bool } + { \bool_set_true:N \l__cooking_units_round_number_bool } + } + \int_compare:nNnT + { \tl_count:n {#2} } > + { + \bool_if:NTF \l__cooking_units_round_to_int_bool + { 0 } + { \l__cooking_units_round_precision_int } + } + { \bool_set_true:N \l__cooking_units_round_number_bool } \use_none_delimit_by_q_recursion_stop:w } -\cs_new:Npn \__cooking_units_round_calculated_input:NN #1#2 +\cs_new:Npn \__cooking_units_round_calculated_input:Nn #1#2 { \__cooking_units_check_number_for_rounding:n {#2} - \tl_set:Nx #1 + \tl_set:Nf #1 { - \bool_if:NTF \l__cooking_units_round_decimal_part_bool + \bool_if:NTF \l__cooking_units_round_number_bool { \fp_eval:n { round ( \__cooking_units_rounding_function:n {#2} ) } } {#2} } } -\cs_generate_variant:Nn \__cooking_units_round_calculated_input:NN { NV } -\cs_new_protected:Npn \__cooking_units_print_input:N #1 { } -\cs_new_protected:Npn \__cooking_units_print_correct_unit: { } -\cs_new_protected:Npn \__cooking_units_do_not_process_input:NN #1#2 { } -\cs_new_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN -\cs_new_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_do_not_process_input:NN -\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cunum: - { - \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_print_numerical_input:N - \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cunum_print_correct_unit: - \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN - \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_do_not_process_input:NN - } -\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cutext: - { - \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_cutext_print_input:N - \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cutext_print_correct_unitname: - \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_cutext_pre_process_input:NN - \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_cutext_post_process_input:NN - } -\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cuam: - { - \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_cuam_print_numerical_input:N - \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cuam_print_correct_unitphrase: - \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN - \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_cuam_post_process_input:NN - } -\cs_new_protected:Npn \__cooking_units_print_numerical_input:N #1 - { - \tl_if_in:NnT #1 { . } - { - \__cooking_units_translate_let:Nxx \l__cooking_units_translation_tmpa_tl - { decimal-mark } \c__cooking_units_postfix_unitname_tl - \tl_replace_once:Nnn #1 { . } { \l__cooking_units_translation_tmpa_tl } - } - \tl_if_in:NnT #1 { - } - { \tl_replace_once:NnV #1 { - } \c__cooking_units_minus_tl } - #1 - } -\cs_new:Npn \__cooking_units_formatiere_fractions:nnn #1#2#3 - { - \bool_if:NT \l__cooking_units_minus_bool { \c__cooking_units_minus_tl } - \tl_if_empty:nF {#1} - { - #1 - \hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { } - } - \__cooking_units_frac:nn {#2} {#3} - } +\cs_generate_variant:Nn \__cooking_units_round_calculated_input:Nn { NV } \cs_new:Npn \__cooking_units_check_temperature_limit:N #1 { \bool_if:NT \l__cooking_units_check_temperature_bool { \seq_if_in:NVT \l__cooking_units_temperatures_to_check_seq \l__cooking_units_option_unit_tl { - \fp_compare:cNnT + \fp_compare:vNnT { c__cooking_units_ \l__cooking_units_option_unit_tl _min_fp } > {#1} { \msg_error:nnxx { cooking-units } @@ -1155,7 +1534,7 @@ \str_if_eq:nnTF {#1} { < } { \tl_if_in:NoT \l__cooking_units_input_allowed_special_signs_tl { < } - { \msg_error:nn {cooking-units} { <-not-allowed-as-special-sign } } + { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } \tl_clear:N \l__cooking_units_tmpa_tl \tl_put_right:Nx \l__cooking_units_tmpa_tl { \tl_to_str:N < } \__cooking_units_grab_arrows_for_safety_do_afterwards:nN @@ -1176,101 +1555,25 @@ \cs_new:Npn \__cooking_units_cunum:nnnnn #1#2#3#4#5 { \__cooking_units_cunum_initialise:nnnnn {#1} {#2} {#3} {#4} {#5} - \__cooking_units_cunum_parse_numerical_input:n {#3} + \l__cooking_units_cunum_hook_tl + \__cooking_units_parse_input:n {#3} \__cooking_units_print_correct_unit: } \cs_new_protected:Npn \__cooking_units_cunum_initialise:nnnnn #1#2#3#4#5 { \__cooking_units_set_process_and_print_for_cunum: \tl_set:Nn \l__cooking_units_phantom_tl {#4} - \__cooking_units_initialise_default:nnn {#1} {#2} {#5} - \__cooking_units_initialise_unit_change:nnn {#1} {#2} {#5} + \__cooking_units_initialise_default:n {#5} + \__cooking_units_initialise_unit_change:n {#2} \__cooking_units_initialise_after_unit_change:nn {#1} {#2} } -\cs_new_protected:Npn \__cooking_units_initialise_default:nnn #1#2#3 - { - \tl_set:Nn \l__cooking_units_given_unit_tl {#3} - \__cooking_units_error_if_unit_not_defined:V \l__cooking_units_given_unit_tl - \bool_set_false:N \l__cooking_units_special_sign_bool - \bool_set_false:N \l__cooking_units_error_bool - \bool_set_false:N \l__cooking_units_range_in_input_bool - \bool_set_false:N \l__cooking_units_fraction_in_input_bool - } -\cs_new_protected:Npn \__cooking_units_initialise_unit_change:nnn #1#2#3 - { - \tl_if_empty:nF {#2} - { - \keys_set_groups:nnn { cooking-units } { change-unit } {#2} - } - \bool_if:NT \l__cooking_units_convert_to_eV_bool { \__cooking_units_convert_to_eV: } - \prop_get:NVNF \l__cooking_units_change_unit_prop \l__cooking_units_given_unit_tl \l__cooking_units_option_unit_tl - { - \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl - } - } -\cs_new_protected:Npn \__cooking_units_initialise_after_unit_change:nn #1#2 - { - \IfNoValueF {#1} - { \__cooking_units_reference_label_and_persons:n {#1} } - \clist_if_empty:cF { l__cooking_units_predefined_option_ \l__cooking_units_option_unit_tl _clist } - { - \keys_set_filter:nnv - { cooking-units } - { change-unit } - { l__cooking_units_predefined_option_ \l__cooking_units_option_unit_tl _clist } - } - \tl_if_empty:nF {#2} - { \keys_set_filter:nnn { cooking-units } { change-unit } {#2} } - \bool_lazy_and:nnTF - { \l__cooking_units_calc_because_ref_was_given_bool } { \l__cooking_units_calc_for_persons_bool } - { \bool_set_true:N \l__cooking_units_calc_persons_bool } - { \bool_set_false:N \l__cooking_units_calc_persons_bool } - } -\cs_new:Npn \__cooking_units_cunum_parse_numerical_input:n #1 - { - \bool_if:NTF \l__cooking_units_parse_input_bool - { \__cooking_units_parse_and_evaluate_input:n {#1} } - { \__cooking_units_do_not_parse:n {#1} } - } -\cs_new:Npn \__cooking_units_do_not_parse:n #1 - { - \tl_set_rescan:Nnn \l__cooking_units_number_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N \ % - } {#1} - \l__cooking_units_number_tmpa_tl - } -\cs_new:Npn \__cooking_units_parse_and_evaluate_input:n #1 - { - \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N \ % - \char_set_catcode_other:N ? % - } {#1} - \tl_if_empty:NF \l__cooking_units_tmpa_tl - { - \tl_if_in:NVT \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl - { - \tl_replace_once:NVn \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } - \bool_set_true:N \l__cooking_units_range_in_input_bool - } - \__cooking_units_parse_input:V \l__cooking_units_tmpa_tl - } - } \cs_new:Npn \__cooking_units_cunum_print_correct_unit: { \tl_if_empty:NF \l__cooking_units_phantom_tl { \phantom { \l__cooking_units_phantom_tl } } \tl_use:N \l__cooking_units_value_unit_space_tl - \bool_lazy_any:nTF - { - { \l__cooking_units_fraction_in_input_bool } - { \l__cooking_units_special_sign_bool } - { ! \l__cooking_units_parse_input_bool } - } - { \__cooking_units_translate:xx \l__cooking_units_given_unit_tl \c__cooking_units_postfix_unit_tl } + \__cooking_units_change_unit:TF { \__cooking_units_translate:xx \l__cooking_units_option_unit_tl \c__cooking_units_postfix_unit_tl } + { \__cooking_units_translate:xx \l__cooking_units_given_unit_tl \c__cooking_units_postfix_unit_tl } } \NewDocumentCommand \cutext { d<> O{} m m } { @@ -1278,9 +1581,12 @@ { \cutext } { \group_begin: - \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4} - \bool_set_false:N \l__cooking_units_cutext_uppercase_word_bool - \__cooking_units_cutext_do:nnnn {#1} {#2} {#3} {#4} + \__cooking_units_change_cutext_to_cunum:nTF {#2} + { \__cooking_units_cunum:nnnnn {#1} {#2} {#3} { } {#4} } + { + \bool_set_false:N \l__cooking_units_cutext_uppercase_word_bool + \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4} + } \group_end: } } @@ -1290,9 +1596,12 @@ { \Cutext } { \group_begin: - \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4} - \bool_set_true:N \l__cooking_units_cutext_uppercase_word_bool - \__cooking_units_cutext_do:nnnn {#1} {#2} {#3} {#4} + \__cooking_units_change_cutext_to_cunum:nTF {#2} + { \__cooking_units_cunum:nnnnn {#1} {#2} {#3} { } {#4} } + { + \bool_set_true:N \l__cooking_units_cutext_uppercase_word_bool + \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4} + } \group_end: } } @@ -1300,56 +1609,28 @@ { \bool_set_true:N \l__cooking_units_using_cutext_bool \__cooking_units_set_process_and_print_for_cutext: - \__cooking_units_initialise_default:nnn {#1} {#2} {#3} + \__cooking_units_initialise_default:n {#3} \bool_if:NTF \l__cooking_units_cutext_change_unit_bool - { \__cooking_units_initialise_unit_change:nnn {#1} {#2} {#3} } + { \__cooking_units_initialise_unit_change:n {#2} } { \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl } \__cooking_units_initialise_after_unit_change:nn {#1} {#2} - } -\cs_new:Npn \__cooking_units_cutext_do:nnnn #1#2#3#4 - { - \bool_if:NTF \l__cooking_units_cutext_to_cunum_bool - { \cunum <#1> [#2] {#3} {#4} } - { - \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4} - } + \bool_if:NT \l__cooking_units_fourty_two_bool + { \tl_set:Nn \l__cooking_units_cutext_last_value_tl { 42 } } } \cs_new:Npn \__cooking_units_cutext:nnnn #1#2#3#4 { - \bool_if:NTF \l__cooking_units_parse_input_bool - { - \bool_if:NTF \l__cooking_units_cutext_old_bool - { - \__cooking_units_old_cutext_default:nnn {#2} {#3} {#4} - \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl - \__cooking_units_cutext_print_correct_unitname: - }{ - \__cooking_units_parse_and_evaluate_input:n {#3} - \__cooking_units_print_correct_unit: - } - }{ - \__cooking_units_do_not_parse:n {#3} - \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl - \__cooking_units_cutext_print_correct_unitname: - } - } -\prg_new_conditional:Npnn \__cooking_units_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:N #1 { TF } - { - \bool_lazy_and:nnTF - { \g__cooking_units_opt_numeral_bool } - { \l__cooking_units_local_numeral_bool } - { - \__cooking_units_if_parse_and_integer:VTF #1 - { - \int_compare:nNnTF {#1} < { \l__cooking_units_print_numerals_below_int } - { \prg_return_true: } - { \prg_return_false: } - }{ \prg_return_false: } - }{ \prg_return_false: } + \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4} + \bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool + { \l__cooking_units_Cutext_hook_tl } + { \l__cooking_units_cutext_hook_tl } + \bool_if:NTF \l__cooking_units_cutext_old_bool + { \__cooking_units_old_cutext:nnn {#2} {#3} {#4} } + { \__cooking_units_parse_input:n {#3} } + \__cooking_units_print_correct_unit: } \cs_new_protected:Npn \__cooking_units_cutext_print_input:Nn #1#2 { - \__cooking_units_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:NTF #1 + \bool_if:NTF \l__cooking_units_lokal_numeral_bool { \__cooking_units_int_if_equal_one:nTF {#1} { @@ -1370,52 +1651,27 @@ } \cs_generate_variant:Nn \__cooking_units_cutext_print_input:Nn { NV } \cs_new_protected:Npn \__cooking_units_cutext_print_input:N #1 - { \__cooking_units_cutext_print_input:NV #1 \l__cooking_units_option_unit_tl } + { + \__cooking_units_change_unit:TF + { \__cooking_units_cutext_print_input:NV #1 \l__cooking_units_option_unit_tl } + { \__cooking_units_cutext_print_input:NV #1 \l__cooking_units_given_unit_tl } + } \cs_new:Npn \__cooking_units_cutext_print_correct_unitname: { \l__cooking_units_cutext_space_tl - \bool_lazy_any:nTF - { - { \l__cooking_units_fraction_in_input_bool } - { \l__cooking_units_special_sign_bool } - { ! \l__cooking_units_parse_input_bool } - } - { \__cooking_units_translate:xx \l__cooking_units_given_unit_tl \c__cooking_units_postfix_unitname_pl_tl } + \__cooking_units_change_unit:TF { \__cooking_units_fp_if_equal_one:nTF { \l__cooking_units_cutext_last_value_tl } { \__cooking_units_translate:xx \l__cooking_units_option_unit_tl \c__cooking_units_postfix_unitname_tl } { \__cooking_units_translate:xx \l__cooking_units_option_unit_tl \c__cooking_units_postfix_unitname_pl_tl } } + { \__cooking_units_translate:xx \l__cooking_units_given_unit_tl \c__cooking_units_postfix_unitname_pl_tl } } \cs_new:Npn \__cooking_units_cutext_pre_process_input:NN #1#2 { - \__cooking_units_cutext_check_unitname_consequences:NN #1#2 - } -\cs_new:Npn \__cooking_units_cutext_post_process_input:NN #1#2 - { - \bool_if:NTF \l__cooking_units_range_in_input_bool - { - \tl_set_eq:NN \l__cooking_units_cutext_last_value_tl #2 - \bool_if:NT \g__cooking_units_opt_numeral_bool - { - \bool_lazy_and:nnF - { \fp_compare_p:nNn {#1} < { \l__cooking_units_print_numerals_below_int } } - { \fp_compare_p:nNn {#2} < { \l__cooking_units_print_numerals_below_int } } - { \bool_set_false:N \l__cooking_units_local_numeral_bool } - } - } - { \tl_set_eq:NN \l__cooking_units_cutext_last_value_tl #1 } - } -\cs_new:Npn \__cooking_units_cutext_check_unitname_consequences:NN #1#2 - { - \bool_lazy_any:nTF - { - { \l__cooking_units_fraction_in_input_bool } - { \l__cooking_units_special_sign_bool } - { ! \l__cooking_units_parse_input_bool } - } - { \tl_set_eq:NN \l__cooking_units_tmpb_tl \l__cooking_units_given_unit_tl } + \__cooking_units_change_unit:TF { \tl_set_eq:NN \l__cooking_units_tmpb_tl \l__cooking_units_option_unit_tl } + { \tl_set_eq:NN \l__cooking_units_tmpb_tl \l__cooking_units_given_unit_tl } \__cooking_units_unitname_get:NxF \l__cooking_units_tmpa_tl \l__cooking_units_tmpb_tl { \msg_warning:nnx @@ -1426,38 +1682,42 @@ \__cooking_units_set_process_and_print_for_cunum: } } -\cs_new:Npn \__cooking_units_old_cutext_default:nnn #1#2#3 +\cs_new:Npn \__cooking_units_cutext_post_process_input:NN #1#2 { - \bool_if:NTF \l__cooking_units_parse_input_bool + \bool_if:NF \l__cooking_units_special_sign_bool { - \tl_set:Nn \l__cooking_units_cutext_last_value_tl {#2} - \tl_if_in:NVTF \l__cooking_units_cutext_last_value_tl \l__cooking_units_input_range_sign_tl - { - \tl_replace_once:NVn \l__cooking_units_cutext_last_value_tl - \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } - \__cooking_units_old_cutext_parse_range:Vn \l__cooking_units_cutext_last_value_tl {#3} - }{ - \__cooking_units_cutext_print_input:Nn \l__cooking_units_cutext_last_value_tl {#3} - } + \__cooking_units_cutext_post_process_input_aux:NN #1#2 } - {#2} } -\cs_new:Npn \__cooking_units_old_cutext_parse_range:Nn #1 #2 +\cs_new:Npn \__cooking_units_cutext_post_process_input_aux:NN #1#2 { - \__cooking_units_old_cutext_parse_range_aux:nww {#2} #1 \q_stop + \__cooking_units_bool_set_if_integers:NNN \l__cooking_units_tmpa_bool #1 #2 + \bool_if:NTF \l__cooking_units_range_in_input_bool + { \tl_set_eq:NN \l__cooking_units_cutext_last_value_tl #2 } + { \tl_set_eq:NN \l__cooking_units_cutext_last_value_tl #1 } + \bool_if:NT \l__cooking_units_lokal_numeral_bool + { \__cooking_units_cutext_post_process_input_numerals:NN #1#2 } } -\cs_generate_variant:Nn \__cooking_units_old_cutext_parse_range:Nn { V } -\cs_new:Npn \__cooking_units_old_cutext_parse_range_aux:nww #1 #2 \q__cooking_units_range #3 \q_stop +\cs_new:Npn \__cooking_units_cutext_post_process_input_numerals:NN #1#2 { - \tl_set:Nn \l__cooking_units_tmpa_tl {#2} - \tl_set:Nn \l__cooking_units_cutext_last_value_tl {#3} - \__cooking_units_cutext_print_input:Nn \l__cooking_units_tmpa_tl {#1} - \tl_use:N \l__cooking_units_cutext_range_sign_tl - \__cooking_units_cutext_print_input:Nn \l__cooking_units_cutext_last_value_tl {#1} + \bool_if:NTF \l__cooking_units_tmpa_bool + { + \bool_if:NTF \l__cooking_units_range_in_input_bool + { + \bool_lazy_and:nnF + { \int_compare_p:nNn {#1} < { \l__cooking_units_print_numerals_below_int } } + { \int_compare_p:nNn {#2} < { \l__cooking_units_print_numerals_below_int } } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + }{ + \int_compare:nNnF {#1} < { \l__cooking_units_print_numerals_below_int } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + } + } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } } \tl_const:Nn \c__cooking_units_cuam_marker_tl { __cooking_units_cunum } \tl_new:c { l__cooking_units_tmpa_ \c__cooking_units_cuam_marker_tl _ tl } -\tl_set:cn { l__cooking_units_tmpa_ \c__cooking_units_cuam_marker_tl _ tl } { \c_one_fp } +\tl_set:cn { l__cooking_units_tmpa_ \c__cooking_units_cuam_marker_tl _ tl } { 1.0 } \clist_new:c { l__cooking_units_predefined_option_ \c__cooking_units_cuam_marker_tl _clist } \NewDocumentCommand \cuam { d<> O{} m } { @@ -1466,115 +1726,94 @@ { \group_begin: \__cooking_units_cuam_initialise:nn {#1} {#2} + \l__cooking_units_cuam_hook_tl \__cooking_units_cuam:n {#3} \group_end: } } \cs_new:Npn \__cooking_units_cuam:n #1 { - \bool_if:NTF \l__cooking_units_parse_input_bool - { - \bool_if:NTF \l__cooking_units_cuam_old_bool - { \__cooking_units_cuam_old:n {#1} } - { - \__cooking_units_parse_and_evaluate_input:n {#1} - \__cooking_units_print_correct_unit: - } - } - { \__cooking_units_do_not_parse:n {#1} } + \bool_if:NTF \l__cooking_units_cuam_old_bool + { \__cooking_units_cuam_old:n {#1} } + { + \__cooking_units_parse_input:n {#1} + \__cooking_units_print_correct_unit: + } } \cs_new_protected:Npn \__cooking_units_cuam_initialise:nn #1#2 { \__cooking_units_set_process_and_print_for_cuam: \tl_set_eq:NN \l__cooking_units_given_unit_tl \c__cooking_units_cuam_marker_tl \tl_set_eq:NN \l__cooking_units_option_unit_tl \c__cooking_units_cuam_marker_tl + \bool_set_false:N \l__cooking_units_lokal_phrase_bool \__cooking_units_initialise_after_unit_change:nn {#1} {#2} } \cs_new_protected:Npn \__cooking_units_cuam_post_process_input:NN #1#2 { - \__cooking_units_if_integer:VTF #1 - { \bool_set_true:N \l__cooking_units_tmpa_bool } - { \bool_set_false:N \l__cooking_units_tmpa_bool } + \bool_if:NF \l__cooking_units_special_sign_bool + { \__cooking_units_cuam_post_process_input_aux:NN #1 #2 } + } +\cs_new:Npn \__cooking_units_cuam_post_process_input_aux:NN #1#2 + { + \__cooking_units_bool_set_if_integers:NNN \l__cooking_units_tmpa_bool #1 #2 \bool_lazy_and:nnT - { \l__cooking_units_range_in_input_bool } { \l__cooking_units_tmpa_bool } + { \l__cooking_units_use_phrases_bool } { \l__cooking_units_tmpa_bool } { - \__cooking_units_if_integer:VTF #2 - { \bool_set_true:N \l__cooking_units_tmpa_bool } - { \bool_set_false:N \l__cooking_units_tmpa_bool } + \__cooking_units_cuam_post_process_input_phrases:NN #1#2 } - \bool_lazy_and:nnT - { \l__cooking_units_use_phrases_bool } { \l__cooking_units_tmpa_bool } + \bool_if:NT \l__cooking_units_lokal_numeral_bool + { + \__cooking_units_cuam_post_process_input_numerals:NN #1#2 + } + } +\cs_new:Npn \__cooking_units_cuam_post_process_input_phrases:NN #1#2 + { + \__cooking_units_get_phrase_for_current_langauge:NNT + \l__cooking_units_phrase_prop + \l__cooking_units_phrase_numbers_clist { - \__cooking_units_if_phrase_list_exists:NT \l__cooking_units_phrase_prop + \__cooking_units_cuam_post_process_input_phrases_aux:NNN + #1 \l__cooking_units_tmpa_int \l__cooking_units_phrase_number_tl + \bool_if:NT \l__cooking_units_lokal_phrase_bool { - \__cooking_units_translate_let:Nxx \l__cooking_units_phrase_numbers_clist - { phrase-list-list } \c__cooking_units_postfix_phrase_tl - \__cooking_units_cuam_process_input_aux:NNN #1 \l__cooking_units_tmpa_int \l__cooking_units_phrase_number_tl - \bool_if:NT \l__cooking_units_check_if_phrase_used_bool + \bool_if:NTF \l__cooking_units_range_in_input_bool { - \bool_if:NTF \l__cooking_units_range_in_input_bool + \__cooking_units_cuam_post_process_input_phrases_aux:NNN + #2 \l__cooking_units_tmpb_int \l__cooking_units_tmpb_tl + \bool_lazy_and:nnF + { \l__cooking_units_lokal_phrase_bool } + { \tl_if_eq_p:NN \l__cooking_units_phrase_number_tl \l__cooking_units_tmpb_tl } + { \bool_set_false:N \l__cooking_units_lokal_phrase_bool } + \bool_if:NT \l__cooking_units_lokal_phrase_bool { - \__cooking_units_cuam_process_input_aux:NNN #2 \l__cooking_units_tmpb_int \l__cooking_units_tmpb_tl - \bool_lazy_and:nnTF - { \l__cooking_units_check_if_phrase_used_bool } - { \tl_if_eq_p:NN \l__cooking_units_phrase_number_tl \l__cooking_units_tmpb_tl } - { \bool_set_true:N \l__cooking_units_check_if_phrase_used_bool } - { \bool_set_false:N \l__cooking_units_check_if_phrase_used_bool } - \bool_if:NT \l__cooking_units_check_if_phrase_used_bool - { - \tl_set:NV #1 \l__cooking_units_tmpa_int - \tl_set:NV #2 \l__cooking_units_tmpb_int - \__cooking_units_cuam_get_phrase_name:NVN - \l__cooking_units_phrase_phrase_tl \l__cooking_units_phrase_number_tl \l__cooking_units_tmpb_int - } - }{ - \tl_set:NV #1 \l__cooking_units_tmpa_int - \__cooking_units_cuam_get_phrase_name:NVN - \l__cooking_units_phrase_phrase_tl \l__cooking_units_phrase_number_tl \l__cooking_units_tmpa_int + \tl_set:NV #1 \l__cooking_units_tmpa_int + \tl_set:NV #2 \l__cooking_units_tmpb_int + \__cooking_units_cuam_get_phrase_name:NVN + \l__cooking_units_phrase_phrase_tl \l__cooking_units_phrase_number_tl \l__cooking_units_tmpb_int } + }{ + \tl_set:NV #1 \l__cooking_units_tmpa_int + \__cooking_units_cuam_get_phrase_name:NVN + \l__cooking_units_phrase_phrase_tl \l__cooking_units_phrase_number_tl \l__cooking_units_tmpa_int } } } - \bool_lazy_and:nnT - { \g__cooking_units_opt_numeral_bool } { \l__cooking_units_local_numeral_bool } - { - \bool_set_eq:NN \l__cooking_units_local_numeral_bool \l__cooking_units_tmpa_bool - \bool_if:NT \l__cooking_units_local_numeral_bool - { - \bool_if:NTF \l__cooking_units_range_in_input_bool - { - \bool_lazy_and:nnF - { \int_compare_p:nNn {#1} < { \l__cooking_units_print_numerals_below_int } } - { \int_compare_p:nNn {#2} < { \l__cooking_units_print_numerals_below_int } } - { \bool_set_false:N \l__cooking_units_local_numeral_bool } - }{ - \int_compare:nNnF {#1} < { \l__cooking_units_print_numerals_below_int } - { \bool_set_false:N \l__cooking_units_local_numeral_bool } - } - } - } } -\prg_new_conditional:Npnn \__cooking_units_cuam_check_if_larger:nn #1#2 { F } +\cs_new:Npn \__cooking_units_cuam_post_process_input_phrases_aux:NNN #1#2#3 { - \int_compare:nNnTF {#1} > {#2} - { \prg_return_true: } - { \prg_return_false: } - } -\cs_new:Npn \__cooking_units_cuam_process_input_aux:NNN #1#2#3 - { - \bool_set_false:N \l__cooking_units_check_if_phrase_used_bool + \bool_set_false:N \l__cooking_units_lokal_phrase_bool \clist_map_inline:Nn \l__cooking_units_phrase_numbers_clist { - \__cooking_units_cuam_check_if_larger:nnF { \int_abs:n {##1} } {#1} + \int_compare:nNnF { \int_abs:n {##1} } > {#1} { - \int_compare:nNnTF {##1} < { \c_zero } - { \int_set_eq:NN \l_tmpa_int \c_one } + \int_compare:nNnTF {##1} < { 0 } + { \int_set:Nn \l_tmpa_int { 1 } } { \int_set:Nn \l_tmpa_int { \int_div_truncate:nn {#1} {##1} } } \int_compare:nNnT { \int_abs:n {##1} * \l_tmpa_int } = {#1} { \int_set_eq:NN #2 \l_tmpa_int \tl_set:Nn #3 {##1} - \bool_set_true:N \l__cooking_units_check_if_phrase_used_bool + \bool_set_true:N \l__cooking_units_lokal_phrase_bool \clist_map_break: } } @@ -1587,14 +1826,29 @@ { \prop_get:NnN \l__cooking_units_phrase_prop { #2-pl } #1 } } \cs_generate_variant:Nn \__cooking_units_cuam_get_phrase_name:NnN { NVN } +\cs_new:Npn \__cooking_units_cuam_post_process_input_numerals:NN #1#2 + { + \bool_if:NTF \l__cooking_units_tmpa_bool + { + \bool_if:NTF \l__cooking_units_range_in_input_bool + { + \bool_lazy_and:nnF + { \int_compare_p:nNn {#1} < { \l__cooking_units_print_numerals_below_int } } + { \int_compare_p:nNn {#2} < { \l__cooking_units_print_numerals_below_int } } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + }{ + \int_compare:nNnF {#1} < { \l__cooking_units_print_numerals_below_int } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + } + } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + } \cs_new_protected:Npn \__cooking_units_cuam_print_numerical_input:N #1 { - \bool_lazy_all:nTF + \bool_lazy_and:nnTF + { \l__cooking_units_lokal_phrase_bool } + { \l__cooking_units_lokal_numeral_bool } { - { \l__cooking_units_check_if_phrase_used_bool } - { \g__cooking_units_opt_numeral_bool } - { \l__cooking_units_local_numeral_bool } - }{ \__cooking_units_int_if_equal_one:nTF {#1} { \__cooking_units_translate_one_to_and_check_existance:Nx \l__cooking_units_translation_tmpa_tl @@ -1606,101 +1860,12 @@ } \cs_new:Npn \__cooking_units_cuam_print_correct_unitphrase: { - \bool_if:NT \l__cooking_units_check_if_phrase_used_bool + \bool_if:NT \l__cooking_units_lokal_phrase_bool { \l__cooking_units_cuphrase_space_tl \l__cooking_units_phrase_phrase_tl } } -\cs_new:Npn \__cooking_units_cuam_old:n #1 - { - \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N\ % - } {#1} - \__cooking_units_cuam_old_parse:V \l__cooking_units_tmpa_tl - } -\cs_new_protected:Npn \__cooking_units_cuam_old_parse:n #1 - { - \tl_if_in:nVTF {#1} \l__cooking_units_input_range_sign_tl - { - \tl_set:Nn \l__cooking_units_tmpa_tl {#1} - \tl_replace_once:NVn \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } - \__cooking_units_cuam_old_parse_range:V \l__cooking_units_tmpa_tl - }{ - \tl_if_in:nnTF {#1} { / } - { - \tl_if_in:nnTF {#1} { _ } - { \__cooking_units_cuam_old_parse_mixed_frac:www #1 \q_stop } - { \__cooking_units_cuam_old_parse_frac:ww #1 \q_stop } - }{ - \tl_if_in:nnTF {#1} { _ } - { \msg_error:nnn { cooking-units } { missing-slash } {#1} } - { \__cooking_units_cuam_old_parse_scale:n {#1} } - } - } - } -\cs_generate_variant:Nn \__cooking_units_cuam_old_parse:n { V } -\cs_new:Npn \__cooking_units_cuam_old_parse_range:n #1 - { - \__cooking_units_cuam_old_parse_range_aux:ww #1 \q_nil - } -\cs_generate_variant:Nn \__cooking_units_cuam_old_parse_range:n { V } -\cs_new:Npn \__cooking_units_cuam_old_parse_range_aux:ww #1 \q__cooking_units_range #2 \q_nil - { - #1 \l__cooking_units_cunum_range_sign_tl #2 - } -\cs_new:Npn \__cooking_units_cuam_old_parse_scale:n #1 {#1} -\cs_new:Npn \__cooking_units_cuam_old_parse_frac:ww #1/#2 \q_stop - { \__cooking_units_frac:nn {#1} {#2} } -\cs_new:Npn \__cooking_units_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop - { - #1 - \hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { } - \__cooking_units_frac:nn {#2} {#3} - } -\NewDocumentCommand \cufrac { O{} m } - { - \msg_error:nnnn { cooking-units } { obsolete-command } { \cufrac } { \cuam } - \group_begin: - \tl_if_empty:nF {#1} - { \keys_set:nn { cooking-units } {#1} } - \__cooking_units_cufrac:n {#2} - \group_end: - } -\cs_new:Npn \__cooking_units_cufrac:n #1 - { - \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N\ % - } {#1} - \__cooking_units_cufrac_parse:V \l__cooking_units_tmpa_tl - } -\cs_new:Npn \__cooking_units_cufrac_parse:n #1 - { - \tl_if_in:nnTF {#1} { / } - { - \tl_if_in:nnTF {#1} { _ } - { \__cooking_units_cufrac_parse_mixed_frac:www #1 \q_stop } - { \__cooking_units_cufrac_parse_frac:ww #1 \q_stop } - }{ - \tl_if_in:nnTF {#1} { _ } - { \msg_error:nnn { cooking-units } { missing-slash } {#1} } - { \__cooking_units_cufrac_parse_scale:n {#1} } - } - } -\cs_generate_variant:Nn \__cooking_units_cufrac_parse:n { V } -\cs_new:Npn \__cooking_units_cufrac_parse_scale:n #1 {#1} -\cs_new:Npn \__cooking_units_cufrac_parse_frac:ww #1/#2 \q_stop - { \__cooking_units_frac:nn {#1} {#2} } -\cs_new:Npn \__cooking_units_cufrac_parse_mixed_frac:www #1_#2/#3 \q_stop - { - #1 - \hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { } - \__cooking_units_frac:nn {#2} {#3} - } \NewDocumentCommand \cudefinekeys { m m } { \bool_set_false:N \l__cooking_units_single_key_bool @@ -1722,11 +1887,11 @@ { \__cooking_units_cukeys_parse_and_create_single_key:nn {#1} {#2} }{ - \fp_set_eq:NN \l__cooking_units_tmpa_fp \c_one_fp + \fp_set:Nn \l__cooking_units_tmpa_fp { 1.0 } \tl_set:Nn \l__cooking_units_given_unit_tl {#1} \__cooking_units_cukeys_parse_and_create_keys:nn {#1} { - {#1} { \c_one_fp } #2 + {#1} { 1.0 } #2 } } } @@ -1758,7 +1923,7 @@ \seq_map_inline:Nn \l__cooking_units_tmpa_seq { \prop_set_eq:cN { l__cooking_units_cukeys_ ##1 _prop } \l__cooking_units_tmpb_prop - \tl_set_eq:cN { l__cooking_units_tmpa_ ##1 _tl } \c_one_fp + \tl_set:cn { l__cooking_units_tmpa_ ##1 _tl } { 1.0 } \seq_map_inline:Nn \l__cooking_units_tmpa_seq { \prop_put:cnx { l__cooking_units_cukeys_ ##1 _prop } @@ -1773,7 +1938,7 @@ } } } -\cs_new:Npn \__cooking_units_cukeys_define_keys:N #1 +\cs_new:Npn \__cooking_units_cukeys_define_keys:n #1 { \seq_map_inline:Nn \l__cooking_units_tmpa_seq { @@ -1801,7 +1966,7 @@ } } } -\cs_generate_variant:Nn \__cooking_units_cukeys_define_keys:N { V } +\cs_generate_variant:Nn \__cooking_units_cukeys_define_keys:n { V } \cs_new:Npn \__cooking_units_cukeys_define_keys_and_single_key_aux:n #1 { \prop_get:cVc @@ -1816,7 +1981,7 @@ { \char_set_catcode_letter:N \# % \char_set_catcode_ignore:N\ % - } { {#1} { \c_one_fp } #2 } + } { {#1} { 1.0 } #2 } \__cooking_units_cusinglekeys_parse_input:V \l__cooking_units_tmpa_tl \__cooking_units_cusinglekeys_create_key_prop:n {#1} \clist_set_from_seq:NN \l__cooking_units_tmpa_clist \l__cooking_units_tmpa_seq @@ -1842,13 +2007,13 @@ } \cs_new:Npn \__cooking_units_cusinglekeys_create_key_prop:n #1 { - \tl_set_eq:cN { l__cooking_units_tmpa_ #1 _tl } \c_one_fp + \tl_set:cn { l__cooking_units_tmpa_ #1 _tl } { 1.0 } \prop_set_eq:cN { l__cooking_units_cukeys_ #1 _prop } \l__cooking_units_tmpa_prop \prop_put:cnn { l__cooking_units_cukeys_ #1 _prop } { Erstes Ding } {#1} \prop_put:cnV { l__cooking_units_cukeys_ #1 _prop } { Liste } \l__cooking_units_tmpa_seq \prop_put:cnV { l__cooking_units_cukeys_ #1 _prop } { prop } \l__cooking_units_tmpa_prop } -\cs_new:Npn \__cooking_units_cukeys_define_singlekey:nN #1#2 +\cs_new:Npn \__cooking_units_cukeys_define_singlekey:nn #1#2 { \seq_if_in:NnF \l__cooking_units_list_of_defined_keys_seq {#1} { \seq_put_right:Nn \l__cooking_units_list_of_defined_keys_seq {#1} } @@ -1873,7 +2038,7 @@ #1 .groups:n = { change-unit } , } } -\cs_generate_variant:Nn \__cooking_units_cukeys_define_singlekey:nN { nV } +\cs_generate_variant:Nn \__cooking_units_cukeys_define_singlekey:nn { nV } \NewDocumentCommand \cuaddkeys { m m } { \bool_set_false:N \l__cooking_units_single_key_bool @@ -1892,7 +2057,7 @@ { \bool_set_false:N \l__cooking_units_single_key_bool \tl_set:Nn \l__cooking_units_tmpa_tl {#1} - \tl_set:Nn \l__cooking_units_tmpb_tl { {#2} { \fp_eval:n { \c_one_fp / (#3) } } } + \tl_set:Nn \l__cooking_units_tmpb_tl { {#2} { \fp_eval:n { 1.0 / (#3) } } } \__cooking_units_cukeys_add_keys_or_single_keys:VV \l__cooking_units_tmpa_tl \l__cooking_units_tmpb_tl } \cs_new:Npn \__cooking_units_cukeys_add_keys_or_single_keys:nn #1#2 @@ -1941,9 +2106,14 @@ \seq_if_in:NnTF \g__cooking_units_list_of_defined_units_seq {#2} { \msg_error:nnn { cooking-units } { unit-already-defined } {#2} } { + \tl_map_inline:nn {#2} + { + \tl_if_in:NnT \l__cooking_units_unit_letter_not_allowed_tl {##1} + { \msg_error:nnn { cooking-units } { character-not-allowed } {#2} } + } \seq_put_right:Nn \g__cooking_units_list_of_defined_units_seq {#2} \tl_new:c { l__cooking_units_tmpa_ #2 _tl } - \tl_set_eq:cN { l__cooking_units_tmpa_ #2 _tl } \c_one_fp + \tl_set:cn { l__cooking_units_tmpa_ #2 _tl } { 1.0 } \clist_new:c { l__cooking_units_predefined_option_#2_clist } \keys_define:nn { cooking-units } { @@ -2124,20 +2294,23 @@ } \__cooking_units_cuprint_define_printed_unit:nn } -\__cooking_units_newtranslation_base:nVn { phrase-list } \c__cooking_units_postfix_phrase_tl { \q__cooking_units_no_translation } -\prg_new_conditional:Npnn \__cooking_units_phrase_list_get_for:NN #1#2 { TF , T , F } +\__cooking_units_newtranslation_base:nVn { phrase-prop } \c__cooking_units_postfix_phrase_tl { \q__cooking_units_no_translation } +\prg_new_conditional:Npnn \__cooking_units_phrase_list_get_for:NN #1#2 { TF } { - \__cooking_units_translate_let:VNxx #2 #1 { phrase-list } \c__cooking_units_postfix_phrase_tl + \__cooking_units_translate_let:VNxx #2 #1 { phrase-prop } \c__cooking_units_postfix_phrase_tl \tl_if_eq:NNTF #1 \q__cooking_units_no_translation { \prg_return_false: } { \prg_return_true: } } -\prg_new_conditional:Npnn \__cooking_units_if_phrase_list_exists:N #1 { TF , T , F } +\prg_new_conditional:Npnn \__cooking_units_get_phrase_for_current_langauge:NN #1#2 { T } { - \__cooking_units_translate_let:Nxx \l_tmpa_tl { phrase-list } \c__cooking_units_postfix_phrase_tl - \tl_if_eq:NNTF \l_tmpa_tl \q__cooking_units_no_translation + \__cooking_units_translate_let:Nxx #1 { phrase-prop } \c__cooking_units_postfix_phrase_tl + \tl_if_eq:NNTF #1 \q__cooking_units_no_translation { \prg_return_false: } - { \prg_return_true: } + { + \__cooking_units_translate_let:Nxx #2 { phrase-clist } \c__cooking_units_postfix_phrase_tl + \prg_return_true: + } } \NewDocumentCommand \cudefinephrase { m m } { @@ -2149,7 +2322,7 @@ \__cooking_units_phrase_list_get_for:NNTF \l__cooking_units_phrase_prop \l__cooking_units_language_tl { \__cooking_units_translate_let:VNxx \l__cooking_units_language_tl \l__cooking_units_phrase_numbers_clist - { phrase-list-list } \c__cooking_units_postfix_phrase_tl + { phrase-clist } \c__cooking_units_postfix_phrase_tl }{ \prop_clear:N \l__cooking_units_phrase_prop \clist_clear:N \l__cooking_units_phrase_numbers_clist @@ -2172,11 +2345,11 @@ } } \__cooking_units_deftranslation_to:VxxV - \l__cooking_units_language_tl { phrase-list } + \l__cooking_units_language_tl { phrase-prop } \c__cooking_units_postfix_phrase_tl \l__cooking_units_phrase_prop \__cooking_units_deftranslation_to:VxxV - \l__cooking_units_language_tl { phrase-list-list } + \l__cooking_units_language_tl { phrase-clist } \c__cooking_units_postfix_phrase_tl \l__cooking_units_phrase_numbers_clist } \cs_new:Npn \__cooking_units_cuphrase_parse:n #1 @@ -2226,6 +2399,164 @@ \c__cooking_units_postfix_gender_tl {#2} \__cooking_units_cuphrase_parse:n } +\cs_new:Npn \__cooking_units_old_cutext:nnn #1#2#3 + { + \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl + \__cooking_units_old_cutext_default:nnn {#1} {#2} {#3} + } +\cs_new:Npn \__cooking_units_old_cutext_default:nnn #1#2#3 + { + \bool_if:NTF \l__cooking_units_draft_bool + {#2} + { + \tl_set:Nn \l__cooking_units_cutext_last_value_tl {#2} + \tl_if_in:NVTF \l__cooking_units_cutext_last_value_tl \l__cooking_units_input_range_sign_tl + { + \tl_replace_once:NVn \l__cooking_units_cutext_last_value_tl + \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } + \__cooking_units_old_cutext_parse_range:Vn \l__cooking_units_cutext_last_value_tl {#3} + }{ + \__cooking_units_old_cutext_print_input:Nn \l__cooking_units_cutext_last_value_tl {#3} + } + } + } +\cs_new_protected:Npn \__cooking_units_old_cutext_print_input:Nn #1#2 + { + \__cooking_units_old_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:NTF #1 + { + \__cooking_units_int_if_equal_one:nTF {#1} + { + \__cooking_units_translate_one_to_and_check_existance:Nx \l__cooking_units_translation_tmpa_tl {#2} + \bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool + { + \exp_args:Nx \tl_upper_case:n { \tl_head:V \l__cooking_units_translation_tmpa_tl } + \tl_tail:V \l__cooking_units_translation_tmpa_tl + } + { \l__cooking_units_translation_tmpa_tl } + }{ + \bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool + { \__cooking_units_print_Numeral:n {#1} } + { \__cooking_units_print_numeral:n {#1} } + } + } + { \__cooking_units_print_numerical_input:N #1 } + } +\prg_new_conditional:Npnn \__cooking_units_old_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:N #1 { TF } + { + \bool_if:NTF \l__cooking_units_lokal_numeral_bool + { + \__cooking_units_if_integer:VTF #1 + { + \int_compare:nNnTF {#1} < { \l__cooking_units_print_numerals_below_int } + { \prg_return_true: } + { \prg_return_false: } + }{ \prg_return_false: } + }{ \prg_return_false: } + } +\cs_new:Npn \__cooking_units_old_cutext_parse_range:nn #1 #2 + { + \__cooking_units_old_cutext_parse_range_aux:nww {#2} #1 \q_stop + } +\cs_generate_variant:Nn \__cooking_units_old_cutext_parse_range:nn { V } +\cs_new:Npn \__cooking_units_old_cutext_parse_range_aux:nww #1 #2 \q__cooking_units_range #3 \q_stop + { + \tl_set:Nn \l__cooking_units_tmpa_tl {#2} + \tl_set:Nn \l__cooking_units_cutext_last_value_tl {#3} + \__cooking_units_old_cutext_print_input:Nn \l__cooking_units_tmpa_tl {#1} + \tl_use:N \l__cooking_units_cutext_range_sign_tl + \__cooking_units_old_cutext_print_input:Nn \l__cooking_units_cutext_last_value_tl {#1} + } +\cs_new:Npn \__cooking_units_cuam_old:n #1 + { + \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N\ % + } {#1} + \bool_if:NTF \l__cooking_units_draft_bool + { \l__cooking_units_tmpa_tl } + { \__cooking_units_cuam_old_parse:V \l__cooking_units_tmpa_tl } + } +\cs_new_protected:Npn \__cooking_units_cuam_old_parse:n #1 + { + \tl_if_in:nVTF {#1} \l__cooking_units_input_range_sign_tl + { + \tl_set:Nn \l__cooking_units_tmpa_tl {#1} + \tl_replace_once:NVn \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } + \__cooking_units_cuam_old_parse_range:V \l__cooking_units_tmpa_tl + }{ + \tl_if_in:nnTF {#1} { / } + { + \tl_if_in:nnTF {#1} { _ } + { \__cooking_units_cuam_old_parse_mixed_frac:www #1 \q_stop } + { \__cooking_units_cuam_old_parse_frac:ww #1 \q_stop } + }{ + \tl_if_in:nnTF {#1} { _ } + { \msg_error:nnn { cooking-units } { missing-slash } {#1} } + { \__cooking_units_cuam_old_parse_scale:n {#1} } + } + } + } +\cs_generate_variant:Nn \__cooking_units_cuam_old_parse:n { V } +\cs_new:Npn \__cooking_units_cuam_old_parse_range:n #1 + { + \__cooking_units_cuam_old_parse_range_aux:ww #1 \q_nil + } +\cs_generate_variant:Nn \__cooking_units_cuam_old_parse_range:n { V } +\cs_new:Npn \__cooking_units_cuam_old_parse_range_aux:ww #1 \q__cooking_units_range #2 \q_nil + { + #1 \l__cooking_units_cunum_range_sign_tl #2 + } +\cs_new:Npn \__cooking_units_cuam_old_parse_scale:n #1 {#1} +\cs_new:Npn \__cooking_units_cuam_old_parse_frac:ww #1/#2 \q_stop + { \__cooking_units_frac:nn {#1} {#2} } +\cs_new:Npn \__cooking_units_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop + { + #1 + \__cooking_units_dim_horizontal:N \l__cooking_units_mixed_frac_dim + \__cooking_units_frac:nn {#2} {#3} + } +\NewDocumentCommand \cufrac { O{} m } + { + \msg_error:nnnn { cooking-units } { obsolete-command } { \cufrac } { \cuam } + \group_begin: + \tl_if_empty:nF {#1} + { \keys_set:nn { cooking-units } {#1} } + \__cooking_units_cufrac:n {#2} + \group_end: + } +\cs_new:Npn \__cooking_units_cufrac:n #1 + { + \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N\ % + } {#1} + \__cooking_units_cufrac_parse:V \l__cooking_units_tmpa_tl + } +\cs_new:Npn \__cooking_units_cufrac_parse:n #1 + { + \tl_if_in:nnTF {#1} { / } + { + \tl_if_in:nnTF {#1} { _ } + { \__cooking_units_cufrac_parse_mixed_frac:www #1 \q_stop } + { \__cooking_units_cufrac_parse_frac:ww #1 \q_stop } + }{ + \tl_if_in:nnTF {#1} { _ } + { \msg_error:nnn { cooking-units } { missing-slash } {#1} } + { \__cooking_units_cufrac_parse_scale:n {#1} } + } + } +\cs_generate_variant:Nn \__cooking_units_cufrac_parse:n { V } +\cs_new:Npn \__cooking_units_cufrac_parse_scale:n #1 {#1} +\cs_new:Npn \__cooking_units_cufrac_parse_frac:ww #1/#2 \q_stop + { \__cooking_units_frac:nn {#1} {#2} } +\cs_new:Npn \__cooking_units_cufrac_parse_mixed_frac:www #1_#2/#3 \q_stop + { + #1 + \__cooking_units_dim_horizontal:N \l__cooking_units_mixed_frac_dim + \__cooking_units_frac:nn {#2} {#3} + } \NewDocumentCommand \cusetup { m } { \keys_set:nn { cooking-units } {#1} @@ -2488,6 +2819,7 @@ F = -459.67 , Re = -218.52 } , + round-precision = 2 , } \endinput %% |