summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2021-06-10 23:26:30 +0000
committerKarl Berry <karl@freefriends.org>2021-06-10 23:26:30 +0000
commit6fa2b67240b617ae507f7ece3c19b7114ef4401e (patch)
tree0faafae4a2c49f56b2d0426fb941ae3940ebb3ac /Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
parente210ea73f3ec3a514f35760dddcbc0b4f7d74312 (diff)
cooking-units (11jun21)
git-svn-id: svn://tug.org/texlive/trunk@59542 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty')
-rw-r--r--Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty3106
1 files changed, 1833 insertions, 1273 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 f0f5dd527d3..8e2ca347148 100644
--- a/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
+++ b/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
@@ -5,7 +5,7 @@
%% The original source files were:
%%
%% cooking-units.dtx (with options: `package')
-%% Copyright (C) 2016--2020 by Ben Vitecek (current Maintainer)
+%% Copyright (C) 2016--2021 by Ben Vitecek (current Maintainer)
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
@@ -30,10 +30,10 @@
{ \RequirePackage {expl3} }
\ProvidesExplPackage
{cooking-units}
- {2020/01/13}
- {1.46}
+ {2021/05/16}
+ {2.00}
{Ein Paket fuer Kocheinheiten}
-\@ifpackagelater { expl3 } { 2018/08/23 }
+\@ifpackagelater { expl3 } { 2021/05/07 }
{ }
{
\PackageError { cooking-units } { Support~package~expl3~too~old }
@@ -47,7 +47,7 @@
\@ifpackageloaded { translations } { } { \RequirePackage { translations } }
\@ifpackageloaded { xfrac } { } { \RequirePackage { xfrac } }
\@ifpackageloaded { l3keys2e } { } { \RequirePackage { l3keys2e } }
-\@ifpackagelater { translations } { 2017/08/31 }
+\@ifpackagelater { translations } { 2021/01/17 }
{ }
{
\PackageError { cooking-units } { Support~package~translations~too~old }
@@ -65,6 +65,12 @@
Please \ replace \ the \ option.
\msg_see_documentation_text:n { cooking-units }
}
+\msg_new:nnnn { cooking-units } { key-unknown }
+ { The~key~'#1'~is~unknown~and~is~being~ignored. }
+ {
+ The~module~'#2'~does~not~have~a~key~called~'#1'.\\
+ Check~that~you~have~spelled~the~key~name~correctly.
+ }
\bool_new:N \g__cookingunits_opt_numeral_bool
\keys_define:nn { cooking-units }
{
@@ -76,6 +82,9 @@
use-numerals .default:n = { false },
use-fmtcount-numerals .bool_gset:N = \g__cookingunits_opt_numeral_bool ,
use-fmtcount-numerals .default:n = { false },
+ unknown .code:n = { \msg_error:nnxx { cooking-units } { key-unknown }
+ { \l_keys_path_str } { cooking-units }
+ }
}
\ProcessKeysOptions { cooking-units }
\bool_if:NT \g__cookingunits_opt_numeral_bool
@@ -87,25 +96,37 @@
use-numerals .code:n =
{
\msg_warning:nnnn { cooking-units } { Option-deprecated } { use-numerals } { use-fmtcount-numerals }
- \msg_error:nnn { cooking-units } { load-time-option } { fmtcount }
+ \msg_error:nnn { cooking-units } { load-time-option } { use-fmtcount-numerals }
} ,
- use-fmtcount-numerals .code:n = { \msg_error:nnn { cooking-units } { load-time-option } { fmtcount } } ,
+ use-fmtcount-numerals .code:n = { \msg_error:nnn { cooking-units } { load-time-option } { use-fmtcount-numerals } } ,
}
+\cs_generate_variant:Nn \msg_redirect_name:nnn { nnV }
\cs_generate_variant:Nn \tl_replace_all:Nnn { NVn }
\cs_generate_variant:Nn \tl_replace_once:Nnn { NVn }
\cs_generate_variant:Nn \tl_if_in:nnTF { nV }
\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 { vNnT }
-\cs_generate_variant:Nn \prop_get:NnN { cVc }
+\cs_generate_variant:Nn \prop_get:NnN { cVc, Nnc }
+\cs_generate_variant:Nn \prop_get:NnNF { Nnc }
\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_generate_variant:Nn \msg_warning:nnn { nnV }
\cs_generate_variant:Nn \prop_put:Nnn { cnx }
+\cs_generate_variant:Nn \seq_remove_all:Nn { NV }
+\cs_generate_variant:Nn \prop_gput:Nnn { Nnv, Nxv }
+\cs_generate_variant:Nn \prop_get:NnN { cnc }
+\cs_generate_variant:Nn \prg_new_conditional:Npnn { c }
+\cs_generate_variant:Nn \text_uppercase:n { x }
\cs_new_eq:NN \__cookingunits_frac:nn \sfrac
+\tl_new:N \l__cookingunits_unit_argument_spec_tl
+\tl_new:N \l__cookingunits_expand_amount_tl
+\tl_set:Nn \l__cookingunits_unit_argument_spec_tl { n }
+\tl_set:Nn \l__cookingunits_expand_amount_tl { n }
\cs_new_eq:NN \__cookingunits_set_amount:Nn \tl_set:Nn
-\cs_new_eq:NN \__cookingunits_set_unit:Nn \tl_set:Nn
+\cs_new_eq:NN \__cookingunits_set_unit:Nn \str_set:Nn
+\cs_new_eq:NN \__cookingunits_to_unit:n \tl_to_str:n
\cs_new:Npn \__cookingunits_print_numeral:n #1
{ \msg_error:nnn {cooking-units} { define-numeral-function } }
\cs_new:Npn \__cookingunits_print_Numeral:n #1
@@ -115,8 +136,12 @@
\cs_set_eq:NN \__cookingunits_print_numeral:n \numberstringnum
\cs_set_eq:NN \__cookingunits_print_Numeral:n \Numberstringnum
}
+\cs_generate_variant:Nn \__cookingunits_print_numeral:n { V }
+\cs_generate_variant:Nn \__cookingunits_print_Numeral:n { V }
\prop_new:N \l__cookingunits_change_unit_prop
\prop_new:N \g__cookingunits_master_changer_prop
+\prop_new:N \g__cookingunits_convert_to_eV_remember_prop
+\prop_new:N \g__cookingunits_convert_bonkers_remember_prop
\tl_new:N \l__cookingunits_number_tmpa_tl
\tl_new:N \l__cookingunits_number_tmpb_tl
\tl_new:N \l__cookingunits_mixed_fraction_tl
@@ -134,16 +159,26 @@
\tl_new:N \g__cookingunits_input_str_hash_one_tl
\tl_new:N \l__cookingunits_input_range_sign_tl
\tl_new:N \l__cookingunits_cutext_space_tl
+\tl_new:N \l__cookingunits_cutext_numeral_space_tl
\tl_new:N \l__cookingunits_cuphrase_space_tl
\tl_new:N \l__cookingunits_translation_tmpa_tl
\tl_new:N \l__cookingunits_cutext_last_value_tl
\tl_new:N \l__cookingunits_phantom_tl
-\tl_new:N \l__cookingunits_phrase_phrase_tl
+\tl_new:N \l__cookingunits_phrase_text_tl
\tl_new:N \l__cookingunits_unit_letter_not_allowed_tl
\tl_new:N \l__cookingunits_input_fraction_sign_tl
\tl_new:N \l__cookingunits_input_mixed_fraction_sign_tl
\tl_new:N \l__cookingunits_list_of_units_tl
\tl_new:N \l__cookingunits_list_of_values_tl
+\tl_new:N \l__cookingunits_allwed_integer_math_operators_tl
+\tl_new:N \l__cookingunits_curr_group_tl
+\tl_new:N \l__cookingunits_curr_unit_tl
+\tl_new:N \l__cookingunits_new_key_base_tl
+\tl_new:N \l__cookingunits_decided_unit_tl
+\tl_new:N \l__cookingunits_stored_units_tl
+\tl_new:N \l__cookingunits_stored_formula_tl
+\tl_new:N \l__cookingunits_base_tl
+\tl_new:N \l__cookingunits_cmd_hook_tl
\tl_new:N \l__cookingunits_cunum_hook_tl
\tl_new:N \l__cookingunits_cutext_hook_tl
\tl_new:N \l__cookingunits_Cutext_hook_tl
@@ -157,10 +192,12 @@
\tl_set:Nn \l__cookingunits_input_allowed_special_signs_tl { ? }
\tl_gset_rescan:Nnn \g__cookingunits_input_str_hash_one_tl
{ \char_set_catcode_letter:N \# } {#1}
+\tl_set:Nn \l__cookingunits_allwed_integer_math_operators_tl { +-()*/ }
\tl_set:Nn \l__cookingunits_cunum_range_sign_tl { -- }
\tl_set:Nn \l__cookingunits_cutext_range_sign_tl { }
\tl_set:Nn \l__cookingunits_value_unit_space_tl { \thinspace }
-\tl_set:Nn \l__cookingunits_cutext_space_tl { \space }
+\tl_set:Nn \l__cookingunits_cutext_space_tl { ~ }
+\tl_set:Nn \l__cookingunits_cutext_numeral_space_tl { \space }
\tl_set:Nn \l__cookingunits_cuphrase_space_tl { \space }
\tl_set:Nn \l__cookingunits_unit_letter_not_allowed_tl { , / }
\AtBeginDocument {
@@ -195,56 +232,58 @@
\int_new:N \l__cookingunits_wanted_number_of_persons_int
\int_set:Nn \l__cookingunits_wanted_number_of_persons_int { 4 }
\int_new:N \l__cookingunits_phrase_number_tl
+\int_new:N \l__cookingunits_phrase_gender_tl
\seq_new:N \l__cookingunits_list_of_defined_keys_seq
\seq_new:N \g__cookingunits_list_of_defined_units_seq
\seq_new:N \g__cookingunits_allowed_special_keys_seq
\seq_new:N \l__cookingunits_phrase_numbers_seq
-\seq_new:N \l__cookingunits_number_of_iterations_seq
-\seq_new:N \l__cookingunits_derivative_unit_list_seq
-\seq_new:N \l__cookingunits_derivative_symbol_list_seq
-\seq_new:N \l__cookingunits_derivative_value_list_seq
-\int_new:N \l__cookingunits_max_depth_int
-\int_new:N \l__cookingunits_curr_depth_int
+\seq_new:N \g__cookingunits_stored_derived_unit_symbol_seq
+\seq_new:N \g__cookingunits_stored_derived_formula_seq
+\seq_new:N \g__cookingunits_stored_derived_unit_print_seq
+\int_new:N \l__cookingunits_nr_of_units_int
+\int_new:N \l__cookingunits_depth_int
+\seq_new:N \g__cookingunits_natural_units_seq
\seq_new:N \l__cookingunits_temperatures_to_check_seq
\seq_new:N \l__cookingunits_curef_do_not_change_seq
\prop_new:N \l__cookingunits_phrase_prop
+\prop_new:N \l__cookingunits_derived_units_prop
+\bool_new:N \l__cookingunits_pckopt_eval_fractions_bool
+\bool_new:N \l__cookingunits_pckopt_convert_fractions_bool
+\bool_new:N \l__cookingunits_pckopt_draft_bool
+\bool_new:N \l__cookingunits_pckopt_round_to_int_bool
+\bool_new:N \l__cookingunits_pckopt_check_temperature_bool
+\bool_new:N \l__cookingunits_pckopt_convert_to_eV_bool
+\bool_new:N \l__cookingunits_pckopt_cuam_old_bool
+\bool_new:N \l__cookingunits_pckopt_recalculate_amount_bool
+\bool_new:N \l__cookingunits_pckopt_cutext_to_cunum_bool
+\bool_new:N \l__cookingunits_pckopt_cutext_old_bool
+\bool_new:N \l__cookingunits_pckopt_cutext_keep_unit_bool
+\bool_new:N \l__cookingunits_pckopt_round_commercial_bool
+\bool_new:N \l__cookingunits_pckopt_use_phrases_bool
+\bool_new:N \l__cookingunits_pckopt_round_precision_negative_bool
+\bool_new:N \l__cookingunits_pckopt_fourty_two_bool
+\bool_new:N \l__cookingunits_pckopt_bonkers_bool
\bool_new:N \l__cookingunits_minus_bool
\bool_new:N \l__cookingunits_round_number_bool
-\bool_new:N \l__cookingunits_error_bool
-\bool_new:N \l__cookingunits_unit_error_bool
-\bool_new:N \l__cookingunits_eval_fractions_bool
-\bool_new:N \l__cookingunits_convert_fractions_bool
-\bool_new:N \l__cookingunits_draft_bool
-\bool_new:N \l__cookingunits_round_to_int_bool
-\bool_new:N \l__cookingunits_special_sign_bool
\bool_new:N \l__cookingunits_single_key_bool
-\bool_new:N \l__cookingunits_check_temperature_bool
-\bool_new:N \l__cookingunits_convert_to_eV_bool
\bool_new:N \l__cookingunits_cutext_uppercase_word_bool
-\bool_new:N \l__cookingunits_using_cutext_bool
-\bool_new:N \l__cookingunits_cuam_old_bool
-\bool_new:N \l__cookingunits_change_number_of_persons_bool
-\bool_new:N \l__cookingunits_calc_because_ref_was_given_bool
-\bool_new:N \l__cookingunits_lokal_persons_bool
-\bool_new:N \l__cookingunits_cutext_to_cunum_bool
-\bool_new:N \l__cookingunits_cutext_old_bool
-\bool_new:N \l__cookingunits_cutext_keep_unit_bool
-\bool_new:N \l__cookingunits_round_commercial_bool
-\bool_new:N \l__cookingunits_use_phrases_bool
+\bool_new:N \l__cookingunits_reference_given_bool
+\bool_new:N \l__cookingunits_lokal_recalc_for_people_bool
\bool_new:N \l__cookingunits_lokal_phrase_bool
-\bool_new:N \l__cookingunits_print_numeral_bool
+\bool_new:N \l__cookingunits_lokal_change_unit_bool
+\bool_new:N \l__cookingunits_pckopt_print_numeral_bool
\bool_new:N \l__cookingunits_lokal_numeral_bool
-\bool_new:N \l__cookingunits_round_precision_negative_bool
-\bool_new:N \l__cookingunits_fourty_two_bool
\bool_new:N \l__cookingunits_phrase_negative_bool
-\bool_new:N \l__cookingunits_range_in_input_bool
-\bool_new:N \l__cookingunits_lokal_fraction_bool
-\bool_new:N \l__cookingunits_print_fraction_bool
+\bool_new:N \l__cookingunits_cutext_last_amount_equ_one_bool
+\bool_new:N \l__cookingunits_symbol_was_set_by_key_bool
+\bool_new:N \l__cookingunits_contains_valid_key_bool
\bool_new:N \l__cookingunits_check_decimal_bool
-\bool_set_false:N \l__cookingunits_cutext_keep_unit_bool
-\bool_set_eq:NN \l__cookingunits_print_numeral_bool \g__cookingunits_opt_numeral_bool
+\bool_new:N \l__cookingunits_unit_error_bool
+\bool_set_false:N \l__cookingunits_pckopt_cutext_keep_unit_bool
+\bool_set_eq:NN \l__cookingunits_pckopt_print_numeral_bool \g__cookingunits_opt_numeral_bool
\quark_new:N \q__cookingunits_range
\quark_new:N \q__cookingunits_no_translation
+\tl_new:N \l__cookingunits_scrap_tl
\tl_new:N \l__cookingunits_tmpa_tl
\tl_new:N \l__cookingunits_tmpb_tl
\tl_new:N \l__cookingunits_tmp_unit_tl
@@ -253,8 +292,11 @@
\prop_new:N \l__cookingunits_tmpa_prop
\prop_new:N \l__cookingunits_tmpb_prop
\seq_new:N \l__cookingunits_tmpa_seq
+\seq_new:N \l__cookingunits_tmpb_seq
\int_new:N \l__cookingunits_tmpa_int
\int_new:N \l__cookingunits_tmpb_int
+\bool_new:N \l__cookingunits_tmpa_bool
+\bool_new:N \l__cookingunits_tmpb_bool
\keys_define:nn { cooking-units }
{
add-unit-to-group .code:n =
@@ -281,18 +323,19 @@
},
erase-all-options .code:n =
{
- \exp_args:Nx \cuclearoptionfor { \seq_use:Nn \g__cookingunits_list_of_defined_units_seq { , } }
- },
+ \clist_set_from_seq:NN \l__cookingunits_tmpa_clist \g__cookingunits_list_of_defined_units_seq
+ \__cookingunits_clear_options_for:V \l__cookingunits_tmpa_clist
+ },
erase-all-options .value_forbidden:n = { true } ,
erase-all-options-for .code:n =
{
- \cuclearoptionfor {#1}
+ \__cookingunits_clear_options_for:n {#1}
},
erase-all-options-for .value_required:n = { true } ,
- cutext-to-cunum .bool_set:N = \l__cookingunits_cutext_to_cunum_bool ,
+ cutext-to-cunum .bool_set:N = \l__cookingunits_pckopt_cutext_to_cunum_bool ,
cutext-to-cunum .default:n = { false } ,
cutext-to-cunum .groups:n = { change-command } ,
- cutext-change-unit .bool_set_inverse:N = \l__cookingunits_cutext_keep_unit_bool ,
+ cutext-change-unit .bool_set_inverse:N = \l__cookingunits_pckopt_cutext_keep_unit_bool ,
cutext-change-unit .default:n = { true } ,
cutext-change-unit .groups:n = { change-unit } ,
cuam-version .choices:nn =
@@ -300,40 +343,45 @@
{
\int_case:nn { \l_keys_choice_int }
{
- { 1 } { \bool_set_false:N \l__cookingunits_cuam_old_bool }
- { 2 } { \bool_set_true:N \l__cookingunits_cuam_old_bool }
+ { 1 } { \bool_set_false:N \l__cookingunits_pckopt_cuam_old_bool }
+ { 2 } { \bool_set_true:N \l__cookingunits_pckopt_cuam_old_bool }
}
} ,
cuam-version .default:n = { new } ,
+ cuam-version .groups:n = { parse } ,
cutext-version .choices:nn =
{ new , old }
{
\int_case:nn { \l_keys_choice_int }
{
- { 1 } { \bool_set_false:N \l__cookingunits_cutext_old_bool }
- { 2 } { \bool_set_true:N \l__cookingunits_cutext_old_bool }
+ { 1 } { \bool_set_false:N \l__cookingunits_pckopt_cutext_old_bool }
+ { 2 } { \bool_set_true:N \l__cookingunits_pckopt_cutext_old_bool }
}
} ,
cutext-version .default:n = { new } ,
+ cutext-version .groups:n = { parse } ,
expand-both .choices:nn =
{ n , o , f , x }
{
- \cs_set_eq:Nc \__cookingunits_set_unit:Nn { tl_set:N \l_keys_choice_tl }
- \cs_set_eq:Nc \__cookingunits_set_amount:Nn { tl_set:N \l_keys_choice_tl }
+ \tl_set_eq:NN \l__cookingunits_unit_argument_spec_tl \l_keys_choice_tl
+ \tl_set_eq:NN \l__cookingunits_expand_amount_tl \l_keys_choice_tl
} ,
expand-both .default:n = { n } ,
+ expand-both .groups:n = { parse } ,
expand-amount .choices:nn =
{ n , o , f , x }
{
- \cs_set_eq:Nc \__cookingunits_set_amount:Nn { tl_set:N \l_keys_choice_tl }
+ \tl_set_eq:NN \l__cookingunits_expand_amount_tl \l_keys_choice_tl
} ,
expand-amount .default:n = { n } ,
+ expand-amount .groups:n = { parse } ,
expand-unit .choices:nn =
{ n , o , f , x }
{
- \cs_set_eq:Nc \__cookingunits_set_unit:Nn { tl_set:N \l_keys_choice_tl }
+ \tl_set_eq:NN \l__cookingunits_unit_argument_spec_tl \l_keys_choice_tl
} ,
expand-unit .default:n = { n } ,
+ expand-unit .groups:n = { parse } ,
set-special-sign .code:n =
{
\tl_map_inline:nn {#1}
@@ -346,6 +394,7 @@
}
\use:n { \tl_set:Nn \l__cookingunits_input_allowed_special_signs_tl {#1} }
} ,
+ set-special-sign .groups:n = { parse } ,
add-special-sign .code:n =
{
\tl_map_inline:nn {#1}
@@ -359,26 +408,28 @@
}
} ,
add-special-sign .default:n = { } ,
+ add-special-sign .groups:n = { parse } ,
set-unknown-message .choices:nn =
{ error , warning , none }
{
- \msg_redirect_name:nnn { cooking-units } { amount-not-known }
- { \l_keys_choice_tl }
+ \msg_redirect_name:nnV { cooking-units } { amount-not-known }
+ \l_keys_choice_tl
} ,
set-unknown-message .default:n = { warning } ,
set-cutext-translation-message .choices:nn =
{ error , warning , none }
{
- \msg_redirect_name:nnn { cooking-units } { cutext-no-translation-available }
- { \l_keys_choice_tl }
+ \msg_redirect_name:nnV { cooking-units } { cutext-no-translation-available }
+ \l_keys_choice_tl
} ,
set-cutext-translation-message .default:n = { warning } ,
- print-numerals .bool_set:N = \l__cookingunits_print_numeral_bool ,
+ print-numerals .bool_set:N = \l__cookingunits_pckopt_print_numeral_bool ,
print-numerals .default:n = { true } ,
use-numerals-below .int_set:N = \l__cookingunits_print_numerals_below_int ,
use-numerals-below .default:n = { 13 } ,
- parse-number .bool_set_inverse:N = \l__cookingunits_draft_bool ,
+ parse-number .bool_set_inverse:N = \l__cookingunits_pckopt_draft_bool ,
parse-number .default:n= { true } ,
+ parse-number .groups:n = { parse } ,
range-sign .meta:n =
{
cunum-range-sign = {#1} ,
@@ -389,7 +440,7 @@
cunum-range-sign .default:n = { -- } ,
cutext-range-sign .tl_set:N = \l__cookingunits_cutext_range_sign_tl ,
cutext-range-sign .default:n = { -- } ,
- use-phrases .bool_set:N = \l__cookingunits_use_phrases_bool ,
+ use-phrases .bool_set:N = \l__cookingunits_pckopt_use_phrases_bool ,
use-phrases .default:n = { true } ,
round-precision .code:n =
{
@@ -397,10 +448,10 @@
\int_compare:nNnTF {#1} < { 0 }
{ \bool_set_true:N }
{ \bool_set_false:N }
- \l__cookingunits_round_precision_negative_bool
+ \l__cookingunits_pckopt_round_precision_negative_bool
} ,
round-precision .default:n = { 2 } ,
- round-to-int .bool_set:N = \l__cookingunits_round_to_int_bool ,
+ round-to-int .bool_set:N = \l__cookingunits_pckopt_round_to_int_bool ,
round-to-int .choices:nn =
{ true , false }
{
@@ -411,22 +462,23 @@
}{
}
- \use:c { bool_set_ \l_keys_choice_tl :N } \l__cookingunits_round_to_int_bool
+ \use:c { bool_set_ \l_keys_choice_tl :N } \l__cookingunits_pckopt_round_to_int_bool
} ,
round-to-int .default:n = { false } ,
round-half .choices:nn =
- { default , commercial }
+ { default , commercial , up }
{
\int_case:nn { \l_keys_choice_int }
{
- { 1 } { \bool_set_false:N \l__cookingunits_round_commercial_bool }
- { 2 } { \bool_set_true:N \l__cookingunits_round_commercial_bool }
+ { 1 } { \bool_set_false:N \l__cookingunits_pckopt_round_commercial_bool }
+ { 2 } { \bool_set_true:N \l__cookingunits_pckopt_round_commercial_bool }
+ { 3 } { \bool_set_true:N \l__cookingunits_pckopt_round_commercial_bool }
}
},
round-half .default:n = { default },
- eval-fraction .bool_set:N = \l__cookingunits_eval_fractions_bool ,
+ eval-fraction .bool_set:N = \l__cookingunits_pckopt_eval_fractions_bool ,
eval-fraction .default:n = { false } ,
- convert-fraction .bool_set:N = \l__cookingunits_convert_fractions_bool ,
+ convert-fraction .bool_set:N = \l__cookingunits_pckopt_convert_fractions_bool ,
convert-fraction .default:n = { true } ,
fraction-command .code:n = { \cs_set_eq:NN \__cookingunits_frac:nn #1 } ,
fraction-command .default:n = { \sfrac } ,
@@ -435,22 +487,24 @@
mixed-fraction-space .dim_set:N = \l__cookingunits_mixed_frac_dim ,
mixed-fraction-space .default:n = { 0.1 em } ,
cutext-space .tl_set:N = \l__cookingunits_cutext_space_tl ,
- cutext-space .default:n = { \space } ,
+ cutext-space .default:n = { ~ } ,
+ cutext-numeral-space .tl_set:N = \l__cookingunits_cutext_numeral_space_tl ,
+ cutext-numeral-space .default:n = { \space } ,
phrase-space .tl_set:N = \l__cookingunits_cuphrase_space_tl ,
- phrase-space .default:n = { \space } ,
+ phrase-space .default:n = { ~ } ,
amount-unit-space .tl_set:N = \l__cookingunits_value_unit_space_tl ,
amount-unit-space .default:n = { \thinspace } ,
- recalculate-amount .bool_set:N = \l__cookingunits_change_number_of_persons_bool ,
+ recalculate-amount .bool_set:N = \l__cookingunits_pckopt_recalculate_amount_bool ,
recalculate-amount .default:n = { false } ,
set-number-of-persons .int_set:N = \l__cookingunits_wanted_number_of_persons_int ,
set-number-of-persons .default:n = { 4 } ,
label .code:n = \__cookingunits_label_and_persons:n {#1} ,
label .value_required:n = { true } ,
get-label .code:n = \__cookingunits_curef:n {#1} ,
- label .value_required:n = { true } ,
+ get-label .value_required:n = { true } ,
ref .code:n = \__cookingunits_reference_label_and_persons:n {#1} ,
ref .value_required:n = { true } ,
- check-temperature .bool_set:N = \l__cookingunits_check_temperature_bool ,
+ check-temperature .bool_set:N = \l__cookingunits_pckopt_check_temperature_bool ,
check-temperature .default:n = { true } ,
add-temperature-to-check .code:n =
{
@@ -460,28 +514,29 @@
{#1}
} ,
temperature-to-check .value_required:n = { true } ,
- convert-to-eV .bool_set:N = \l__cookingunits_convert_to_eV_bool ,
+ convert-to-eV .bool_set:N = \l__cookingunits_pckopt_convert_to_eV_bool ,
convert-to-eV .default:n = { true } ,
- convert-to-eV .groups:n = { change-unit } ,
add-natural-unit .code:n =
{
\seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
\seq_map_inline:Nn \l__cookingunits_tmpa_seq
{
- \__cookingunits_error_if_unit_not_defined:nF {##1}
+ \__cookingunits_error_if_unit_not_defined:nNF {##1} \l__cookingunits_curr_unit_tl
{
- \seq_if_in:NnF \g__cookingunits_natural_units_seq {##1}
- { \seq_gput_right:Nn \g__cookingunits_natural_units_seq {##1} }
+ \seq_if_in:NVF \g__cookingunits_natural_units_seq \l__cookingunits_curr_unit_tl
+ { \seq_gput_right:NV \g__cookingunits_natural_units_seq \l__cookingunits_curr_unit_tl }
}
}
} ,
add-natural-unit .value_required:n = { true } ,
42 .choice: ,
- 42 / true .code:n = { \bool_set_true:N \l__cookingunits_fourty_two_bool } ,
+ 42 / true .code:n = { \bool_set_true:N \l__cookingunits_pckopt_fourty_two_bool } ,
42 / false .code:n = { \msg_fatal:nnn { cooking-units } { 42-is-...-wrong? } } ,
42 .default:n = { true } ,
+ 42 .groups:n = { parse } ,
input-range-sign .tl_set:N = \l__cookingunits_input_range_sign_tl ,
input-range-sign .default:n = { -- } ,
+ input-range-sign .groups:n = { parse } ,
numeral-function .code:n = { \cs_set_eq:NN \__cookingunits_print_numeral:n #1 } ,
Numeral-function .code:n = { \cs_set_eq:NN \__cookingunits_print_Numeral:n #1 } ,
commands-add-hook .meta:n =
@@ -495,6 +550,11 @@
cutext-add-hook .code:n = { \tl_put_right:Nn \l__cookingunits_cutext_hook_tl {#1} } ,
Cutext-add-hook .code:n = { \tl_put_right:Nn \l__cookingunits_Cutext_hook_tl {#1} } ,
cuam-add-hook .code:n = { \tl_put_right:Nn \l__cookingunits_cuam_hook_tl {#1} } ,
+ cunum-add-hook .groups:n = { parse } ,
+ cutext-add-hook .groups:n = { parse } ,
+ Cutext-add-hook .groups:n = { parse } ,
+ cuam-add-hook .groups:n = { parse } ,
+ commands-add-hook .groups:n = { parse } ,
curef-add-forbidden-unit .code:n = { \__cookingunits_add_forbidden_unit:n {#1} } ,
curef-add-forbidden-unit .default:n = { } ,
curef-remove-forbidden-unit .code:n = { \__cookingunits_remove_forbidden_unit:n {#1} } ,
@@ -503,6 +563,82 @@
curef-clear-forbidden-units/true .code:n = { \__cookingunits_clear_forbidden_unit: } ,
curef-clear-forbidden-units/false .code:n = { } ,
curef-clear-forbidden-units .value_required:n = true,
+ definition / symbol .code:n =
+ {
+ \bool_set_true:N \l__cookingunits_contains_valid_key_bool
+ \bool_set_true:N \l__cookingunits_symbol_was_set_by_key_bool
+ \tl_set:cn { l__cookingunits_default_unit_ \l__cookingunits_original_unit_tl _tl } {#1}
+ },
+ definition / symbol .value_required:n = { true } ,
+ definition / gender .code:n =
+ {
+ \bool_set_true:N \l__cookingunits_contains_valid_key_bool
+ \__cookingunits_if_gender_error:nTF {#1}
+ { \__cookingunits_culang_def_base:nVn { gender } \l__cookingunits_original_unit_tl { m } }
+ { \__cookingunits_culang_def_base:nVn { gender } \l__cookingunits_original_unit_tl {#1} }
+ },
+ definition / gender .value_required:n = { true } ,
+ definition / set-option .code:n =
+ {
+ \bool_set_true:N \l__cookingunits_contains_valid_key_bool
+ \__cookingunits_set_options_for:Vn \l__cookingunits_original_unit_tl {#1}
+ },
+ definition / set-option .value_required:n = { true } ,
+ definition / add-to-group .code:n =
+ {
+ \bool_set_true:N \l__cookingunits_contains_valid_key_bool
+ \__cookingunits_add_to_unit_group:nV {#1} \l__cookingunits_original_unit_tl
+ },
+ definition / add-to-group .value_required:n = { true } ,
+ definition / natural-unit .code:n =
+ {
+ \bool_set_true:N \l__cookingunits_contains_valid_key_bool
+ \seq_if_in:NVF \g__cookingunits_natural_units_seq \l__cookingunits_original_unit_tl
+ { \seq_gput_right:NV \g__cookingunits_natural_units_seq \l__cookingunits_original_unit_tl }
+ },
+ definition / natural-unit .default:n = { true } ,
+ definition / unknown .code:n =
+ {
+ \tl_if_empty:nF {#1}
+ {
+ \msg_error:nnxx
+ { cooking-units }
+ { definition-key-mistyped? }
+ \l_keys_key_str
+ {#1}
+ }
+ },
+ nothing-special .code:n =
+ {
+ \prop_gclear:N \g__cookingunits_master_changer_prop
+ \prop_gclear:N \g__cookingunits_convert_bonkers_remember_prop
+ \bool_set_false:N \l__cookingunits_pckopt_bonkers_bool
+ \tl_set_eq:NN \l__cookingunits_bonkers_state_tl \c__cookingunits_bonkers_state_normal_tl
+ },
+ nothing-special .value_forbidden:n = { true } ,
+ going-bonkers .code:n =
+ {
+ \prop_gclear:N \g__cookingunits_convert_bonkers_remember_prop
+ \bool_set_true:N \l__cookingunits_pckopt_bonkers_bool
+ \tl_set_eq:NN \l__cookingunits_bonkers_state_tl \c__cookingunits_bonkers_state_going_tl
+ },
+ going-bonkers .value_forbidden:n = { true } ,
+ fully-bonkers .code:n =
+ {
+ \prop_gclear:N \g__cookingunits_master_changer_prop
+ \prop_gclear:N \g__cookingunits_convert_bonkers_remember_prop
+ \bool_set_true:N \l__cookingunits_pckopt_bonkers_bool
+ \tl_set_eq:NN \l__cookingunits_bonkers_state_tl \c__cookingunits_bonkers_state_fully_tl
+ },
+ fully-bonkers .value_forbidden:n = { true } ,
+ xD-lol .code:n =
+ {
+ \prop_gclear:N \g__cookingunits_master_changer_prop
+ \prop_gclear:N \g__cookingunits_convert_bonkers_remember_prop
+ \bool_set_true:N \l__cookingunits_pckopt_bonkers_bool
+ \tl_set_eq:NN \l__cookingunits_bonkers_state_tl \c__cookingunits_bonkers_state_xD_tl
+ },
+ xD-lol .value_forbidden:n = { true } ,
}
\msg_new:nnnn { cooking-units } { fraction-not-allowed-with-range }
{
@@ -560,6 +696,12 @@
You \ probably \ have \ forgotten \ a \ curly-brace \ pair.
\msg_see_documentation_text:n {cooking-units}
}
+\msg_new:nnnn { cooking-units } { symbol-and-special-keys-error }
+ { You \ cannot \ use \ special-key \ '#1' \ with \ symbol \ '#2' \ definitions. }
+ {
+ You \ cannot \ redefine \ a \ symbol \ of \ a \ special-key.
+ \msg_see_documentation_text:n {cooking-units}
+ }
\msg_new:nnnn { cooking-units } { Division-by-zero }
{ Division\ by \ zero \ is \ not \ allowed \ in \ '#1'. }
{ See \ a \ math \ book \ of \ your \ choice \ or \ for \ example \ Wikipedia. }
@@ -596,6 +738,15 @@
This \ key \ is \ not \ defined, \ perhaps \ you \ misspelled \ it.
\msg_see_documentation_text:n {cooking-units}
}
+\msg_new:nnnn { cooking-units } { Key-chain-unit-not-found }
+ {
+ It \ appears \ that \ \token_to_str:N \cuaddtokeychain\ was \ not \ able \ to \ find
+ a \ key-chain-unit. Define \ key-chains \ first \ using \token_to_str:N \cudefinekeychain.
+ }
+ {
+ No \ key-chain-unit\ was \ found, \ perhaps \ you \ misspelled \ it?
+ \msg_see_documentation_text:n {cooking-units}
+ }
\msg_new:nnnn { cooking-units } { Temperature-too-low }
{
The \ temperature \ '#1' \ is \ too \ low.\ It \ cannot \ be \
@@ -618,6 +769,14 @@
\token_to_str:N \cuaddsinglekeys ~ and \ \token_to_str:N \cuaddtokeys.
\msg_see_documentation_text:n {cooking-units}
}
+\msg_new:nnnn { cooking-units } { key-no-knows-value }
+ {
+ It \ appears \ that \ the \ key \ '#1' \ does \ not \ accept \ the \ value
+ '#2'. \ Are \ you \ sure \ it \ is \ in \ the \ same \ key-chain?
+ }{
+ The \ key \ accepts \ only \ a \ fixed \ set \ of \ choices. \
+ \msg_see_documentation_text:n {cooking-units}
+ }
\msg_new:nnnn { cooking-units } { group-choice-not-allowed }
{
The \ group \ key \ '#1' \ accepts \ only \
@@ -668,6 +827,14 @@
Each \ element \ of \ the \ list \ needs \ a \ value.
\msg_see_documentation_text:n { cooking-units }
}
+\msg_new:nnnn { cooking-units } { Adding-single-to-multi-key-or-vice-verca }
+ {
+ You \ are \ trying \ to \ add \ a \ single-key \ to \ a \ multi-key \
+ or \ vice-versa.
+ }{
+ This \ is \ not \ allowed!
+ \msg_see_documentation_text:n { cooking-units }
+ }
\msg_new:nnnn { cooking-units } { Value-not-allowed }
{
The \ key-list \ in \ '#1' \ does \ not \ take \ a \ value.
@@ -748,6 +915,13 @@
not \ available \ yet.
\msg_see_documentation_text:n { cooking-units }
}
+\msg_new:nnnn { cooking-units } { formula-in-non-singlekeys }
+ {
+ The \ conversion \ value \ '#1' \ seems \ to \ be \ a \ formula. \
+ This \ is \ not \ allowed \ for \ NON-\ singlekeys!
+ }{
+ \msg_see_documentation_text:n { cooking-units }
+ }
\msg_new:nnnn { cooking-units } { <-not-allowed-as-special-sign }
{
Currently \ (and \ probably \ forever) \ the \ sign \ '<' \
@@ -764,6 +938,14 @@
Please \ remove \ spaces \ if \ there \ are \ some.
\msg_see_documentation_text:n { cooking-units }
}
+\msg_new:nnnn { cooking-units } { no-natural-unit-known }
+ {
+ It \ seems\ that \ I \ cannot \ convert \ '#1' \ in \ a \ natural \
+ unit \ as \ there \ is \ no \ conversion-factor \ defined.
+ }{
+ Not \ converting \ the \unit.
+ \msg_see_documentation_text:n { cooking-units }
+ }
\msg_new:nnnn { cooking-units } { curef-not-inside-list }
{
'#1' \ cannot \ be \ removed \ from \ the \ 'forbidden \ unit' \ list \ because
@@ -821,6 +1003,13 @@
The \ amount \ given \ is \ empty.
\msg_see_documentation_text:n { cooking-units }
}
+\msg_new:nnnn { cooking-units } { unknown-unit-option }
+ {
+ The \ unit-option \ '#1' \ is \ not \ defined.
+ }{
+ Please \ define \ the \ key \ '#1' \ via \ \newcukeysadd \ and \ friends.
+ \msg_see_documentation_text:n { cooking-units }
+ }
\msg_new:nnnn { cooking-units } { unknown-option }
{
The \ option \ '#1' \ is \ not \ defined.
@@ -828,27 +1017,65 @@
Perhaps \ you \ misspelled \ the \ option.
\msg_see_documentation_text:n { cooking-units }
}
+\msg_new:nnnn { cooking-units } { unknown-choice }
+ {
+ The \ choice \ '#2' \ for \ key \ '#1' \ is \ not \ defined.
+ }{
+ Perhaps \ you \ misspelled \ the \ choice.
+ \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. \ The \ error \ code \ is \ '#1'.
+ \ up. \ The \ error \ code \ is \ '#1'. \
+ Addition \ is \ '#2'.
}{
Please \ send \ me \ a \ bug \ report.
\msg_see_documentation_text:n { cooking-units }
}
-\prg_new_protected_conditional:Npnn \__cookingunits_error_if_unit_not_defined:n #1 { TF, T, F }
+\msg_new:nnnn { cooking-units } { definition-key-mistyped? }
{
- \seq_if_in:NnTF \g__cookingunits_list_of_defined_units_seq {#1}
+ This \ message \ shows \ during \ the \ definition \ of \ unit-keys. \
+ You \ may \ have \ mistyped \ the \ key \ '#1'. \ You \ may \ see \
+ this \ message \ because \ you \ have \ used \ a \ '=' \ sign \ in \ the \
+ optional \ argument. \ If \ this \ is \ the \ case \ and \ you \ still \ want
+ \ to \ use \ '=' \ in \ a \ symbol, \ please \ wrap \ the \ symbol
+ \ in \ two \ braces: \ {{#1=#2}}.
+ }{
+ Or \ try \ using \ the \ 'symbol' \ option.
+ \msg_see_documentation_text:n { cooking-units }
+ }
+\prg_new_protected_conditional:Npnn \__cookingunits_if_unit_defined:nN #1 #2 { TF , T }
+ {
+ \__cookingunits_set_unit:Nn #2 {#1}
+ \seq_if_in:NVTF \g__cookingunits_list_of_defined_units_seq #2
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+\prg_new_protected_conditional:Npnn \__cookingunits_error_if_unit_not_defined:nN #1#2 { TF, T, F }
+ {
+ \__cookingunits_if_unit_defined:nNTF {#1} #2
{ \prg_return_false: }
{
\msg_error:nnn { cooking-units } { unknown-unit } {#1}
\prg_return_true:
}
}
-\cs_new:Npn \__cookingunits_error_if_unit_not_defined:n #1
- { \__cookingunits_error_if_unit_not_defined:nTF {#1} { } { } }
+\prg_new_protected_conditional:Npnn \__cookingunits_error_if_unit_not_defined:n #1 { TF, T, F }
+ {
+ \__cookingunits_error_if_unit_not_defined:nNTF {#1} \l__cookingunits_scrap_tl
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
\cs_generate_variant:Nn \__cookingunits_error_if_unit_not_defined:nTF { V }
+\prg_new_protected_conditional:Npnn \__cookingunits_if_unit_has_a_key:n #1 { T , F, TF }
+ {
+ \keys_if_exist:nnTF { cooking-units } {#1}
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+\prg_generate_conditional_variant:Nnn \__cookingunits_if_unit_has_a_key:n { V } { T, TF }
\cs_new:Npn \__cookingunits_seq_use_msg:N #1
{ \seq_use:Nnnn #1 { ' , ~ ' } { ' , ~ ' } { ' ~ and ~ ' } }
\cs_generate_variant:Nn \__cookingunits_seq_use_msg:N { c }
@@ -858,45 +1085,66 @@
{
\tl_if_in:NnF \l__cookingunits_input_digits_tl {##1}
{
- \tl_map_break:n { \use_iii:nnn }
+ \tl_map_break:n { \use_i:nn \prg_return_false: }
}
}
- \use_i:nn \prg_return_true: \prg_return_false:
+ \prg_return_true:
}
\cs_generate_variant:Nn \__cookingunits_if_integer:nTF { V }
-\cs_generate_variant:Nn \__cookingunits_if_integer:nF { V }
-\cs_new:Npn \__cookingunits_bool_set_if_integers:NNN #1#2#3
+\prg_new_protected_conditional:Npnn \__cookingunits_if_evaluation_is_integer:n #1 { TF , T , F }
{
- \__cookingunits_if_integer:VTF #2
- { \bool_set_true:N #1 }
- { \bool_set_false:N #1 }
- \bool_lazy_and:nnT
- { \l__cookingunits_range_in_input_bool } {#1}
+ \tl_concat:NNN \l__cookingunits_tmpa_tl
+ \l__cookingunits_input_digits_tl \l__cookingunits_allwed_integer_math_operators_tl
+ \tl_map_inline:nn {#1}
{
- \__cookingunits_if_integer:VF #3
- { \bool_set_false:N #1 }
+ \tl_if_in:NnF \l__cookingunits_tmpa_tl {##1}
+ { \tl_map_break:n { \use_iii:nnn } }
}
- }
-\prg_new_conditional:Npnn \__cookingunits_fp_if_equal_one:n #1 { TF }
- {
- \fp_compare:nNnTF {#1} = { 1.0 }
+ \use_i:nn
{ \prg_return_true: }
{ \prg_return_false: }
}
-\prg_new_conditional:Npnn \__cookingunits_int_if_equal_one:n #1 { TF }
+\prg_new_conditional:Npnn \__cookingunits_if_integers:NN #1#2 { TF }
{
- \int_compare:nNnTF {#1} = { 1 }
- { \prg_return_true: }
+ \__cookingunits_if_integer:VTF #1
+ {
+ \__cookingunits_if_print_type_equal:nTF { range }
+ {
+ \__cookingunits_if_integer:VTF #2
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+ { \prg_return_true: }
+ }
{ \prg_return_false: }
}
-\prg_new_conditional:Npnn \__cookingunits_change_cutext_to_cunum:n #1 { TF }
+\prg_new_conditional:Npnn \__cookingunits_if_contains_decimal:N #1 { TF }
+ {
+ \exp_after:wN \__cookingunits_check_for_decimal:w #1 . \q_nil . \q_stop
+ }
+\cs_new:Npn \__cookingunits_check_for_decimal:w #1 . #2 . \q_stop
+ {
+ \if_meaning:w \q_nil #2
+ \exp_after:wN \prg_return_false:
+ \else:
+ \exp_after:wN \prg_return_true:
+ \fi:
+ }
+\prg_new_conditional:Npnn \__cookingunits_if_contain_decimals:NN #1#2 { TF }
{
- \keys_set_groups:nnn { cooking-units } { change-command } {#1}
- \bool_if:NTF \l__cookingunits_cutext_to_cunum_bool
+ \__cookingunits_if_contains_decimal:NTF #1
{ \prg_return_true: }
- { \prg_return_false: }
+ {
+ \__cookingunits_if_print_type_equal:nTF { range }
+ {
+ \__cookingunits_if_contains_decimal:NTF #2
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+ { \prg_return_false: }
+ }
}
-\prg_new_conditional:Npnn \__cookingunits_if_gender_error:n #1 { TF }
+\prg_new_conditional:Npnn \__cookingunits_if_gender_error:n #1 { TF, F , T }
{
\str_case:nnTF {#1}
{
@@ -910,120 +1158,185 @@
\prg_return_true:
}
}
-\cs_new:Npn \__cookingunits_check_if_correct_gender_input:n #1
+\prg_new_conditional:Npnn \__cookingunits_error_if_group_not_defined:nN #1#2 { F, T , TF }
{
- \str_case:nnF {#1}
+ \__cookingunits_set_unit:Nn #2 {#1}
+ \seq_if_exist:cTF { l__cookingunits_group_ #2 _seq }
+ { \prg_return_false: }
{
- { m } { }
- { f } { }
- { n } { }
- } { \msg_error:nnn { cooking-units } { unknown-gender } {#1} }
+ \msg_error:nn { cooking-units} { group-key-unknown }
+ \prg_return_true:
+ }
}
-\cs_new:Npn \__cookingunits_define_clear_unit_group:nn #1#2
+\prg_new_conditional:Npnn \__cookingunits_error_if_group_not_defined:n #1 { F }
{
- \seq_clear_new:c { l__cookingunits_group_ #1 _seq }
+ \seq_if_exist:cTF { l__cookingunits_group_ \__cookingunits_to_unit:n {#1} _seq }
+ { \prg_return_false: }
+ {
+ \msg_error:nn { cooking-units} { group-key-unknown }
+ \prg_return_true:
+ }
+ }
+\cs_new:Npn \__cookingunits_define_clear_unit_group:n #1
+ {
+ \__cookingunits_set_unit:Nn \l__cookingunits_tmpa_tl {#1}
+ \seq_clear_new:c { l__cookingunits_group_ \l__cookingunits_tmpa_tl _seq }
\keys_define:nn { cooking-units }
{
#1 .code:n = { \__cookingunits_unit_group_convert_units:nn {#1} {##1} } ,
#1 .groups:n = { change-unit } ,
}
}
+\cs_new:Npn \__cookingunits_unit_group_convert_units:nn #1#2
+ {
+ \bool_set_true:N \l__cookingunits_tmpa_bool
+ \__cookingunits_error_if_group_not_defined:nNT {#1} \l__cookingunits_curr_group_tl
+ { \bool_set_false:N \l__cookingunits_tmpa_bool }
+ \__cookingunits_error_if_unit_not_defined:nNT {#2} \l__cookingunits_curr_unit_tl
+ { \bool_set_false:N \l__cookingunits_tmpa_bool }
+ \bool_if:NT \l__cookingunits_tmpa_bool
+ {
+ \seq_if_in:cVTF { l__cookingunits_group_ \l__cookingunits_curr_group_tl _seq } \l__cookingunits_curr_unit_tl
+ {
+ \seq_map_inline:cn { l__cookingunits_group_ \l__cookingunits_curr_group_tl _seq }
+ { \__cookingunits_keys_set:nnn { cooking-units } {##1} {#2} }
+ }{
+ \msg_error:nnxxx
+ { cooking-units }
+ { group-choice-not-allowed }
+ { \l__cookingunits_curr_group_tl } { \l__cookingunits_curr_unit_tl }
+ { \__cookingunits_seq_use_msg:c { l__cookingunits_group_ \l__cookingunits_curr_group_tl _seq } }
+ }
+ }
+ }
\cs_new:Npn \__cookingunits_add_to_unit_group_error:n #1
{ \msg_error:nnn { cooking-units } { No-Value-given } { add-unit-to-group } }
\cs_new:Npn \__cookingunits_add_to_unit_group:nn #1#2
{
- \__cookingunits_error_if_group_not_defined:nF {#1}
+ \__cookingunits_error_if_group_not_defined:nNF {#1} \l__cookingunits_curr_group_tl
{
\clist_map_inline:nn {#2}
{
- \__cookingunits_error_if_unit_not_defined:nF {##1}
+ \__cookingunits_error_if_unit_not_defined:nNF {##1} \l__cookingunits_curr_unit_tl
{
- \seq_if_in:cnF { l__cookingunits_group_ #1 _seq } {##1}
- { \seq_put_right:cn { l__cookingunits_group_ #1 _seq } {##1} }
+ \seq_if_in:cVF { l__cookingunits_group_ \l__cookingunits_curr_group_tl _seq } \l__cookingunits_curr_unit_tl
+ {
+ \seq_put_right:cV
+ { l__cookingunits_group_ \l__cookingunits_curr_group_tl _seq }
+ \l__cookingunits_curr_unit_tl
+ }
}
}
}
}
-\prg_new_conditional:Npnn \__cookingunits_error_if_group_not_defined:n #1 { F }
+\cs_generate_variant:Nn \__cookingunits_add_to_unit_group:nn { nV }
+\cs_new:Npn \__cookingunits_seq_get_overlap:NNTF #1#2 #3#4
{
- \seq_if_exist:cTF { l__cookingunits_group_ #1 _seq }
- { \prg_return_false: }
+ \seq_map_inline:Nn #1
{
- \msg_error:nn { cooking-units} { group-key-unknown }
- \prg_return_true:
+ \seq_if_in:NnT #2 {##1}
+ { #3 \seq_map_break:n { \use_none:nn } }
}
+ \use:n {#4}
}
-\cs_new:Npn \__cookingunits_unit_group_convert_units:nn #1#2
+\cs_new:Npn \__cookingunits_keys_set:nnn #1#2#3
+ { \keys_set:nn {#1} { #2 = #3 } }
+\cs_generate_variant:Nn \__cookingunits_keys_set:nnn { nVV , nVn }
+\cs_new:Npn \__cookingunits_convert_to_eV:N #1
{
- \__cookingunits_error_if_group_not_defined:nF {#1}
+ \prop_get:NVNTF \g__cookingunits_convert_to_eV_remember_prop
+ #1 \l__cookingunits_tmpa_tl
+ { \__cookingunits_keys_set:nVV { cooking-units } #1 \l__cookingunits_tmpa_tl }
{
- \__cookingunits_error_if_unit_not_defined:nF {#2}
+ \__cookingunits_if_unit_has_a_key:VTF #1
{
- \seq_if_in:cnTF { l__cookingunits_group_ #1 _seq } {#2}
+ \tl_set_eq:Nc \l__cookingunits_tmp_unit_tl { l__cookingunits_base_key_unit_ #1 _tl }
+ \prop_get:cnNT { l__cookingunits_new_cukeys_ \l__cookingunits_tmp_unit_tl _prop }
+ { Liste } \l__cookingunits_tmpa_seq
{
- \seq_map_inline:cn { l__cookingunits_group_ #1 _seq }
- { \__cookingunits_keys_set:nnn { cooking-units } {##1} {#2} }
- }{
- \msg_error:nnxxx
- { cooking-units }
- { group-choice-not-allowed }
- {#1} {#2}
- { \__cookingunits_seq_use_msg:c { l__cookingunits_group_ #1 _seq } }
+ \__cookingunits_seq_get_overlap:NNTF \g__cookingunits_natural_units_seq \l__cookingunits_tmpa_seq
+ {
+ \prop_gput:NVn \g__cookingunits_convert_to_eV_remember_prop #1 {##1}
+ \__cookingunits_keys_set:nVn { cooking-units } #1 {##1}
+ }
+ { \msg_warning:nnx { cooking-units } { no-natural-unit-known } {#1} }
}
}
+ { \msg_warning:nnx { cooking-units } { Key-not-defined } {#1} }
}
}
-\seq_new:N \g__cookingunits_natural_units_seq
-\prop_new:N \g__cookingunits_convert_to_eV_remember_prop
-\seq_gset_from_clist:Nn \g__cookingunits_natural_units_seq
+\cs_new:Npn \__cookingunits_changing_unit_bonkers:N #1
{
- eV ,
- eVc-2 ,
- hbareV-1 ,
- chbareV-1 ,
- (chbareV-1)3 ,
- }
-\cs_new:Npn \__cookingunits_keys_set:nnn #1#2#3
- { \keys_set:nn {#1} { #2 = #3 } }
-\cs_generate_variant:Nn \__cookingunits_keys_set:nnn { nVV , nVn }
-\cs_new:Npn \__cookingunits_convert_to_eV:
- {
- \tl_set_eq:Nc \l__cookingunits_tmp_unit_tl { l__cookingunits_base_key_unit_ \l__cookingunits_original_unit_tl _tl }
- \tl_if_empty:NF \l__cookingunits_tmp_unit_tl
+ \prop_get:NVNTF \g__cookingunits_convert_bonkers_remember_prop
+ #1 \l__cookingunits_tmpa_tl
+ { \__cookingunits_keys_set:nVV { cooking-units } #1 \l__cookingunits_tmpa_tl }
{
- \prop_get:NVNTF \g__cookingunits_convert_to_eV_remember_prop
- \l__cookingunits_original_unit_tl \l__cookingunits_tmpa_tl
- { \__cookingunits_keys_set:nVV { cooking-units } \l__cookingunits_original_unit_tl \l__cookingunits_tmpa_tl }
+ \tl_case:NnF \l__cookingunits_bonkers_state_tl
{
- \prop_get:cnNTF { l__cookingunits_cukeys_ \l__cookingunits_tmp_unit_tl _prop } { Liste } \l__cookingunits_tmpa_seq
- {
- \seq_map_inline:Nn \g__cookingunits_natural_units_seq
- {
- \seq_if_in:NnT \l__cookingunits_tmpa_seq {##1}
- {
- \prop_gput:NVn \g__cookingunits_convert_to_eV_remember_prop
- \l__cookingunits_original_unit_tl {##1}
- \__cookingunits_keys_set:nVn { cooking-units } \l__cookingunits_original_unit_tl {##1}
- \seq_map_break:
- }
- }
- }
- { \msg_error:nnn { cooking-units } { internal-error } { convert-to-eV } }
+ \c__cookingunits_bonkers_state_going_tl { \__cookingunits_convert_going_bonkers:N #1 }
+ \c__cookingunits_bonkers_state_fully_tl { \__cookingunits_convert_fully_bonkers:N #1 }
+ \c__cookingunits_bonkers_state_xD_tl { \__cookingunits_convert_xD_bonkers:N #1 }
}
+ { \__cookingunits_create_internal_error:nN { going-bonkers } \l__cookingunits_bonkers_state_tl }
}
}
-\cs_new:Npn \__cookingunits_tl_eval:Nn #1#2 { \tl_set:Nf #1 { \fp_eval:n {#2} } }
-\cs_generate_variant:Nn \__cookingunits_tl_eval:Nn { Nv }
-\prg_new_conditional:Npnn \__cookingunits_change_unit: { TF , T }
+\cs_new:Npn \__cookingunits_convert_going_bonkers:N #1
{
- \bool_lazy_any:nTF
+ \__cookingunits_if_unit_has_a_key:VT #1
{
- { \l__cookingunits_lokal_fraction_bool }
- { \l__cookingunits_special_sign_bool }
- { \l__cookingunits_draft_bool }
+ \__cookingunits_prepare_going_bonkers:N #1
+ \keys_set:nn { cooking-units } { eval-fraction = true }
+ \__cookingunits_keys_set:nVV { cooking-units } #1 \l__cookingunits_tmpa_tl
+ \prop_gput:NVV \g__cookingunits_convert_bonkers_remember_prop #1 \l__cookingunits_tmpa_tl
}
+ }
+\cs_new:Npn \__cookingunits_convert_fully_bonkers:N #1
+ {
+ \__cookingunits_if_unit_has_a_key:VT #1
+ {
+ \__cookingunits_prepare_going_bonkers:N #1
+ \keys_set:nn { cooking-units }
+ { eval-fraction = true , curef-clear-forbidden-units = true }
+ \prop_put:NVV \l__cookingunits_change_unit_prop {#1} \l__cookingunits_tmpa_tl
+ \__cookingunits_cukeys_calculate_change_value:VVV #1 \l__cookingunits_tmpa_tl \l__cookingunits_tmp_unit_tl
+ }
+ }
+\cs_new:Npn \__cookingunits_prepare_going_bonkers:N #1
+ {
+ \tl_set_eq:Nc \l__cookingunits_tmp_unit_tl { l__cookingunits_base_key_unit_ #1 _tl }
+ \prop_get:cnN { l__cookingunits_new_cukeys_ \l__cookingunits_tmp_unit_tl _prop } { Liste } \l__cookingunits_tmpa_seq
+ \bool_set_false:N \l__cookingunits_tmpa_bool
+ \bool_until_do:Nn \l__cookingunits_tmpa_bool
+ {
+ \tl_set:Nf \l__cookingunits_tmpa_tl { \seq_rand_item:N \l__cookingunits_tmpa_seq }
+ \seq_if_in:NVF \g__cookingunits_natural_units_seq \l__cookingunits_tmpa_tl
+ { \bool_set_true:N \l__cookingunits_tmpa_bool }
+ }
+ }
+\cs_new:Npn \__cookingunits_convert_xD_bonkers:N #1
+ {
+ \keys_set:nn { cooking-units } { eval-fraction = true , curef-clear-forbidden-units = true }
+ \bool_set_false:N \l__cookingunits_tmpa_bool
+ \bool_until_do:Nn \l__cookingunits_tmpa_bool
+ {
+ \tl_set:Nx \l__cookingunits_tmpa_tl { \seq_rand_item:N \g__cookingunits_list_of_defined_units_seq }
+ \__cookingunits_if_no_unit_marker:NF \l__cookingunits_tmpa_tl
+ { \bool_set_true:N \l__cookingunits_tmpa_bool }
+ }
+ \prop_put:NVV \l__cookingunits_change_unit_prop {#1} \l__cookingunits_tmpa_tl
+ \tl_set:cf { l__cookingunits_unit_change_ #1 _tl } { \fp_eval:n { rand() * randint(255) } }
+ }
+\cs_new:Npn \__cookingunits_tl_eval:Nn #1#2 { \tl_set:Nf #1 { \fp_eval:n {#2} } }
+\cs_generate_variant:Nn \__cookingunits_tl_eval:Nn { Nv, cn }
+\prg_new_conditional:Npnn \__cookingunits_change_unit: { TF }
+ {
+ \__cookingunits_if_print_type_equal:nTF { fraction }
{ \prg_return_false: }
- { \prg_return_true: }
+ {
+ \__cookingunits_if_state_equal:nTF { special_sign }
+ { \prg_return_false: }
+ { \prg_return_true: }
+ }
}
\cs_new:Npn \__cookingunits_temperature_to_check_print_error:n #1
{
@@ -1032,16 +1345,14 @@
}
\cs_new:Npn \__cookingunits_temperatures_to_check_define:nn #1#2
{
- \__cookingunits_error_if_unit_not_defined:nF {#1}
+ \__cookingunits_error_if_unit_not_defined:nNF {#1} \l__cookingunits_curr_unit_tl
{
- \fp_if_exist:cTF { l__cookingunits_ #1 _min_fp }
+ \fp_if_exist:cF { l__cookingunits_ \l__cookingunits_curr_unit_tl _min_fp }
{
- \fp_set:cn { l__cookingunits_ #1 _min_fp } {#2}
- }{
- \seq_put_right:Nn \l__cookingunits_temperatures_to_check_seq {#1}
- \fp_new:c { l__cookingunits_ #1 _min_fp }
- \fp_set:cn { l__cookingunits_ #1 _min_fp } {#2}
+ \seq_put_right:NV \l__cookingunits_temperatures_to_check_seq \l__cookingunits_curr_unit_tl
+ \fp_new:c { l__cookingunits_ \l__cookingunits_curr_unit_tl _min_fp }
}
+ \fp_set:cn { l__cookingunits_ \l__cookingunits_curr_unit_tl _min_fp } {#2}
}
}
\cs_new:Npn \__cookingunits_set_options_for_error:n #1
@@ -1049,30 +1360,23 @@
\__cookingunits_error_if_unit_not_defined:n {#1}
\msg_error:nnn { cooking-units } { No-Value-given } { set-option-for }
}
-\cs_new:Npn \__cookingunits_set_options_for:nn #1#2
- { \cusetoptionfor {#1} {#2} }
\cs_new:Npn \__cookingunits_add_options_for_error:n #1
{
\__cookingunits_error_if_unit_not_defined:n {#1}
\msg_error:nnn { cooking-units } { No-Value-given } { add-option-for }
}
-\cs_new:Npn \__cookingunits_add_options_for:nn #1#2
- { \cuaddoptionfor {#1} {#2} }
\cs_new:Npn \__cookingunits_rounding_function:n #1
{
#1
, \l__cookingunits_round_precision_int
- \bool_if:NT \l__cookingunits_round_commercial_bool
+ \bool_if:NT \l__cookingunits_pckopt_round_commercial_bool
{ , #1 }
}
\cs_new:Npn \__cookingunits_label_and_persons:n #1
{
- \tl_if_in:nnTF {#1} { * }
- {
- \__cookingunits_label_and_persons_times_persons:ww #1 \q_stop
- }{
- \msg_error:nnn { cooking-units} { Number-of-persons-missing } {#1}
- }
+ \str_if_in:nnTF {#1} { * }
+ { \__cookingunits_label_and_persons_times_persons:ww #1 \q_stop }
+ { \msg_error:nnn { cooking-units} { Number-of-persons-missing } {#1} }
}
\cs_new:Npn \__cookingunits_label_and_persons_times_persons:ww #1 * #2 \q_stop
{
@@ -1081,13 +1385,13 @@
\cs_new:Npn \__cookingunits_culabel:nn #1#2
{
\int_if_exist:cTF { g__cookingunits_number_of_persons_ #1 _int }
+ { \msg_error:nnn { cooking-units } { label-already-defined } {#1} }
{
- \msg_error:nnn { cooking-units } { label-already-defined } {#1}
- }{
- \__cookingunits_if_integer:nTF {#2}
+ \__cookingunits_if_evaluation_is_integer:nTF {#2}
{
+ \int_set:Nn \l__cookingunits_tmpa_int {#2}
\int_new:c { g__cookingunits_number_of_persons_ #1 _int }
- \int_gset:cn { g__cookingunits_number_of_persons_ #1 _int } {#2}
+ \int_gset_eq:cN { g__cookingunits_number_of_persons_ #1 _int } \l__cookingunits_tmpa_int
}
{ \msg_error:nnn { cooking-units } { Number-of-persons-is-not-an-integer } {#2} }
}
@@ -1096,7 +1400,7 @@
{
\int_if_exist:cTF { g__cookingunits_number_of_persons_ #1 _int }
{
- \bool_set_true:N \l__cookingunits_calc_because_ref_was_given_bool
+ \bool_set_true:N \l__cookingunits_reference_given_bool
\int_set_eq:Nc \l__cookingunits_local_number_of_persons_int
{ g__cookingunits_number_of_persons_ #1 _int }
}
@@ -1106,192 +1410,568 @@
{
\int_if_exist:cTF { g__cookingunits_number_of_persons_ #1 _int }
{
- \bool_if:NTF \l__cookingunits_change_number_of_persons_bool
+ \bool_if:NTF \l__cookingunits_pckopt_recalculate_amount_bool
{ \int_use:N \l__cookingunits_wanted_number_of_persons_int }
{ \int_use:c { g__cookingunits_number_of_persons_ #1 _int } }
}{ \msg_error:nnn { cooking-units } { label-not-defined } {#1} }
}
\NewDocumentCommand \culabel { m m } { \__cookingunits_culabel:nn {#1} {#2} }
\NewExpandableDocumentCommand \curef { m } { \__cookingunits_curef:n {#1} }
-\cs_new:Npn \__cookingunits_bool_reverse:N #1
- {
- \bool_if:NTF #1
- { \bool_set_false:N }
- { \bool_set_true:N }
- #1
- }
\cs_new:Npn \__cookingunits_check_minus_remove_and_reverse:NN #1#2
{
\quark_if_nil:NF #2
{
+ %% Maybe simplify by a command?
\tl_if_in:NnT #2 { - }
{
\tl_remove_once:Nn #2 { - }
- \__cookingunits_bool_reverse:N #1
+ \bool_if:NTF #1 { \bool_set_false:N } { \bool_set_true:N } #1
}
- \__cookingunits_check_minus_remove_and_reverse:NN #1
+ \__cookingunits_check_minus_remove_and_reverse:NN #1
}
}
-\tl_const:Nn \c__cookingunits_postfix_unit_tl { ( cu-unit ) }
-\tl_const:Nn \c__cookingunits_postfix_unit_pl_tl { ( cu-unit-pl ) }
-\tl_const:Nn \c__cookingunits_postfix_unitname_tl { ( cu-unitname ) }
-\tl_const:Nn \c__cookingunits_postfix_unitname_pl_tl { ( cu-unitname-pl ) }
-\tl_const:Nn \c__cookingunits_postfix_gender_tl { ( cu-unitgender ) }
-\tl_const:Nn \c__cookingunits_postfix_phrase_tl { ( cu-unitphrase ) }
-\cs_new:Npn \__cookingunits_deftranslation_base:nnn #1#2#3
+\cs_new:Npn \__cookingunits_add_forbidden_unit:n #1
{
- \declaretranslationfallback { #1 #2 } {#3}
+ \seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
+ \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ {
+ \__cookingunits_error_if_unit_not_defined:nNF {##1} \l__cookingunits_curr_unit_tl
+ {
+ \seq_if_in:NVF \l__cookingunits_curef_do_not_change_seq \l__cookingunits_curr_unit_tl
+ { \seq_put_right:NV \l__cookingunits_curef_do_not_change_seq \l__cookingunits_curr_unit_tl }
+ }
+ }
}
-\cs_new:Npn \__cookingunits_deftranslation_to:nnnn #1#2#3#4
+\cs_new:Npn \__cookingunits_remove_forbidden_unit:n #1
{
- \declaretranslation {#1} { #2 #3 } {#4}
+ \seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
+ \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ {
+ \__cookingunits_error_if_unit_not_defined:nNF {##1} \l__cookingunits_curr_unit_tl
+ {
+ \seq_if_in:NVTF \l__cookingunits_curef_do_not_change_seq \l__cookingunits_curr_unit_tl
+ { \seq_remove_all:NV \l__cookingunits_curef_do_not_change_seq \l__cookingunits_curr_unit_tl }
+ {
+ \msg_warning:nnnn { cooking-units } { curef-not-inside-list } {##1}
+ { \__cookingunits_seq_use_msg:N \l__cookingunits_curef_do_not_change_seq }
+ }
+ }
+ }
}
-\cs_generate_variant:Nn \__cookingunits_deftranslation_base:nnn { xV }
-\cs_generate_variant:Nn \__cookingunits_deftranslation_to:nnnn { VxVv, VxVV , VxVn }
-\cs_new:Npn \__cookingunits_newtranslation_base:nnn #1#2#3
+\cs_new:Npn \__cookingunits_clear_forbidden_unit:
+ { \seq_clear:N \l__cookingunits_curef_do_not_change_seq }
+\NewDocumentCommand \cudeclareunitgroup { m m }
{
- \definetranslationfallback { #1 #2 } {#3}
+ \__cookingunits_define_clear_unit_group:n {#1}
+ \__cookingunits_add_to_unit_group:nn {#1} {#2}
}
-\cs_new:Npn \__cookingunits_newtranslation_to:nnnn #1#2#3#4
+\NewDocumentCommand \cuaddtounitgroup { m m }
{
- \definetranslation {#1} { #2 #3 } {#4}
+ \__cookingunits_add_to_unit_group:nn {#1} {#2}
}
-\cs_generate_variant:Nn \__cookingunits_newtranslation_base:nnn { nVn }
-\cs_generate_variant:Nn \__cookingunits_newtranslation_to:nnnn { nnVn }
-\cs_new:Npn \__cookingunits_translate:nn #1#2
+\NewDocumentCommand \cuclearunitgroup { m }
{
- \GetTranslation { #1 #2 }
+ \__cookingunits_error_if_group_not_defined:nF {#1}
+ { \__cookingunits_define_clear_unit_group:n {#1} }
+ }
+\NewDocumentCommand \cusetoptionfor { m m }
+ { \__cookingunits_set_options_for:nn {#1} {#2} }
+\NewDocumentCommand \cuaddoptionfor { m m }
+ { \__cookingunits_add_options_for:nn {#1} {#2} }
+\NewDocumentCommand \cuclearoptionfor { m }
+ { \__cookingunits_clear_options_for:n {#1} }
+\cs_new:Npn \__cookingunits_set_options_for:nn #1#2
+ {
+ \__cookingunits_map_trough_valid_unit_options:nnn {#1} {#2} { \clist_set:cV }
+ }
+\cs_new:Npn \__cookingunits_add_options_for:nn #1#2
+ {
+ \__cookingunits_map_trough_valid_unit_options:nnn {#1} {#2} { \clist_put_right:cV }
+ }
+\cs_new:Npn \__cookingunits_clear_options_for:n #1
+ {
+ \__cookingunits_map_trough_valid_unit_options:nnn {#1} { \q_no_value } { \clist_clear:c }
+ }
+\cs_generate_variant:Nn \__cookingunits_set_options_for:nn { V }
+\cs_generate_variant:Nn \__cookingunits_clear_options_for:n { V }
+\cs_new:Npn \__cookingunits_map_trough_valid_unit_options:nnn #1#2 #3
+ {
+ \seq_clear:N \l__cookingunits_tmpa_seq
+ \clist_clear:N \l__cookingunits_tmpa_clist
+ \clist_map_inline:nn {#1}
+ {
+ \__cookingunits_error_if_unit_not_defined:nNF {##1} \l__cookingunits_curr_unit_tl
+ { \seq_put_right:NV \l__cookingunits_tmpa_seq \l__cookingunits_curr_unit_tl }
+ }
+ \quark_if_no_value:nTF {#2}
+ {
+ \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ { #3 { l__cookingunits_unit_option_ ##1 _clist } }
+ }{
+ \tl_if_empty:nF {#2}
+ { \__cookingunits_unit_options_check_validity:n {#2} }
+ \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ { #3 { l__cookingunits_unit_option_ ##1 _clist } \l__cookingunits_tmpa_clist }
+ }
}
-\cs_new:Npn \__cookingunits_translate_let:Nnn #1#2#3
+\cs_new:Npn \__cookingunits_unit_options_check_validity:n #1
{
- \SaveTranslation {#1} { #2 #3 }
+ \keyval_parse:NNn
+ \__cookingunits_unit_options_check_validity_aux_i:n
+ \__cookingunits_unit_options_check_validity_aux_ii:nn
+ {#1}
}
-\cs_new:Npn \__cookingunits_translate_let:nNnn #1#2#3#4
+\cs_new:Npn \__cookingunits_unit_options_check_validity_aux_i:n #1
{
- \SaveTranslationFor {#2} {#1} { #3 #4 }
+ \keys_if_exist:nnTF { cooking-units } {#1}
+ { \clist_put_right:Nn \l__cookingunits_tmpa_clist {#1} }
+ { \msg_error:nnn { cooking-units } { unknown-option } {#1} }
}
-\cs_generate_variant:Nn \__cookingunits_translate:nn { VV, nV }
-\cs_generate_variant:Nn \__cookingunits_translate_let:Nnn { NnV }
-\cs_generate_variant:Nn \__cookingunits_translate_let:nNnn { VNnV, nNnV }
-\prg_new_conditional:Npnn \__cookingunits_unitname_get:Nn #1#2 { F }
+\cs_new:Npn \__cookingunits_unit_options_check_validity_aux_ii:nn #1#2
{
- \__cookingunits_translate_let:NnV #1 {#2} \c__cookingunits_postfix_unitname_tl
+ \keys_if_exist:nnTF { cooking-units } {#1}
+ {
+ \clist_put_right:Nn \l__cookingunits_tmpa_clist { #1= {#2} }
+ }
+ { \msg_error:nnn { cooking-units } { unknown-option } {#1} }
+ }
+\cs_new:Npn \__cookingunits_culang_def_base:nnn #1#2#3
+ { \declaretranslationfallback { #2 - #1 (__cookingunits) } {#3} }
+\cs_generate_variant:Nn \__cookingunits_culang_def_base:nnn { nnv, nVn }
+\cs_new:Npn \__cookingunits_culang_def_for:nnnn #1#2#3#4
+ { \declaretranslation {#1} { #3 - #2 (__cookingunits) } {#4} }
+\cs_generate_variant:Nn \__cookingunits_culang_def_for:nnnn { VnnV, V }
+\cs_new:Npn \__cookingunits_culang_print:nn #1#2
+ { \GetTranslation { #2 - #1 (__cookingunits) } }
+\cs_generate_variant:Nn \__cookingunits_culang_print:nn { nV }
+\cs_new:Npn \__cookingunits_culang_let:nnN #1#2#3
+ { \SaveTranslation #3 { #2 - #1 (__cookingunits) } }
+\cs_new:Npn \__cookingunits_culang_let_for:nnnN #1#2#3#4
+ { \SaveTranslationFor #4 {#1} { #3-#2 (__cookingunits) } }
+\cs_generate_variant:Nn \__cookingunits_culang_let_for:nnnN { V }
+\cs_new:Npn \__cookingunits_culang_if_translation_exists_for:nnnTF #1#2#3
+ { \IfTranslation {#1} { #3 - #2 (__cookingunits) } }
+\cs_generate_variant:Nn \__cookingunits_culang_if_translation_exists_for:nnnTF { V }
+\prg_new_conditional:Npnn \__cookingunits_culang_unitname_let:Nn #1#2 { TF, F , T }
+ {
+ \__cookingunits_culang_let:nnN { name } {#2} #1
\tl_if_eq:NNTF #1 \q__cookingunits_no_translation
{ \prg_return_false: }
{ \prg_return_true: }
}
-\cs_generate_variant:Nn \__cookingunits_unitname_get:NnF { Nx }
-\cs_new:Npn \__cookingunits_translate_one_and_check_existance:Nn #1#2
+\cs_generate_variant:Nn \__cookingunits_culang_unitname_let:NnTF { NV, Nx }
+\cs_generate_variant:Nn \__cookingunits_culang_unitname_let:NnT { Nx }
+\prg_new_conditional:Npnn \__cookingunits_culang_one_let:Nn #1#2 { T }
+ {
+ \__cookingunits_culang_let:nnN { gender } {#2} \l__cookingunits_tmpa_tl
+ \__cookingunits_culang_one_let_by_gender:NVTF #1 \l__cookingunits_tmpa_tl
+ { \prg_return_true: }
+ {
+ \tl_set:Nn #1 { 1 }
+ \prg_return_false:
+ }
+ }
+\cs_generate_variant:Nn \__cookingunits_culang_one_let:NnT { NV }
+\prg_new_conditional:Npnn \__cookingunits_culang_one_let_by_gender:Nn #1#2 { TF }
{
- \__cookingunits_translate_let:NnV #1 {#2} \c__cookingunits_postfix_gender_tl
- \__cookingunits_unitname_get:NxF #1 { one (#1) }
+ \__cookingunits_culang_unitname_let:NnTF #1 { one (#2) }
+ { \prg_return_true: }
{
- \__cookingunits_translate_let:NnV #1 {#2} \c__cookingunits_postfix_gender_tl
- \msg_error:nnn { cooking-units } { Translation-not-available } { one (#1) }
+ \msg_error:nnx { cooking-units } { Translation-not-available } { one (#2) }
+ \prg_return_false:
}
}
-\cs_generate_variant:Nn \__cookingunits_translate_one_and_check_existance:Nn { Nx }
+\cs_generate_variant:Nn \__cookingunits_culang_one_let_by_gender:NnTF { NV }
\seq_gset_from_clist:Nn \g__cookingunits_allowed_special_keys_seq
{
+ cutext-range-sign ,
decimal-mark ,
one (m) ,
one (f) ,
one (n)
}
-\__cookingunits_newtranslation_base:nVn { decimal-mark } \c__cookingunits_postfix_unitname_tl { . }
-\__cookingunits_newtranslation_base:nVn { decimal-mark } \c__cookingunits_postfix_unitname_pl_tl { \q__cookingunits_no_translation }
-\__cookingunits_newtranslation_to:nnVn { German } { decimal-mark } \c__cookingunits_postfix_unitname_tl { , }
-\__cookingunits_newtranslation_base:nVn { one (m) } \c__cookingunits_postfix_unitname_tl { \q__cookingunits_no_translation }
-\__cookingunits_newtranslation_base:nVn { one (f) } \c__cookingunits_postfix_unitname_tl { \q__cookingunits_no_translation }
-\__cookingunits_newtranslation_base:nVn { one (n) } \c__cookingunits_postfix_unitname_tl { \q__cookingunits_no_translation }
-\__cookingunits_newtranslation_base:nVn { one (m) } \c__cookingunits_postfix_unitname_pl_tl { \q__cookingunits_no_translation }
-\__cookingunits_newtranslation_base:nVn { one (f) } \c__cookingunits_postfix_unitname_pl_tl { \q__cookingunits_no_translation }
-\__cookingunits_newtranslation_base:nVn { one (n) } \c__cookingunits_postfix_unitname_pl_tl { \q__cookingunits_no_translation }
-\__cookingunits_newtranslation_to:nnVn { English } { one (m) } \c__cookingunits_postfix_unitname_tl { one }
-\__cookingunits_newtranslation_to:nnVn { English } { one (f) } \c__cookingunits_postfix_unitname_tl { one }
-\__cookingunits_newtranslation_to:nnVn { English } { one (n) } \c__cookingunits_postfix_unitname_tl { one }
-\__cookingunits_newtranslation_to:nnVn { German } { one (m) } \c__cookingunits_postfix_unitname_tl { ein }
-\__cookingunits_newtranslation_to:nnVn { German } { one (f) } \c__cookingunits_postfix_unitname_tl { eine }
-\__cookingunits_newtranslation_to:nnVn { German } { one (n) } \c__cookingunits_postfix_unitname_tl { ein }
-\__cookingunits_newtranslation_base:nVn { cutext-range-sign } \c__cookingunits_postfix_unitname_tl { -- }
-\__cookingunits_newtranslation_base:nVn { cutext-range-sign } \c__cookingunits_postfix_unitname_pl_tl { \q__cookingunits_no_translation }
-\__cookingunits_newtranslation_to:nnVn { German } { cutext-range-sign } \c__cookingunits_postfix_unitname_tl { ~bis~ }
-\__cookingunits_newtranslation_to:nnVn { English } { cutext-range-sign } \c__cookingunits_postfix_unitname_tl { ~to~ }
-\cs_new_protected:Npn \__cookingunits_initialise_default:n #1
- {
- \__cookingunits_set_unit:Nn \l__cookingunits_original_unit_tl {#1}
- \bool_set_false:N \l__cookingunits_error_bool
+\__cookingunits_culang_def_base:nnn { name } { decimal-mark } { . }
+\__cookingunits_culang_def_base:nnn { name-pl } { decimal-mark } { \q__cookingunits_no_translation }
+\__cookingunits_culang_def_for:nnnn { German } { name-pl } { decimal-mark } { , }
+\__cookingunits_culang_def_base:nnn { name } { one (m) } { \q__cookingunits_no_translation }
+\__cookingunits_culang_def_base:nnn { name } { one (f) } { \q__cookingunits_no_translation }
+\__cookingunits_culang_def_base:nnn { name } { one (n) } { \q__cookingunits_no_translation }
+\__cookingunits_culang_def_base:nnn { name-pl } { one (m) } { \q__cookingunits_no_translation }
+\__cookingunits_culang_def_base:nnn { name-pl } { one (f) } { \q__cookingunits_no_translation }
+\__cookingunits_culang_def_base:nnn { name-pl } { one (n) } { \q__cookingunits_no_translation }
+\__cookingunits_culang_def_for:nnnn { English } { name } { one (m) } { one }
+\__cookingunits_culang_def_for:nnnn { English } { name } { one (f) } { one }
+\__cookingunits_culang_def_for:nnnn { English } { name } { one (n) } { one }
+\__cookingunits_culang_def_for:nnnn { German } { name } { one (m) } { ein }
+\__cookingunits_culang_def_for:nnnn { German } { name } { one (f) } { eine }
+\__cookingunits_culang_def_for:nnnn { German } { name } { one (n) } { ein }
+\__cookingunits_culang_def_base:nnn { name } { cutext-range-sign } { -- }
+\__cookingunits_culang_def_base:nnn { name-pl } { cutext-range-sign } { \q__cookingunits_no_translation }
+\__cookingunits_culang_def_for:nnnn { German } { name } { cutext-range-sign } { ~bis~ }
+\__cookingunits_culang_def_for:nnnn { English } { name } { cutext-range-sign } { ~to~ }
+\cs_new:Npn \__cookingunits_def_new_type:nnn #1#2#3
+ {
+ \tl_new:c { l__cookingunits_ #1 _tl }
+ \clist_map_inline:nn {#3}
+ { \tl_const:cn { c__cookingunits_ #1 _ ##1 _tl } {##1} }
+ \__cookingunits_def_new_type_aux:cnn { l__cookingunits_ #1 _tl } {#1} {#2}
+ }
+\cs_new:Npn \__cookingunits_def_new_type_aux:Nnn #1#2#3
+ {
+ \cs_new:cpn { __cookingunits_set_ #2 _to:n } ##1
+ {
+ \tl_if_exist:cF { c__cookingunits_#2_ ##1 _tl } { \tl_show:n { ERROR-set-#2-##1 } }
+ \tl_set_eq:Nc #1 { c__cookingunits_#2_ ##1 _tl }
+ }
+ \tl_if_empty:nF {#3}
+ {
+ \prg_new_conditional:cpnn { __cookingunits_if_ #2 _equal:n } ##1 {#3}
+ {
+ \tl_if_exist:cF { c__cookingunits_#2_ ##1 _tl } { \tl_show:n { ERROR-check-#2-##1 } }
+ \tl_if_eq:NcTF #1 { c__cookingunits_#2_ ##1 _tl }
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+ }
+ }
+\cs_generate_variant:Nn \__cookingunits_def_new_type_aux:Nnn { c }
+\__cookingunits_def_new_type:nnn { state } { TF , T , F , p }
+ { normal , special_sign , 42 , error }
+\__cookingunits_def_new_type:nnn { cmd_type } { TF , T , p }
+ { cunum , cCutext , cuam }
+\__cookingunits_def_new_type:nnn { parse_and_process_type } { TF , T }
+ { number , range , fraction }
+\__cookingunits_def_new_type:nnn { print_type } { TF , T }
+ { unknown , number , range , fraction }
+\__cookingunits_def_new_type:nnn { bonkers_state } { }
+ { normal , going , fully , xD }
+\tl_set_eq:NN \l__cookingunits_bonkers_state_tl \c__cookingunits_bonkers_state_normal_tl
+\cs_new:Npn \__cookingunits_expand_unit_input:Nn #1#2
+ {
+ \cs_if_exist_use:c { exp_args:NN \l__cookingunits_unit_argument_spec_tl }
+ \__cookingunits_set_unit:Nn #1 {#2}
+ }
+\cs_new:Npn \__cookingunits_expand_amount_input:Nn #1#2
+ {
+ \cs_if_exist_use:c { exp_args:NN \l__cookingunits_expand_amount_tl }
+ \__cookingunits_set_amount:Nn #1 {#2}
+ }
+\bool_new:N \l__cookingunits_skip_first_part_bool
+\cs_new:Npn \__cookingunits_do_the_stuff:nnnnnn #1#2#3#4#5#6
+ {
+ \__cookingunits_initialice_accordingly:nnnn {#1} {#4} {#2} {#5}
+ \__cookingunits_use_hook_accordingly:
+ \__cookingunits_parse_the_amount:n {#3}
+ \__cookingunits_general_checkups:
+ \__cookingunits_if_state_equal:nTF { normal }
+ { \__cookingunits_process_amount_normally:n {#2} }
+ { \__cookingunits_process_amount_special: }
+ \__cookingunits_new_print_amount_correctly:
+ \__cookingunits_new_print_unit_correctly:
+ }
+\cs_generate_variant:Nn \__cookingunits_do_the_stuff:nnnnnn { nnnnV }
+\cs_new:Npn \__cookingunits_initialice_accordingly:nnnn #1#2#3#4
+ {
+ \__cookingunits_initialize_new_default:nnn {#1} {#3} {#4}
+ \__cookingunits_initialize_new_default_units:
+ \tl_case:NnF \l__cookingunits_cmd_type_tl
+ {
+ \c__cookingunits_cmd_type_cunum_tl { \tl_set:Nn \l__cookingunits_phantom_tl {#2} }
+ \c__cookingunits_cmd_type_cCutext_tl { \__cookingunits_initialice_addon_cutext: }
+ \c__cookingunits_cmd_type_cuam_tl { }
+ }
+ { \__cookingunits_create_internal_error:nN { init-acc } \l__cookingunits_cmd_type_tl }
+ }
+\cs_new:Npn \__cookingunits_initialice_addon_cutext:
+ {
+ \bool_if:NT \l__cookingunits_pckopt_cutext_to_cunum_bool
+ { \__cookingunits_set_cmd_type_to:n { cunum } }
+ \bool_set_false:N \l__cookingunits_cutext_last_amount_equ_one_bool
+ }
+\cs_new:Npn \__cookingunits_initialize_new_default:nnn #1#2#3
+ {
+ \tl_clear:N \l__cookingunits_option_unit_tl
+ \tl_if_empty:nF {#2} { \keys_set:nn { cooking-units } {#2} }
+ \IfNoValueF {#1}
+ { \__cookingunits_reference_label_and_persons:n {#1} }
+ \__cookingunits_expand_unit_input:Nn \l__cookingunits_original_unit_tl {#3}
\__cookingunits_error_if_unit_not_defined:VTF \l__cookingunits_original_unit_tl
{
+ \__cookingunits_set_state_to:n { error }
\bool_set_true:N \l__cookingunits_unit_error_bool
- \cs_set_eq:NN \__cookingunits_print_correct_unit: \__cookingunits_print_default_unit:
}
- { \bool_set_false:N \l__cookingunits_unit_error_bool }
- \bool_set_false:N \l__cookingunits_special_sign_bool
- \bool_set_false:N \l__cookingunits_range_in_input_bool
- \bool_set_false:N \l__cookingunits_lokal_fraction_bool
- \bool_set_false:N \l__cookingunits_minus_bool
+ { \__cookingunits_set_state_to:n { normal } }
+ \__cookingunits_set_parse_and_process_type_to:n { number }
+ \__cookingunits_set_print_type_to:n { unknown }
+ \tl_clear:N \l__cookingunits_phantom_tl
+ \__cookingunits_initialize_new_default_units:
}
-\cs_new_protected:Npn \__cookingunits_initialise_unit_change:n #1
+\cs_new:Npn \__cookingunits_initialize_new_default_units:
{
- \tl_if_empty:nF {#1}
- { \keys_set_groups:nnn { cooking-units } { change-unit } {#1} }
- \bool_if:NT \l__cookingunits_convert_to_eV_bool
- { \__cookingunits_convert_to_eV: }
+ \__cookingunits_if_no_unit_marker:NTF \l__cookingunits_original_unit_tl
+ { \tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_original_unit_tl }
+ { \__cookingunits_intialize_new_default_units_aux: }
+ }
+\cs_new:Npn \__cookingunits_intialize_new_default_units_aux:
+ {
+ \bool_if:NTF \l__cookingunits_pckopt_bonkers_bool
+ { \__cookingunits_changing_unit_bonkers:N \l__cookingunits_original_unit_tl }
+ {
+ \bool_if:NT \l__cookingunits_pckopt_convert_to_eV_bool
+ { \__cookingunits_convert_to_eV:N \l__cookingunits_original_unit_tl }
+ }
\prop_get:NVNF \l__cookingunits_change_unit_prop \l__cookingunits_original_unit_tl \l__cookingunits_option_unit_tl
{ \tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_original_unit_tl }
}
-\cs_new_protected:Npn \__cookingunits_initialise_after_unit_change:nn #1#2
+\cs_new_protected:Npn \__cookingunits_initialise_new_after_parsing:n #1
{
- \IfNoValueF {#1}
- { \__cookingunits_reference_label_and_persons:n {#1} }
- \clist_if_empty:cF { l__cookingunits_unit_option_ \l__cookingunits_option_unit_tl _clist }
+ \clist_if_empty:cF { l__cookingunits_unit_option_ \l__cookingunits_decided_unit_tl _clist }
{
\keys_set_filter:nnv
{ cooking-units }
{ change-unit }
- { l__cookingunits_unit_option_ \l__cookingunits_option_unit_tl _clist }
+ { l__cookingunits_unit_option_ \l__cookingunits_decided_unit_tl _clist }
+ \tl_if_empty:nF {#1} { \keys_set:nn { cooking-units } {#1} }
+ }
+ \bool_set_eq:NN \l__cookingunits_lokal_numeral_bool \l__cookingunits_pckopt_print_numeral_bool
+ }
+\cs_new:Npn \__cookingunits_decide_unit:
+ {
+ \__cookingunits_change_unit:TF
+ { \tl_set_eq:NN \l__cookingunits_decided_unit_tl \l__cookingunits_option_unit_tl }
+ { \tl_set_eq:NN \l__cookingunits_decided_unit_tl \l__cookingunits_original_unit_tl }
+ }
+\cs_new:Npn \__cookingunits_new_setup_bools_for_process_and_prints:
+ {
+ \bool_set_false:N \l__cookingunits_lokal_recalc_for_people_bool
+ \bool_lazy_and:nnT
+ { \l__cookingunits_reference_given_bool }
+ { \l__cookingunits_pckopt_recalculate_amount_bool }
+ {
+ \int_compare:nNnF
+ { \l__cookingunits_wanted_number_of_persons_int }
+ =
+ { \l__cookingunits_local_number_of_persons_int }
+ { \bool_set_true:N \l__cookingunits_lokal_recalc_for_people_bool }
+ }
+ \__cookingunits_if_print_type_equal:nT { fraction }
+ {
+ \bool_lazy_or:nnTF
+ { \l__cookingunits_pckopt_eval_fractions_bool }
+ { \l__cookingunits_lokal_recalc_for_people_bool }
+ { \__cookingunits_set_print_type_to:n { number } }
+ {
+ \bool_lazy_and:nnT
+ { \l__cookingunits_pckopt_convert_fractions_bool }
+ { ! \tl_if_eq_p:NN \l__cookingunits_option_unit_tl \l__cookingunits_original_unit_tl }
+ { \__cookingunits_set_print_type_to:n { number } }
+ }
}
- \tl_if_empty:nF {#2}
- { \keys_set_filter:nnn { cooking-units } { change-unit } {#2} }
- \bool_lazy_and:nnTF
- { \l__cookingunits_calc_because_ref_was_given_bool } { \l__cookingunits_change_number_of_persons_bool }
- { \bool_set_true:N \l__cookingunits_lokal_persons_bool }
- { \bool_set_false:N \l__cookingunits_lokal_persons_bool }
- \bool_set_eq:NN \l__cookingunits_lokal_numeral_bool \l__cookingunits_print_numeral_bool
}
-\cs_new_protected:Npn \__cookingunits_print_input:N #1 { }
-\cs_new_protected:Npn \__cookingunits_print_correct_unit: { }
-\cs_new_protected:Npn \__cookingunits_do_not_process_input:NN #1#2 { }
-\cs_new_eq:NN \__cookingunits_pre_process_input:NN \__cookingunits_do_not_process_input:NN
-\cs_new_eq:NN \__cookingunits_post_process_input:NN \__cookingunits_do_not_process_input:NN
-\cs_new_protected:Npn \__cookingunits_set_process_and_print_for_cunum:
+\cs_new:Npn \__cookingunits_use_hook_accordingly:
{
- \cs_set_eq:NN \__cookingunits_print_input:N \__cookingunits_print_numerical_input:N
- \cs_set_eq:NN \__cookingunits_print_correct_unit: \__cookingunits_cunum_print_correct_unit:
- \cs_set_eq:NN \__cookingunits_pre_process_input:NN \__cookingunits_do_not_process_input:NN
- \cs_set_eq:NN \__cookingunits_post_process_input:NN \__cookingunits_do_not_process_input:NN
+ \l__cookingunits_cmd_hook_tl
+ \tl_case:NnF \l__cookingunits_cmd_type_tl
+ {
+ \c__cookingunits_cmd_type_cunum_tl { \l__cookingunits_cunum_hook_tl }
+ \c__cookingunits_cmd_type_cCutext_tl
+ {
+ \bool_if:NTF \l__cookingunits_cutext_uppercase_word_bool
+ { \l__cookingunits_Cutext_hook_tl }
+ { \l__cookingunits_cutext_hook_tl }
+ }
+ \c__cookingunits_cmd_type_cuam_tl { \l__cookingunits_cuam_hook_tl }
+ }
+ { \__cookingunits_create_internal_error:nN { use-hook-acc } \l__cookingunits_cmd_type_tl }
}
-\cs_new_protected:Npn \__cookingunits_set_process_and_print_for_cutext:
+\cs_new:Npn \__cookingunits_general_checkups:
{
- \cs_set_eq:NN \__cookingunits_print_input:N \__cookingunits_cutext_print_input:N
- \cs_set_eq:NN \__cookingunits_print_correct_unit: \__cookingunits_cutext_print_correct_unitname:
- \cs_set_eq:NN \__cookingunits_pre_process_input:NN \__cookingunits_cutext_pre_process_input:NN
- \cs_set_eq:NN \__cookingunits_post_process_input:NN \__cookingunits_cutext_post_process_input:NN
+ \tl_set_eq:NN \l__cookingunits_print_type_tl \l__cookingunits_parse_and_process_type_tl
+ \__cookingunits_if_state_equal:nT { normal }
+ { \__cookingunits_new_setup_bools_for_process_and_prints: }
+ \__cookingunits_decide_unit:
+ \__cookingunits_if_cmd_type_equal:nT { cCutext }
+ { \__cookingunits_cutext_check_if_translation_available: }
}
-\cs_new_protected:Npn \__cookingunits_set_process_and_print_for_cuam:
+\cs_new:Npn \__cookingunits_process_amount_normally:n #1
{
- \cs_set_eq:NN \__cookingunits_print_input:N \__cookingunits_cuam_print_numerical_input:N
- \cs_set_eq:NN \__cookingunits_print_correct_unit: \__cookingunits_cuam_print_correct_unitphrase:
- \cs_set_eq:NN \__cookingunits_pre_process_input:NN \__cookingunits_do_not_process_input:NN
- \cs_set_eq:NN \__cookingunits_post_process_input:NN \__cookingunits_cuam_post_process_input:NN
+ \__cookingunits_initialise_new_after_parsing:n {#1}
+ \tl_case:NnF \l__cookingunits_parse_and_process_type_tl
+ {
+ \c__cookingunits_parse_and_process_type_number_tl \__cookingunits_new_process_number_in_input:
+ \c__cookingunits_parse_and_process_type_range_tl \__cookingunits_new_process_range_in_input:
+ \c__cookingunits_parse_and_process_type_fraction_tl \__cookingunits_new_process_fraction_in_input:
+ }
+ { \__cookingunits_create_internal_error:nN { process_the_input } \l__cookingunits_parse_and_process_type_tl }
+ }
+\cs_new:Npn \__cookingunits_process_amount_special:
+ {
+ \__cookingunits_if_state_equal:nT { special_sign }
+ { \msg_warning:nnV { cooking-units } { amount-not-known } \l__cookingunits_original_amount_tl }
+ \bool_if:NT \l__cookingunits_pckopt_fourty_two_bool
+ { \__cookingunits_prepare_fourty_two_amount: }
+ }
+\cs_new:Npn \__cookingunits_prepare_fourty_two_amount:
+ {
+ \tl_set:Nn \l__cookingunits_number_tmpa_tl { 42 }
+ \tl_set:Nn \l__cookingunits_number_tmpb_tl { 42 }
+ \tl_if_empty:NF \l__cookingunits_mixed_fraction_tl
+ { \tl_set:Nn \l__cookingunits_mixed_fraction_tl { 42 } }
+ \__cookingunits_if_state_equal:nT { special_sign }
+ {
+ \tl_put_right:Nn \l__cookingunits_number_tmpa_tl { (!) }
+ \tl_put_right:Nn \l__cookingunits_number_tmpb_tl { (!) }
+ \tl_if_empty:NF \l__cookingunits_mixed_fraction_tl
+ { \tl_put_right:Nn \l__cookingunits_mixed_fraction_tl { (!) } }
+ }
+ }
+\cs_new:Npn \__cookingunits_new_process_number_in_input:
+ {
+ \__cookingunits_calculate_and_store_in:N \l__cookingunits_number_tmpa_tl
+ \__cookingunits_post_process_accordingly:NN \l__cookingunits_number_tmpa_tl \q_no_value
+ }
+\cs_new:Npn \__cookingunits_new_process_range_in_input:
+ {
+ \__cookingunits_calculate_and_store_in:N \l__cookingunits_number_tmpa_tl
+ \__cookingunits_calculate_and_store_in:N \l__cookingunits_number_tmpb_tl
+ \__cookingunits_post_process_accordingly:NN \l__cookingunits_number_tmpa_tl \l__cookingunits_number_tmpb_tl
+ }
+\cs_new:Npn \__cookingunits_new_process_fraction_in_input:
+ {
+ \__cookingunits_process_and_remove_minus_in_fraction:NNNN \l__cookingunits_minus_bool
+ \l__cookingunits_mixed_fraction_tl
+ \l__cookingunits_number_tmpa_tl
+ \l__cookingunits_number_tmpb_tl
+ \__cookingunits_if_print_type_equal:nT { number }
+ {
+ \__cookingunits_convert_fraction_to_number_in_input:NNN
+ \l__cookingunits_mixed_fraction_tl
+ \l__cookingunits_number_tmpa_tl
+ \l__cookingunits_number_tmpb_tl
+ }
+ }
+\cs_new:Npn \__cookingunits_process_and_remove_minus_in_fraction:NNNN #1 #2#3#4
+ {
+ \bool_set_false:N #1
+ \__cookingunits_check_minus_remove_and_reverse:NN
+ #1 #2#3#4
+ \q_nil
+ }
+\cs_new:Npn \__cookingunits_convert_fraction_to_number_in_input:NNN #1#2#3
+ {
+ \fp_compare:nNnTF {#3} = { 0 }
+ { \__cookingunits_create_error:n { Division-by-zero } }
+ {
+ \__cookingunits_tl_eval:Nn \l__cookingunits_number_tmpa_tl { #1 + #2 / #3 }
+ \bool_if:NT \l__cookingunits_minus_bool
+ { \tl_put_left:Nn \l__cookingunits_number_tmpa_tl { - } }
+ \__cookingunits_new_process_number_in_input:
+ }
+ }
+\cs_new:Npn \__cookingunits_new_print_amount_correctly:
+ {
+ \__cookingunits_if_state_equal:nTF { error }
+ { \l__cookingunits_original_amount_tl }
+ {
+ \tl_case:NnF \l__cookingunits_print_type_tl
+ {
+ \c__cookingunits_print_type_number_tl
+ {
+ \__cookingunits_print_number_accordingly:N
+ \l__cookingunits_number_tmpa_tl
+ }
+ \c__cookingunits_print_type_range_tl
+ {
+ \__cookingunits_print_range_accordingly:NN
+ \l__cookingunits_number_tmpa_tl
+ \l__cookingunits_number_tmpb_tl
+ }
+ \c__cookingunits_print_type_fraction_tl
+ {
+ \__cookingunits_culang_let:nnN { name } { decimal-mark } \l__cookingunits_translation_tmpa_tl
+ \tl_replace_once:Nnn \l__cookingunits_mixed_fraction_tl { . } \l__cookingunits_translation_tmpa_tl
+ \tl_replace_once:Nnn \l__cookingunits_number_tmpa_tl { . } \l__cookingunits_translation_tmpa_tl
+ \tl_replace_once:Nnn \l__cookingunits_number_tmpb_tl { . } \l__cookingunits_translation_tmpa_tl
+ \__cookingunits_print_fractions:Nnn
+ \l__cookingunits_mixed_fraction_tl
+ \l__cookingunits_number_tmpa_tl
+ \l__cookingunits_number_tmpb_tl
+ }
+ }
+ { \__cookingunits_create_internal_error:nN { print_the_input } \l__cookingunits_print_type_tl }
+ }
+ }
+\cs_new:Npn \__cookingunits_new_print_unit_correctly:
+ {
+ \__cookingunits_if_state_equal:nTF { error }
+ { \__cookingunits_print_unit_in_case_of_error: }
+ {
+ \tl_case:NnF \l__cookingunits_cmd_type_tl
+ {
+ \c__cookingunits_cmd_type_cunum_tl { \__cookingunits_cunum_print_correct_unit: }
+ \c__cookingunits_cmd_type_cCutext_tl { \__cookingunits_cutext_print_correct_unitname: }
+ \c__cookingunits_cmd_type_cuam_tl { \__cookingunits_cuam_print_correct_unitphrase: }
+ }
+ { \__cookingunits_create_internal_error:nN { print-unit-acc } \l__cookingunits_cmd_type_tl }
+ }
+ }
+\cs_new:Npn \__cookingunits_print_unit_in_case_of_error:
+ {
+ \tl_if_empty:NF \l__cookingunits_phantom_tl { \phantom { \l__cookingunits_phantom_tl } }
+ \tl_use:N \l__cookingunits_value_unit_space_tl
+ \bool_if:NTF \l__cookingunits_unit_error_bool
+ { \l__cookingunits_original_unit_tl }
+ { \__cookingunits_culang_print:nV { unit-symbol } \l__cookingunits_original_unit_tl }
+ }
+\cs_new:Npn \__cookingunits_print_number_accordingly:N #1
+ {
+ \tl_case:NnF \l__cookingunits_cmd_type_tl
+ {
+ \c__cookingunits_cmd_type_cunum_tl { \__cookingunits_print_numerical_input:N #1 }
+ \c__cookingunits_cmd_type_cCutext_tl { \__cookingunits_cutext_print_input:N #1 }
+ \c__cookingunits_cmd_type_cuam_tl { \__cookingunits_cuam_print_numerical_input:N #1 }
+ }
+ { \__cookingunits_create_internal_error:nN { print-input-acc } \l__cookingunits_cmd_type_tl }
+ }
+\cs_new:Npn \__cookingunits_print_range_accordingly:NN #1#2
+ {
+ \__cookingunits_print_number_accordingly:N #1
+ \__cookingunits_print_range_sign:
+ \__cookingunits_print_number_accordingly:N #2
+ }
+\cs_new:Npn \__cookingunits_print_range_sign:
+ {
+ \__cookingunits_if_cmd_type_equal:nTF { cunum }
+ { \tl_use:N \l__cookingunits_cunum_range_sign_tl }
+ {
+ \bool_lazy_or:nnTF
+ { \__cookingunits_if_cmd_type_equal_p:n { cCutext } }
+ { \l__cookingunits_lokal_numeral_bool }
+ {
+ \bool_set_false:N \l__cookingunits_cutext_uppercase_word_bool
+ \tl_if_empty:NTF \l__cookingunits_cutext_range_sign_tl
+ { \__cookingunits_culang_print:nn { name } { cutext-range-sign } }
+ { \tl_use:N \l__cookingunits_cutext_range_sign_tl }
+ }
+ { \tl_use:N \l__cookingunits_cunum_range_sign_tl }
+ }
+ }
+\cs_new:Npn \__cookingunits_post_process_accordingly:NN #1#2
+ {
+ \tl_case:NnF \l__cookingunits_cmd_type_tl
+ {
+ \c__cookingunits_cmd_type_cunum_tl { }
+ \c__cookingunits_cmd_type_cCutext_tl { \__cookingunits_cutext_post_process_input:NN #1#2 }
+ \c__cookingunits_cmd_type_cuam_tl { \__cookingunits_cuam_post_process_input:NN #1#2 }
+ }{
+ \__cookingunits_create_internal_error:nN { post-process } \l__cookingunits_cmd_type_tl
+ }
}
\cs_new_protected:Npn \__cookingunits_print_numerical_input:N #1
{
\tl_if_in:NnT #1 { . }
{
- \__cookingunits_translate_let:NnV \l__cookingunits_translation_tmpa_tl
- { decimal-mark } \c__cookingunits_postfix_unitname_tl
+ \__cookingunits_culang_let:nnN { name } { decimal-mark } \l__cookingunits_translation_tmpa_tl
\tl_replace_once:Nnn #1 { . } { \l__cookingunits_translation_tmpa_tl }
}
\tl_replace_once:Nnn #1 { - } \c__cookingunits_minus_tl
@@ -1307,53 +1987,29 @@
}
\__cookingunits_frac:nn {#2} {#3}
}
-\cs_new:Npn \__cookingunits_print_ranges:NN #1#2
+\cs_new:Npn \__cookingunits_create_internal_error:nN #1#2
{
- \__cookingunits_print_input:N #1
- \bool_if:NTF \l__cookingunits_using_cutext_bool
- {
- \tl_if_empty:NTF \l__cookingunits_cutext_range_sign_tl
- { \__cookingunits_translate:nV { cutext-range-sign } \c__cookingunits_postfix_unitname_tl }
- { \tl_use:N \l__cookingunits_cutext_range_sign_tl }
- \bool_set_false:N \l__cookingunits_cutext_uppercase_word_bool
- }
- { \tl_use:N \l__cookingunits_cunum_range_sign_tl }
- \__cookingunits_print_input:N #2
+ \__cookingunits_set_case_to:n { error }
+ \msg_error:nnnV { cooking-units } { internal-error } {#1} #2
}
\cs_new:Npn \__cookingunits_create_error:n #1
{
- \bool_set_true:N \l__cookingunits_error_bool
+ \__cookingunits_set_case_to:n { error }
\msg_error:nnV { cooking-units } {#1} \l__cookingunits_original_amount_tl
}
\cs_new:Npn \__cookingunits_create_error_and_stop:n #1
{
- \bool_set_true:N \l__cookingunits_error_bool
- \msg_error:nnV { cooking-units } {#1} \l__cookingunits_original_amount_tl
+ \__cookingunits_create_error:n {#1}
\use_none_delimit_by_q_nil:w
}
\cs_new:Npn \__cookingunits_create_error:nn #1#2
{
- \bool_set_true:N \l__cookingunits_error_bool
+ \__cookingunits_set_case_to:n { error }
\msg_error:nnnV { cooking-units } {#1} {#2} \l__cookingunits_original_amount_tl
}
-\cs_new:Npn \__cookingunits_process_tmp: { }
-\cs_new:Npn \__cookingunits_process_and_print_input:
- {
- \bool_lazy_or:nnTF
- { \l__cookingunits_error_bool }
- { \l__cookingunits_unit_error_bool }
- { \l__cookingunits_original_amount_tl }
- { \__cookingunits_process_tmp: }
- }
-\cs_new:Npn \__cookingunits_process_default: { \l__cookingunits_original_amount_tl }
-\cs_new:Npn \__cookingunits_print_default_unit:
- {
- \tl_if_empty:NF \l__cookingunits_phantom_tl { \phantom { \l__cookingunits_phantom_tl } }
- \,\l__cookingunits_original_unit_tl
- }
-\cs_new:Npn \__cookingunits_parse_input:n #1
+\cs_new:Npn \__cookingunits_parse_the_amount:n #1
{
- \__cookingunits_set_amount:Nn \l__cookingunits_original_amount_tl {#1}
+ \__cookingunits_expand_amount_input:Nn \l__cookingunits_original_amount_tl {#1}
\tl_set_rescan:NnV \l__cookingunits_original_amount_tl
{
\char_set_catcode_letter:N \_ %
@@ -1362,89 +2018,83 @@
} \l__cookingunits_original_amount_tl
\bool_lazy_any:nTF
{
- { \l__cookingunits_fourty_two_bool }
- { \l__cookingunits_draft_bool }
{ \tl_if_empty_p:N \l__cookingunits_original_amount_tl }
- }{
- \cs_set_eq:NN \__cookingunits_process_tmp: \__cookingunits_process_default:
- \tl_if_empty:NT \l__cookingunits_original_amount_tl
- { \msg_error:nnV { cooking-units } { empty-amount } \l__cookingunits_original_amount_tl }
- \bool_if:NT \l__cookingunits_fourty_two_bool
- { \tl_set:Nn \l__cookingunits_original_amount_tl { 42 } }
- }{
- \tl_set_eq:NN \l__cookingunits_tmpa_tl \l__cookingunits_original_amount_tl
- \__cookingunits_split_input:N \l__cookingunits_tmpa_tl
+ { \l__cookingunits_pckopt_draft_bool }
}
+ { \__cookingunits_prepare_just_print_input: }
+ { \__cookingunits_split_and_parse_input: }
+ }
+\cs_new:Npn \__cookingunits_split_and_parse_input:
+ {
+ \bool_if:NT \l__cookingunits_pckopt_fourty_two_bool
+ { \__cookingunits_set_state_to:n { 42 } }
+ \tl_set_eq:NN \l__cookingunits_tmpa_tl \l__cookingunits_original_amount_tl
+ \__cookingunits_prepare_to_split_input:N \l__cookingunits_tmpa_tl
}
-\cs_new:Npn \__cookingunits_split_input:N #1
+\cs_new:Npn \__cookingunits_prepare_just_print_input:
+ {
+ \__cookingunits_set_state_to:n { error }
+ \tl_if_empty:NT \l__cookingunits_original_amount_tl
+ { \__cookingunits_create_error:nn { cooking-units } { empty-amount } }
+ }
+\cs_new:Npn \__cookingunits_prepare_to_split_input:N #1
{
\tl_if_in:NVT #1 \l__cookingunits_input_range_sign_tl
{
\tl_replace_once:NVn #1 \l__cookingunits_input_range_sign_tl { \q__cookingunits_range }
- \bool_set_true:N \l__cookingunits_range_in_input_bool
+ \__cookingunits_set_parse_and_process_type_to:n { range }
}
\tl_if_in:NnT #1 { / }
{
- \bool_set_true:N \l__cookingunits_lokal_fraction_bool
- \bool_if:NT \l__cookingunits_range_in_input_bool
+ \__cookingunits_if_parse_and_process_type_equal:nT { range }
{ \__cookingunits_create_error_and_stop:n { fraction-not-allowed-with-range } }
+ \__cookingunits_set_parse_and_process_type_to:n { fraction }
}
- \__cookingunits_split:N #1
+ \__cookingunits_split_and_parse:N #1
\use_none_delimit_by_q_nil:w \q_nil
}
-\cs_new:Npn \__cookingunits_split:N #1
+\cs_new:Npn \__cookingunits_split_and_parse:N #1
{
- \bool_if:NTF \l__cookingunits_lokal_fraction_bool
- { \__cookingunits_split_fraction:V }
+ \tl_case:NnF \l__cookingunits_parse_and_process_type_tl
{
- \bool_if:NTF \l__cookingunits_range_in_input_bool
- { \__cookingunits_split_range:V }
- { \__cookingunits_split_number:V }
+ \c__cookingunits_parse_and_process_type_number_tl { \__cookingunits_split_and_parse_number:V }
+ \c__cookingunits_parse_and_process_type_range_tl { \__cookingunits_split_and_parse_range:V }
+ \c__cookingunits_parse_and_process_type_fraction_tl { \__cookingunits_split_and_parse_fraction:V }
}
+ { \__cookingunits_create_internal_error:nN { split } \l__cookingunits_parse_and_process_type_tl }
#1
}
-\cs_new:Npn \__cookingunits_split_number:n #1
+\cs_new:Npn \__cookingunits_split_and_parse_number:n #1
{
- \cs_set_eq:NN \__cookingunits_process_tmp: \__cookingunits_process_number_in_input:
\__cookingunits_parse_input_and_safe_in:nN {#1} \l__cookingunits_number_tmpa_tl
}
-\cs_new:Npn \__cookingunits_split_range:n #1
+\cs_new:Npn \__cookingunits_split_and_parse_range:n #1
{
- \cs_set_eq:NN \__cookingunits_process_tmp: \__cookingunits_process_range_in_input:
- \__cookingunits_split_range_aux:ww #1 \q_stop
+ \__cookingunits_split_and_parse_range_aux:ww #1 \q_stop
}
-\cs_new:Npn \__cookingunits_split_range_aux:ww #1 \q__cookingunits_range #2 \q_stop
+\cs_new:Npn \__cookingunits_split_and_parse_range_aux:ww #1 \q__cookingunits_range #2 \q_stop
{
\__cookingunits_parse_input_and_safe_in:nN {#1} \l__cookingunits_number_tmpa_tl
\__cookingunits_parse_input_and_safe_in:nN {#2} \l__cookingunits_number_tmpb_tl
}
-\cs_new:Npn \__cookingunits_split_fraction:n #1
+\cs_new:Npn \__cookingunits_split_and_parse_fraction:n #1
{
- \cs_set_eq:NN \__cookingunits_process_tmp: \__cookingunits_process_generel_fraction_in_input:
- \__cookingunits_split_fraction_mixed:ww
+ \__cookingunits_split_and_parse_fraction_mixed:ww
#1 \q_stop / \q_recursion_tail _ \q_nil \q_stop
\q_recursion_stop
- \bool_lazy_or:nnT
- { \l__cookingunits_lokal_persons_bool }{ \l__cookingunits_eval_fractions_bool }
- { \bool_set_false:N \l__cookingunits_lokal_fraction_bool }
- \bool_if:NT \l__cookingunits_convert_fractions_bool
- {
- \tl_if_eq:NNF \l__cookingunits_original_unit_tl \l__cookingunits_option_unit_tl
- { \bool_set_false:N \l__cookingunits_lokal_fraction_bool }
- }
}
-\cs_new:Npn \__cookingunits_split_fraction_mixed:ww #1 _ #2 \q_stop
+\cs_new:Npn \__cookingunits_split_and_parse_fraction_mixed:ww #1 _ #2 \q_stop
{
\quark_if_nil:nTF {#2}
{
\tl_clear:N \l__cookingunits_mixed_fraction_tl
- \__cookingunits_split_fraction_frac:ww #1 \q_stop
+ \__cookingunits_split_and_parse_fraction_frac:ww #1 \q_stop
}{
\__cookingunits_parse_input_and_safe_in:nN {#1} \l__cookingunits_mixed_fraction_tl
- \__cookingunits_split_fraction_frac:ww #2 \q_stop
+ \__cookingunits_split_and_parse_fraction_frac:ww #2 \q_stop
}
}
-\cs_new:Npn \__cookingunits_split_fraction_frac:ww #1 / #2 \q_stop
+\cs_new:Npn \__cookingunits_split_and_parse_fraction_frac:ww #1 / #2 \q_stop
{
\quark_if_recursion_tail_stop_do:nn {#2}
{ \__cookingunits_create_error:n { fraction-wrong-order } }
@@ -1452,17 +2102,16 @@
\__cookingunits_parse_input_and_safe_in:nN {#2} \l__cookingunits_number_tmpb_tl
\use_none_delimit_by_q_recursion_stop:w
}
-\cs_generate_variant:Nn \__cookingunits_split_number:n { V }
-\cs_generate_variant:Nn \__cookingunits_split_range:n { V }
-\cs_generate_variant:Nn \__cookingunits_split_fraction:n { V }
+\cs_generate_variant:Nn \__cookingunits_split_and_parse_number:n { V }
+\cs_generate_variant:Nn \__cookingunits_split_and_parse_range:n { V }
+\cs_generate_variant:Nn \__cookingunits_split_and_parse_fraction:n { V }
\cs_new:Npn \__cookingunits_parse_input_and_safe_in:nN #1 #2
{
\tl_clear:N \l__cookingunits_tmpa_tl
\bool_set_false:N \l__cookingunits_check_decimal_bool
\cs_set_eq:NN \__cookingunits_parse:N \__cookingunits_start_loop:N
\tl_map_function:nN {#1} \__cookingunits_parse:N
- \bool_if:NTF \l__cookingunits_error_bool
- { }
+ \__cookingunits_if_state_equal:nF { error }
{ \tl_set_eq:NN #2 \l__cookingunits_tmpa_tl }
}
\cs_new:Npn \__cookingunits_start_loop:N #1
@@ -1470,9 +2119,7 @@
\cs_set_eq:NN \__cookingunits_parse:N \__cookingunits_parse_input_loop_aux:N
\tl_if_in:NnTF \l__cookingunits_input_value_signs_tl {#1}
{ \tl_put_right:Nn \l__cookingunits_tmpa_tl {#1} }
- {
- \tl_map_function:nN {#1} \__cookingunits_parse:N
- }
+ { \tl_map_function:nN {#1} \__cookingunits_parse:N }
}
\cs_new:Npn \__cookingunits_parse_input_loop_aux:N #1
{
@@ -1486,23 +2133,22 @@
}{
\tl_if_in:NnTF \l__cookingunits_input_allowed_special_signs_tl {#1}
{
- \bool_set_true:N \l__cookingunits_special_sign_bool
+ \__cookingunits_if_state_equal:nF { error }
+ { \__cookingunits_set_state_to:n { special_sign } }
\tl_put_right:Nn \l__cookingunits_tmpa_tl {#1}
- }{
- \bool_set_true:N \l__cookingunits_error_bool
- \__cookingunits_check_error:n {#1}
}
+ { \__cookingunits_check_which_error:n {#1} }
}
}
}
-\cs_new:Npn \__cookingunits_check_error:n #1
+\cs_new:Npn \__cookingunits_check_which_error:n #1
{
\tl_if_in:NnTF \l__cookingunits_input_fraction_sign_tl {#1}
{ \__cookingunits_create_error:n { Second-fraction-sign-not-allowed } }
{
\tl_if_in:NnTF \l__cookingunits_input_mixed_fraction_sign_tl {#1}
{
- \bool_if:NTF \l__cookingunits_lokal_fraction_bool
+ \__cookingunits_if_parse_and_process_type_equal:nTF { fraction }
{ \__cookingunits_create_error:n { Second-mixed-fraction-sign-not-allowed } }
{ \__cookingunits_create_error:n { missing-slash } }
}
@@ -1515,167 +2161,89 @@
{ \__cookingunits_create_error:n { Second-decimal-sign-not-allowed } }
{ \bool_set_true:N #1 }
}
-\cs_new:Npn \__cookingunits_process_number_in_input:
- {
- \__cookingunits_process_and_print_number_in_input:N \l__cookingunits_number_tmpa_tl
- }
-\cs_new:Npn \__cookingunits_process_and_print_number_in_input:N #1
- {
- \__cookingunits_pre_process_input:NN #1 \q_no_value
- \__cookingunits_calculate_and_store_in:N #1
- \__cookingunits_post_process_input:NN #1 \q_no_value
- \__cookingunits_print_input:N #1
- }
-\cs_new:Npn \__cookingunits_process_range_in_input:
+\cs_new:Npn \__cookingunits_calculate_and_store_in:N #1
{
- \__cookingunits_pre_process_input:NN \l__cookingunits_number_tmpa_tl \l__cookingunits_number_tmpb_tl
- \__cookingunits_calculate_and_store_in:N \l__cookingunits_number_tmpa_tl
- \__cookingunits_calculate_and_store_in:N \l__cookingunits_number_tmpb_tl
- \__cookingunits_post_process_input:NN \l__cookingunits_number_tmpa_tl \l__cookingunits_number_tmpb_tl
- \__cookingunits_print_ranges:NN \l__cookingunits_number_tmpa_tl \l__cookingunits_number_tmpb_tl
+ \__cookingunits_calculate_input_and_store_in:N #1
+ \__cookingunits_calc_references_and_store_in:N #1
+ \__cookingunits_round_calculated_input_and_store_in:N #1
+ \__cookingunits_check_temperature_limit:N #1
}
-\cs_new:Npn \__cookingunits_process_generel_fraction_in_input:
+\cs_new:Npn \__cookingunits_calculate_input_and_store_in:N #1
{
- \__cookingunits_check_minus_remove_and_reverse:NN
- \l__cookingunits_mixed_fraction_tl
- \l__cookingunits_number_tmpa_tl
- \l__cookingunits_number_tmpb_tl
- \q_nil
- \bool_lazy_or:nnTF
- { \l__cookingunits_lokal_fraction_bool }
- { \l__cookingunits_special_sign_bool }
+ \tl_if_eq:NNF \l__cookingunits_decided_unit_tl \l__cookingunits_original_unit_tl
{
- \bool_if:NT \l__cookingunits_special_sign_bool
+ \fp_set:Nn \l__cookingunits_tmpa_fp {#1}
+ \tl_if_in:cnTF { l__cookingunits_unit_change_ \l__cookingunits_original_unit_tl _tl } { \l__cookingunits_tmpa_fp }
{
- \msg_warning:nnV { cooking-units } { amount-not-known } \l__cookingunits_original_amount_tl
- }
- \__cookingunits_print_fractions:Nnn
- \l__cookingunits_mixed_fraction_tl
- { \l__cookingunits_number_tmpa_tl }
- { \l__cookingunits_number_tmpb_tl }
- }{
- \fp_compare:nNnT { \l__cookingunits_number_tmpb_tl } = { 0 }
- { \msg_error:nnV { cooking-units } { Division-by-zero } \l__cookingunits_original_amount_tl }
- \__cookingunits_tl_eval:Nn \l__cookingunits_number_tmpa_tl
- {
- \l__cookingunits_mixed_fraction_tl +
- \l__cookingunits_number_tmpa_tl / \l__cookingunits_number_tmpb_tl
+ \__cookingunits_tl_eval:Nv #1 { l__cookingunits_unit_change_ \l__cookingunits_original_unit_tl _tl }
+ }{
+ \__cookingunits_tl_eval:Nn #1
+ { \l__cookingunits_tmpa_fp * \tl_use:c { l__cookingunits_unit_change_ \l__cookingunits_original_unit_tl _tl } }
}
- \bool_if:NT \l__cookingunits_minus_bool
- { \tl_put_left:Nn \l__cookingunits_number_tmpa_tl { - } }
- \__cookingunits_process_and_print_number_in_input:N \l__cookingunits_number_tmpa_tl
- }
- }
-\cs_new:Npn \__cookingunits_calculate_and_store_in:N #1
- {
- \bool_if:NTF \l__cookingunits_special_sign_bool
- {
- \msg_warning:nnV { cooking-units } { amount-not-known } #1
- }{
- \bool_lazy_and:nnTF
- { \l__cookingunits_using_cutext_bool } { \l__cookingunits_cutext_keep_unit_bool }
- { \tl_set_eq:NN \l__cookingunits_tmpa_tl #1 }
- { \__cookingunits_calculate_input_and_store_in:nN {#1} \l__cookingunits_tmpa_tl }
- \__cookingunits_calc_references:NN \l__cookingunits_tmpa_tl \l__cookingunits_tmpa_tl
- \__cookingunits_round_calculated_input:NV \l__cookingunits_tmpa_tl \l__cookingunits_tmpa_tl
- \__cookingunits_check_temperature_limit:N \l__cookingunits_tmpa_tl
- \tl_set_eq:NN #1 \l__cookingunits_tmpa_tl
}
}
-\cs_new:Npn \__cookingunits_calculate_input_and_store_in:nN #1#2
+\cs_new:Npn \__cookingunits_calc_references_and_store_in:N #1
{
- \fp_set:Nn \l__cookingunits_tmpa_fp {#1}
- \tl_if_in:cnTF { l__cookingunits_unit_change_ \l__cookingunits_original_unit_tl _tl } { \l__cookingunits_tmpa_fp }
+ \bool_if:NT \l__cookingunits_lokal_recalc_for_people_bool
{
- \__cookingunits_tl_eval:Nv #2 { l__cookingunits_unit_change_ \l__cookingunits_original_unit_tl _tl }
- }{
- \__cookingunits_tl_eval:Nn #2
- { \l__cookingunits_tmpa_fp * \tl_use:c { l__cookingunits_unit_change_ \l__cookingunits_original_unit_tl _tl } }
+ \seq_if_in:NVTF \l__cookingunits_curef_do_not_change_seq \l__cookingunits_decided_unit_tl
+ { \msg_error:nnV { cooking-units } { curef-forbidden-unit } \l__cookingunits_decided_unit_tl }
+ { \__cookingunits_calc_references_and_store_in_aux:N #1 }
}
}
-\cs_new:Npn \__cookingunits_calc_references:NN #1#2
- {
- \bool_if:NT \l__cookingunits_lokal_persons_bool
- {
- \int_compare:nNnF
- { \l__cookingunits_wanted_number_of_persons_int }
- =
- { \l__cookingunits_local_number_of_persons_int }
- {
- \tl_set_eq:NN \l__cookingunits_tmpb_tl \l__cookingunits_original_unit_tl
- \seq_if_in:NVTF \l__cookingunits_curef_do_not_change_seq \l__cookingunits_tmpb_tl
- { \msg_error:nnV { cooking-units } { curef-forbidden-unit } \l__cookingunits_tmpb_tl }
- { \__cookingunits_calc_references_aux:NN #1 #2 }
- }
- }
- }
-\cs_new:Npn \__cookingunits_calc_references_aux:NN #1#2
+\cs_new:Npn \__cookingunits_calc_references_and_store_in_aux:N #1
{
\__cookingunits_tl_eval:Nn #1
{
- #2 *
+ #1 *
\l__cookingunits_wanted_number_of_persons_int /
\l__cookingunits_local_number_of_persons_int
}
}
+\cs_new:Npn \__cookingunits_round_calculated_input_and_store_in:N #1
+ {
+ \bool_if:NTF \l__cookingunits_pckopt_round_precision_negative_bool
+ { \bool_set_true:N \l__cookingunits_round_number_bool }
+ { \__cookingunits_check_number_for_rounding:V #1 }
+ \bool_if:NT \l__cookingunits_round_number_bool
+ { \__cookingunits_tl_eval:Nn #1 { round ( \__cookingunits_rounding_function:n {#1} ) } }
+ }
\cs_new:Npn \__cookingunits_check_number_for_rounding:n #1
{
\bool_set_false:N \l__cookingunits_round_number_bool
\__cookingunits_check_number_after_dot_aux:ww #1 . \q_recursion_tail .
\q_recursion_stop
}
+\cs_generate_variant:Nn \__cookingunits_check_number_for_rounding:n { V }
\cs_new:Npn \__cookingunits_check_number_after_dot_aux:ww #1 . #2 .
{
- \quark_if_recursion_tail_stop_do:nn {#2}
- {
- \bool_if:NT \l__cookingunits_round_precision_negative_bool
- { \bool_set_true:N \l__cookingunits_round_number_bool }
- }
- \int_compare:nNnT
- { \tl_count:n {#2} } >
- { \l__cookingunits_round_precision_int }
- { \bool_set_true:N \l__cookingunits_round_number_bool }
+ \quark_if_recursion_tail_stop:n {#2}
+ \int_compare:nNnT
+ { \tl_count:n {#2} } >
+ { \l__cookingunits_round_precision_int }
+ { \bool_set_true:N \l__cookingunits_round_number_bool }
\use_none_delimit_by_q_recursion_stop:w
}
-\cs_new:Npn \__cookingunits_round_calculated_input:Nn #1#2
- {
- \__cookingunits_check_number_for_rounding:n {#2}
- \bool_if:NTF \l__cookingunits_round_number_bool
- { \__cookingunits_tl_eval:Nn #1 { round ( \__cookingunits_rounding_function:n {#2} ) } }
- { \tl_set:Nn #1 {#2} }
- }
-\cs_generate_variant:Nn \__cookingunits_round_calculated_input:Nn { NV }
\cs_new:Npn \__cookingunits_check_temperature_limit:N #1
{
- \bool_if:NT \l__cookingunits_check_temperature_bool
+ \bool_if:NT \l__cookingunits_pckopt_check_temperature_bool
{
- \seq_if_in:NVT \l__cookingunits_temperatures_to_check_seq \l__cookingunits_option_unit_tl
+ \seq_if_in:NVT \l__cookingunits_temperatures_to_check_seq \l__cookingunits_decided_unit_tl
{
\fp_compare:vNnT
- { l__cookingunits_ \l__cookingunits_option_unit_tl _min_fp } > {#1}
+ { l__cookingunits_ \l__cookingunits_decided_unit_tl _min_fp } > {#1}
{
\msg_error:nnxx { cooking-units }
{ Temperature-too-low }
- { #1 \space \l__cookingunits_option_unit_tl }
+ { #1 \space \l__cookingunits_decided_unit_tl }
{
- \fp_use:c { l__cookingunits_ \l__cookingunits_option_unit_tl _min_fp }
- \space \l__cookingunits_option_unit_tl
+ \fp_use:c { l__cookingunits_ \l__cookingunits_decided_unit_tl _min_fp }
+ \space \l__cookingunits_decided_unit_tl
}
}
}
}
}
-\cs_new_nopar:Npn \__cookingunits_grab_arrows_for_safety_do_afterwards:nN #1#2
- {
- \str_if_eq:nnTF {#2} { > }
- {
- \tl_put_right:Nx \l__cookingunits_tmpa_tl { \tl_to_str:N > }
- \exp_last_unbraced:NV #1 \l__cookingunits_tmpa_tl
- }{
- \tl_put_right:Nn \l__cookingunits_tmpa_tl {#2}
- \__cookingunits_grab_arrows_for_safety_do_afterwards:nN {#1}
- }
- }
\cs_new_nopar:Npn \__cookingunits_if_arrow_grab_until_close_do:nnTF #1#2#3#4
{
\str_if_eq:nnTF {#1} { < }
@@ -1684,11 +2252,21 @@
{ \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } }
\tl_clear:N \l__cookingunits_tmpa_tl
\tl_put_right:Nx \l__cookingunits_tmpa_tl { \tl_to_str:N < }
- \__cookingunits_grab_arrows_for_safety_do_afterwards:nN
- {#3} #2
+ \__cookingunits_grab_arrows_for_safety_do_afterwards:nN {#3} #2
}
{#4}
}
+\cs_new_nopar:Npn \__cookingunits_grab_arrows_for_safety_do_afterwards:nN #1#2
+ {
+ \str_if_eq:nnTF {#2} { > }
+ {
+ \tl_put_right:Nx \l__cookingunits_tmpa_tl { \tl_to_str:N > }
+ \exp_last_unbraced:NV #1 \l__cookingunits_tmpa_tl
+ }{
+ \tl_put_right:Nn \l__cookingunits_tmpa_tl {#2}
+ \__cookingunits_grab_arrows_for_safety_do_afterwards:nN {#1}
+ }
+ }
\NewDocumentCommand \cunum { d<> O{} m O{} m }
{
\__cookingunits_if_arrow_grab_until_close_do:nnTF {#3} {#5}
@@ -1701,27 +2279,14 @@
}
\cs_new:Npn \__cookingunits_cunum:nnnnn #1#2#3#4#5
{
- \__cookingunits_cunum_initialise:nnnnn {#1} {#2} {#3} {#4} {#5}
- \l__cookingunits_cunum_hook_tl
- \__cookingunits_parse_input:n {#3}
- \__cookingunits_process_and_print_input:
- \__cookingunits_print_correct_unit:
- }
-\cs_new_protected:Npn \__cookingunits_cunum_initialise:nnnnn #1#2#3#4#5
- {
- \__cookingunits_set_process_and_print_for_cunum:
- \tl_set:Nn \l__cookingunits_phantom_tl {#4}
- \__cookingunits_initialise_default:n {#5}
- \__cookingunits_initialise_unit_change:n {#2}
- \__cookingunits_initialise_after_unit_change:nn {#1} {#2}
+ \__cookingunits_set_cmd_type_to:n { cunum }
+ \__cookingunits_do_the_stuff:nnnnnn {#1} {#2} {#3} {#4} {#5} { }
}
\cs_new:Npn \__cookingunits_cunum_print_correct_unit:
{
\tl_if_empty:NF \l__cookingunits_phantom_tl { \phantom { \l__cookingunits_phantom_tl } }
\tl_use:N \l__cookingunits_value_unit_space_tl
- \__cookingunits_change_unit:TF
- { \__cookingunits_translate:VV \l__cookingunits_option_unit_tl \c__cookingunits_postfix_unit_tl }
- { \__cookingunits_translate:VV \l__cookingunits_original_unit_tl \c__cookingunits_postfix_unit_tl }
+ \__cookingunits_culang_print:nV { unit-symbol } \l__cookingunits_decided_unit_tl
}
\NewDocumentCommand \cutext { d<> O{} m m }
{
@@ -1729,12 +2294,8 @@
{ \cutext }
{
\group_begin:
- \__cookingunits_change_cutext_to_cunum:nTF {#2}
- { \__cookingunits_cunum:nnnnn {#1} {#2} {#3} { } {#4} }
- {
- \bool_set_false:N \l__cookingunits_cutext_uppercase_word_bool
- \__cookingunits_cutext:nnnn {#1} {#2} {#3} {#4}
- }
+ \bool_set_false:N \l__cookingunits_cutext_uppercase_word_bool
+ \__cookingunits_cutext:nnnn {#1} {#2} {#3} {#4}
\group_end:
}
}
@@ -1744,132 +2305,122 @@
{ \Cutext }
{
\group_begin:
- \__cookingunits_change_cutext_to_cunum:nTF {#2}
- { \__cookingunits_cunum:nnnnn {#1} {#2} {#3} { } {#4} }
- {
- \bool_set_true:N \l__cookingunits_cutext_uppercase_word_bool
- \__cookingunits_cutext:nnnn {#1} {#2} {#3} {#4}
- }
+ \bool_set_true:N \l__cookingunits_cutext_uppercase_word_bool
+ \__cookingunits_cutext:nnnn {#1} {#2} {#3} {#4}
\group_end:
}
}
-\cs_new_protected:Npn \__cookingunits_cutext_initialise:nnn #1#2#3
+\cs_new:Npn \__cookingunits_cutext:nnnn #1#2#3#4
{
- \bool_set_true:N \l__cookingunits_using_cutext_bool
- \__cookingunits_set_process_and_print_for_cutext:
- \__cookingunits_initialise_default:n {#3}
- \__cookingunits_initialise_unit_change:n {#2}
- \bool_if:NT \l__cookingunits_cutext_keep_unit_bool
- { \tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_original_unit_tl }
- \__cookingunits_initialise_after_unit_change:nn {#1} {#2}
- \bool_if:NT \l__cookingunits_fourty_two_bool
- { \tl_set:Nn \l__cookingunits_cutext_last_value_tl { 42 } }
+ \__cookingunits_set_cmd_type_to:n { cCutext }
+ \__cookingunits_do_the_stuff:nnnnnn {#1} {#2} {#3} { } {#4} { }
}
-\cs_new:Npn \__cookingunits_cutext:nnnn #1#2#3#4
+\cs_new_protected:Npn \__cookingunits_cutext_print_input:N #1
{
- \__cookingunits_cutext_initialise:nnn {#1} {#2} {#4}
- \bool_if:NTF \l__cookingunits_cutext_uppercase_word_bool
- { \l__cookingunits_Cutext_hook_tl }
- { \l__cookingunits_cutext_hook_tl }
- \bool_if:NTF \l__cookingunits_cutext_old_bool
- { \__cookingunits_old_cutext:nnn {#2} {#3} {#4} }
+ \bool_if:NTF \l__cookingunits_lokal_numeral_bool
{
- \__cookingunits_parse_input:n {#3}
- \__cookingunits_process_and_print_input:
+ \__cookingunits_cutext_print_input_aux:NV #1 \l__cookingunits_decided_unit_tl
}
- \__cookingunits_print_correct_unit:
+ { \__cookingunits_print_numerical_input:N #1 }
}
-\cs_new_protected:Npn \__cookingunits_cutext_print_input:Nn #1#2
+\cs_new_protected:Npn \__cookingunits_cutext_print_input_aux:Nn #1#2
{
- \bool_if:NTF \l__cookingunits_lokal_numeral_bool
+ \int_compare:nNnTF {#1} = { 1 }
{
- \__cookingunits_int_if_equal_one:nTF {#1}
+ \__cookingunits_culang_one_let:NnT \l__cookingunits_translation_tmpa_tl {#2}
{
- \__cookingunits_translate_one_and_check_existance:Nx \l__cookingunits_translation_tmpa_tl {#2}
- \bool_if:NTF \l__cookingunits_cutext_uppercase_word_bool
+ \bool_if:NT \l__cookingunits_cutext_uppercase_word_bool
{
- \exp_args:Nx \tl_upper_case:n { \tl_head:V \l__cookingunits_translation_tmpa_tl }
- \tl_tail:V \l__cookingunits_translation_tmpa_tl
+ \text_uppercase:x { \tl_head:V \l__cookingunits_translation_tmpa_tl }
+ \tl_tail:V
}
- { \l__cookingunits_translation_tmpa_tl }
- }{
- \bool_if:NTF \l__cookingunits_cutext_uppercase_word_bool
- { \__cookingunits_print_Numeral:n {#1} }
- { \__cookingunits_print_numeral:n {#1} }
}
+ \l__cookingunits_translation_tmpa_tl
+ }{
+ \bool_if:NTF \l__cookingunits_cutext_uppercase_word_bool
+ { \__cookingunits_print_Numeral:V #1 }
+ { \__cookingunits_print_numeral:V #1 }
}
- { \__cookingunits_print_numerical_input:N #1 }
- }
-\cs_generate_variant:Nn \__cookingunits_cutext_print_input:Nn { NV }
-\cs_new_protected:Npn \__cookingunits_cutext_print_input:N #1
- {
- \__cookingunits_change_unit:TF
- { \__cookingunits_cutext_print_input:NV #1 \l__cookingunits_option_unit_tl }
- { \__cookingunits_cutext_print_input:NV #1 \l__cookingunits_original_unit_tl }
}
+\cs_generate_variant:Nn \__cookingunits_cutext_print_input_aux:Nn { NV }
\cs_new:Npn \__cookingunits_cutext_print_correct_unitname:
{
- \l__cookingunits_cutext_space_tl
- \__cookingunits_change_unit:TF
- {
- \__cookingunits_fp_if_equal_one:nTF { \l__cookingunits_cutext_last_value_tl }
- { \__cookingunits_translate:VV \l__cookingunits_option_unit_tl \c__cookingunits_postfix_unitname_tl }
- { \__cookingunits_translate:VV \l__cookingunits_option_unit_tl \c__cookingunits_postfix_unitname_pl_tl }
- }
- { \__cookingunits_translate:VV \l__cookingunits_original_unit_tl \c__cookingunits_postfix_unitname_pl_tl }
+ \bool_if:NTF \l__cookingunits_lokal_numeral_bool
+ { \l__cookingunits_cutext_numeral_space_tl }
+ { \l__cookingunits_cutext_space_tl }
+ \bool_if:NTF \l__cookingunits_cutext_last_amount_equ_one_bool
+ { \__cookingunits_culang_print:nV { name } \l__cookingunits_decided_unit_tl }
+ { \__cookingunits_culang_print:nV { name-pl } \l__cookingunits_decided_unit_tl }
}
-\cs_new:Npn \__cookingunits_cutext_pre_process_input:NN #1#2
+\cs_new:Npn \__cookingunits_cutext_check_if_translation_available:
{
- \__cookingunits_change_unit:TF
- { \tl_set_eq:NN \l__cookingunits_tmpb_tl \l__cookingunits_option_unit_tl }
- { \tl_set_eq:NN \l__cookingunits_tmpb_tl \l__cookingunits_original_unit_tl }
- \__cookingunits_unitname_get:NxF \l__cookingunits_tmpa_tl \l__cookingunits_tmpb_tl
+ \bool_if:NTF \l__cookingunits_pckopt_cutext_keep_unit_bool
+ { \tl_set_eq:NN \l__cookingunits_curr_unit_tl \l__cookingunits_original_unit_tl }
+ { \tl_set_eq:NN \l__cookingunits_curr_unit_tl \l__cookingunits_decided_unit_tl }
+ \__cookingunits_culang_unitname_let:NVTF \l__cookingunits_scrap_tl \l__cookingunits_curr_unit_tl
{
+ \bool_if:NT \l__cookingunits_pckopt_cutext_keep_unit_bool
+ {
+ \tl_set_eq:NN \l__cookingunits_decided_unit_tl \l__cookingunits_original_unit_tl
+ \tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_original_unit_tl
+ }
+ }{
\msg_warning:nnx
{ cooking-units }
{ cutext-no-translation-available }
- \l__cookingunits_tmpb_tl
- \bool_set_false:N \l__cookingunits_using_cutext_bool
- \__cookingunits_set_process_and_print_for_cunum:
+ \l__cookingunits_curr_unit_tl
+ \__cookingunits_set_cmd_type_to:n { cunum }
+ \__cookingunits_decide_unit:
}
}
\cs_new:Npn \__cookingunits_cutext_post_process_input:NN #1#2
{
- \bool_if:NF \l__cookingunits_special_sign_bool
+ \__cookingunits_if_parse_and_process_type_equal:nTF { range }
+ { \__cookingunits_cutext_check_if_amount_single:N #2 }
+ { \__cookingunits_cutext_check_if_amount_single:N #1 }
+ \bool_if:NT \l__cookingunits_lokal_numeral_bool
{
- \__cookingunits_cutext_post_process_input_aux:NN #1#2
+ \__cookingunits_if_contain_decimals:NNTF #1#2
+ { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
+ { \__cookingunits_check_if_integer_can_be_numerals:NN #1#2 }
}
}
-\cs_new:Npn \__cookingunits_cutext_post_process_input_aux:NN #1#2
+\cs_new:Npn \__cookingunits_cutext_check_if_amount_single:N #1
{
- \bool_if:NTF \l__cookingunits_range_in_input_bool
- { \tl_set_eq:NN \l__cookingunits_cutext_last_value_tl #2 }
- { \tl_set_eq:NN \l__cookingunits_cutext_last_value_tl #1 }
- \bool_if:NT \l__cookingunits_lokal_numeral_bool
- { \__cookingunits_cutext_post_process_input_numerals:NN #1#2 }
+ \fp_compare:nNnTF {#1} = { 1.0 }
+ { \bool_set_true:N } { \bool_set_false:N }
+ \l__cookingunits_cutext_last_amount_equ_one_bool
}
-\cs_new:Npn \__cookingunits_cutext_post_process_input_numerals:NN #1#2
+\cs_new:Npn \__cookingunits_check_if_integer_can_be_numerals:NN #1#2
{
- \__cookingunits_bool_set_if_integers:NNN \l__cookingunits_tmpa_bool #1 #2
- \bool_if:NTF \l__cookingunits_tmpa_bool
+ \__cookingunits_if_parse_and_process_type_equal:nTF { range }
{
- \bool_if:NTF \l__cookingunits_range_in_input_bool
+ \bool_lazy_all:nF
{
- \bool_lazy_and:nnF
- { \int_compare_p:nNn {#1} < { \l__cookingunits_print_numerals_below_int } }
- { \int_compare_p:nNn {#2} < { \l__cookingunits_print_numerals_below_int } }
- { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
- }{
- \int_compare:nNnF {#1} < { \l__cookingunits_print_numerals_below_int }
- { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
+ { \int_compare_p:nNn {#1} < { \l__cookingunits_print_numerals_below_int } }
+ { \int_compare_p:nNn {#2} < { \l__cookingunits_print_numerals_below_int } }
+ { \int_compare_p:nNn {#1} > { 0 } }
+ { \int_compare_p:nNn {#2} > { 0 } }
}
+ { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
+ }{
+ \bool_lazy_and:nnF
+ { \int_compare_p:nNn {#1} < { \l__cookingunits_print_numerals_below_int } }
+ { \int_compare_p:nNn {#1} > { 0 } }
+ { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
}
- { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
}
-\tl_const:Nn \c__cookingunits_cuam_marker_tl { __cookingunits_cunum }
-\tl_new:c { l__cookingunits_unit_change_ \c__cookingunits_cuam_marker_tl _tl }
-\tl_set:cn { l__cookingunits_unit_change_ \c__cookingunits_cuam_marker_tl _tl } { 1.0 }
-\clist_new:c { l__cookingunits_unit_option_ \c__cookingunits_cuam_marker_tl _clist }
+\tl_const:Nx \c__cookingunits_no_unit_marker_tl { \__cookingunits_to_unit:n { __cookingunits_no_unit } }
+\prg_new_conditional:Npnn \__cookingunits_if_no_unit_marker:N #1 { TF , F }
+ {
+ \tl_if_eq:NNTF \c__cookingunits_no_unit_marker_tl #1
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+\seq_gput_right:NV \g__cookingunits_list_of_defined_units_seq \c__cookingunits_no_unit_marker_tl
+\tl_new:c { l__cookingunits_unit_change_ \c__cookingunits_no_unit_marker_tl _tl }
+\tl_set:cn { l__cookingunits_unit_change_ \c__cookingunits_no_unit_marker_tl _tl } { 1.0 }
+\clist_new:c { l__cookingunits_unit_option_ \c__cookingunits_no_unit_marker_tl _clist }
\NewDocumentCommand \cuam { d<> O{} m }
{
\__cookingunits_if_arrow_grab_until_close_do:nnTF {#3} { }
@@ -1882,69 +2433,48 @@
}
\cs_new:Npn \__cookingunits_cuam:nnn #1#2#3
{
- \__cookingunits_cuam_initialise:nn {#1} {#2}
- \l__cookingunits_cuam_hook_tl
- \bool_if:NTF \l__cookingunits_cuam_old_bool
- { \__cookingunits_cuam_old:n {#3} }
- {
- \__cookingunits_parse_input:n {#3}
- \__cookingunits_process_and_print_input:
- \__cookingunits_print_correct_unit:
- }
- }
-\cs_new_protected:Npn \__cookingunits_cuam_initialise:nn #1#2
- {
- \__cookingunits_set_process_and_print_for_cuam:
- \tl_set_eq:NN \l__cookingunits_original_unit_tl \c__cookingunits_cuam_marker_tl
- \tl_set_eq:NN \l__cookingunits_option_unit_tl \c__cookingunits_cuam_marker_tl
- \bool_set_false:N \l__cookingunits_lokal_phrase_bool
- \__cookingunits_initialise_after_unit_change:nn {#1} {#2}
+ \__cookingunits_set_cmd_type_to:n { cuam }
+ \__cookingunits_do_the_stuff:nnnnVn {#1} {#2} {#3} { } \c__cookingunits_no_unit_marker_tl { }
}
\cs_new_protected:Npn \__cookingunits_cuam_post_process_input:NN #1#2
{
- \bool_if:NF \l__cookingunits_special_sign_bool
- { \__cookingunits_cuam_post_process_input_aux:NN #1 #2 }
- }
-\cs_new:Npn \__cookingunits_cuam_post_process_input_aux:NN #1#2
- {
- \__cookingunits_bool_set_if_integers:NNN \l__cookingunits_tmpa_bool #1 #2
- \bool_lazy_and:nnT
- { \l__cookingunits_use_phrases_bool } { \l__cookingunits_tmpa_bool }
- { \__cookingunits_cuam_post_process_input_phrases:NN #1#2 }
- \bool_if:NT \l__cookingunits_lokal_numeral_bool
- { \__cookingunits_cuam_post_process_input_numerals:NN #1#2 }
+ \__cookingunits_if_contain_decimals:NNTF #1#2
+ { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
+ {
+ \bool_if:NT \l__cookingunits_pckopt_use_phrases_bool
+ { \__cookingunits_cuam_post_process_input_phrases:NN #1#2 }
+ \bool_if:NT \l__cookingunits_lokal_numeral_bool
+ { \__cookingunits_check_if_integer_can_be_numerals:NN #1#2 }
+ }
}
\cs_new:Npn \__cookingunits_cuam_post_process_input_phrases:NN #1#2
{
- \__cookingunits_get_phrase_for_current_langauge:NNT
- \l__cookingunits_phrase_prop
- \l__cookingunits_phrase_numbers_seq
- {
- \__cookingunits_cuam_post_process_input_phrases_aux:NNN
- #1 \l__cookingunits_tmpa_int \l__cookingunits_phrase_number_tl
- \bool_if:NT \l__cookingunits_lokal_phrase_bool
- {
- \bool_if:NTF \l__cookingunits_range_in_input_bool
- {
- \bool_if:NF \l__cookingunits_phrase_negative_bool
- {
- \__cookingunits_cuam_post_process_input_phrases_range:NN
- #2 \l__cookingunits_tmpb_int
- \bool_if:NT \l__cookingunits_lokal_phrase_bool
- {
- \tl_set:NV #1 \l__cookingunits_tmpa_int
- \tl_set:NV #2 \l__cookingunits_tmpb_int
- \__cookingunits_cuam_get_phrase_name:NVN
- \l__cookingunits_phrase_phrase_tl \l__cookingunits_phrase_number_tl \l__cookingunits_tmpb_int
- }
- }
- }{
- \tl_set:NV #1 \l__cookingunits_tmpa_int
- \__cookingunits_cuam_get_phrase_name:NVN
- \l__cookingunits_phrase_phrase_tl \l__cookingunits_phrase_number_tl \l__cookingunits_tmpa_int
- }
- }
+ \__cookingunits_culang_let:nnN { phrase } { phrase-prop } \l__cookingunits_phrase_prop
+ \tl_if_eq:NNT \q__cookingunits_no_translation \l__cookingunits_phrase_prop
+ { \use_none_delimit_by_q_stop:w }
+ \prop_get:NnN \l__cookingunits_phrase_prop { seq } \l__cookingunits_phrase_numbers_seq
+ \__cookingunits_cuam_post_process_input_phrases_aux:NNN
+ #1 \l__cookingunits_tmpa_int \l__cookingunits_phrase_number_tl
+ \bool_if:NF \l__cookingunits_lokal_phrase_bool
+ { \use_none_delimit_by_q_stop:w }
+ \__cookingunits_if_parse_and_process_type_equal:nTF { range }
+ {
+ \bool_if:NT \l__cookingunits_phrase_negative_bool
+ { \use_none_delimit_by_q_stop:w }
+ \__cookingunits_cuam_post_process_input_phrases_range:NN
+ #2 \l__cookingunits_tmpb_int
+ \bool_if:NF \l__cookingunits_lokal_phrase_bool
+ { \use_none_delimit_by_q_stop:w }
+ \tl_set:NV #1 \l__cookingunits_tmpa_int
+ \tl_set:NV #2 \l__cookingunits_tmpb_int
+ \__cookingunits_cuam_get_phrase_name:NVN
+ \l__cookingunits_phrase_text_tl \l__cookingunits_phrase_number_tl #2
+ }{
+ \tl_set:NV #1 \l__cookingunits_tmpa_int
+ \__cookingunits_cuam_get_phrase_name:NVN
+ \l__cookingunits_phrase_text_tl \l__cookingunits_phrase_number_tl #1
}
+ \use_none_delimit_by_q_stop:w \q_stop
}
\cs_new:Npn \__cookingunits_cuam_post_process_input_phrases_aux:NNN #1#2#3
{
@@ -1953,15 +2483,16 @@
{
\int_compare:nNnF { \int_abs:n {##1} } > {#1}
{
- \int_compare:nNnTF {##1} < { 0 }
+ \prop_get:NnN \l__cookingunits_phrase_prop { ##1-singlebool } \l_tmpa_tl
+ \int_compare:nNnTF { \l_tmpa_tl } = { 1 }
+ { \bool_set_true:N \l__cookingunits_phrase_negative_bool }
{
- \bool_set_true:N \l__cookingunits_phrase_negative_bool
- \int_set:Nn \l_tmpa_int { 1 }
+ \bool_set_false:N \l__cookingunits_phrase_negative_bool
+ \tl_set:Nf \l_tmpa_tl { \int_div_truncate:nn {#1} {##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_compare:nNnT { \int_abs:n {##1} * \l_tmpa_tl } = {#1}
{
- \int_set_eq:NN #2 \l_tmpa_int
+ \tl_set_eq:NN #2 \l_tmpa_tl
\tl_set:Nn #3 {##1}
\bool_set_true:N \l__cookingunits_lokal_phrase_bool
\seq_map_break:
@@ -1971,8 +2502,11 @@
}
\cs_new:Npn \__cookingunits_cuam_post_process_input_phrases_range:NN #1#2
{
- \int_set:Nn \l_tmpa_int { \int_div_truncate:nn {#1} { \l__cookingunits_phrase_number_tl } }
- \int_compare:nNnTF { \l__cookingunits_phrase_number_tl * \l_tmpa_int } = {#1}
+ \int_set:Nn \l_tmpa_int
+ {
+ \int_div_truncate:nn {#1} { \int_abs:n {\l__cookingunits_phrase_number_tl } }
+ }
+ \int_compare:nNnTF { \int_abs:n {\l__cookingunits_phrase_number_tl} * \l_tmpa_int } = {#1}
{
\int_set_eq:NN #2 \l_tmpa_int
\bool_set_true:N \l__cookingunits_lokal_phrase_bool
@@ -1982,141 +2516,290 @@
}
\cs_new:Npn \__cookingunits_cuam_get_phrase_name:NnN #1#2#3
{
- \__cookingunits_int_if_equal_one:nTF {#3}
+ \int_compare:nNnTF {#3} = { 1 }
{ \prop_get:NnN \l__cookingunits_phrase_prop {#2} #1 }
{ \prop_get:NnN \l__cookingunits_phrase_prop { #2-pl } #1 }
+ \prop_get:NnN \l__cookingunits_phrase_prop { #2-gender } \l__cookingunits_phrase_gender_tl
}
\cs_generate_variant:Nn \__cookingunits_cuam_get_phrase_name:NnN { NVN }
-\cs_new:Npn \__cookingunits_cuam_post_process_input_numerals:NN #1#2
- {
- \bool_if:NTF \l__cookingunits_tmpa_bool
- {
- \bool_if:NTF \l__cookingunits_range_in_input_bool
- {
- \bool_lazy_and:nnF
- { \int_compare_p:nNn {#1} < { \l__cookingunits_print_numerals_below_int } }
- { \int_compare_p:nNn {#2} < { \l__cookingunits_print_numerals_below_int } }
- { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
- }{
- \int_compare:nNnF {#1} < { \l__cookingunits_print_numerals_below_int }
- { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
- }
- }
- { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
- }
\cs_new_protected:Npn \__cookingunits_cuam_print_numerical_input:N #1
{
\bool_lazy_and:nnTF
{ \l__cookingunits_lokal_phrase_bool }
{ \l__cookingunits_lokal_numeral_bool }
{
- \__cookingunits_int_if_equal_one:nTF {#1}
+ \__cookingunits_cuam_print_numerical_input_aux:NV #1\l__cookingunits_phrase_number_tl
+ }
+ { \__cookingunits_print_numerical_input:N #1 }
+ }
+\cs_new:Npn \__cookingunits_cuam_print_numerical_input_aux:Nn #1#2
+ {
+ \int_compare:nNnTF {#1} = { 1 }
+ {
+ \__cookingunits_culang_one_let_by_gender:NVTF
+ \l__cookingunits_translation_tmpa_tl \l__cookingunits_phrase_gender_tl
+ { \l__cookingunits_translation_tmpa_tl }
{
- \__cookingunits_translate_one_and_check_existance:Nx
- \l__cookingunits_translation_tmpa_tl
- { \l__cookingunits_phrase_number_tl -phrase-gender }
- \l__cookingunits_translation_tmpa_tl
+ \__cookingunits_print_numeral:V #1
+ \bool_set_false:N \l__cookingunits_lokal_numeral_bool
}
- { \exp_args:NV \__cookingunits_print_numeral:n #1 }
- }{ \__cookingunits_print_numerical_input:N #1 }
+ }
+ { \__cookingunits_print_numeral:V #1 }
}
+\cs_generate_variant:Nn \__cookingunits_cuam_print_numerical_input_aux:Nn { NV }
\cs_new:Npn \__cookingunits_cuam_print_correct_unitphrase:
{
\bool_if:NT \l__cookingunits_lokal_phrase_bool
{
\l__cookingunits_cuphrase_space_tl
- \l__cookingunits_phrase_phrase_tl
+ \l__cookingunits_phrase_text_tl
}
}
+
+%% To be deleted. In order to remove error messages.
\NewDocumentCommand \cudefinekeys { m m }
{
\bool_set_false:N \l__cookingunits_single_key_bool
- \__cookingunits_cukeys_define_keys_and_single_keys:nn {#1} {#2}
+ \__cookingunits_initialice_cukeys_define:n {#1}
+ \__cookingunits_cukeys_prepare_parsing_keys:nn {#1} {#2}
}
\NewDocumentCommand \cudefinesinglekey { m m }
{
\bool_set_true:N \l__cookingunits_single_key_bool
- \__cookingunits_cukeys_define_keys_and_single_keys:nn {#1} {#2}
+ \__cookingunits_initialice_cukeys_define:n {#1}
+ \tl_set_rescan:Nno \l__cookingunits_tmpa_tl
+ { \char_set_catcode_letter:N \# } {#2}
+ \__cookingunits_cukeys_prepare_parsing_keys:nV {#1} \l__cookingunits_tmpa_tl
+ }
+\cs_new:Npn \__cookingunits_initialice_cukeys_define:n #1
+ {
+ \__cookingunits_set_state_to:n { normal }
+ \seq_clear:N \l__cookingunits_tmpa_seq
+ \seq_clear:N \l__cookingunits_tmpb_seq
+ \prop_clear:N \l__cookingunits_tmpa_prop
+ \tl_set:Nn \l__cookingunits_new_key_base_tl { 1 }
+ \__cookingunits_error_if_unit_not_defined:nNT {#1} \l__cookingunits_original_unit_tl
+ { \__cookingunits_set_state_to:n { error } }
}
-\cs_new:Npn \__cookingunits_cukeys_define_keys_and_single_keys:nn #1#2
+\NewDocumentCommand \cudefinekeychain { m }
{
- \__cookingunits_error_if_unit_not_defined:nTF {#1}
- { \bool_set_true:N } { \bool_set_false:N }
- \l__cookingunits_unit_error_bool
- \tl_if_blank:nF {#2}
+ \bool_set_false:N \l__cookingunits_single_key_bool
+ \__cookingunits_initialice_cukeychain_define:n {#1}
+ \__cookingunits_cukeys_prepare_parsing_keys:n {#1}
+ }
+\cs_new:Npn \__cookingunits_initialice_cukeychain_define:n #1
+ {
+ \__cookingunits_cukeychain_get_first_unit_aux:nn #1
+ \q_recursion_tail \q_recursion_tail \q_recursion_stop
+ \__cookingunits_if_state_equal:nF { error }
{
- \prop_gclear:N \g__cookingunits_master_changer_prop
- \prop_gclear:N \g__cookingunits_convert_to_eV_remember_prop
- \seq_clear:N \l__cookingunits_tmpa_seq
- \prop_clear:N \l__cookingunits_tmpa_prop
- \prop_clear_new:c { l__cookingunits_cukeys_ #1 _prop }
- \bool_if:NTF \l__cookingunits_single_key_bool
- {
- \__cookingunits_cukeys_parse_and_create_single_key:nn {#1} {#2}
- }{
- \fp_set:Nn \l__cookingunits_tmpa_fp { 1.0 }
- \tl_set:Nn \l__cookingunits_original_unit_tl {#1}
- \__cookingunits_cukeys_parse_and_create_keys:nn {#1}
- {
- {#1} { 1.0 } #2
- }
- }
+ \exp_args:NV \__cookingunits_initialice_cukeys_define:n \l__cookingunits_curr_unit_tl
+ \__cookingunits_tl_eval:Nn \l__cookingunits_new_key_base_tl { 1 / (\l__cookingunits_base_tl) }
+ \tl_clear:N \l__cookingunits_curr_unit_tl
}
}
-\cs_new:Npn \__cookingunits_cukeys_parse_and_create_keys:nn #1#2
+\cs_new:Npn \__cookingunits_cukeychain_get_first_unit_aux:nn #1#2
{
- \__cookingunits_cukeys_parse_input:nn #2
- \q_recursion_tail \q_recursion_tail \q_recursion_stop
- \bool_if:NF \l__cookingunits_unit_error_bool
+ \quark_if_recursion_tail_stop_do:nn {#1}
+ { \__cookingunits_set_state_to:n { error } }
+ \quark_if_recursion_tail_stop_do:nn {#2}
+ {
+ \msg_error:nn { cooking-units } { missing-argument }
+ \__cookingunits_set_state_to:n { error }
+ }
+ \tl_set:Nn \l__cookingunits_curr_unit_tl {#1}
+ \tl_set:Nn \l__cookingunits_base_tl {#2}
+ \use_none_delimit_by_q_recursion_stop:w
+ \__cookingunits_cukeychain_get_first_unit_aux:nn
+ }
+\NewDocumentCommand \cuaddkeys { m m }
+ {
+ \bool_set_false:N \l__cookingunits_single_key_bool
+ \__cookingunits_initialice_cukeys_add:n {#1}
+ \__cookingunits_cukeys_prepare_parsing_keys:nn {#1} {#2}
+ }
+\NewDocumentCommand \cuaddtokeys { m m m }
+ {
+ \bool_set_false:N \l__cookingunits_single_key_bool
+ \__cookingunits_initialice_cukeys_add:n {#1}
+ \tl_set:Nn \l__cookingunits_tmpa_tl { {#2} { \fp_eval:n { 1.0 / (#3) } } }
+ \__cookingunits_cukeys_prepare_parsing_keys:nV {#1} \l__cookingunits_tmpa_tl
+ }
+\NewDocumentCommand \cuaddsinglekeys { m m }
+ {
+ \bool_set_true:N \l__cookingunits_single_key_bool
+ \__cookingunits_initialice_cukeys_add:n {#1}
+ \tl_set_rescan:Nno \l__cookingunits_tmpa_tl
+ { \char_set_catcode_letter:N \# } {#2}
+ \__cookingunits_cukeys_prepare_parsing_keys:nV {#1} \l__cookingunits_tmpa_tl
+ }
+\cs_new:Npn \__cookingunits_initialice_cukeys_add:n #1
+ {
+ \seq_clear:N \l__cookingunits_tmpa_seq
+ \seq_clear:N \l__cookingunits_tmpb_seq
+ \__cookingunits_set_state_to:n { normal }
+ \__cookingunits_error_if_unit_not_defined:nNT {#1} \l__cookingunits_curr_unit_tl
+ {
+ \__cookingunits_set_state_to:n { error }
+ \use_none_delimit_by_q_stop:w
+ }
+ \__cookingunits_if_unit_has_a_key:nF {#1}
+ {
+ \msg_error:nnx { cooking-units } { Key-not-defined } \l__cookingunits_curr_unit_tl
+ \__cookingunits_set_state_to:n { error }
+ \use_none_delimit_by_q_stop:w
+ }
+ \tl_set_eq:Nc \l__cookingunits_original_unit_tl { l__cookingunits_base_key_unit_ \l__cookingunits_curr_unit_tl _tl }
+ \prop_set_eq:Nc \l__cookingunits_tmpa_prop { l__cookingunits_new_cukeys_ \l__cookingunits_original_unit_tl _prop }
+ \prop_get:NnN \l__cookingunits_tmpa_prop {#1} \l__cookingunits_new_key_base_tl
+ \prop_get:NnN \l__cookingunits_tmpa_prop { Liste } \l__cookingunits_tmpa_seq
+ \prop_get:NnN \l__cookingunits_tmpa_prop { single } \l__cookingunits_tmpa_tl
+ \int_compare:nNnF { \l__cookingunits_single_key_bool } = { \l__cookingunits_tmpa_tl }
+ {
+ \msg_error:nn { cooking-units } { Adding-single-to-multi-key-or-vice-verca }
+ \__cookingunits_set_state_to:n { error }
+ }
+ \use_none_delimit_by_q_stop:w \q_stop
+ }
+\cs_generate_variant:Nn \__cookingunits_initialice_cukeys_add:n { V }
+\NewDocumentCommand \cuaddtokeychain { m }
+ {
+ \bool_set_false:N \l__cookingunits_single_key_bool
+ \__cookingunits_initialice_cukeys_keychain_add:n {#1}
+ \__cookingunits_cukeys_prepare_parsing_keys:n {#1}
+ }
+\cs_new:Npn \__cookingunits_initialice_cukeys_keychain_add:n #1
+ {
+ \__cookingunits_cukeys_keychain_get_first_valid_unit:n {#1}
+ \__cookingunits_if_state_equal:nF { error }
+ {
+ \__cookingunits_initialice_cukeys_add:V \l__cookingunits_curr_unit_tl
+ \__cookingunits_tl_eval:Nn \l__cookingunits_new_key_base_tl { (\l__cookingunits_new_key_base_tl) / (\l__cookingunits_base_tl) }
+ }
+ }
+\cs_new:Npn \__cookingunits_cukeys_keychain_get_first_valid_unit:n #1
+ {
+ \__cookingunits_cukeys_keychain_get_first_valid_unit_aux:nn #1
+ \q_recursion_tail \q_recursion_tail \q_recursion_stop
+ }
+\cs_new:Npn \__cookingunits_cukeys_keychain_get_first_valid_unit_aux:nn #1#2
+ {
+ \quark_if_recursion_tail_stop_do:nn {#1}
+ {
+ \msg_error:nn { cooking-units } { Key-chain-unit-not-found }
+ \__cookingunits_set_state_to:n { error }
+ }
+ \quark_if_recursion_tail_stop_do:nn {#2}
+ {
+ \msg_error:nn { cooking-units } { missing-argument }
+ \__cookingunits_set_state_to:n { error }
+ }
+ \__cookingunits_if_unit_has_a_key:nT {#1}
+ {
+ \__cookingunits_error_if_unit_not_defined:nNT {#1} \l__cookingunits_curr_unit_tl
+ { \__cookingunits_set_state_to:n { error } }
+ \tl_set_eq:NN \l__cookingunits_original_unit_tl \l__cookingunits_curr_unit_tl
+ \tl_set:Nn \l__cookingunits_base_tl {#2}
+ \use_none_delimit_by_q_recursion_stop:w
+ }
+ \__cookingunits_cukeys_keychain_get_first_valid_unit_aux:nn
+ }
+\cs_new:Npn \__cookingunits_cukeys_prepare_parsing_keys:nn #1#2
+ {
+ \__cookingunits_cukeys_prepare_parsing_keys:n { {#1} { 1.0 } #2 }
+ }
+\cs_new:Npn \__cookingunits_cukeys_prepare_parsing_keys:n #1
+ {
+ \__cookingunits_cukeys_parse_keys:n {#1}
+ \bool_lazy_or:nnF
+ { \int_compare_p:nNn \l__cookingunits_nr_of_units_int = 0 }
+ { \__cookingunits_if_state_equal_p:n { error } }
{
- \__cookingunits_cukeys_create_key_prop:n {#1}
- \clist_set_from_seq:NN \l__cookingunits_tmpa_clist \l__cookingunits_tmpa_seq
- \__cookingunits_cukeys_define_keys:V \l__cookingunits_tmpa_clist
+ \prop_gclear:N \g__cookingunits_master_changer_prop
+ \__cookingunits_cukeys_prepare_lists:N \l__cookingunits_original_unit_tl
+ \__cookingunits_new_cukeys_create_keys:V \l__cookingunits_original_unit_tl
}
}
-\cs_generate_variant:Nn \__cookingunits_cukeys_parse_and_create_keys:nn { Vn }
-\cs_new:Npn \__cookingunits_cukeys_parse_input:nn #1#2
+\cs_generate_variant:Nn \__cookingunits_cukeys_prepare_parsing_keys:nn { nV }
+\cs_new:Npn \__cookingunits_cukeys_parse_keys:n #1
+ {
+ \int_zero:N \l__cookingunits_nr_of_units_int
+ \__cookingunits_cukeys_parse_keys_aux:nn #1
+ \q_recursion_tail \q_recursion_tail \q_recursion_stop
+ }
+\cs_new:Npn \__cookingunits_cukeys_parse_keys_aux:nn #1#2
{
\quark_if_recursion_tail_stop:n {#1}
\quark_if_recursion_tail_stop_do:nn {#2}
- { \msg_error:nn { cooking-units } { missing-argument } }
- \__cookingunits_error_if_unit_not_defined:nF {#1}
{
- \seq_if_in:NnF \l__cookingunits_tmpa_seq {#1}
- { \seq_put_right:Nn \l__cookingunits_tmpa_seq {#1} }
- \prop_put:Nnx \l__cookingunits_tmpa_prop {#1} { \fp_eval:n { (#2) * \l__cookingunits_tmpa_fp } }
+ \msg_error:nn { cooking-units } { missing-argument }
+ \__cookingunits_set_state_to:n { error }
+ }
+ \__cookingunits_error_if_unit_not_defined:nNT {#1} \l__cookingunits_option_unit_tl
+ { \__cookingunits_set_state_to:n { error } }
+ \tl_set:Nn \l__cookingunits_tmpb_tl {#2}
+ \tl_if_in:NVT \l__cookingunits_tmpb_tl \g__cookingunits_input_str_hash_one_tl
+ {
+ \bool_if:NTF \l__cookingunits_single_key_bool
+ { \tl_replace_all:NVn \l__cookingunits_tmpb_tl \g__cookingunits_input_str_hash_one_tl { \l__cookingunits_tmpa_fp } }
+ {
+ \msg_error:nnx { cooking-units } { formula-in-non-singlekeys } \l__cookingunits_tmpb_tl
+ \__cookingunits_set_state_to:n { error }
+ }
}
- \__cookingunits_cukeys_parse_input:nn
+ \__cookingunits_if_state_equal:nF { error }
+ {
+ \int_incr:N \l__cookingunits_nr_of_units_int
+ \bool_if:NF \l__cookingunits_single_key_bool
+ { \__cookingunits_tl_eval:Nn \l__cookingunits_tmpb_tl { (\l__cookingunits_tmpb_tl) * (\l__cookingunits_new_key_base_tl) } }
+ \seq_if_in:NVF \l__cookingunits_tmpa_seq \l__cookingunits_option_unit_tl
+ { \seq_put_right:NV \l__cookingunits_tmpa_seq \l__cookingunits_option_unit_tl }
+ \prop_put:NnV \l__cookingunits_tmpa_prop {#1} \l__cookingunits_tmpb_tl
+ }
+ \__cookingunits_cukeys_parse_keys_aux:nn
}
-
-\cs_new:Npn \__cookingunits_cukeys_create_key_prop:n #1
+\cs_new:Npn \__cookingunits_cukeys_prepare_lists:N #1
{
- \prop_set_eq:cN { l__cookingunits_cukeys_ #1 _prop } \l__cookingunits_tmpa_prop
- \prop_put:cnV { l__cookingunits_cukeys_ #1 _prop } { Liste } \l__cookingunits_tmpa_seq
- \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ \prop_clear_new:c { l__cookingunits_new_cukeys_ #1 _prop }
+ \prop_set_eq:cN { l__cookingunits_new_cukeys_ #1 _prop } \l__cookingunits_tmpa_prop
+ \prop_put:cnV { l__cookingunits_new_cukeys_ #1 _prop } { Liste } \l__cookingunits_tmpa_seq
+ \prop_put:cnV { l__cookingunits_new_cukeys_ #1 _prop } { single } \l__cookingunits_single_key_bool
+ \tl_set:cn { l__cookingunits_unit_change_ #1 _tl } { 1 }
+ \tl_set_eq:cN { l__cookingunits_base_key_unit_ #1 _tl } #1
+ \bool_if:NF \l__cookingunits_single_key_bool
{
- \tl_set_eq:cN { l__cookingunits_base_key_unit_ ##1 _tl } \l__cookingunits_original_unit_tl
- \tl_set:cn { l__cookingunits_unit_change_ ##1 _tl } { 1.0 }
+ \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ {
+ \tl_set_eq:cN { l__cookingunits_base_key_unit_ ##1 _tl } #1
+ \tl_set:cn { l__cookingunits_unit_change_ ##1 _tl } { 1 }
+ }
}
}
-\cs_new:Npn \__cookingunits_cukeys_define_keys:n #1
+\cs_new:Npn \__cookingunits_new_cukeys_create_keys:n #1
{
- \seq_map_inline:Nn \l__cookingunits_tmpa_seq
- {
- \__cookingunits_cukeys_keys_define:nn {##1} {#1}
- }
+ \clist_set_from_seq:NN \l__cookingunits_tmpa_clist \l__cookingunits_tmpa_seq
+ \bool_if:NTF \l__cookingunits_single_key_bool
+ {
+ \__cookingunits_new_cukeys_define_key:nVn
+ {#1} \l__cookingunits_tmpa_clist {#1}
+ }{
+ \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ {
+ \__cookingunits_new_cukeys_define_key:nVn
+ {##1} \l__cookingunits_tmpa_clist {#1}
+ }
+ }
}
-\cs_new:Npn \__cookingunits_cukeys_keys_define:nn #1#2
+\cs_generate_variant:Nn \__cookingunits_new_cukeys_create_keys:n { V }
+\cs_new:Npn \__cookingunits_new_cukeys_define_key:nnn #1#2#3
{
- \seq_if_in:NnF \l__cookingunits_list_of_defined_keys_seq {#1}
+ \__cookingunits_if_unit_has_a_key:nF {#1}
{ \seq_put_right:Nn \l__cookingunits_list_of_defined_keys_seq {#1} }
\keys_define:nn { cooking-units }
{
#1 .choices:nn =
{#2}
- {
- \__cookingunits_cukeys_define_keys_and_single_key_aux:n {#1}
- } ,
+ { \__cookingunits_change_unit_from_to:nVn {#1} \l_keys_choice_tl {#3} } ,
#1 / unknown .code:n=
{
\seq_set_split:Nnn \l_tmpa_seq { , } {#2}
@@ -2131,289 +2814,246 @@
#1 .groups:n = { change-unit }
}
}
-\cs_generate_variant:Nn \__cookingunits_cukeys_define_keys:n { V }
-\prg_new_conditional:Npnn \__cookingunits_prop_get_master:nnN #1#2#3 { F }
+\cs_generate_variant:Nn \__cookingunits_new_cukeys_define_key:nnn { nVn }
+\cs_new:Npn \__cookingunits_change_unit_from_to:nnn #1#2#3
{
- \prop_get:NnNTF \g__cookingunits_master_changer_prop { #1 ~->~ #2 } #3
- { \prg_return_true: }
- { \prg_return_false: }
- }
-\cs_generate_variant:Nn \__cookingunits_prop_get_master:nnNF { nVc }
-\cs_new:Npn \__cookingunits_prop_gput_master:nnn #1#2#3
- {
- \prop_gput:Nnn \g__cookingunits_master_changer_prop { #1 ~->~ #2 } {#3}
- }
-\cs_generate_variant:Nn \__cookingunits_prop_gput_master:nnn { nVV, nVv }
-\cs_new:Npn \__cookingunits_cukeys_define_keys_and_single_key_aux:n #1
- {
- \__cookingunits_prop_get_master:nVcF {#1} \l_keys_choice_tl { l__cookingunits_unit_change_ #1_tl }
+ \prop_put:Nnn \l__cookingunits_change_unit_prop {#1} {#2}
+ \prop_get:NncF
+ \g__cookingunits_master_changer_prop
+ { #1 ~->~ #2 }
+ { l__cookingunits_unit_change_ #1_tl }
{
- \prop_if_exist:cTF { l__cookingunits_cukeys_ #1 _prop }
- {
- \prop_get:cVc
- { l__cookingunits_cukeys_ #1 _prop }
- \l_keys_choice_tl
- { l__cookingunits_unit_change_ #1_tl }
- \__cookingunits_prop_gput_master:nVv {#1} \l_keys_choice_tl { l__cookingunits_unit_change_ #1_tl }
- }{
- \tl_set_eq:Nc \l__cookingunits_tmpa_tl { l__cookingunits_base_key_unit_ #1 _tl }
- \prop_set_eq:Nc \l__cookingunits_tmpa_prop { l__cookingunits_cukeys_ \l__cookingunits_tmpa_tl _prop }
- \__cookingunits_tl_eval:Nn \l__cookingunits_tmpb_tl
- {
- (\exp_args:NNV\prop_item:Nn \l__cookingunits_tmpa_prop \l_keys_choice_tl) /
- (\prop_item:Nn \l__cookingunits_tmpa_prop {#1})
- }
- \__cookingunits_prop_gput_master:nVV {#1} \l_keys_choice_tl \l__cookingunits_tmpb_tl
- \tl_set:cV { l__cookingunits_unit_change_ #1 _tl } \l__cookingunits_tmpb_tl
- }
+ \__cookingunits_cukeys_calculate_change_value:nnn {#1} {#2} {#3}
+ \prop_gput:Nnv \g__cookingunits_master_changer_prop
+ { #1 ~->~ #2 }
+ { l__cookingunits_unit_change_ #1 _tl }
}
- \prop_put:NnV \l__cookingunits_change_unit_prop {#1} \l_keys_choice_tl
}
-\cs_new:Npn \__cookingunits_cukeys_parse_and_create_single_key:nn #1#2
+\cs_generate_variant:Nn \__cookingunits_change_unit_from_to:nnn { nVn }
+\cs_new:Npn \__cookingunits_cukeys_calculate_change_value:nnn #1 #2 #3
{
- \tl_set_rescan:Nnn \l__cookingunits_tmpa_tl
- {
- \char_set_catcode_letter:N \# %
- \char_set_catcode_ignore:N\ %
- } { {#1} { 1.0 } #2 }
- \__cookingunits_cusinglekeys_parse_input:V \l__cookingunits_tmpa_tl
- \bool_if:NF \l__cookingunits_unit_error_bool
+ \str_if_eq:nnTF {#1} {#3}
{
- \__cookingunits_cusinglekeys_create_key_prop:n {#1}
- \clist_set_from_seq:NN \l__cookingunits_tmpa_clist \l__cookingunits_tmpa_seq
- \__cookingunits_cukeys_define_singlekey:nV {#1} \l__cookingunits_tmpa_clist
+ \prop_get:cnc { l__cookingunits_new_cukeys_ #1 _prop } {#2} { l__cookingunits_unit_change_ #1 _tl }
+ }{
+ \prop_set_eq:Nc \l__cookingunits_tmpa_prop { l__cookingunits_new_cukeys_ #3 _prop }
+ \__cookingunits_tl_eval:cn { l__cookingunits_unit_change_ #1 _tl }
+ {
+ ( \prop_item:Nn \l__cookingunits_tmpa_prop {#2} ) /
+ ( \prop_item:Nn \l__cookingunits_tmpa_prop {#1} )
+ }
}
}
-\cs_new:Npn \__cookingunits_cusinglekeys_parse_input:n #1
+\cs_generate_variant:Nn \__cookingunits_cukeys_calculate_change_value:nnn { VVV }
+\NewDocumentCommand \declarecookingunit { o m }
{
- \__cookingunits_cusinglekeys_parse_input_aux:nn #1
- \q_recursion_tail \q_recursion_tail \q_recursion_stop
+ \__cookingunits_if_unit_defined:nNTF {#2} \l__cookingunits_original_unit_tl
+ { \msg_info:nnx { cooking-units } { redefine-unit } { \l__cookingunits_original_unit_tl } }
+ { \__cookingunits_new_cooking_unit:V \l__cookingunits_original_unit_tl }
+ \__cookingunits_set_cooking_unit:nnV {#1} {#2} \l__cookingunits_original_unit_tl
}
-\cs_generate_variant:Nn \__cookingunits_cusinglekeys_parse_input:n { V }
-\cs_new:Npn \__cookingunits_cusinglekeys_parse_input_aux:nn #1#2
+\NewDocumentCommand \newcookingunit { o m }
{
- \quark_if_recursion_tail_stop:n {#1}
- \quark_if_recursion_tail_stop_do:nn {#2}
- { \msg_error:nn { cooking-units } { missing-argument } }
- \__cookingunits_error_if_unit_not_defined:nF {#1}
+ \__cookingunits_if_unit_defined:nNTF {#2} \l__cookingunits_original_unit_tl
+ { \msg_error:nnV { cooking-units } { unit-already-defined } \l__cookingunits_original_unit_tl }
{
- \seq_if_in:NnF \l__cookingunits_tmpa_seq {#1}
- { \seq_put_right:Nn \l__cookingunits_tmpa_seq {#1} }
- \tl_set:Nn \l__cookingunits_tmpa_tl {#2}
- \tl_replace_all:NVn \l__cookingunits_tmpa_tl \g__cookingunits_input_str_hash_one_tl { \l__cookingunits_tmpa_fp }
- \prop_put:NnV \l__cookingunits_tmpa_prop {#1} \l__cookingunits_tmpa_tl
+ \__cookingunits_new_cooking_unit:V \l__cookingunits_original_unit_tl
+ \__cookingunits_set_cooking_unit:nnV {#1} {#2} \l__cookingunits_original_unit_tl
}
- \__cookingunits_cusinglekeys_parse_input_aux:nn
- }
-\cs_new:Npn \__cookingunits_cusinglekeys_create_key_prop:n #1
- {
- \tl_set:cn { l__cookingunits_unit_change_ #1 _tl } { 1.0 }
- \tl_set:cn { l__cookingunits_base_key_unit_ #1 _tl } {#1}
- \prop_set_eq:cN { l__cookingunits_cukeys_ #1 _prop } \l__cookingunits_tmpa_prop
- \prop_put:cnV { l__cookingunits_cukeys_ #1 _prop } { Liste } \l__cookingunits_tmpa_seq
- }
-\cs_new:Npn \__cookingunits_cukeys_define_singlekey:nn #1#2
- {
- \__cookingunits_cukeys_keys_define:nn {#1} {#2}
}
-\cs_generate_variant:Nn \__cookingunits_cukeys_define_singlekey:nn { nV }
-\NewDocumentCommand \cuaddkeys { m m }
- {
- \bool_set_false:N \l__cookingunits_single_key_bool
- \__cookingunits_cukeys_add_keys_or_single_keys:nn {#1} {#2}
- }
-\NewDocumentCommand \cuaddsinglekeys { m m }
+\NewDocumentCommand \providecookingunit { o m }
{
- \bool_set_true:N \l__cookingunits_single_key_bool
- \__cookingunits_cukeys_add_keys_or_single_keys:nn {#1} {#2}
+ \__cookingunits_if_unit_defined:nNT {#2} \l__cookingunits_original_unit_tl
+ {
+ \__cookingunits_new_cooking_unit:V \l__cookingunits_original_unit_tl
+ \__cookingunits_set_cooking_unit:nnV {#1} {#2} \l__cookingunits_original_unit_tl
+ }
}
-\NewDocumentCommand \cuaddtokeys { m m m }
+\cs_new:Npn \__cookingunits_new_cooking_unit:n #1
{
- \bool_set_false:N \l__cookingunits_single_key_bool
- \tl_set:Nn \l__cookingunits_tmpb_tl { {#2} { \fp_eval:n { 1.0 / (#3) } } }
- \__cookingunits_cukeys_add_keys_or_single_keys:nV {#1} \l__cookingunits_tmpb_tl
+ \tl_map_inline:nn {#1}
+ {
+ \tl_if_in:NnT \l__cookingunits_unit_letter_not_allowed_tl {##1}
+ { \msg_error:nnn { cooking-units } { character-not-allowed } {#1} }
+ }
+ \seq_gput_right:Nn \g__cookingunits_list_of_defined_units_seq {#1}
+ \tl_new:c { l__cookingunits_unit_change_ #1 _tl }
+ \tl_new:c { l__cookingunits_base_key_unit_ #1 _tl }
+ \tl_new:c { l__cookingunits_default_unit_ #1 _tl }
+ \clist_new:c { l__cookingunits_unit_option_ #1 _clist }
+ \tl_set:cn { l__cookingunits_unit_change_ #1 _tl } { 1 }
+ \keys_define:nn { cooking-units }
+ {
+ set-unit-hook-#1 .code:n = { \__cookingunits_set_options_for:nn {#1} {##1} } ,
+ add-unit-hook-#1 .code:n = { \__cookingunits_add_options_for:nn {#1} {##1} },
+ set-option-for-#1 .meta:n = { set-unit-hook-#1 = {##1} } ,
+ add-option-for-#1 .meta:n = { add-unit-hook-#1 = {##1} } ,
+ }
}
-\cs_new:Npn \__cookingunits_cukeys_add_keys_or_single_keys:nn #1#2
+\cs_generate_variant:Nn \__cookingunits_new_cooking_unit:n { V }
+\cs_new:Npn \__cookingunits_set_cooking_unit:nnn #1#2#3
{
- \__cookingunits_error_if_unit_not_defined:nF {#1}
+ \__cookingunits_set_cooking_unit_base_translation:n {#3}
+ \bool_set_false:N \l__cookingunits_symbol_was_set_by_key_bool
+ \bool_set_false:N \l__cookingunits_contains_valid_key_bool
+ \IfNoValueF {#1}
{
- \seq_if_in:NnF \l__cookingunits_list_of_defined_keys_seq {#1}
- { \msg_error:nnn { cooking-units } { Key-not-defined } {#1} }
- \tl_if_blank:nF {#2}
+ \tl_if_head_is_group:nF {#1}
+ { \keys_set:nn { cooking-units / definition } {#1} }
+ }
+ \bool_if:NF \l__cookingunits_symbol_was_set_by_key_bool
+ {
+ \IfNoValueTF {#1}
+ { \tl_set:cn { l__cookingunits_default_unit_ #3 _tl } {#2} }
{
- \prop_gclear:N \g__cookingunits_master_changer_prop
- \__cookingunits_cukeys_add_keys_and_single_key_aux:n {#1}
- \bool_if:NTF \l__cookingunits_single_key_bool
- { \__cookingunits_cukeys_parse_and_create_single_key:nn {#1} {#2} }
- { \__cookingunits_cukeys_parse_and_create_keys:Vn \l__cookingunits_original_unit_tl {#2} }
+ \bool_if:NTF \l__cookingunits_contains_valid_key_bool
+ { \tl_set:cn { l__cookingunits_default_unit_ #3 _tl } {#2} }
+ { \tl_set:cn { l__cookingunits_default_unit_ #3 _tl } {#1} }
}
}
+ \__cookingunits_culang_def_base:nnv { unit-symbol } {#3} { l__cookingunits_default_unit_ #3 _tl }
}
-\cs_generate_variant:Nn \__cookingunits_cukeys_add_keys_or_single_keys:nn { nV }
-\cs_new:Npn \__cookingunits_cukeys_add_keys_and_single_key_aux:n #1
- {
- \tl_set_eq:Nc \l__cookingunits_original_unit_tl { l__cookingunits_base_key_unit_ #1 _tl }
- \prop_set_eq:Nc \l__cookingunits_tmpa_prop { l__cookingunits_cukeys_ \l__cookingunits_original_unit_tl _prop }
- \prop_get:NnN\l__cookingunits_tmpa_prop { Liste } \l__cookingunits_tmpa_seq
- \prop_get:NnN \l__cookingunits_tmpa_prop {#1} \l__cookingunits_tmpa_fp
- }
-\NewDocumentCommand \declarecookingunit { o m }
+\cs_generate_variant:Nn \__cookingunits_set_cooking_unit:nnn { nnV }
+\cs_new:Npn \__cookingunits_set_cooking_unit_base_translation:n #1
{
- \seq_if_in:NnTF \g__cookingunits_list_of_defined_units_seq {#2}
- { \msg_info:nnn { cooking-units } { redefine-unit } {#2} }
- { \__cookingunits_new_cooking_unit:nn {#1} {#2} }
- \__cookingunits_set_cooking_unit:nn {#1} {#2}
+ \__cookingunits_culang_def_base:nnn { name } {#1} \q__cookingunits_no_translation
+ \__cookingunits_culang_def_base:nnn { name-pl } {#1} \q__cookingunits_no_translation
+ \__cookingunits_culang_def_base:nnn { gender } {#1} { m }
}
-\NewDocumentCommand \newcookingunit { o m }
- {
- \__cookingunits_new_cooking_unit:nn {#1} {#2}
- \__cookingunits_set_cooking_unit:nn {#1} {#2}
- }
-\NewDocumentCommand \providecookingunit { o m }
+\NewDocumentCommand \declarecookingderivatives { m m m m }
{
- \seq_if_in:NnF \g__cookingunits_list_of_defined_units_seq {#2}
- {
- \__cookingunits_new_cooking_unit:nn {#1} {#2}
- \__cookingunits_set_cooking_unit:nn {#1} {#2}
- }
+ \__cookingunits_declare_cooking_derivative:nnnn {#1} {#2} {#3} {#4}
}
-\cs_new:Npn \__cookingunits_new_cooking_unit:nn #1#2
+\cs_new:Npn \__cookingunits_declare_cooking_derivative:nnnn #1#2#3#4
{
- \seq_if_in:NnTF \g__cookingunits_list_of_defined_units_seq {#2}
- { \msg_error:nnn { cooking-units } { unit-already-defined } {#2} }
+ \seq_clear:N \l__cookingunits_list_of_units_seq
+ \__cookingunits_set_state_to:n { normal }
+ \clist_map_inline:nn {#1}
{
- \tl_map_inline:nn {#2}
- {
- \tl_if_in:NnT \l__cookingunits_unit_letter_not_allowed_tl {##1}
- { \msg_error:nnn { cooking-units } { character-not-allowed } {#2} }
- }
- \seq_gput_right:Nn \g__cookingunits_list_of_defined_units_seq {#2}
- \tl_new:c { l__cookingunits_unit_change_ #2 _tl }
- \tl_set:cn { l__cookingunits_unit_change_ #2 _tl } { 1.0 }
- \clist_new:c { l__cookingunits_unit_option_ #2 _clist }
- \keys_define:nn { cooking-units }
+ \__cookingunits_if_unit_defined:nNTF {##1} \l__cookingunits_tmpa_tl
{
- set-option-for-#2 .code:n = { \cusetoptionfor {#2} {##1} } ,
- add-option-for-#2 .code:n = { \cuaddoptionfor {#2} {##1} },
- }
- \tl_new:c { l__cookingunits_base_key_unit_ #2 _tl }
- \tl_new:c { l__cookingunits_default_unit_ #2 _tl }
+ \__cookingunits_if_unit_has_a_key:VTF \l__cookingunits_tmpa_tl
+ { \seq_put_right:NV \l__cookingunits_list_of_units_seq \l__cookingunits_tmpa_tl }
+ {
+ \tl_show:n { Error-no-key-defined } {##1}
+ \__cookingunits_set_state_to:n { error }
+ }
+ } { \__cookingunits_set_state_to:n { error } }
}
+ \__cookingunits_if_state_equal:nT { error }
+ { \use_none_delimit_by_q_recursion_stop:w }
+ \int_set:Nn \l__cookingunits_nr_of_units_int { \seq_count:N \l__cookingunits_list_of_units_seq }
+ \cs_generate_from_arg_count:NNnn \__cookingunits_create_unit:w \cs_set:Npn
+ { \l__cookingunits_nr_of_units_int }
+ {
+ \seq_gpush:Nn \g__cookingunits_stored_derived_unit_symbol_seq {#2}
+ \seq_gpush:Nn \g__cookingunits_stored_derived_unit_print_seq {#4}
+ }
+ \cs_generate_from_arg_count:NNnn \__cookingunits_create_formula:w \cs_set:Npn
+ { \l__cookingunits_nr_of_units_int }
+ {
+ \seq_gpush:Nn \g__cookingunits_stored_derived_formula_seq {#3}
+ }
+ \__cookingunits_prepare_sequence_loop:
+ \__cookingunits_step_loop_start:n { }
+ \seq_get_right:NN \g__cookingunits_stored_derived_unit_symbol_seq \l__cookingunits_curr_unit_tl
+ \seq_map_inline:Nn \g__cookingunits_stored_derived_unit_symbol_seq
+ {
+ \seq_pop:NN \g__cookingunits_stored_derived_formula_seq \l__cookingunits_tmpb_tl
+ \prop_put:NnV \l__cookingunits_derived_units_prop {##1} \l__cookingunits_tmpb_tl
+ \seq_pop:NN \g__cookingunits_stored_derived_unit_print_seq \l__cookingunits_tmpa_tl
+ \exp_args:NNx \declarecookingunit [ {symbol={\l__cookingunits_tmpa_tl}} ] {##1}
+ \tl_set_eq:cN { l__cookingunits_base_key_unit_ ##1 _tl } \l__cookingunits_curr_unit_tl
+ }
+ \seq_gclear:N \g__cookingunits_stored_derived_unit_symbol_seq
+ \seq_gclear:N \g__cookingunits_stored_derived_unit_print_seq
+ \seq_gclear:N \g__cookingunits_stored_derived_formula_seq
+ \cs_undefine:N \__cookingunits_create_unit:w
+ \cs_undefine:N \__cookingunits_create_formula:w
+ \use_none_delimit_by_q_recursion_stop:w
+ \q_recursion_stop
}
-\cs_new:Npn \__cookingunits_set_cooking_unit:nn #1#2
+\cs_new:Npn \__cookingunits_prepare_sequence_loop:
{
- \IfNoValueTF {#1}
+ \seq_map_indexed_inline:Nn \l__cookingunits_list_of_units_seq
{
- \tl_set:cn { l__cookingunits_default_unit_ #2 _tl } {#2}
- \__cookingunits_deftranslation_base:xVn {#2} \c__cookingunits_postfix_unit_tl {#2}
- }{
- \tl_set:cn { l__cookingunits_default_unit_ #2 _tl } {#1}
- \__cookingunits_deftranslation_base:xVn {#2} \c__cookingunits_postfix_unit_tl {#1}
+ \prop_clear_new:c { l__cookingunits_keys_ ##1 _prop }
+ \seq_clear_new:c { l__cookingunits_list_ ##1 _seq }
+ \tl_set_eq:Nc \l__cookingunits_curr_unit_tl { l__cookingunits_base_key_unit_ ##2 _tl }
+ \prop_set_eq:cc { l__cookingunits_keys_ ##1 _prop }
+ { l__cookingunits_new_cukeys_ \l__cookingunits_curr_unit_tl _prop }
+ \prop_get:cnc { l__cookingunits_keys_ ##1 _prop } { Liste } { l__cookingunits_list_ ##1 _seq }
}
- \__cookingunits_deftranslation_base:xVn {#2} \c__cookingunits_postfix_unitname_tl { \q__cookingunits_no_translation }
- \__cookingunits_deftranslation_base:xVn {#2} \c__cookingunits_postfix_unitname_pl_tl { \q__cookingunits_no_translation }
- \__cookingunits_deftranslation_base:xVn {#2} \c__cookingunits_postfix_gender_tl { m }
}
-\NewDocumentCommand \declarecookingderivatives { m m m m }
+\cs_new:Npn \__cookingunits_step_loop_start:n #1
{
- \__cookingunits_declare_cooking_derivative:nnnn {#1} {#2} {#3} {#4}
+ \tl_clear:N \l__cookingunits_stored_units_tl
+ \tl_clear:N \l__cookingunits_stored_formula_tl
+ \int_set:Nn \l__cookingunits_depth_int { 1 }
+ \seq_map_function:cN
+ { l__cookingunits_list_ \int_use:N \l__cookingunits_depth_int _seq } \__cookingunits_seq_recursive_loop_function:n
}
-\cs_new:Npn \__cookingunits_tl_set_list:Nnn #1#2#3
+\cs_new:Npn \__cookingunits_seq_recursive_loop_function:n #1
{
- \__cookingunits_tl_set_list_aux:Nnnnnnnnn #1 {#2} #3
- \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil
- \q_recursion_stop
+ \group_begin:
+ \tl_put_right:Nn \l__cookingunits_stored_units_tl { {#1} }
+ \tl_set_eq:Nc \l__cookingunits_original_unit_tl { l__cookingunits_base_key_unit_ #1 _tl }
+ \tl_put_right:Nx \l__cookingunits_stored_formula_tl
+ { { (
+ \exp_not:N \prop_item:Nn
+ \exp_not:c { l__cookingunits_new_cukeys_ \l__cookingunits_original_unit_tl _prop } {#1}
+ ) } }
+ \int_compare:nNnTF { \l__cookingunits_depth_int } = { \l__cookingunits_nr_of_units_int }
+ {
+ \exp_after:wN \__cookingunits_create_unit:w \l__cookingunits_stored_units_tl
+ \exp_after:wN \__cookingunits_create_formula:w \l__cookingunits_stored_formula_tl
+ }{
+ \int_incr:N \l__cookingunits_depth_int
+ \seq_map_function:cN
+ { l__cookingunits_list_ \int_use:N \l__cookingunits_depth_int _seq } \__cookingunits_seq_recursive_loop_function:n
+ }
+ \group_end:
}
-\cs_generate_variant:Nn \__cookingunits_tl_set_list:Nnn { NnV, NVV }
-\cs_new:Npn \__cookingunits_tl_set_list_aux:Nnnnnnnnn #1#2#3#4#5#6#7#8#9
+\keys_define:nn { cooking-units }
{
- \tl_set:Nf #1
+ unknown .code:n =
{
- \int_case:nn { \l__cookingunits_curr_depth_int }
+ \__cookingunits_if_key_ais_derived_unit:VTF \l_keys_key_str
+ { \__cookingunits_convert_derived_unit:Vn \l_keys_key_str {#1} }
{
- { 1 } { }
- { 2 } { {#3} }
- { 3 } { {#3}{#4} }
- { 4 } { {#3}{#4}{#5} }
- { 5 } { {#3}{#4}{#5}{#6} }
- { 6 } { {#3}{#4}{#5}{#6}{#7} }
- { 7 } { {#3}{#4}{#5}{#6}{#7}{#8} }
- { 8 } { {#3}{#4}{#5}{#6}{#7}{#8}{#9} }
+ \msg_error:nnxx { cooking-units } { key-unknown }
+ { \l_keys_path_str } { cooking-units }
}
- {#2}
}
- \use_none_delimit_by_q_recursion_stop:w
}
-\cs_new:Npn \__cookingunits_declare_cooking_derivative:nnnn #1#2#3#4
+\prg_new_conditional:Npnn \__cookingunits_if_key_ais_derived_unit:n #1 { TF }
{
- \prop_gclear:N \g__cookingunits_master_changer_prop
- \seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
- \seq_clear:N \l__cookingunits_number_of_iterations_seq
- \seq_clear:N \l__cookingunits_derivative_unit_list_seq
- \seq_clear:N \l__cookingunits_derivative_symbol_list_seq
- \seq_clear:N \l__cookingunits_derivative_value_list_seq
- \int_set:Nn \l__cookingunits_max_depth_int { \seq_count:N \l__cookingunits_tmpa_seq }
- \int_set:Nn \l__cookingunits_curr_depth_int { 1 }
- \cs_generate_from_arg_count:NNnn \__cookingunits_tmp_unit_and_symbol_list:w \cs_set:Npn
- { \l__cookingunits_max_depth_int }
- {
- \seq_put_right:Nn \l__cookingunits_derivative_unit_list_seq {#2}
- \seq_put_right:Nn \l__cookingunits_derivative_symbol_list_seq {#4}
- }
- \cs_generate_from_arg_count:NNnn \__cookingunits_tmp_value_list:w \cs_set:Npn
- { \l__cookingunits_max_depth_int }
- { \seq_put_right:Nx \l__cookingunits_derivative_value_list_seq { \fp_eval:n {#3} } }
- \int_step_inline:nn { \l__cookingunits_max_depth_int }
- {
- \tl_set_eq:Nc \l__cookingunits_original_unit_tl
- { l__cookingunits_base_key_unit_ \seq_item:Nn \l__cookingunits_tmpa_seq {##1} _tl }
- \prop_set_eq:Nc \l__cookingunits_tmpa_prop { l__cookingunits_cukeys_ \l__cookingunits_original_unit_tl _prop }
- \prop_get:NnN \l__cookingunits_tmpa_prop { Liste } \l__cookingunits_tmpb_seq
- \int_set:Nn \l__cookingunits_tmpa_int { \seq_count:N \l__cookingunits_tmpb_seq }
- \seq_put_right:NV \l__cookingunits_number_of_iterations_seq \l__cookingunits_tmpa_int
- \seq_clear_new:c { l__cookingunits_tmp_ ##1 _seq }
- \prop_clear_new:c { l__cookingunits_tmp_ ##1 _prop }
- \seq_set_eq:cN { l__cookingunits_tmp_ ##1 _seq } \l__cookingunits_tmpb_seq
- \prop_set_eq:cN { l__cookingunits_tmp_ ##1 _prop } \l__cookingunits_tmpa_prop
- }
- \seq_map_function:cN
- { l__cookingunits_tmp_ \int_use:N \l__cookingunits_curr_depth_int _seq }
- \__cookingunits_seq_step_function:n
- \seq_get_left:NN \l__cookingunits_derivative_unit_list_seq \l__cookingunits_original_unit_tl
- \prop_clear_new:c { l__cookingunits_cukeys_ \l__cookingunits_original_unit_tl _prop }
- \int_zero:N \l__cookingunits_tmpa_int
- \clist_set_from_seq:NN \l__cookingunits_tmpa_clist \l__cookingunits_derivative_unit_list_seq
- \seq_map_inline:Nn \l__cookingunits_derivative_unit_list_seq
- {
- \int_incr:N \l__cookingunits_tmpa_int
- \tl_set:Nx \l__cookingunits_tmpa_tl { \seq_item:Nn \l__cookingunits_derivative_symbol_list_seq { \l__cookingunits_tmpa_int } }
- \exp_after:wN \declarecookingunit \exp_after:wN [ \l__cookingunits_tmpa_tl ] {##1}
- \prop_put:cnx
- { l__cookingunits_cukeys_ \l__cookingunits_original_unit_tl _prop }
- {##1}
- { \seq_item:Nn \l__cookingunits_derivative_value_list_seq { \l__cookingunits_tmpa_int } }
- \tl_clear_new:c { l__cookingunits_base_key_unit_ ##1 _tl }
- \tl_set_eq:cN { l__cookingunits_base_key_unit_ ##1 _tl } \l__cookingunits_original_unit_tl
- \exp_args:NnV \__cookingunits_cukeys_keys_define:nn {##1} \l__cookingunits_tmpa_clist
- }
- }
-\cs_new:Npn \__cookingunits_seq_step_function:n #1
- {
- \__cookingunits_tl_set_list:NnV \l__cookingunits_list_of_units_tl {#1} \l__cookingunits_list_of_units_tl
- \prop_get:cnN { l__cookingunits_tmp_ \int_use:N \l__cookingunits_curr_depth_int _prop } {#1} \l__cookingunits_tmpa_tl
- \__cookingunits_tl_set_list:NVV \l__cookingunits_list_of_values_tl \l__cookingunits_tmpa_tl \l__cookingunits_list_of_values_tl
- \int_compare:nNnTF { \l__cookingunits_curr_depth_int } = { \l__cookingunits_max_depth_int }
- {
- \exp_after:wN \__cookingunits_tmp_unit_and_symbol_list:w \l__cookingunits_list_of_units_tl
- \exp_after:wN \__cookingunits_tmp_value_list:w \l__cookingunits_list_of_values_tl
+ \tl_if_exist:cTF { l__cookingunits_base_key_unit_ #1 _tl }
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+\cs_generate_variant:Nn \__cookingunits_if_key_ais_derived_unit:nTF { V }
+\cs_new:Npn \__cookingunits_convert_derived_unit:nn #1#2
+ {
+ \tl_if_eq:ccTF
+ { l__cookingunits_base_key_unit_ #1 _tl }
+ { l__cookingunits_base_key_unit_ #2 _tl }
+ {
+ \prop_get:NnN \l__cookingunits_derived_units_prop {#1} \l__cookingunits_tmpa_tl
+ \prop_get:NnN \l__cookingunits_derived_units_prop {#2} \l__cookingunits_tmpb_tl
+ \prop_put:Nnn \l__cookingunits_change_unit_prop {#1} {#2}
+ \__cookingunits_tl_eval:cn { l__cookingunits_unit_change_ #1 _tl }
+ {
+ (\l__cookingunits_tmpb_tl) / (\l__cookingunits_tmpa_tl)
+ }
+ \prop_gput:Nnv \g__cookingunits_master_changer_prop
+ { #1 ~->~ #2 }
+ { l__cookingunits_unit_change_ #1 _tl }
}{
- \int_incr:N \l__cookingunits_curr_depth_int
- \seq_map_function:cN
- { l__cookingunits_tmp_ \int_use:N \l__cookingunits_curr_depth_int _seq }
- \__cookingunits_seq_step_function:n
- \int_decr:N \l__cookingunits_curr_depth_int
+ \msg_error:nnnn { cooking-units } { key-no-knows-value } {#1} {#2}
}
}
+\cs_generate_variant:Nn \__cookingunits_convert_derived_unit:nn { V }
\tl_new:N \l__cookingunits_sanitise_tl
\cs_new_protected:Npn \__cookingunits_sanitise_aux:w #1 \q_mark
{ \tl_set:Nn \l__cookingunits_sanitise_tl {#1} }
@@ -2479,83 +3119,78 @@
{
\tl_set:Nn \l__cookingunits_language_tl {#1}
\__cookingunits_sanitize_arrows:n {#2}
- \exp_last_unbraced:NV
- \__cookingunits_cuname_parse_input:n \l__cookingunits_sanitise_tl
- \q_recursion_tail \q_recursion_tail \q_recursion_stop
+ \exp_after:wN
+ \__cookingunits_parse_definename_start_cycle: \l__cookingunits_sanitise_tl
+ \q_recursion_tail \q_recursion_tail \q_recursion_stop
}
-\cs_new:Npn \__cookingunits_cuname_parse_input:n #1
+\cs_new:Npn \__cookingunits_parse_definename_start_cycle:
{
- \peek_meaning_ignore_spaces:NTF [
- {
- \__cookingunits_cuname_parse_unit_symbol:nw {#1}
- }{
- \seq_if_in:NnTF \g__cookingunits_allowed_special_keys_seq {#1}
- { \__cookingunits_cuname_parse_input_aux:nn {#1} }
- { \__cookingunits_cuname_parse_unit_symbol:nw {#1} [ \q_no_value ] }
- }
+ \__cookingunits_set_state_to:n { normal }
+ \tl_clear:N \l__cookingunits_curr_unit_tl
+ \prop_clear:N \l__cookingunits_tmpa_prop
+ \bool_set_false:N \l__cookingunits_tmpa_bool
+ \__cookingunits_parse_definename_unit:n
}
-\cs_new:Npn \__cookingunits_cuname_parse_unit_symbol:nw #1 [#2]
+\cs_new:Npn \__cookingunits_parse_definename_unit:n #1
{
\quark_if_recursion_tail_stop:n {#1}
- \quark_if_recursion_tail_stop_do:nn {#2}
- { \msg_error:nn { cooking-units } { missing-argument } }
- \__cookingunits_error_if_unit_not_defined:nT {#1}
- { \use_none_delimit_by_q_recursion_stop:w }
- \quark_if_no_value:nTF {#2}
+ \seq_if_in:NnTF \g__cookingunits_allowed_special_keys_seq {#1}
{
- \__cookingunits_deftranslation_to:VxVv
- \l__cookingunits_language_tl {#1}
- \c__cookingunits_postfix_unit_tl
- { l__cookingunits_default_unit_ #1 _tl }
+ \__cookingunits_set_unit:Nn \l__cookingunits_curr_unit_tl {#1}
+ \bool_set_true:N \l__cookingunits_tmpa_bool
}{
- \__cookingunits_deftranslation_to:VxVn
- \l__cookingunits_language_tl {#1}
- \c__cookingunits_postfix_unit_tl {#2}
+ \__cookingunits_error_if_unit_not_defined:nNT {#1} \l__cookingunits_curr_unit_tl
+ { \__cookingunits_set_state_to:n { error } }
}
- \__cookingunits_cuname_parse_input_aux:nn {#1}
+ \peek_meaning_ignore_spaces:NTF [
+ { \__cookingunits_parse_definename_optional_unitsymbol:w }
+ { \__cookingunits_parse_definename_singular:n }
}
-\cs_new:Npn \__cookingunits_cuname_parse_input_aux:nn #1#2
+\cs_new:Npn \__cookingunits_parse_definename_optional_unitsymbol:w [#1]
{
- \quark_if_recursion_tail_stop:n {#1}
- \quark_if_recursion_tail_stop_do:nn {#2}
- { \msg_error:nn { cooking-units } { missing-argument } }
- \seq_if_in:NnF \g__cookingunits_allowed_special_keys_seq {#1}
+ \bool_if:NTF \l__cookingunits_tmpa_bool
{
- \__cookingunits_error_if_unit_not_defined:nT {#1}
- { \use_none_delimit_by_q_recursion_stop:w }
+ \__cookingunits_set_state_to:n { error }
+ \msg_error:nnxn { cooking-units } { symbol-and-special-keys-error }
+ \l__cookingunits_curr_unit_tl {#1}
}
- \__cookingunits_deftranslation_to:VxVn
- \l__cookingunits_language_tl {#1}
- \c__cookingunits_postfix_unitname_tl {#2}
+ { \prop_put:Nnn \l__cookingunits_tmpa_prop { unit-symbol } {#1} }
+ \__cookingunits_parse_definename_singular:n
+ }
+\cs_new:Npn \__cookingunits_parse_definename_singular:n #1
+ {
+ \quark_if_recursion_tail_stop_do:nn {#1}
+ { \msg_error:nn { cooking-units } { missing-argument } }
+ \prop_put:Nnn \l__cookingunits_tmpa_prop { name } {#1}
\peek_meaning_ignore_spaces:NTF [
- { \__cookingunits_cuname_parse_bracket:nw {#1} }
- { \__cookingunits_cuname_parse_bracket:nw {#1} [#2] }
+ { \__cookingunits_parse_definename_optional_plural:w }
+ { \__cookingunits_parse_definename_optional_plural:w [#1] }
}
-\cs_new:Npn \__cookingunits_cuname_parse_bracket:nw #1 [#2]
+\cs_new:Npn \__cookingunits_parse_definename_optional_plural:w [#1]
{
- \seq_if_in:NnF \g__cookingunits_allowed_special_keys_seq {#1}
- {
- \__cookingunits_deftranslation_to:VxVn \l__cookingunits_language_tl {#1}
- \c__cookingunits_postfix_unitname_pl_tl {#2}
- }
+ \prop_put:Nnn \l__cookingunits_tmpa_prop { name-pl } {#1}
\peek_meaning_ignore_spaces:NTF <
- { \__cookingunits_cuname_parse_gender:nw {#1} }
- { \__cookingunits_cuname_parse_gender:nw {#1} <m> }
+ { \__cookingunits_parse_definename_optional_gender:w }
+ { \__cookingunits_parse_definename_optional_gender:w <m> }
+ }
+\cs_new:Npn \__cookingunits_parse_definename_optional_gender:w <#1>
+ {
+ \__cookingunits_if_gender_error:nT {#1}
+ { \__cookingunits_set_state_to:n { error } }
+ \prop_put:Nnn \l__cookingunits_tmpa_prop { gender } {#1}
+ \__cookingunits_parse_name_finish_cycle_and_start_new:VV
+ \l__cookingunits_language_tl \l__cookingunits_curr_unit_tl
}
-\cs_new:Npn \__cookingunits_cuname_parse_gender:nw #1 <#2>
+\cs_new:Npn \__cookingunits_parse_name_finish_cycle_and_start_new:nn #1#2
{
- \__cookingunits_if_gender_error:nTF {#2}
+ \__cookingunits_if_state_equal:nT { normal }
{
- \__cookingunits_deftranslation_to:VxVn
- \l__cookingunits_language_tl {#1}
- \c__cookingunits_postfix_gender_tl { m }
- }{
- \__cookingunits_deftranslation_to:VxVn
- \l__cookingunits_language_tl {#1}
- \c__cookingunits_postfix_gender_tl {#2}
+ \prop_map_inline:Nn \l__cookingunits_tmpa_prop
+ { \__cookingunits_culang_def_for:nnnn {#1} {##1} {#2} {##2} }
}
- \__cookingunits_cuname_parse_input:n
+ \__cookingunits_parse_definename_start_cycle:
}
+\cs_generate_variant:Nn \__cookingunits_parse_name_finish_cycle_and_start_new:nn { VV }
\NewDocumentCommand \cudefinesymbol { m m }
{
\tl_set:Nn \l__cookingunits_language_tl {#1}
@@ -2568,130 +3203,134 @@
\quark_if_recursion_tail_stop_do:nn {#2}
{ \msg_error:nn { cooking-units } { missing-argument } }
\seq_if_in:NnTF \g__cookingunits_allowed_special_keys_seq {#1}
+ { \__cookingunits_culang_def_for:Vnnn \l__cookingunits_language_tl { name } }
{
- \__cookingunits_deftranslation_to:VxVn \l__cookingunits_language_tl {#1}
- \c__cookingunits_postfix_unitname_tl {#2}
- }{
- \__cookingunits_error_if_unit_not_defined:nF {#1}
- {
- \__cookingunits_deftranslation_to:VxVn
- \l__cookingunits_language_tl {#1}
- \c__cookingunits_postfix_unit_tl {#2}
- }
+ \__cookingunits_error_if_unit_not_defined:nTF {#1}
+ { \use_none:nn }
+ { \__cookingunits_culang_def_for:Vnnn \l__cookingunits_language_tl { unit-symbol } }
}
+ {#1} {#2}
\__cookingunits_cuprint_define_printed_unit:nn
}
-\__cookingunits_newtranslation_base:nVn { phrase-prop } \c__cookingunits_postfix_phrase_tl { \q__cookingunits_no_translation }
-\prg_new_conditional:Npnn \__cookingunits_phrase_list_get_for:NN #1#2 { TF }
+\__cookingunits_culang_def_base:nnn { phrase } { phrase-prop } { \q__cookingunits_no_translation }
+\NewDocumentCommand \cudefinephrase { m m }
{
- \__cookingunits_translate_let:VNnV #2 #1 { phrase-prop } \c__cookingunits_postfix_phrase_tl
- \tl_if_eq:NNTF #1 \q__cookingunits_no_translation
- { \prg_return_false: }
- { \prg_return_true: }
+ \__cookingunits_new_cuphrase_add:nn {#1} {#2}
}
-\prg_new_conditional:Npnn \__cookingunits_get_phrase_for_current_langauge:NN #1#2 { T }
+\cs_new:Npn \__cookingunits_new_cuphrase_add:nn #1#2
{
- \__cookingunits_translate_let:NnV #1 { phrase-prop } \c__cookingunits_postfix_phrase_tl
- \tl_if_eq:NNTF #1 \q__cookingunits_no_translation
- { \prg_return_false: }
+ \tl_set:Nn \l__cookingunits_language_tl {#1}
+ \__cookingunits_culang_if_translation_exists_for:VnnTF \l__cookingunits_language_tl
+ { phrase } { phrase-prop }
{
- \__cookingunits_translate_let:NnV #2 { phrase-clist } \c__cookingunits_postfix_phrase_tl
- \prg_return_true:
+ \__cookingunits_culang_let_for:VnnN \l__cookingunits_language_tl { phrase } { phrase-prop }
+ \l__cookingunits_phrase_prop
+ \prop_get:NnN \l__cookingunits_phrase_prop { seq } \l__cookingunits_phrase_numbers_seq
+ }{
+ \prop_clear:N \l__cookingunits_phrase_prop
+ \seq_clear:N \l__cookingunits_phrase_numbers_seq
}
+ \__cookingunits_sanitize_arrows:n {#2}
+ \__cookingunits_parse_phrase:V \l__cookingunits_sanitise_tl
+ \__cookingunits_new_cuphrase_sort_sequence:N \l__cookingunits_phrase_numbers_seq
+ \prop_put:NnV \l__cookingunits_phrase_prop { seq } \l__cookingunits_phrase_numbers_seq
+ \__cookingunits_culang_def_for:VnnV
+ \l__cookingunits_language_tl { phrase } { phrase-prop } \l__cookingunits_phrase_prop
}
-\NewDocumentCommand \cudefinephrase { m m }
+\cs_new:Npn \__cookingunits_parse_phrase:n #1
{
- \__cookingunits_cuphrase:nn {#1} {#2}
+ \__cookingunits_parse_phrase_start_cycle: #1
+ \q_recursion_tail \q_recursion_tail \q_recursion_stop
}
-\cs_new:Npn \__cookingunits_cuphrase:nn #1#2
+\cs_generate_variant:Nn \__cookingunits_parse_phrase:n { V }
+\cs_new:Npn \__cookingunits_parse_phrase_start_cycle:
{
- \tl_set:Nn \l__cookingunits_language_tl {#1}
- \__cookingunits_phrase_list_get_for:NNTF \l__cookingunits_phrase_prop \l__cookingunits_language_tl
- {
- \__cookingunits_translate_let:VNnV \l__cookingunits_language_tl \l__cookingunits_phrase_numbers_seq
- { phrase-clist } \c__cookingunits_postfix_phrase_tl
- }{
- \prop_clear:N \l__cookingunits_phrase_prop
- \seq_clear:N \l__cookingunits_phrase_numbers_seq
- }
- \__cookingunits_sanitize_arrows:n {#2}
- \exp_last_unbraced:NV
- \__cookingunits_cuphrase_parse:n \l__cookingunits_sanitise_tl
- \q_recursion_tail \q_recursion_tail \q_recursion_stop
- \seq_sort:Nn \l__cookingunits_phrase_numbers_seq
- {
- \int_compare:nNnTF { \int_abs:n {##1} } < { \int_abs:n {##2} }
- { \sort_return_swapped: }
- {
- \int_compare:nNnTF { \int_abs:n {##1} } = { \int_abs:n {##2} }
- {
- \int_compare:nNnTF {##1} < {##2}
- { \sort_return_same: }
- { \sort_return_swapped: }
- }{ \sort_return_same: }
- }
- }
- \__cookingunits_deftranslation_to:VxVV
- \l__cookingunits_language_tl { phrase-prop }
- \c__cookingunits_postfix_phrase_tl
- \l__cookingunits_phrase_prop
- \__cookingunits_deftranslation_to:VxVV
- \l__cookingunits_language_tl { phrase-clist }
- \c__cookingunits_postfix_phrase_tl \l__cookingunits_phrase_numbers_seq
+ \__cookingunits_set_state_to:n { normal }
+ \bool_set_false:N \l__cookingunits_tmpa_bool
+ \tl_clear:N \l__cookingunits_curr_unit_tl
+ \prop_clear:N \l__cookingunits_tmpa_prop
+ \__cookingunits_parse_stuff_mandatories_plus_star:nn
}
-\cs_new:Npn \__cookingunits_cuphrase_parse:n #1
+\cs_new:Npn \__cookingunits_parse_stuff_mandatories_plus_star:nn #1#2
{
\quark_if_recursion_tail_stop:n {#1}
- \__cookingunits_if_integer:nF {#1}
- { \msg_error:nnn { cooking-units} { phrase-unit-not-an-integer } {#1} }
- \peek_meaning_remove_ignore_spaces:NTF *
+ \quark_if_recursion_tail_stop_do:nn {#2}
+ { \msg_error:nn { cooking-units } { missing-argument } }
+ \str_if_eq:nnTF {#2} { * }
{
- \int_set:Nn \l__cookingunits_tmpa_int {-#1}
- \__cookingunits_cuphrase_parse_normal:Vn \l__cookingunits_tmpa_int
+ \bool_set_true:N \l__cookingunits_tmpa_bool
+ \__cookingunits_parse_stuff_mandatories_plus_star:nn {#1}
}{
- \int_set:Nn \l__cookingunits_tmpa_int {#1}
- \__cookingunits_cuphrase_parse_normal:Vn \l__cookingunits_tmpa_int
+ \__cookingunits_if_evaluation_is_integer:nTF {#1}
+ {
+ \int_set:Nn \l__cookingunits_tmpa_int {#1}
+ \tl_set:NV \l__cookingunits_curr_unit_tl \l__cookingunits_tmpa_int
+ \bool_if:NT \l__cookingunits_tmpa_bool
+ { \tl_put_left:Nn \l__cookingunits_curr_unit_tl { - } }
+ }{
+ \__cookingunits_set_state_to:n { error }
+ \msg_error:nnn { cooking-units} { phrase-unit-not-an-integer } {#1}
+ }
+ \prop_put:Nnn \l__cookingunits_tmpa_prop { } {#2}
+ \prop_put:NnV \l__cookingunits_tmpa_prop { - singlebool } \l__cookingunits_tmpa_bool
+ \__cookingunits_parse_phrase_optionals:n {#2}
}
}
-\cs_new:Npn \__cookingunits_cuphrase_parse_normal:nn #1#2
+\cs_new:Npn \__cookingunits_parse_phrase_optionals:n #1
{
- \quark_if_recursion_tail_stop_do:nn {#2}
- { \msg_error:nn { cooking-units } { missing-argument } }
- \prop_put:Nnn \l__cookingunits_phrase_prop {#1} {#2}
- \seq_if_in:NnF \l__cookingunits_phrase_numbers_seq {#1}
- { \seq_push:Nn \l__cookingunits_phrase_numbers_seq {#1} }
\peek_meaning_ignore_spaces:NTF [
- {
- \__cookingunits_chuphrase_parse_plural:nw {#1}
- }{
- \__cookingunits_chuphrase_parse_plural:nw {#1} [#2]
- }
+ { \__cookingunits_parse_stuff_plural:w }
+ { \__cookingunits_parse_stuff_plural:w [#1] }
}
-\cs_generate_variant:Nn \__cookingunits_cuphrase_parse_normal:nn { V }
-\cs_new:Npn \__cookingunits_chuphrase_parse_plural:nw #1 [#2]
+\cs_new:Npn \__cookingunits_parse_stuff_plural:w [#1]
{
- \prop_put:Nnn \l__cookingunits_phrase_prop { #1-pl } {#2}
+ \prop_put:Nnn \l__cookingunits_tmpa_prop { -pl } {#1}
\peek_meaning_ignore_spaces:NTF <
+ { \__cookingunits_parse_stuff_gender:w }
+ { \__cookingunits_parse_stuff_gender:w <m> }
+ }
+\cs_new:Npn \__cookingunits_parse_stuff_gender:w <#1>
+ {
+ \__cookingunits_if_gender_error:nTF {#1}
+ { \__cookingunits_set_state_to:n { error } }
+ { \prop_put:Nnn \l__cookingunits_tmpa_prop { -gender } {#1} }
+ \__cookingunits_parse_phrase_finish_cycle_and_start_anew:V \l__cookingunits_curr_unit_tl
+ }
+\cs_new:Npn \__cookingunits_parse_phrase_finish_cycle_and_start_anew:n #1
+ {
+ \__cookingunits_if_state_equal:nT { normal }
{
- \__cookingunits_chuphrase_parse_gender:nw {#1}
- }{
- \__cookingunits_chuphrase_parse_gender:nw {#1} < m >
+ \seq_if_in:NnF \l__cookingunits_phrase_numbers_seq {#1}
+ { \seq_put_right:Nn \l__cookingunits_phrase_numbers_seq {#1} }
+ \prop_map_inline:Nn \l__cookingunits_tmpa_prop
+ {
+ \prop_put:Nnn \l__cookingunits_phrase_prop { #1 ##1 } {##2}
+ }
}
+ \__cookingunits_parse_phrase_start_cycle:
}
-\cs_new:Npn \__cookingunits_chuphrase_parse_gender:nw #1 <#2>
+\cs_generate_variant:Nn \__cookingunits_parse_phrase_finish_cycle_and_start_anew:n { V }
+\cs_new:Npn \__cookingunits_new_cuphrase_sort_sequence:N #1
{
- \__cookingunits_if_gender_error:nTF {#2}
+ \seq_sort:Nn #1
{
- \__cookingunits_deftranslation_to:VxVn
- \l__cookingunits_language_tl { #1-phrase-gender }
- \c__cookingunits_postfix_gender_tl { m }
- }{
- \__cookingunits_deftranslation_to:VxVn
- \l__cookingunits_language_tl { #1-phrase-gender }
- \c__cookingunits_postfix_gender_tl {#2}
+ \int_set:Nn \l__cookingunits_tmpa_int { \int_abs:n {##1} }
+ \int_set:Nn \l__cookingunits_tmpb_int { \int_abs:n {##2} }
+ \int_compare:nNnTF { \l__cookingunits_tmpa_int } < { \l__cookingunits_tmpb_int }
+ { \sort_return_swapped: }
+ {
+ \int_compare:nNnTF { \l__cookingunits_tmpa_int } > { \l__cookingunits_tmpb_int }
+ { \sort_return_same: }
+ {
+ \prop_get:NnN \l__cookingunits_phrase_prop { ##1 - singlebool } \l__cookingunits_tmpa_int
+ \int_compare:nNnTF { \l__cookingunits_tmpa_int } = { 1 }
+ { \sort_return_same: }
+ { \sort_return_swapped: }
+ }
+ }
}
- \__cookingunits_cuphrase_parse:n
}
+%% \@@_cuphrase:nn {#1} {#2}
\cs_new:Npn \__cookingunits_old_cutext:nnn #1#2#3
{
\tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_original_unit_tl
@@ -2699,7 +3338,7 @@
}
\cs_new:Npn \__cookingunits_old_cutext_default:nnn #1#2#3
{
- \bool_if:NTF \l__cookingunits_draft_bool
+ \bool_if:NTF \l__cookingunits_pckopt_draft_bool
{#2}
{
\tl_set:Nn \l__cookingunits_cutext_last_value_tl {#2}
@@ -2717,19 +3356,21 @@
{
\__cookingunits_old_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:NTF #1
{
- \__cookingunits_int_if_equal_one:nTF {#1}
+ \int_compare:nNnTF {#1} = { 1 }
{
- \__cookingunits_translate_one_and_check_existance:Nx \l__cookingunits_translation_tmpa_tl {#2}
- \bool_if:NTF \l__cookingunits_cutext_uppercase_word_bool
+ \__cookingunits_culang_one_let:NnT \l__cookingunits_translation_tmpa_tl {#2}
{
- \exp_args:Nx \tl_upper_case:n { \tl_head:V \l__cookingunits_translation_tmpa_tl }
- \tl_tail:V \l__cookingunits_translation_tmpa_tl
+ \bool_if:NT \l__cookingunits_cutext_uppercase_word_bool
+ {
+ \text_uppercase:x { \tl_head:V \l__cookingunits_translation_tmpa_tl }
+ \tl_tail:V
+ }
}
- { \l__cookingunits_translation_tmpa_tl }
+ \l__cookingunits_translation_tmpa_tl
}{
\bool_if:NTF \l__cookingunits_cutext_uppercase_word_bool
- { \__cookingunits_print_Numeral:n {#1} }
- { \__cookingunits_print_numeral:n {#1} }
+ { \__cookingunits_print_Numeral:V #1 }
+ { \__cookingunits_print_numeral:V #1 }
}
}
{ \__cookingunits_print_numerical_input:N #1 }
@@ -2766,7 +3407,7 @@
\char_set_catcode_letter:N \_ %
\char_set_catcode_ignore:N\ %
} {#1}
- \bool_if:NTF \l__cookingunits_draft_bool
+ \bool_if:NTF \l__cookingunits_pckopt_draft_bool
{ \l__cookingunits_tmpa_tl }
{ \__cookingunits_cuam_old_parse:V \l__cookingunits_tmpa_tl }
}
@@ -2850,100 +3491,6 @@
\skip_horizontal:N \l__cookingunits_mixed_frac_dim
\__cookingunits_frac:nn {#2} {#3}
}
-\cs_new:Npn \__cookingunits_add_forbidden_unit:n #1
- {
- \seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
- \seq_map_inline:Nn \l__cookingunits_tmpa_seq
- {
- \__cookingunits_error_if_unit_not_defined:nF {##1}
- {
- \seq_if_in:NnF \l__cookingunits_curef_do_not_change_seq {##1}
- { \seq_put_right:Nn \l__cookingunits_curef_do_not_change_seq {##1} }
- }
- }
- }
-\cs_new:Npn \__cookingunits_remove_forbidden_unit:n #1
- {
- \seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
- \seq_map_inline:Nn \l__cookingunits_tmpa_seq
- {
- \__cookingunits_error_if_unit_not_defined:nF {##1}
- {
- \seq_if_in:NnTF \l__cookingunits_curef_do_not_change_seq {##1}
- { \seq_remove_all:Nn \l__cookingunits_curef_do_not_change_seq {##1} }
- {
- \msg_warning:nnnn { cooking-units } { curef-not-inside-list } {##1}
- { \__cookingunits_seq_use_msg:N \l__cookingunits_curef_do_not_change_seq }
- }
- }
- }
- }
-\cs_new:Npn \__cookingunits_clear_forbidden_unit:
- { \seq_clear:N \l__cookingunits_curef_do_not_change_seq }
-\NewDocumentCommand \cudeclareunitgroup { m m }
- {
- \__cookingunits_define_clear_unit_group:nn {#1} {#2}
- \__cookingunits_add_to_unit_group:nn {#1} {#2}
- }
-\NewDocumentCommand \cuaddtounitgroup { m m }
- {
- \__cookingunits_add_to_unit_group:nn {#1} {#2}
- }
-\NewDocumentCommand \cuclearunitgroup { m }
- {
- \__cookingunits_error_if_group_not_defined:nF {#1}
- { \__cookingunits_define_clear_unit_group:nn {#1} { } }
- }
-\NewDocumentCommand \cusetoptionfor { m m }
- {
- \__cookingunits_map_trough_valid_unit_options:nnn {#1} {#2}
- { \clist_set:cn { l__cookingunits_unit_option_ ##1 _clist } {##2} }
- }
-\NewDocumentCommand \cuaddoptionfor { m m }
- {
- \__cookingunits_map_trough_valid_unit_options:nnn {#1} {#2}
- { \clist_put_right:cn { l__cookingunits_unit_option_ ##1 _clist } {##2} }
- }
-\NewDocumentCommand \cuclearoptionfor { m }
- {
- \__cookingunits_map_trough_valid_unit_options:nnn {#1} { }
- { \clist_clear:c { l__cookingunits_unit_option_ ##1 _clist } }
- }
-\cs_new:Npn \__cookingunits_tmp:w { }
-\cs_new:Npn \__cookingunits_map_trough_valid_unit_options:nnn #1#2 #3
- {
- \seq_clear:N \l__cookingunits_tmpa_seq
- \clist_clear:N \l__cookingunits_tmpa_clist
- \cs_set:Npn \__cookingunits_tmp:w ##1##2 {#3}
- \clist_map_inline:nn {#1}
- {
- \__cookingunits_error_if_unit_not_defined:nF {##1}
- { \seq_put_right:Nn \l__cookingunits_tmpa_seq {##1} }
- }
- \tl_if_empty:nF {#2}
- { \__cookingunits_unit_options_check_validity:n {#2} }
- \seq_map_inline:Nn \l__cookingunits_tmpa_seq
- { \exp_args:NnV \__cookingunits_tmp:w {##1} \l__cookingunits_tmpa_clist }
- }
-\cs_new:Npn \__cookingunits_unit_options_check_validity:n #1
- {
- \keyval_parse:NNn
- \__cookingunits_unit_options_check_validity_aux_i:n
- \__cookingunits_unit_options_check_validity_aux_ii:nn
- {#1}
- }
-\cs_new:Npn \__cookingunits_unit_options_check_validity_aux_i:n #1
- {
- \keys_if_exist:nnTF { cooking-units } {#1}
- { \clist_put_right:Nn \l__cookingunits_tmpa_clist {#1} }
- { \msg_error:nnn { cooking-units } { unknown-option } {#1} }
- }
-\cs_new:Npn \__cookingunits_unit_options_check_validity_aux_ii:nn #1#2
- {
- \keys_if_exist:nnTF { cooking-units } {#1}
- { \clist_put_right:Nn \l__cookingunits_tmpa_clist { #1={#2} } }
- { \msg_error:nnn { cooking-units } { unknown-option } {#1} }
- }
\NewDocumentCommand \cusetup { m }
{
\keys_set:nn { cooking-units } {#1}
@@ -2954,7 +3501,10 @@
\newcookingunit { oz }
\newcookingunit { lb }
\newcookingunit { stick }
-\newcookingunit [ \ensuremath{ \__cookingunits_frac:nn { eV } { c^2 } } ] { eVc-2 }
+\newcookingunit [
+ symbol={\ensuremath{ \__cookingunits_frac:nn { eV } { c^2 } } } ,
+ natural-unit
+ ] { eVc-2 }
\newcookingunit { K }
\newcookingunit [ \ensuremath{ {} ^ { \circ } } \kern-\scriptspace C ] { C }
\newcookingunit [ \ensuremath{ {} ^ { \circ } } \kern-\scriptspace F ] { F }
@@ -2963,23 +3513,30 @@
\newcookingunit { h }
\newcookingunit { min }
\newcookingunit { s }
-\newcookingunit [ \ensuremath{ \__cookingunits_frac:nn { \hbar } { eV } } ] { hbareV-1 }
+\newcookingunit [
+ symbol={\ensuremath{ \__cookingunits_frac:nn { \hbar } { eV } } },
+ natural-unit
+ ] { hbareV-1 }
\newcookingunit { m }
\newcookingunit { cm }
\newcookingunit { dm }
\newcookingunit { mm }
\newcookingunit { in }
-\newcookingunit [ \ensuremath{ \__cookingunits_frac:nn { c\hbar } { eV } } ] { chbareV-1 }
+\newcookingunit [
+ symbol={ \ensuremath{ \__cookingunits_frac:nn { c\hbar } { eV } } } , natural-unit
+ ] { chbareV-1 }
\newcookingunit { l }
\newcookingunit { dl }
\newcookingunit { cl }
\newcookingunit { ml }
-\newcookingunit [ \ensuremath { \__cookingunits_frac:nn { c^3 \hbar^3 } { eV^3 } } ] { (chbareV-1)3 }
+\newcookingunit [
+ symbol={ \ensuremath { \__cookingunits_frac:nn { c^3 \hbar^3 } { eV^3 } } }, natural-unit
+ ] { (chbareV-1)3 }
\newcookingunit { cal }
\newcookingunit { kcal }
\newcookingunit { J }
\newcookingunit { kJ }
-\newcookingunit { eV }
+\newcookingunit [ natural-unit ] { eV }
\newcookingunit [ pinch ] { pn }
\newcookingunit { EL }
\newcookingunit { TL }
@@ -3122,21 +3679,22 @@
{ one (f) } { une }
{ one (n) } { un }
}
-\cudefinekeys { kg }
+\cudefinekeychain
{
+ { kg } { 1 }
{ dag }{ 100 }
{ g } { 1000 }
{ lb } { 1/0.45359237 }
{ oz } { 16/0.45359237 }
{ stick } { 4/0.45359237 }
- { eVc-2 } { 560958865.0e+27 } %% 560958865.0 +- 3.5 e+27
+ { eVc-2 } { 560958865.0e+27 } %% (560958865.0 +- 3.5) e+27
}
\cudefinekeys { d }
{
{ h } { 24 }
{ min }{ 1440 }
{ s } { 86400 }
- { hbareV-1 } { 151926746.1e+7 * 86400 } %% 151926746.1 +- 2.1 e+7
+ { hbareV-1 } { 151926746.1e+7 * 86400 } %% (151926746.1 +- 2.1) e+7
}
\cudefinekeys { m }
{
@@ -3158,7 +3716,7 @@
{ kJ }{ 1e-3 }
{ cal }{ 0.2388459 }
{ kcal }{ 0.2388459e-3 }
- { eV }{ 624150912.6e+10 } %% 624150912.6 +- 3.9 e+10
+ { eV }{ 624150912.6e+10 } %% (624150912.6 +- 3.9) e+10
}
\fp_const:Nn \c__cookingunits_kb_eV_fp { 8.617 330 3 e-5 }
\cudefinesinglekey { C }
@@ -3212,6 +3770,8 @@
} ,
round-precision = 2 ,
}
+
+
\endinput
%%
%% End of file `cooking-units.sty'.