From 08541f1238259e89340cc52f9838c8591dbab1f5 Mon Sep 17 00:00:00 2001 From: Karl Berry Date: Mon, 23 Oct 2017 22:21:26 +0000 Subject: cooking-units (23oct17) git-svn-id: svn://tug.org/texlive/trunk@45585 c570f23f-e606-0410-a88d-b1316a301751 --- .../tex/latex/cooking-units/cooking-units.sty | 1942 +++++++++++++------- 1 file changed, 1282 insertions(+), 660 deletions(-) (limited to 'Master/texmf-dist/tex') 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 701f8c3a718..466ca5b3b63 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 by Ben Vitecek (current Maintainer) +%% Copyright (C) 2016--2017 by Ben Vitecek (current Maintainer) %% %% This file may be distributed and/or modified under the %% conditions of the LaTeX Project Public License, either @@ -14,7 +14,7 @@ %% %% http://www.latex-project.org/lppl.txt %% -%% and version 1.3c or later is part of all distributions of +%% and version 1.3 or later is part of all distributions of %% LaTeX version 2008-05-04 or later. %% %% This work has the LPPL maintenance status `maintained'. @@ -22,6 +22,7 @@ %% This work consists of the files README.md, cooking-units.dtx and cooking-units.ins %% and the derived file cooking-units.sty. %% +%% \@ifpackageloaded {xparse} { } { \RequirePackage {xparse} } @@ -30,10 +31,10 @@ { \RequirePackage {expl3} } \ProvidesExplPackage {cooking-units} - {2016/11/13} - {1.10} + {2017/10/23} + {1.2} {Ein Paket fuer Kocheinheiten} -\@ifpackagelater { expl3 } { 2016/05/18 } +\@ifpackagelater { expl3 } { 2017/09/18 } { } { \PackageError { cooking-units } { Support~package~expl3~too~old } @@ -44,70 +45,92 @@ } \tex_endinput:D } -\@ifpackageloaded { translator } { } { \RequirePackage { translator } } +\@ifpackageloaded { translations } { } { \RequirePackage { translations } } \@ifpackageloaded { xfrac } { } { \RequirePackage { xfrac } } \@ifpackageloaded { l3keys2e } { } { \RequirePackage { l3keys2e } } -\bool_new:N \g__cooking_units_load_if_opt_numeral_bool +\@ifpackagelater { translations } { 2017/08/31 } + { } + { + \PackageError { cooking-units } { Support~package~translations~too~old } + { + You~need~to~update~your~installation~of~the~package~'translations'.\MessageBreak + Loading~cooking-units~will~abort! + } + \tex_endinput:D + } +\bool_new:N \g__cooking_units_opt_numeral_bool \keys_define:nn { cooking-units } { - use-numerals .bool_gset:N = \g__cooking_units_load_if_opt_numeral_bool , + use-numerals .bool_gset:N = \g__cooking_units_opt_numeral_bool , use-numerals .default:n = { false }, } \ProcessKeysOptions { cooking-units } -\bool_if:NT \g__cooking_units_load_if_opt_numeral_bool +\bool_if:NT \g__cooking_units_opt_numeral_bool { \@ifpackageloaded { fmtcount } { } { \RequirePackage { fmtcount } } } \keys_define:nn { cooking-units } { - use-numerals .code:n = \msg_error:nnn { cooking-units } { load-time-option } { fmtcount } , + use-numerals .code:n = { \msg_error:nnn { cooking-units } { load-time-option } { fmtcount } } , } \cs_generate_variant:Nn \tl_replace_all:Nnn { NVn } \cs_generate_variant:Nn \tl_replace_once:Nnn { NnV, NVn } \cs_generate_variant:Nn \tl_if_in:nnTF { nVTF } -\cs_generate_variant:Nn \tl_if_in:NnTF { NVTF } +\cs_generate_variant:Nn \tl_if_in:NnTF { NVTF } \cs_generate_variant:Nn \tl_if_in:NnT { NVT } \cs_generate_variant:Nn \fp_compare:nNnT { cNnT } \cs_generate_variant:Nn \fp_eval:n { c } \cs_generate_variant:Nn \prop_get:cVN { cVc } \cs_generate_variant:Nn \int_abs:n { c } -\cs_generate_variant:Nn \tl_show:n { f , x } -\cs_generate_variant:Nn \fp_compare:nNnTF { v } +\cs_generate_variant:Nn \tl_show:n { x , f } \cs_new_eq:NN \__cooking_units_frac:nn \sfrac +\cs_new:Npn \__cooking_units_print_numeral:n #1 {} +\cs_new:Npn \__cooking_units_print_Numeral:n #1 {} +\bool_if:NT \g__cooking_units_opt_numeral_bool + { + \cs_set_eq:NN \__cooking_units_print_numeral:n \numberstringnum + \cs_set_eq:NN \__cooking_units_print_Numeral:n \Numberstringnum + } \prop_new:N \l__cooking_units_change_unit_prop +\tl_new:N \l__cooking_units_number_tmpa_tl +\tl_new:N \l__cooking_units_number_tmpb_tl \tl_new:N \l__cooking_units_tmpa_tl \tl_new:N \l__cooking_units_tmpb_tl \tl_new:N \l__cooking_units_mixed_fraction_tl -\tl_new:N \l__cooking_units_tmp_unit_tl +\tl_new:N \l__cooking_units_given_unit_tl \tl_new:N \l__cooking_units_option_unit_tl \tl_new:N \l__cooking_units_language_tl \tl_new:N \l__cooking_units_cunum_range_sign_tl \tl_new:N \l__cooking_units_cutext_range_sign_tl \tl_new:N \l__cooking_units_value_unit_space_tl \tl_new:N \l__cooking_units_input_digits_tl -\tl_new:N \l__cooking_units_decimal_mark_tl -\tl_new:N \l__cooking_units_value_signs_tl -\tl_new:N \l__cooking_units_allowed_special_signs_tl -\tl_new:N \c__cooking_units_str_hash_one_tl +\tl_new:N \l__cooking_units_input_decimal_mark_tl +\tl_new:N \l__cooking_units_input_value_signs_tl +\tl_new:N \l__cooking_units_input_allowed_special_signs_tl +\tl_new:N \c__cooking_units_input_str_hash_one_tl \tl_new:N \l__cooking_units_input_range_sign_tl -\tl_new:N \l__cooking_units_input_for_persons_sign \tl_new:N \l__cooking_units_input_times_persons_sign \tl_new:N \l__cooking_units_cutext_space_tl +\tl_new:N \l__cooking_units_cuphrase_space_tl \tl_new:N \l__cooking_units_translation_tmpa_tl -\tl_new:N \l__cooking_units_cutext_tmp_tl -\tl_set:Nn \l__cooking_units_cunum_range_sign_tl { -- } -\tl_set:Nn \l__cooking_units_cutext_range_sign_tl { -- } -\tl_set:Nn \l__cooking_units_value_unit_space_tl { \thinspace } +\tl_new:N \l__cooking_units_cutext_last_value_tl +\tl_new:N \l__cooking_units_phantom_tl +\tl_new:N \l__cooking_units_phrase_phrase_tl +\tl_new:N \l__cooking_units_unit_key_not_allowed_tl \tl_set:Nn \l__cooking_units_input_digits_tl { 0123456789 } -\tl_set:Nn \l__cooking_units_input_for_persons_sign { @ } \tl_set:Nn \l__cooking_units_input_times_persons_sign { * } -\tl_set:Nn \l__cooking_units_decimal_mark_tl { . , } -\tl_set:Nn \l__cooking_units_value_signs_tl { + - } \tl_set:Nn \l__cooking_units_input_range_sign_tl { -- } -\tl_set:Nn \l__cooking_units_allowed_special_signs_tl { ? } -\tl_set_rescan:Nnn \c__cooking_units_str_hash_one_tl +\tl_set:Nn \l__cooking_units_input_decimal_mark_tl { . , } +\tl_set:Nn \l__cooking_units_input_value_signs_tl { + - } +\tl_set:Nn \l__cooking_units_input_allowed_special_signs_tl { ? } +\tl_set_rescan:Nnn \c__cooking_units_input_str_hash_one_tl { \char_set_catcode_letter:N \# } {#1} +\tl_set:Nn \l__cooking_units_cunum_range_sign_tl { -- } +\tl_set:Nn \l__cooking_units_cutext_range_sign_tl { -- } +\tl_set:Nn \l__cooking_units_value_unit_space_tl { \thinspace } \tl_set:Nn \l__cooking_units_cutext_space_tl { \space } +\tl_set:Nn \l__cooking_units_cuphrase_space_tl { \space } +\tl_set:Nn \l__cooking_units_unit_key_not_allowed_tl { , / } \AtBeginDocument { \cs_if_free:cT { T@TS1 } { @@ -132,59 +155,61 @@ } \dim_new:N \l__cooking_units_mixed_frac_dim \dim_set:Nn \l__cooking_units_mixed_frac_dim { 0.1 em } -\int_new:N \l__cooking_units_persons_tmp_int \int_new:N \l__cooking_units_significant_figures_int \int_new:N \l__cooking_units_significant_figures_plus_one_int \int_set:Nn \l__cooking_units_significant_figures_int { 2 } \int_set:Nn \l__cooking_units_significant_figures_plus_one_int { 2 + 1 } \int_new:N \l__cooking_units_print_numerals_below_int \int_set:Nn \l__cooking_units_print_numerals_below_int { 13 } +\int_new:N \l__cooking_units_number_of_persons_tmpa_int \int_new:N \l__cooking_units_calc_for_number_of_persons_int \int_set:Nn \l__cooking_units_calc_for_number_of_persons_int { 4 } -\clist_new:N \l__cooking_units_list_of_defined_keys_clist -\clist_new:N \g__cooking_units_list_of_defined_units_clist -\clist_new:N \g__cooking_units_allowed_unit_phrases_clist -\clist_new:N \l__cooking_units_temperatures_to_check_clist +\int_new:N \l__cooking_units_phrase_number_tl +\seq_new:N \l__cooking_units_list_of_defined_keys_seq +\seq_new:N \g__cooking_units_list_of_defined_units_seq +\clist_new:N \g__cooking_units_allowed_special_keys_clist +\clist_new:N \l__cooking_units_phrase_numbers_clist +\seq_new:N \l__cooking_units_temperatures_to_check_seq +\prop_new:N \l__cooking_units_phrase_prop +\bool_new:N \l__cooking_units_minus_bool +\bool_new:N \l__cooking_units_round_decimal_part_bool \bool_new:N \l__cooking_units_error_bool \bool_new:N \l__cooking_units_eval_fractions_bool \bool_new:N \l__cooking_units_parse_input_bool \bool_new:N \l__cooking_units_round_to_int_bool \bool_new:N \l__cooking_units_special_sign_bool -\bool_new:N \l__cooking_units_decimal_in_input_bool \bool_new:N \l__cooking_units_single_key_bool -\bool_new:N \l__cooking_units_fraction_in_input_bool \bool_new:N \l__cooking_units_check_temperature_bool \bool_new:N \l__cooking_units_convert_to_eV_bool \bool_new:N \l__cooking_units_cutext_uppercase_word_bool \bool_new:N \l__cooking_units_error_for_unknown_value_bool -\bool_new:N \l__cooking_units_parse_range_bool \bool_new:N \l__cooking_units_using_cutext_bool \bool_new:N \l__cooking_units_cuam_old_bool \bool_new:N \l__cooking_units_calc_for_persons_bool \bool_new:N \l__cooking_units_calc_because_ref_was_given_bool -\bool_new:N \l__cooking_units_calc_persons_tmp_bool +\bool_new:N \l__cooking_units_calc_persons_bool \bool_new:N \l__cooking_units_cutext_to_cunum_bool \bool_new:N \l__cooking_units_cutext_old_bool \bool_new:N \l__cooking_units_cutext_change_unit_bool \bool_new:N \l__cooking_units_round_commercial_bool +\bool_new:N \l__cooking_units_use_phrases_bool +\bool_new:N \l__cooking_units_check_if_phrase_used_bool +\bool_new:N \l__cooking_units_local_numeral_bool +\bool_new:N \l__cooking_units_range_in_input_bool +\bool_new:N \l__cooking_units_fraction_in_input_bool +\bool_new:N \l__cooking_units_decimal_in_input_bool \bool_set_true:N \l__cooking_units_parse_input_bool \bool_set_true:N \l__cooking_units_cutext_change_unit_bool +\bool_set_eq:NN \l__cooking_units_local_numeral_bool \g__cooking_units_opt_numeral_bool \quark_new:N \q__cooking_units_range -\clist_gset:Nn \g__cooking_units_allowed_unit_phrases_clist - { - decimal-mark , - one (m) , - one (f) , - one (n) - } -\newtranslation { decimal-mark (cu-unitname) } { . } -\newtranslation [ to=German ] { decimal-mark (cu-unitname) } { , } -\newtranslation { one (m) (cu-unitname) } { one } -\newtranslation { one (f) (cu-unitname) } { one } -\newtranslation { one (n) (cu-unitname) } { one } -\newtranslation [ to=German ] { one (m) (cu-unitname) } { ein } -\newtranslation [ to=German ] { one (f) (cu-unitname) } { eine } -\newtranslation [ to=German ] { one (n) (cu-unitname) } { ein } +\quark_new:N \q__cooking_units_no_translation +\fp_new:N \l__cooking_units_tmpa_fp +\clist_new:N \l__cooking_units_tmpa_clist +\prop_new:N \l__cooking_units_tmpa_prop +\prop_new:N \l__cooking_units_tmpb_prop +\seq_new:N \l__cooking_units_tmpa_seq +\int_new:N \l__cooking_units_tmpa_int +\int_new:N \l__cooking_units_tmpb_int \keys_define:nn { cooking-units } { eval-fraction .bool_set:N = \l__cooking_units_eval_fractions_bool , @@ -207,19 +232,29 @@ cunum-range-sign .default:n = { -- } , cutext-range-sign .tl_set:N = \l__cooking_units_cutext_range_sign_tl , cutext-range-sign .default:n = { -- } , - value-unit-space .tl_set:N = \l__cooking_units_value_unit_space_tl , - value-unit-space .default:n = { \thinspace } , + amount-unit-space .tl_set:N = \l__cooking_units_value_unit_space_tl , + amount-unit-space .default:n = { \thinspace } , fraction-command .code:n = { \cs_set_eq:NN \__cooking_units_frac:nn #1 } , fraction-command .default:n = { \sfrac } , fraction-inline .code:n = { \cs_set:Npn \__cooking_units_frac:nn ##1##2 {#1} } , - fraction-inline .default:n = { \sfrac {#1}{#2} } , + fraction-inline .default:n = { \sfrac {#1} {#2} } , mixed-fraction-space .dim_set:N = \l__cooking_units_mixed_frac_dim , mixed-fraction-space .default:n = { 0.1 em } , parse-number .bool_set:N = \l__cooking_units_parse_input_bool , parse-number .default:n= { true } , - add-special-sign .code:n = { \tl_put_right:Nn \l__cooking_units_allowed_special_signs_tl {#1} } , + add-special-sign .code:n = + { + \str_if_eq:nnTF {#1} { < } + { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } + { \tl_put_right:Nn \l__cooking_units_input_allowed_special_signs_tl {#1} } + } , add-special-sign .default:n = { } , - set-special-sign .tl_set:N = \l__cooking_units_allowed_special_signs_tl , + set-special-sign .code:n = + { + \str_if_eq:nnTF {#1} { < } + { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } + { \tl_set:Nn \l__cooking_units_input_allowed_special_signs_tl {#1} } + } , input-range-sign .tl_set:N = \l__cooking_units_input_range_sign_tl , input-range-sign .default:n = { -- } , check-temperature .bool_set:N = \l__cooking_units_check_temperature_bool , @@ -244,9 +279,16 @@ { \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 } + } , + set-cutext-translation-message .default:n = { warning } , erase-all-options .code:n = { - \clist_map_inline:Nn \g__cooking_units_list_of_defined_units_clist + \seq_map_inline:Nn \g__cooking_units_list_of_defined_units_seq { \clist_clear:c { l__cooking_units_predefined_option_##1_clist } } @@ -304,8 +346,16 @@ cutext-to-cunum .default:n = { false } , cutext-space .tl_set:N = \l__cooking_units_cutext_space_tl , cutext-space .default:n = { \space } , + phrase-space .tl_set:N = \l__cooking_units_cuphrase_space_tl , + phrase-space .default:n = { \space } , cutext-change-unit .bool_set:N = \l__cooking_units_cutext_change_unit_bool , cutext-change-unit .default:n = { true } , + use-phrases .bool_set:N = \l__cooking_units_use_phrases_bool , + use-phrases .default:n = { true } , + print-numerals .bool_set:N = \l__cooking_units_local_numeral_bool , + print-numerals .default:n = { true } , + numeral-function .code:n = { \cs_set_eq:NN \__cooking_units_print_numeral:n #1 } , + Numeral-function .code:n = { \cs_set_eq:NN \__cooking_units_print_Numeral:n #1 } , } \msg_new:nnnn { cooking-units } { fraction-not-allowed-with-range } { @@ -324,7 +374,7 @@ a \ normal \ fraction \ ('/'). \msg_see_documentation_text:n { cooking-units } } -\msg_new:nnnn { cooking-units } { unknown - unit } +\msg_new:nnnn { cooking-units } { unknown-unit } { The \ unit \ '#1' \ is \ not \ defined. \ Use \ \newcookingunit \ to \ define \ new \ units. @@ -355,13 +405,13 @@ The \ command \ accepts \ only \ a \ fixed \ number \ of \ tokens. \msg_see_documentation_text:n {cooking-units} } -\msg_new:nnnn { cooking-units } { Second - decimal -sign - not - allowed } +\msg_new:nnnn { cooking-units } { Second-decimal-sign-not-allowed } { A \ second \ decimal \ sign \ is \ not \ allowed. } { Perhaps \ you \ didn't \ type \ it \ correctly. \msg_see_documentation_text:n {cooking-units} } -\msg_new:nnnn { cooking-units } { Key - not -defined } +\msg_new:nnnn { cooking-units } { Key-not-defined } { The \ key \ '#1' \ is \ not \ defined. \ Use \ \cudefinekeys or \ \cudefinesinglekey to \ define \ keys. @@ -370,11 +420,13 @@ This \ key \ is \ not \ defined, \ perhaps \ you \ misspelled \ it. \msg_see_documentation_text:n {cooking-units} } -\msg_new:nnnn { cooking-units } { Temperature-to-low } +\msg_new:nnnn { cooking-units } { Temperature-too-low } { - The \ temperature \ '#1' \ is \ to \ low.\ It \ cannot \ be \ + The \ temperature \ '#1' \ is \ too \ low.\ It \ cannot \ be \ below \ the \ absolute \ zero - point \ of \ '#2'. \ Note \ that \ - by \ default \ the \ temperatures \ 'C', \ 'F' , \ 'K' \ and \ 'Re' \ + the \ temperatures \ + '\seq_use:Nnnn \l__cooking_units_temperatures_to_check_seq + { ', ~ ' } { ', ~ ' } { ' ~ and ~ ' }' \ are \ rounded \ to \ integers. \\\\ You \ can \ disable \ the \ option \ 'check-temperature' \ to \ @@ -389,7 +441,7 @@ { The \ key \ accepts \ accepts\ only \ a \ fixed \ set \ of \ choices. \ You \ can \ add \ new \ choices \ via \ \cuaddkeys, \ \cuaddsinglekeys \ - and \ \cuaddtokeys. + and \ \cuaddtokeys{}. \msg_see_documentation_text:n {cooking-units} } \msg_new:nnnn { cooking-units } { amount-not-known } @@ -452,7 +504,7 @@ \msg_new:nnnn { cooking-units } { Number-of-persons-is-not-an-integer } { The \ number \ of \ persons \ the \ recipe \ is \ for \ must \ be \ an \ - integer. + integer. \ '#1' \ is \ not \ allowed. } { The \ number \ '#1' \ is \ not \ allowed. @@ -482,13 +534,59 @@ { \msg_see_documentation_text:n { cooking-units } } +\msg_new:nnnn { cooking-units } { phrase-unit-not-an-integer } + { + A \ phrase \ must \ be \ an \ integer, \ '#1' \ is \ not \ allowed. + } + { + You \ can \ only \ use \ integers. + \msg_see_documentation_text:n { cooking-units } + } +\msg_new:nnnn { cooking-units } { cutext-no-translation-available } %% ToDo + { + For \ the \ unit \ '#1' \ there \ exists \ no \ translation \ to \ be \ used \ + for \ \cutext and \ \Cutext{}. \ + You \ can \ define \ new \ translations \ for \ a \ given \ language \ using \ + \cudefinename{}. + } + { + \cunum \ is \ used \ instead. + \msg_see_documentation_text:n { cooking-units } + } +\msg_new:nnnn { cooking-units } { Translation-not-available } %% ToDo + { + The \ translation \ for \ #1 \ does \ not \ exist. + Please \ define \ it \ using \ \cudefinename{}. + } + { + And \ you \ may \ send \ me \ the \ translation \ as \ it \ is \ + not \ available \ yet. + \msg_see_documentation_text:n { cooking-units } + } +\msg_new:nnnn { cooking-units } { <-not-allowed-as-special-sign } + { + Currently \ (and \ probably \ forever) \ the \ sign \ '<' \ + is \ not \ allowed \ to \ be \ used \ as \ a \ special \ sign. + } + { + I \ apologize \ for \ the \ inconvenience. + \msg_see_documentation_text:n { cooking-units } + } +\msg_new:nnnn { cooking-units } { unknown-gender } + { + '#1' \ is \ not \ allowed \ to \ be \ used \ as \ a \ gender-specification. + Only \ 'm', \ 'f' \ or \ 'n' \ are \ allowed + }{ + Please \ remove \ spaces \ if \ there \ are \ some. + \msg_see_documentation_text:n { cooking-units } + } \cs_new:Npn \__cooking_units_error_if_unit_not_defined:n #1 { - \clist_if_in:NnF \g__cooking_units_list_of_defined_units_clist {#1} + \seq_if_in:NnF \g__cooking_units_list_of_defined_units_seq {#1} { \msg_error:nnn { cooking-units } { unknown-unit } {#1} } } \cs_generate_variant:Nn \__cooking_units_error_if_unit_not_defined:n { V } -\prg_new_protected_conditional:Npnn \__cooking_units_if_integer:n #1 { TF } +\prg_new_protected_conditional:Npnn \__cooking_units_if_integer:n #1 { TF , F , T } { \tl_map_inline:nn {#1} { @@ -499,7 +597,10 @@ } \use_i:nn \prg_return_true: \prg_return_false: } -\prg_new_protected_conditional:Npnn \__cooking_units_if_integer_and_parse:n #1 { TF } +\cs_generate_variant:Nn \__cooking_units_if_integer:nTF { V } +\cs_generate_variant:Nn \__cooking_units_if_integer:nT { V } +\cs_generate_variant:Nn \__cooking_units_if_integer:nF { V } +\prg_new_protected_conditional:Npnn \__cooking_units_if_parse_and_integer:n #1 { TF } { \bool_if:NTF \l__cooking_units_parse_input_bool { @@ -509,48 +610,70 @@ } { \prg_return_false: } } -\cs_generate_variant:Nn \__cooking_units_if_integer_and_parse:nTF { V } -\cs_new:Npn \__cooking_units_convert_to_eV: +\cs_generate_variant:Nn \__cooking_units_if_parse_and_integer:nTF { V } +\prg_new_conditional:Npnn \__cooking_units_fp_if_equal_one:n #1 { TF } { - \keys_set:nn { cooking-units } - { - m= chbareV-1, - cm= chbareV-1, - dm= chbareV-1, - mm= chbareV-1, - in= chbareV-1, - kg= eVc-2, - dag= eVc-2, - g= eVc-2, - oz= eVc-2, - lb= eVc-2, - d= hbareV-1, - h= hbareV-1, - min= hbareV-1, - s= hbareV-1, - cal= eV, - kcal= eV, - J= eV, - kJ= eV, - F= eV, - K= eV, - C= eV, - Re= eV, - l= (chbareV-1)3 , - dl= (chbareV-1)3 , - cl= (chbareV-1)3 , - ml= (chbareV-1)3 , - } - } -\cs_new:Npn \__cooking_units_deftranslation:Nnn #1#2#3 - { - \deftranslation [ to=#1 ] {#2} {#3} - } -\cs_generate_variant:Nn \__cooking_units_deftranslation:Nnn { Vnn , Vnv } -\cs_new:Npn \__cooking_units_tl_set_fp_and_eval:Nn #1#2 + \fp_compare:nNnTF {#1} = { \c_one_fp } + { \prg_return_true: } + { \prg_return_false: } + } +\prg_new_conditional:Npnn \__cooking_units_int_if_equal_one:n #1 { TF } + { + \int_compare:nNnTF {#1} = { \c_one } + { \prg_return_true: } + { \prg_return_false: } + } +\cs_new:Npn \__cooking_units_check_if_correct_gender_input:n #1 + { + \str_case:nnF {#1} + { + { m } {} + { f } {} + { n } {} + } { \msg_error:nnn { cooking-units } { unknown-gender } {#1} } + } +\seq_new:N \g__cooking_units_natural_units_seq +\prop_new:N \g__cooking_units_convert_to_eV_remember_prop +\seq_set_split:Nnn \g__cooking_units_natural_units_seq { , } + { + eV , + eVc-2 , + hbareV-1 , + chbareV-1 , + (chbareV-1)3 , + } +\cs_new:Npn \__cooking_units_keys_set:nnn #1#2#3 + { + \keys_set:nn {#1} { #2 = #3 } + } +\cs_generate_variant:Nn \__cooking_units_keys_set:nnn { nVV , nVn } +\cs_new:Npn \__cooking_units_convert_to_eV: { - \tl_set:Nf #1 { \fp_eval:n {#2} } + \prop_if_exist:cT { l__cooking_units_cukeys_ \l__cooking_units_given_unit_tl _prop } + { + \prop_get:NVNTF \g__cooking_units_convert_to_eV_remember_prop + \l__cooking_units_given_unit_tl \l__cooking_units_tmpa_tl + { + \__cooking_units_keys_set:nVV { cooking-units } \l__cooking_units_given_unit_tl \l__cooking_units_tmpa_tl + }{ + \prop_get:cnNT { l__cooking_units_cukeys_ \l__cooking_units_given_unit_tl _prop } { Liste } \l__cooking_units_tmpa_seq + { + \seq_map_inline:Nn \g__cooking_units_natural_units_seq + { + \seq_if_in:NnT \l__cooking_units_tmpa_seq {##1} + { + \prop_gput:NVn \g__cooking_units_convert_to_eV_remember_prop + \l__cooking_units_given_unit_tl {##1} + \__cooking_units_keys_set:nVn { cooking-units } \l__cooking_units_given_unit_tl {##1} + \seq_map_break: + } + } + } + } + } } +\cs_new:Npn \__cooking_units_tl_set_fp_and_eval:Nn #1#2 + { \tl_set:Nx #1 { \fp_eval:n {#2} } } \cs_generate_variant:Nn \__cooking_units_tl_set_fp_and_eval:Nn { Nc } \cs_new:Npn \__cooking_units_temperature_to_check_print_error:n #1 { @@ -562,7 +685,7 @@ \fp_if_exist:cTF { c__cooking_units_ #1 _min_fp } { \msg_warning:nnn { cooking-units } { Minimum-already-defined } {#1} } { - \clist_put_right:Nn \l__cooking_units_temperatures_to_check_clist {#1} + \seq_put_right:Nn \l__cooking_units_temperatures_to_check_seq {#1} \fp_const:cn { c__cooking_units_ #1 _min_fp } {#2} } } @@ -571,81 +694,70 @@ #1 \bool_if:NTF \l__cooking_units_round_commercial_bool { + , \bool_if:NTF \l__cooking_units_round_to_int_bool - { , \c_zero_fp } - { , \l__cooking_units_significant_figures_int } + { \c_zero_fp } + { \l__cooking_units_significant_figures_int } , #1 } { \bool_if:NF \l__cooking_units_round_to_int_bool { , \l__cooking_units_significant_figures_int } } } \cs_new:Npn \__cooking_units_label_and_persons:n #1 { - \tl_if_in:nnTF {#1} { @ } + \tl_if_in:nnTF {#1} { * } { - \__cooking_units_label_and_persons_for_persons:ww #1 \q_stop + \__cooking_units_label_and_persons_times_persons:ww #1 \q_stop }{ - \tl_if_in:nnTF {#1} { * } - { - \__cooking_units_label_and_persons_times_persons:ww #1 \q_stop - }{ - \msg_error:nnn { cooking-units} { Number-of-persons-missing } {#1} - } + \msg_error:nnn { cooking-units} { Number-of-persons-missing } {#1} } } -\cs_new:Npn \__cooking_units_label_and_persons_for_persons:ww #1 @ #2 \q_stop - { - \__cooking_units_culabel:nnn {#1} {#2} { } - } \cs_new:Npn \__cooking_units_label_and_persons_times_persons:ww #1 * #2 \q_stop { - \__cooking_units_culabel:nnn {#1} {#2} { - } - } -\cs_new:Npn \__cooking_units_reference_label_and_persons:n #1 - { - \int_if_exist:cTF { l__cooking_units_persons_ #1 _int } - { - \bool_set_true:N \l__cooking_units_calc_because_ref_was_given_bool - \int_set:Nn \l__cooking_units_persons_tmp_int - { - \int_abs:c { l__cooking_units_persons_ #1 _int } - } - } - { \msg_error:nnn { cooking-units } { label-not-defined } {#1} } + \__cooking_units_culabel:nn {#1} {#2} } -\cs_new:Npn \__cooking_units_culabel:nnn #1#2#3 +\cs_new:Npn \__cooking_units_culabel:nn #1#2 { - \int_if_exist:cTF { l__cooking_units_persons_ #1 _int } + \int_if_exist:cTF { l__cooking_units_number_of_persons_ #1 _int } { \msg_error:nnn { cooking-units } { label-already-defined } {#1} }{ \__cooking_units_if_integer:nTF {#2} { - \int_new:c { l__cooking_units_persons_ #1 _int } - \int_gset:cn { l__cooking_units_persons_ #1 _int } { #3 #2 } + \int_new:c { l__cooking_units_number_of_persons_ #1 _int } + \int_gset:cn { l__cooking_units_number_of_persons_ #1 _int } {#2} } { \msg_error:nnn { cooking-units } { Number-of-persons-is-not-an-integer } {#2} } } } +\cs_new:Npn \__cooking_units_reference_label_and_persons:n #1 + { + \int_if_exist:cTF { l__cooking_units_number_of_persons_ #1 _int } + { + \bool_set_true:N \l__cooking_units_calc_because_ref_was_given_bool + \int_set_eq:Nc \l__cooking_units_number_of_persons_tmpa_int + { l__cooking_units_number_of_persons_ #1 _int } + } + { \msg_error:nnn { cooking-units } { label-not-defined } {#1} } + } \cs_new:Npn \__cooking_units_curef:n #1 { - \int_if_exist:cTF { l__cooking_units_persons_ #1 _int } + \int_if_exist:cTF { l__cooking_units_number_of_persons_ #1 _int } { \bool_if:NTF \l__cooking_units_calc_for_persons_bool { \int_use:N \l__cooking_units_calc_for_number_of_persons_int } - { \int_abs:c { l__cooking_units_persons_ #1 _int } } + { \int_use:c { l__cooking_units_number_of_persons_ #1 _int } } }{ \msg_error:nnn { cooking-units } { label-not-defined } {#1} } } -\NewDocumentCommand \culabel { m m } { \__cooking_units_culabel:nnn {#1} {#2} {} } -\DeclareExpandableDocumentCommand \curef { m } { \__cooking_units_curef:n {#1} } +\NewDocumentCommand \culabel { m m } { \__cooking_units_culabel:nn {#1} {#2} } +\NewExpandableDocumentCommand \curef { m } { \__cooking_units_curef:n {#1} } \cs_new:Npn \__cooking_units_tl_if_in_remove_and_set_bool:NnN #1#2#3 { \tl_if_in:NnTF #1 {#2} { \bool_set_true:N #3 \tl_remove_once:Nn #1 {#2} - }{ - \bool_set_false:N #3 } + { \bool_set_false:N #3 } } \cs_new:Npn \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN #1#2#3 { @@ -657,13 +769,97 @@ \tl_remove_once:Nn #1 {#2} } } -\cs_new:Npn \__cooking_units_cunum_parse_input:N #1 +\tl_const:Nn \c__cooking_units_postfix_unit_tl { ( cu-unit ) } +\tl_const:Nn \c__cooking_units_postfix_unit_pl_tl { ( cu-unit-pl ) } +\tl_const:Nn \c__cooking_units_postfix_unitname_tl { ( cu-unitname ) } +\tl_const:Nn \c__cooking_units_postfix_unitname_pl_tl { ( cu-unitname-pl ) } +\tl_const:Nn \c__cooking_units_postfix_gender_tl { ( cu-unitgender ) } +\tl_const:Nn \c__cooking_units_postfix_phrase_tl { ( cu-unitphrase ) } +\cs_new:Npn \__cooking_units_deftranslation_base:nnn #1#2#3 + { + \declaretranslationfallback { #1 #2 } {#3} + } +\cs_new:Npn \__cooking_units_deftranslation_to:nnnn #1#2#3#4 + { + \declaretranslation {#1} { #2 #3 } {#4} + } +\cs_generate_variant:Nn \__cooking_units_deftranslation_base:nnn { xx , xxV } +\cs_generate_variant:Nn \__cooking_units_deftranslation_to:nnnn { Vxxv, VxxV , Vxxn, Vxxx,Vxxo,Vxxf } +\cs_new:Npn \__cooking_units_newtranslation_base:nnn #1#2#3 + { + \definetranslationfallback { #1 #2 } {#3} + } +\cs_new:Npn \__cooking_units_newtranslation_to:nnnn #1#2#3#4 + { + \definetranslation {#1} { #2 #3 } {#4} + } +\cs_generate_variant:Nn \__cooking_units_newtranslation_base:nnn { nVn } +\cs_generate_variant:Nn \__cooking_units_newtranslation_to:nnnn { nnVn } +\cs_new:Npn \__cooking_units_translate:nn #1#2 + { + \GetTranslation { #1 #2 } + } +\cs_new:Npn \__cooking_units_translate_let:Nnn #1#2#3 + { + \SaveTranslation {#1} { #2 #3 } + } +\cs_new:Npn \__cooking_units_translate_let:nNnn #1#2#3#4 + { + \SaveTranslationFor {#2} {#1} { #3 #4 } + } +\cs_generate_variant:Nn \__cooking_units_translate:nn { xx } +\cs_generate_variant:Nn \__cooking_units_translate_let:Nnn { Nxx } +\cs_generate_variant:Nn \__cooking_units_translate_let:nNnn { VNxx, nNxx } +\prg_new_conditional:Npnn \__cooking_units_unitname_get:Nn #1#2 { F } + { + \__cooking_units_translate_let:Nxx #1 {#2} \c__cooking_units_postfix_unitname_tl + \tl_if_eq:NNTF #1 \q__cooking_units_no_translation + { \prg_return_false: } + { \prg_return_true: } + } +\cs_generate_variant:Nn \__cooking_units_unitname_get:NnF { Nx } +\cs_new:Npn \__cooking_units_translate_one_to_and_check_existance:Nx #1#2 + { + \__cooking_units_translate_let:Nxx #1 {#2} \c__cooking_units_postfix_gender_tl + \__cooking_units_unitname_get:NxF #1 { one (#1) } + { + \__cooking_units_translate_let:Nxx #1 {#2} \c__cooking_units_postfix_gender_tl + \msg_error:nnn { cooking-units } { Translation-not-available } { one (#1) } + } + } +\clist_gset:Nn \g__cooking_units_allowed_special_keys_clist { - \bool_if:NTF \l__cooking_units_parse_range_bool + decimal-mark , + one (m) , + one (f) , + one (n) + } +\__cooking_units_newtranslation_base:nVn { decimal-mark } \c__cooking_units_postfix_unitname_tl { . } +\__cooking_units_newtranslation_base:nVn { decimal-mark } \c__cooking_units_postfix_unitname_pl_tl { \q__cooking_units_no_translation } +\__cooking_units_newtranslation_to:nnVn { German } { decimal-mark } \c__cooking_units_postfix_unitname_tl { , } +\__cooking_units_newtranslation_base:nVn { one (m) } \c__cooking_units_postfix_unitname_tl { \q__cooking_units_no_translation } +\__cooking_units_newtranslation_base:nVn { one (f) } \c__cooking_units_postfix_unitname_tl { \q__cooking_units_no_translation } +\__cooking_units_newtranslation_base:nVn { one (n) } \c__cooking_units_postfix_unitname_tl { \q__cooking_units_no_translation } +\__cooking_units_newtranslation_base:nVn { one (m) } \c__cooking_units_postfix_unitname_pl_tl { \q__cooking_units_no_translation } +\__cooking_units_newtranslation_base:nVn { one (f) } \c__cooking_units_postfix_unitname_pl_tl { \q__cooking_units_no_translation } +\__cooking_units_newtranslation_base:nVn { one (n) } \c__cooking_units_postfix_unitname_pl_tl { \q__cooking_units_no_translation } +\__cooking_units_newtranslation_to:nnVn { English } { one (m) } \c__cooking_units_postfix_unitname_tl { one } +\__cooking_units_newtranslation_to:nnVn { English } { one (f) } \c__cooking_units_postfix_unitname_tl { one } +\__cooking_units_newtranslation_to:nnVn { English } { one (n) } \c__cooking_units_postfix_unitname_tl { one } +\__cooking_units_newtranslation_to:nnVn { German } { one (m) } \c__cooking_units_postfix_unitname_tl { ein } +\__cooking_units_newtranslation_to:nnVn { German } { one (f) } \c__cooking_units_postfix_unitname_tl { eine } +\__cooking_units_newtranslation_to:nnVn { German } { one (n) } \c__cooking_units_postfix_unitname_tl { ein } +\cs_new:Npn \__cooking_units_parse_input:N #1 + { + \bool_if:NTF \l__cooking_units_range_in_input_bool { \__cooking_units_parse_range_in_input:ww #1 \q_stop } { \tl_if_in:nnTF {#1} { / } { + \bool_lazy_or:nnTF + { \l__cooking_units_calc_persons_bool }{ \l__cooking_units_eval_fractions_bool } + { \bool_set_false:N \l__cooking_units_fraction_in_input_bool } + { \bool_set_true:N \l__cooking_units_fraction_in_input_bool } \tl_if_in:nnTF {#1} { _ } { \__cooking_units_parse_mixed_fraction_in_input:www #1 \q_stop } { \__cooking_units_parse_fraction_in_input:ww #1 \q_stop } @@ -671,83 +867,93 @@ { \__cooking_units_parse_number_in_input:n {#1} } } } -\cs_generate_variant:Nn \__cooking_units_cunum_parse_input:N { V } +\cs_generate_variant:Nn \__cooking_units_parse_input:N { V } \cs_new:Npn \__cooking_units_parse_number_in_input:n #1 { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_tmpa_tl - \__cooking_units_calculate_and_print_input:N \l__cooking_units_tmpa_tl + \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_number_tmpa_tl + \__cooking_units_process_and_print_number_in_input:N \l__cooking_units_number_tmpa_tl + } +\cs_new:Npn \__cooking_units_process_and_print_number_in_input:N #1 + { + \__cooking_units_pre_process_input:NN #1 \q_no_value + \__cooking_units_calculate_and_store_in:N #1 + \__cooking_units_post_process_input:NN #1 \q_no_value + \__cooking_units_print_input:N #1 } \cs_new:Npn \__cooking_units_parse_range_in_input:ww #1 \q__cooking_units_range #2 \q_stop { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_tmpa_tl - \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_tmpb_tl - \__cooking_units_calculate_and_print_input:N \l__cooking_units_tmpa_tl + \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_number_tmpa_tl + \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_number_tmpb_tl + \__cooking_units_pre_process_input:NN \l__cooking_units_number_tmpa_tl \l__cooking_units_number_tmpb_tl + \__cooking_units_calculate_and_store_in:N \l__cooking_units_number_tmpa_tl + \__cooking_units_calculate_and_store_in:N \l__cooking_units_number_tmpb_tl + \__cooking_units_post_process_input:NN \l__cooking_units_number_tmpa_tl \l__cooking_units_number_tmpb_tl + \__cooking_units_print_input:N \l__cooking_units_number_tmpa_tl \bool_if:NTF \l__cooking_units_using_cutext_bool { \tl_use:N \l__cooking_units_cutext_range_sign_tl } { \tl_use:N \l__cooking_units_cunum_range_sign_tl } - \__cooking_units_calculate_and_print_input:N \l__cooking_units_tmpb_tl + \__cooking_units_print_input:N \l__cooking_units_number_tmpb_tl } \cs_new:Npn \__cooking_units_parse_fraction_in_input:ww #1/#2 \q_stop { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_tmpa_tl - \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_tmpb_tl - \bool_if:nTF - { - \l__cooking_units_calc_persons_tmp_bool || - \l__cooking_units_eval_fractions_bool - } + \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_number_tmpa_tl + \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_number_tmpb_tl + \bool_lazy_or:nnTF + { \l__cooking_units_fraction_in_input_bool } + { \l__cooking_units_special_sign_bool } { - \__cooking_units_calculate_and_print_input:n - { \l__cooking_units_tmpa_tl / \l__cooking_units_tmpb_tl } - }{ - \__cooking_units_tl_if_in_remove_and_set_bool:NnN \l__cooking_units_tmpa_tl { - } \l_tmpb_bool - \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_tmpb_tl { - } \l_tmpb_bool - \__cooking_units_formatiere_fractions:nNN + \__cooking_units_tl_if_in_remove_and_set_bool:NnN \l__cooking_units_number_tmpa_tl { - } \l__cooking_units_minus_bool + \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_number_tmpb_tl { - } \l__cooking_units_minus_bool + \__cooking_units_formatiere_fractions:nnn { } - { \l__cooking_units_tmpa_tl } - { \l__cooking_units_tmpb_tl } + { \l__cooking_units_number_tmpa_tl } + { \l__cooking_units_number_tmpb_tl } + }{ + \__cooking_units_tl_set_fp_and_eval:Nn \l__cooking_units_number_tmpa_tl + { \l__cooking_units_number_tmpa_tl / \l__cooking_units_number_tmpb_tl } + \__cooking_units_process_and_print_number_in_input:N \l__cooking_units_number_tmpa_tl } } \cs_new:Npn \__cooking_units_parse_mixed_fraction_in_input:www #1_#2/#3 \q_stop { \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_mixed_fraction_tl - \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_tmpa_tl - \__cooking_units_parse_input_and_safe_in:nN {#3} \l__cooking_units_tmpb_tl - \__cooking_units_tl_if_in_remove_and_set_bool:NnN \l__cooking_units_mixed_fraction_tl { - } \l_tmpb_bool - \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_tmpa_tl { - } \l_tmpb_bool - \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_tmpb_tl { - } \l_tmpb_bool - \bool_if:nTF - { - \l__cooking_units_calc_persons_tmp_bool || - \l__cooking_units_eval_fractions_bool + \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_number_tmpa_tl + \__cooking_units_parse_input_and_safe_in:nN {#3} \l__cooking_units_number_tmpb_tl + \__cooking_units_tl_if_in_remove_and_set_bool:NnN \l__cooking_units_mixed_fraction_tl { - } \l__cooking_units_minus_bool + \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_number_tmpa_tl { - } \l__cooking_units_minus_bool + \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_number_tmpb_tl { - } \l__cooking_units_minus_bool + \bool_lazy_or:nnTF + { \l__cooking_units_fraction_in_input_bool } + { \l__cooking_units_special_sign_bool } + { + \__cooking_units_formatiere_fractions:nnn + { \l__cooking_units_mixed_fraction_tl } + { \l__cooking_units_number_tmpa_tl } + { \l__cooking_units_number_tmpb_tl } }{ - \__cooking_units_calculate_and_print_input:n + \__cooking_units_tl_set_fp_and_eval:Nn \l__cooking_units_number_tmpa_tl { - \bool_if:NTF \l_tmpb_bool + \bool_if:NTF \l__cooking_units_minus_bool { - \l__cooking_units_mixed_fraction_tl - } { \l__cooking_units_mixed_fraction_tl + } - \l__cooking_units_tmpa_tl / \l__cooking_units_tmpb_tl + \l__cooking_units_number_tmpa_tl / \l__cooking_units_number_tmpb_tl } - }{ - \__cooking_units_formatiere_fractions:nNN - { \l__cooking_units_mixed_fraction_tl } - { \l__cooking_units_tmpa_tl } - { \l__cooking_units_tmpb_tl } + \__cooking_units_process_and_print_number_in_input:N \l__cooking_units_number_tmpa_tl } } \cs_new:Npn \__cooking_units_parse_input_and_safe_in:nN #1 #2 { - \tl_clear:N \l_tmpa_tl + \tl_clear:N \l__cooking_units_tmpa_tl \bool_set_false:N \l__cooking_units_decimal_in_input_bool \__cooking_units_parse_vorzeichen_and_rest:Nw #1 \q_stop \bool_if:NTF \l__cooking_units_error_bool { \tl_set:Nn #2 {#1} } - { \tl_set_eq:NN #2 \l_tmpa_tl } + { \tl_set_eq:NN #2 \l__cooking_units_tmpa_tl } } \cs_new:Npn \__cooking_units_parse_vorzeichen_and_rest:Nw #1#2 \q_stop { - \tl_if_in:NnTF \l__cooking_units_value_signs_tl {#1} - { \tl_put_right:Nn \l_tmpa_tl {#1} } + \tl_if_in:NnTF \l__cooking_units_input_value_signs_tl {#1} + { \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} } { \tl_map_function:nN {#1} \__cooking_units_parse_input_for_safety_aux:N } @@ -757,24 +963,24 @@ \cs_new:Npn \__cooking_units_parse_input_for_safety_aux:N #1 { \tl_if_in:NnTF \l__cooking_units_input_digits_tl {#1} - { \tl_put_right:Nn \l_tmpa_tl {#1} } + { \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} } { - \tl_if_in:NnTF \l__cooking_units_decimal_mark_tl {#1} + \tl_if_in:NnTF \l__cooking_units_input_decimal_mark_tl {#1} { \bool_if:NT \l__cooking_units_decimal_in_input_bool { \msg_error:nn { cooking-units } - { Second - decimal -sign - not - allowed } + { Second-decimal-sign-not-allowed } } \bool_set_true:N \l__cooking_units_decimal_in_input_bool - \tl_put_right:Nn \l_tmpa_tl { . } + \tl_put_right:Nn \l__cooking_units_tmpa_tl { . } }{ - \tl_if_in:NnTF \l__cooking_units_allowed_special_signs_tl {#1} + \tl_if_in:NnTF \l__cooking_units_input_allowed_special_signs_tl {#1} { \bool_set_true:N \l__cooking_units_special_sign_bool - \tl_put_right:Nn \l_tmpa_tl {#1} + \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} }{ - \bool_if:NTF \l__cooking_units_parse_range_bool + \bool_if:NTF \l__cooking_units_range_in_input_bool { \tl_if_in:nnTF { / _ } {#1} { \msg_error:nnn { cooking-units } { fraction-not-allowed-with-range } {#1} } @@ -790,39 +996,36 @@ } } } -\cs_new:Npn \__cooking_units_calculate_and_print_input:n #1 +\cs_new:Npn \__cooking_units_calculate_and_store_in:N #1 { - \bool_if:NTF \l__cooking_units_error_bool - {#1} + \bool_if:NF \l__cooking_units_error_bool { \bool_if:NTF \l__cooking_units_special_sign_bool { - \tl_set:Nf \l_tmpa_tl {#1} - \msg_warning:nnx { cooking-units } { amount-not-known } \l_tmpa_tl - } - { - \bool_if:nTF - { \l__cooking_units_using_cutext_bool && ! \l__cooking_units_cutext_change_unit_bool } - { \tl_set:Nf \l_tmpa_tl {#1} } - { \__cooking_units_calculate_input_and_store_in:nN {#1} \l_tmpa_tl } - \bool_if:NT \l__cooking_units_calc_persons_tmp_bool - { \__cooking_units_calc_for_number_of_persons_and_store_in:NN \l_tmpa_tl \l_tmpa_tl } - \__cooking_units_round_calculated_input:NV \l_tmpa_tl \l_tmpa_tl - \__cooking_units_check_temperature_limit:N \l_tmpa_tl + \tl_set_eq:NN \l__cooking_units_tmpa_tl #1 + \msg_warning:nnx { cooking-units } { amount-not-known } \l__cooking_units_tmpa_tl + }{ + \bool_lazy_and:nnTF + { \l__cooking_units_using_cutext_bool } { ! \l__cooking_units_cutext_change_unit_bool } + { \tl_set_eq:NN \l__cooking_units_tmpa_tl #1 } + { \__cooking_units_calculate_input_and_store_in:nN {#1} \l__cooking_units_tmpa_tl } + \bool_if:NT \l__cooking_units_calc_persons_bool + { \__cooking_units_calc_for_number_of_persons_and_store_in:NN \l__cooking_units_tmpa_tl \l__cooking_units_tmpa_tl } + \__cooking_units_round_calculated_input:NV \l__cooking_units_tmpa_tl \l__cooking_units_tmpa_tl + \__cooking_units_check_temperature_limit:N \l__cooking_units_tmpa_tl } - \__cooking_units_print_output:N \l_tmpa_tl + \tl_set_eq:NN #1 \l__cooking_units_tmpa_tl } } -\cs_generate_variant:Nn \__cooking_units_calculate_and_print_input:n { N } \cs_new:Npn \__cooking_units_calculate_input_and_store_in:nN #1#2 { - \fp_set:Nn \l_tmpa_fp {#1} - \tl_if_in:cnTF { l__cooking_units_tmpa_ \l__cooking_units_tmp_unit_tl _ tl } { \l_tmpa_fp } + \fp_set:Nn \l__cooking_units_tmpa_fp {#1} + \tl_if_in:cnTF { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } { \l__cooking_units_tmpa_fp } { - \__cooking_units_tl_set_fp_and_eval:Nc #2 { l__cooking_units_tmpa_ \l__cooking_units_tmp_unit_tl _ tl } + \__cooking_units_tl_set_fp_and_eval:Nc #2 { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } }{ \__cooking_units_tl_set_fp_and_eval:Nn #2 - { \l_tmpa_fp * \tl_use:c { l__cooking_units_tmpa_ \l__cooking_units_tmp_unit_tl _ tl } } + { \l__cooking_units_tmpa_fp * \tl_use:c { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } } } } \cs_new:Npn \__cooking_units_calc_for_number_of_persons_and_store_in:NN #1#2 @@ -830,18 +1033,19 @@ \int_compare:nNnF { \l__cooking_units_calc_for_number_of_persons_int } = - { \l__cooking_units_persons_tmp_int } + { \l__cooking_units_number_of_persons_tmpa_int } { \__cooking_units_tl_set_fp_and_eval:Nn #1 { \l__cooking_units_calc_for_number_of_persons_int / - \l__cooking_units_persons_tmp_int * + \l__cooking_units_number_of_persons_tmpa_int * #2 } } } -\cs_new:Npn \__cooking_units_check_number_after_dot:n #1 +\cs_new:Npn \__cooking_units_check_number_for_rounding:n #1 { + \bool_set_false:N \l__cooking_units_round_decimal_part_bool \__cooking_units_check_number_after_dot_aux:w #1 . \q_recursion_tail . \q_recursion_stop } @@ -851,43 +1055,63 @@ \bool_if:NTF \l__cooking_units_round_to_int_bool { \int_zero:N \l_tmpa_int } { \int_set_eq:NN \l_tmpa_int \l__cooking_units_significant_figures_plus_one_int } - \int_compare:nNnTF + \int_compare:nNnF { \tl_count:n {#2} } < { \l_tmpa_int } - { \bool_set_false:N \l_tmpa_bool } - { \bool_set_true:N \l_tmpa_bool } + { \bool_set_true:N \l__cooking_units_round_decimal_part_bool } \use_none_delimit_by_q_recursion_stop:w } \cs_new:Npn \__cooking_units_round_calculated_input:NN #1#2 { - \__cooking_units_check_number_after_dot:n {#2} - \tl_set:Nf #1 + \__cooking_units_check_number_for_rounding:n {#2} + \tl_set:Nx #1 { - \bool_if:NTF \l_tmpa_bool + \bool_if:NTF \l__cooking_units_round_decimal_part_bool { \fp_eval:n { round ( \__cooking_units_rounding_function:n {#2} ) } } {#2} } } \cs_generate_variant:Nn \__cooking_units_round_calculated_input:NN { NV } -\cs_new_protected:Npn \__cooking_units_print_output:N #1 +\cs_new_protected:Npn \__cooking_units_print_input:N #1 { } +\cs_new_protected:Npn \__cooking_units_print_correct_unit: { } +\cs_new_protected:Npn \__cooking_units_do_not_process_input:NN #1#2 { } +\cs_new_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN +\cs_new_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_do_not_process_input:NN +\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cunum: { - \bool_if:NTF \l__cooking_units_using_cutext_bool - { - \tl_set_eq:NN \l__cooking_units_cutext_tmp_tl #1 - \__cooking_units_cutext_print_output:NV #1 \l__cooking_units_option_unit_tl - } - { \__cooking_units_print_nummerical_output:N #1 } + \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_print_numerical_input:N + \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cunum_print_correct_unit: + \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN + \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_do_not_process_input:NN + } +\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cutext: + { + \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_cutext_print_input:N + \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cutext_print_correct_unitname: + \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_cutext_pre_process_input:NN + \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_cutext_post_process_input:NN + } +\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cuam: + { + \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_cuam_print_numerical_input:N + \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cuam_print_correct_unitphrase: + \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN + \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_cuam_post_process_input:NN } -\cs_new_protected:Npn \__cooking_units_print_nummerical_output:N #1 +\cs_new_protected:Npn \__cooking_units_print_numerical_input:N #1 { - \translatelet \l__cooking_units_translation_tmpa_tl { decimal-mark ( cu-unitname ) } - \tl_replace_once:NnV #1 { . } \l__cooking_units_translation_tmpa_tl - \tl_replace_once:NnV #1 { - } \c__cooking_units_minus_tl + \tl_if_in:NnT #1 { . } + { + \__cooking_units_translate_let:Nxx \l__cooking_units_translation_tmpa_tl + { decimal-mark } \c__cooking_units_postfix_unitname_tl + \tl_replace_once:Nnn #1 { . } { \l__cooking_units_translation_tmpa_tl } + } + \tl_if_in:NnT #1 { - } + { \tl_replace_once:NnV #1 { - } \c__cooking_units_minus_tl } #1 } -\cs_new:Npn \__cooking_units_formatiere_fractions:nNN #1#2#3 +\cs_new:Npn \__cooking_units_formatiere_fractions:nnn #1#2#3 { - \bool_set_true:N \l__cooking_units_fraction_in_input_bool - \bool_if:NT \l_tmpb_bool { \c__cooking_units_minus_tl } + \bool_if:NT \l__cooking_units_minus_bool { \c__cooking_units_minus_tl } \tl_if_empty:nF {#1} { #1 @@ -899,13 +1123,13 @@ { \bool_if:NT \l__cooking_units_check_temperature_bool { - \clist_if_in:NVT \l__cooking_units_temperatures_to_check_clist \l__cooking_units_option_unit_tl + \seq_if_in:NVT \l__cooking_units_temperatures_to_check_seq \l__cooking_units_option_unit_tl { \fp_compare:cNnT { c__cooking_units_ \l__cooking_units_option_unit_tl _min_fp } > {#1} { \msg_error:nnxx { cooking-units } - { Temperature-to-low } + { Temperature-too-low } { #1 \space \l__cooking_units_option_unit_tl } { \fp_use:c { c__cooking_units_ \l__cooking_units_option_unit_tl _min_fp } @@ -914,43 +1138,77 @@ } } } - } + } +\cs_new_nopar:Npn \__cooking_units_grab_arrows_for_safety_do_afterwards:nN #1#2 + { + \str_if_eq:nnTF {#2} { > } + { + \tl_put_right:Nx \l__cooking_units_tmpa_tl { \tl_to_str:N > } + \exp_last_unbraced:NV #1 \l__cooking_units_tmpa_tl + }{ + \tl_put_right:Nn \l__cooking_units_tmpa_tl {#2} + \__cooking_units_grab_arrows_for_safety_do_afterwards:nN {#1} + } + } +\cs_new_nopar:Npn \__cooking_units_if_arrow_grab_until_close_do:nnTF #1#2#3#4 + { + \str_if_eq:nnTF {#1} { < } + { + \tl_if_in:NoT \l__cooking_units_input_allowed_special_signs_tl { < } + { \msg_error:nn {cooking-units} { <-not-allowed-as-special-sign } } + \tl_clear:N \l__cooking_units_tmpa_tl + \tl_put_right:Nx \l__cooking_units_tmpa_tl { \tl_to_str:N < } + \__cooking_units_grab_arrows_for_safety_do_afterwards:nN + {#3} #2 + } + {#4} + } \NewDocumentCommand \cunum { d<> O{} m O{} m } { - \group_begin: + \__cooking_units_if_arrow_grab_until_close_do:nnTF {#3} {#5} + { \cunum } + { + \group_begin: + \__cooking_units_cunum:nnnnn {#1} {#2} {#3} {#4} {#5} + \group_end: + } + } +\cs_new:Npn \__cooking_units_cunum:nnnnn #1#2#3#4#5 + { \__cooking_units_cunum_initialise:nnnnn {#1} {#2} {#3} {#4} {#5} - \bool_if:NTF \l__cooking_units_parse_input_bool - { \__cooking_units_parse_and_evaluate_input:n {#3} } - { \__cooking_units_cunum_do_not_parse:nnn {#3} {#4} {#5} } - \__cooking_units_cunum_print_correct_unit:nVV {#4} \l__cooking_units_option_unit_tl \l__cooking_units_tmp_unit_tl - \group_end: + \__cooking_units_cunum_parse_numerical_input:n {#3} + \__cooking_units_print_correct_unit: } \cs_new_protected:Npn \__cooking_units_cunum_initialise:nnnnn #1#2#3#4#5 { + \__cooking_units_set_process_and_print_for_cunum: + \tl_set:Nn \l__cooking_units_phantom_tl {#4} \__cooking_units_initialise_default:nnn {#1} {#2} {#5} \__cooking_units_initialise_unit_change:nnn {#1} {#2} {#5} - \__cooking_units_initialise_after_unit_change:nnn {#1} {#2} {#5} + \__cooking_units_initialise_after_unit_change:nn {#1} {#2} } \cs_new_protected:Npn \__cooking_units_initialise_default:nnn #1#2#3 { - \tl_set:Nn \l__cooking_units_tmp_unit_tl {#3} - \__cooking_units_error_if_unit_not_defined:V \l__cooking_units_tmp_unit_tl + \tl_set:Nn \l__cooking_units_given_unit_tl {#3} + \__cooking_units_error_if_unit_not_defined:V \l__cooking_units_given_unit_tl \bool_set_false:N \l__cooking_units_special_sign_bool \bool_set_false:N \l__cooking_units_error_bool - \bool_set_false:N \l__cooking_units_parse_range_bool + \bool_set_false:N \l__cooking_units_range_in_input_bool + \bool_set_false:N \l__cooking_units_fraction_in_input_bool } -\cs_generate_variant:Nn \__cooking_units_initialise_default:nnn { nnV} \cs_new_protected:Npn \__cooking_units_initialise_unit_change:nnn #1#2#3 { \tl_if_empty:nF {#2} - { \keys_set_groups:nnn { cooking-units } { change-unit } {#2} } - \bool_if:NT \l__cooking_units_convert_to_eV_bool - { \__cooking_units_convert_to_eV: } - \prop_get:NVN \l__cooking_units_change_unit_prop \l__cooking_units_tmp_unit_tl \l__cooking_units_option_unit_tl - \quark_if_no_value:NT \l__cooking_units_option_unit_tl - { \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_tmp_unit_tl } + { + \keys_set_groups:nnn { cooking-units } { change-unit } {#2} + } + \bool_if:NT \l__cooking_units_convert_to_eV_bool { \__cooking_units_convert_to_eV: } + \prop_get:NVNF \l__cooking_units_change_unit_prop \l__cooking_units_given_unit_tl \l__cooking_units_option_unit_tl + { + \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl + } } -\cs_new_protected:Npn \__cooking_units_initialise_after_unit_change:nnn #1#2#3 +\cs_new_protected:Npn \__cooking_units_initialise_after_unit_change:nn #1#2 { \IfNoValueF {#1} { \__cooking_units_reference_label_and_persons:n {#1} } @@ -963,130 +1221,571 @@ } \tl_if_empty:nF {#2} { \keys_set_filter:nnn { cooking-units } { change-unit } {#2} } - \bool_set:Nn \l__cooking_units_calc_persons_tmp_bool - { \l__cooking_units_calc_because_ref_was_given_bool && \l__cooking_units_calc_for_persons_bool } + \bool_lazy_and:nnTF + { \l__cooking_units_calc_because_ref_was_given_bool } { \l__cooking_units_calc_for_persons_bool } + { \bool_set_true:N \l__cooking_units_calc_persons_bool } + { \bool_set_false:N \l__cooking_units_calc_persons_bool } + } +\cs_new:Npn \__cooking_units_cunum_parse_numerical_input:n #1 + { + \bool_if:NTF \l__cooking_units_parse_input_bool + { \__cooking_units_parse_and_evaluate_input:n {#1} } + { \__cooking_units_do_not_parse:n {#1} } } -\cs_new:Npn \__cooking_units_cunum_do_not_parse:nnn #1#2#3 +\cs_new:Npn \__cooking_units_do_not_parse:n #1 { - \tl_set_rescan:Nnn \l_tmpa_tl + \tl_set_rescan:Nnn \l__cooking_units_number_tmpa_tl { \char_set_catcode_letter:N \_ % \char_set_catcode_ignore:N \ % } {#1} - \l_tmpa_tl + \l__cooking_units_number_tmpa_tl } \cs_new:Npn \__cooking_units_parse_and_evaluate_input:n #1 { - \tl_set_rescan:Nnn \l_tmpa_tl + \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl { \char_set_catcode_letter:N \_ % \char_set_catcode_ignore:N \ % \char_set_catcode_other:N ? % } {#1} - \tl_if_empty:VF \l_tmpa_tl + \tl_if_empty:NF \l__cooking_units_tmpa_tl { - \tl_if_in:NVT \l_tmpa_tl \l__cooking_units_input_range_sign_tl + \tl_if_in:NVT \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { - \tl_replace_once:NVn \l_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } - \bool_set_true:N \l__cooking_units_parse_range_bool + \tl_replace_once:NVn \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } + \bool_set_true:N \l__cooking_units_range_in_input_bool } - \__cooking_units_cunum_parse_input:V \l_tmpa_tl + \__cooking_units_parse_input:V \l__cooking_units_tmpa_tl } } -\cs_new:Npn \__cooking_units_cunum_print_correct_unit:nnn #1#2#3 +\cs_new:Npn \__cooking_units_cunum_print_correct_unit: { - \tl_if_empty:nF {#1} { \phantom {#1} } + \tl_if_empty:NF \l__cooking_units_phantom_tl { \phantom { \l__cooking_units_phantom_tl } } \tl_use:N \l__cooking_units_value_unit_space_tl - \bool_if:nTF + \bool_lazy_any:nTF { - ! \l__cooking_units_parse_input_bool || - \l__cooking_units_fraction_in_input_bool || - \l__cooking_units_special_sign_bool + { \l__cooking_units_fraction_in_input_bool } + { \l__cooking_units_special_sign_bool } + { ! \l__cooking_units_parse_input_bool } } - { \translate { #3 ( cu-unit ) } } - { \translate { #2 ( cu-unit ) } } + { \__cooking_units_translate:xx \l__cooking_units_given_unit_tl \c__cooking_units_postfix_unit_tl } + { \__cooking_units_translate:xx \l__cooking_units_option_unit_tl \c__cooking_units_postfix_unit_tl } } -\cs_generate_variant:Nn \__cooking_units_cunum_print_correct_unit:nnn { nVV } -\NewDocumentCommand \cudefinekeys { m m } +\NewDocumentCommand \cutext { d<> O{} m m } { - \bool_set_false:N \l__cooking_units_single_key_bool - \__cooking_units_cukeys_define_keys_and_single_keys:nn {#1} {#2} + \__cooking_units_if_arrow_grab_until_close_do:nnTF {#3} {#4} + { \cutext } + { + \group_begin: + \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4} + \bool_set_false:N \l__cooking_units_cutext_uppercase_word_bool + \__cooking_units_cutext_do:nnnn {#1} {#2} {#3} {#4} + \group_end: + } } -\NewDocumentCommand \cudefinesinglekey { m m } +\NewDocumentCommand \Cutext { d<> O{} m m } { - \bool_set_true:N \l__cooking_units_single_key_bool - \__cooking_units_cukeys_define_keys_and_single_keys:nn {#1} {#2} + \__cooking_units_if_arrow_grab_until_close_do:nnTF {#3} {#4} + { \Cutext } + { + \group_begin: + \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4} + \bool_set_true:N \l__cooking_units_cutext_uppercase_word_bool + \__cooking_units_cutext_do:nnnn {#1} {#2} {#3} {#4} + \group_end: + } } -\cs_new:Npn \__cooking_units_cukeys_define_keys_and_single_keys:nn #1#2 +\cs_new_protected:Npn \__cooking_units_cutext_initialise:nnn #1#2#3 { - \__cooking_units_error_if_unit_not_defined:n {#1} - \tl_if_blank:nF {#2} + \bool_set_true:N \l__cooking_units_using_cutext_bool + \__cooking_units_set_process_and_print_for_cutext: + \__cooking_units_initialise_default:nnn {#1} {#2} {#3} + \bool_if:NTF \l__cooking_units_cutext_change_unit_bool + { \__cooking_units_initialise_unit_change:nnn {#1} {#2} {#3} } + { \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl } + \__cooking_units_initialise_after_unit_change:nn {#1} {#2} + } +\cs_new:Npn \__cooking_units_cutext_do:nnnn #1#2#3#4 + { + \bool_if:NTF \l__cooking_units_cutext_to_cunum_bool + { \cunum <#1> [#2] {#3} {#4} } { - \clist_clear:N \l_tmpa_clist - \prop_clear:N \l_tmpa_prop - \bool_if:NTF \l__cooking_units_single_key_bool + \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4} + } + } +\cs_new:Npn \__cooking_units_cutext:nnnn #1#2#3#4 + { + \bool_if:NTF \l__cooking_units_parse_input_bool + { + \bool_if:NTF \l__cooking_units_cutext_old_bool { - \__cooking_units_cukeys_parse_and_create_single_key:nn {#1} {#2} + \__cooking_units_old_cutext_default:nnn {#2} {#3} {#4} + \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl + \__cooking_units_cutext_print_correct_unitname: }{ - \fp_set_eq:NN \l_tmpa_fp \c_one_fp - \tl_set:Nn \l__cooking_units_tmp_unit_tl {#1} - \__cooking_units_cukeys_parse_and_create_keys:nn {#1} + \__cooking_units_parse_and_evaluate_input:n {#3} + \__cooking_units_print_correct_unit: + } + }{ + \__cooking_units_do_not_parse:n {#3} + \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl + \__cooking_units_cutext_print_correct_unitname: + } + } +\prg_new_conditional:Npnn \__cooking_units_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:N #1 { TF } + { + \bool_lazy_and:nnTF + { \g__cooking_units_opt_numeral_bool } + { \l__cooking_units_local_numeral_bool } + { + \__cooking_units_if_parse_and_integer:VTF #1 + { + \int_compare:nNnTF {#1} < { \l__cooking_units_print_numerals_below_int } + { \prg_return_true: } + { \prg_return_false: } + }{ \prg_return_false: } + }{ \prg_return_false: } + } +\cs_new_protected:Npn \__cooking_units_cutext_print_input:Nn #1#2 + { + \__cooking_units_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:NTF #1 + { + \__cooking_units_int_if_equal_one:nTF {#1} + { + \__cooking_units_translate_one_to_and_check_existance:Nx \l__cooking_units_translation_tmpa_tl {#2} + \bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool { - {#1} { \c_one_fp } #2 + \exp_args:Nx \tl_upper_case:n { \tl_head:V \l__cooking_units_translation_tmpa_tl } + \tl_tail:V \l__cooking_units_translation_tmpa_tl } + { \l__cooking_units_translation_tmpa_tl } + }{ + \bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool + { \__cooking_units_print_Numeral:n {#1} } + { \__cooking_units_print_numeral:n {#1} } } } + { \__cooking_units_print_numerical_input:N #1 } } -\cs_new:Npn \__cooking_units_cukeys_parse_and_create_keys:nn #1#2 +\cs_generate_variant:Nn \__cooking_units_cutext_print_input:Nn { NV } +\cs_new_protected:Npn \__cooking_units_cutext_print_input:N #1 + { \__cooking_units_cutext_print_input:NV #1 \l__cooking_units_option_unit_tl } +\cs_new:Npn \__cooking_units_cutext_print_correct_unitname: { - \__cooking_units_cukeys_parse_input:nn #2 - \q_recursion_tail \q_recursion_tail \q_recursion_stop - \__cooking_units_cukeys_create_key_prop:n {#1} - \__cooking_units_cukeys_define_keys:V \l_tmpa_clist + \l__cooking_units_cutext_space_tl + \bool_lazy_any:nTF + { + { \l__cooking_units_fraction_in_input_bool } + { \l__cooking_units_special_sign_bool } + { ! \l__cooking_units_parse_input_bool } + } + { \__cooking_units_translate:xx \l__cooking_units_given_unit_tl \c__cooking_units_postfix_unitname_pl_tl } + { + \__cooking_units_fp_if_equal_one:nTF { \l__cooking_units_cutext_last_value_tl } + { \__cooking_units_translate:xx \l__cooking_units_option_unit_tl \c__cooking_units_postfix_unitname_tl } + { \__cooking_units_translate:xx \l__cooking_units_option_unit_tl \c__cooking_units_postfix_unitname_pl_tl } + } } -\cs_new:Npn \__cooking_units_cukeys_parse_input:nn #1#2 +\cs_new:Npn \__cooking_units_cutext_pre_process_input: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 } } - \__cooking_units_error_if_unit_not_defined:n {#1} - \clist_put_right:Nn \l_tmpa_clist {#1} - \prop_put:Nnx \l_tmpa_prop {#1} { \fp_eval:n { #2 / \l_tmpa_fp } } - \__cooking_units_cukeys_parse_input:nn + \__cooking_units_cutext_check_unitname_consequences:NN #1#2 } -\cs_new:Npn \__cooking_units_cukeys_create_key_prop:n #1 +\cs_new:Npn \__cooking_units_cutext_post_process_input:NN #1#2 { - \prop_clear:N \l_tmpb_prop - \prop_put:NnV \l_tmpb_prop { Liste } \l_tmpa_clist - \prop_put:NnV \l_tmpb_prop { prop } \l_tmpa_prop - \prop_put:NnV \l_tmpb_prop { Erstes Ding } \l__cooking_units_tmp_unit_tl - \clist_map_inline:Nn \l_tmpa_clist + \bool_if:NTF \l__cooking_units_range_in_input_bool { - \prop_set_eq:cN { l__cooking_units_cukeys_ ##1 _prop } \l_tmpb_prop - \tl_set_eq:cN { l__cooking_units_tmpa_ ##1 _tl } \c_one_fp - \clist_map_inline:Nn \l_tmpa_clist + \tl_set_eq:NN \l__cooking_units_cutext_last_value_tl #2 + \bool_if:NT \g__cooking_units_opt_numeral_bool { - \prop_put:cnx { l__cooking_units_cukeys_ ##1 _prop } - {####1} - { - \fp_eval:n - { \prop_item:Nn \l_tmpa_prop {####1} / \prop_item:Nn \l_tmpa_prop {##1} } - } + \bool_lazy_and:nnF + { \fp_compare_p:nNn {#1} < { \l__cooking_units_print_numerals_below_int } } + { \fp_compare_p:nNn {#2} < { \l__cooking_units_print_numerals_below_int } } + { \bool_set_false:N \l__cooking_units_local_numeral_bool } } } + { \tl_set_eq:NN \l__cooking_units_cutext_last_value_tl #1 } } -\cs_new:Npn \__cooking_units_cukeys_define_keys:N #1 +\cs_new:Npn \__cooking_units_cutext_check_unitname_consequences:NN #1#2 { - \clist_map_inline:Nn \l_tmpa_clist - { - \clist_put_right:Nn \l__cooking_units_list_of_defined_keys_clist {##1} - \keys_define:nn { cooking-units } - { - ##1 .choices:Vn = - \l_tmpa_clist - { - \__cooking_units_cukeys_define_keys_and_single_key_aux:n {##1} - } , + \bool_lazy_any:nTF + { + { \l__cooking_units_fraction_in_input_bool } + { \l__cooking_units_special_sign_bool } + { ! \l__cooking_units_parse_input_bool } + } + { \tl_set_eq:NN \l__cooking_units_tmpb_tl \l__cooking_units_given_unit_tl } + { \tl_set_eq:NN \l__cooking_units_tmpb_tl \l__cooking_units_option_unit_tl } + \__cooking_units_unitname_get:NxF \l__cooking_units_tmpa_tl \l__cooking_units_tmpb_tl + { + \msg_warning:nnx + { cooking-units } + { cutext-no-translation-available } + \l__cooking_units_tmpb_tl + \bool_set_false:N \l__cooking_units_using_cutext_bool + \__cooking_units_set_process_and_print_for_cunum: + } + } +\cs_new:Npn \__cooking_units_old_cutext_default:nnn #1#2#3 + { + \bool_if:NTF \l__cooking_units_parse_input_bool + { + \tl_set:Nn \l__cooking_units_cutext_last_value_tl {#2} + \tl_if_in:NVTF \l__cooking_units_cutext_last_value_tl \l__cooking_units_input_range_sign_tl + { + \tl_replace_once:NVn \l__cooking_units_cutext_last_value_tl + \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } + \__cooking_units_old_cutext_parse_range:Vn \l__cooking_units_cutext_last_value_tl {#3} + }{ + \__cooking_units_cutext_print_input:Nn \l__cooking_units_cutext_last_value_tl {#3} + } + } + {#2} + } +\cs_new:Npn \__cooking_units_old_cutext_parse_range:Nn #1 #2 + { + \__cooking_units_old_cutext_parse_range_aux:nww {#2} #1 \q_stop + } +\cs_generate_variant:Nn \__cooking_units_old_cutext_parse_range:Nn { V } +\cs_new:Npn \__cooking_units_old_cutext_parse_range_aux:nww #1 #2 \q__cooking_units_range #3 \q_stop + { + \tl_set:Nn \l__cooking_units_tmpa_tl {#2} + \tl_set:Nn \l__cooking_units_cutext_last_value_tl {#3} + \__cooking_units_cutext_print_input:Nn \l__cooking_units_tmpa_tl {#1} + \tl_use:N \l__cooking_units_cutext_range_sign_tl + \__cooking_units_cutext_print_input:Nn \l__cooking_units_cutext_last_value_tl {#1} + } +\tl_const:Nn \c__cooking_units_cuam_marker_tl { __cooking_units_cunum } +\tl_new:c { l__cooking_units_tmpa_ \c__cooking_units_cuam_marker_tl _ tl } +\tl_set:cn { l__cooking_units_tmpa_ \c__cooking_units_cuam_marker_tl _ tl } { \c_one_fp } +\clist_new:c { l__cooking_units_predefined_option_ \c__cooking_units_cuam_marker_tl _clist } +\NewDocumentCommand \cuam { d<> O{} m } + { + \__cooking_units_if_arrow_grab_until_close_do:nnTF {#3} { } + { \cuam } + { + \group_begin: + \__cooking_units_cuam_initialise:nn {#1} {#2} + \__cooking_units_cuam:n {#3} + \group_end: + } + } +\cs_new:Npn \__cooking_units_cuam:n #1 + { + \bool_if:NTF \l__cooking_units_parse_input_bool + { + \bool_if:NTF \l__cooking_units_cuam_old_bool + { \__cooking_units_cuam_old:n {#1} } + { + \__cooking_units_parse_and_evaluate_input:n {#1} + \__cooking_units_print_correct_unit: + } + } + { \__cooking_units_do_not_parse:n {#1} } + } +\cs_new_protected:Npn \__cooking_units_cuam_initialise:nn #1#2 + { + \__cooking_units_set_process_and_print_for_cuam: + \tl_set_eq:NN \l__cooking_units_given_unit_tl \c__cooking_units_cuam_marker_tl + \tl_set_eq:NN \l__cooking_units_option_unit_tl \c__cooking_units_cuam_marker_tl + \__cooking_units_initialise_after_unit_change:nn {#1} {#2} + } +\cs_new_protected:Npn \__cooking_units_cuam_post_process_input:NN #1#2 + { + \__cooking_units_if_integer:VTF #1 + { \bool_set_true:N \l__cooking_units_tmpa_bool } + { \bool_set_false:N \l__cooking_units_tmpa_bool } + \bool_lazy_and:nnT + { \l__cooking_units_range_in_input_bool } { \l__cooking_units_tmpa_bool } + { + \__cooking_units_if_integer:VTF #2 + { \bool_set_true:N \l__cooking_units_tmpa_bool } + { \bool_set_false:N \l__cooking_units_tmpa_bool } + } + \bool_lazy_and:nnT + { \l__cooking_units_use_phrases_bool } { \l__cooking_units_tmpa_bool } + { + \__cooking_units_if_phrase_list_exists:NT \l__cooking_units_phrase_prop + { + \__cooking_units_translate_let:Nxx \l__cooking_units_phrase_numbers_clist + { phrase-list-list } \c__cooking_units_postfix_phrase_tl + \__cooking_units_cuam_process_input_aux:NNN #1 \l__cooking_units_tmpa_int \l__cooking_units_phrase_number_tl + \bool_if:NT \l__cooking_units_check_if_phrase_used_bool + { + \bool_if:NTF \l__cooking_units_range_in_input_bool + { + \__cooking_units_cuam_process_input_aux:NNN #2 \l__cooking_units_tmpb_int \l__cooking_units_tmpb_tl + \bool_lazy_and:nnTF + { \l__cooking_units_check_if_phrase_used_bool } + { \tl_if_eq_p:NN \l__cooking_units_phrase_number_tl \l__cooking_units_tmpb_tl } + { \bool_set_true:N \l__cooking_units_check_if_phrase_used_bool } + { \bool_set_false:N \l__cooking_units_check_if_phrase_used_bool } + \bool_if:NT \l__cooking_units_check_if_phrase_used_bool + { + \tl_set:NV #1 \l__cooking_units_tmpa_int + \tl_set:NV #2 \l__cooking_units_tmpb_int + \__cooking_units_cuam_get_phrase_name:NVN + \l__cooking_units_phrase_phrase_tl \l__cooking_units_phrase_number_tl \l__cooking_units_tmpb_int + } + }{ + \tl_set:NV #1 \l__cooking_units_tmpa_int + \__cooking_units_cuam_get_phrase_name:NVN + \l__cooking_units_phrase_phrase_tl \l__cooking_units_phrase_number_tl \l__cooking_units_tmpa_int + } + } + } + } + \bool_lazy_and:nnT + { \g__cooking_units_opt_numeral_bool } { \l__cooking_units_local_numeral_bool } + { + \bool_set_eq:NN \l__cooking_units_local_numeral_bool \l__cooking_units_tmpa_bool + \bool_if:NT \l__cooking_units_local_numeral_bool + { + \bool_if:NTF \l__cooking_units_range_in_input_bool + { + \bool_lazy_and:nnF + { \int_compare_p:nNn {#1} < { \l__cooking_units_print_numerals_below_int } } + { \int_compare_p:nNn {#2} < { \l__cooking_units_print_numerals_below_int } } + { \bool_set_false:N \l__cooking_units_local_numeral_bool } + }{ + \int_compare:nNnF {#1} < { \l__cooking_units_print_numerals_below_int } + { \bool_set_false:N \l__cooking_units_local_numeral_bool } + } + } + } + } +\prg_new_conditional:Npnn \__cooking_units_cuam_check_if_larger:nn #1#2 { F } + { + \int_compare:nNnTF {#1} > {#2} + { \prg_return_true: } + { \prg_return_false: } + } +\cs_new:Npn \__cooking_units_cuam_process_input_aux:NNN #1#2#3 + { + \bool_set_false:N \l__cooking_units_check_if_phrase_used_bool + \clist_map_inline:Nn \l__cooking_units_phrase_numbers_clist + { + \__cooking_units_cuam_check_if_larger:nnF { \int_abs:n {##1} } {#1} + { + \int_compare:nNnTF {##1} < { \c_zero } + { \int_set_eq:NN \l_tmpa_int \c_one } + { \int_set:Nn \l_tmpa_int { \int_div_truncate:nn {#1} {##1} } } + \int_compare:nNnT { \int_abs:n {##1} * \l_tmpa_int } = {#1} + { + \int_set_eq:NN #2 \l_tmpa_int + \tl_set:Nn #3 {##1} + \bool_set_true:N \l__cooking_units_check_if_phrase_used_bool + \clist_map_break: + } + } + } + } +\cs_new:Npn \__cooking_units_cuam_get_phrase_name:NnN #1#2#3 + { + \__cooking_units_int_if_equal_one:nTF {#3} + { \prop_get:NnN \l__cooking_units_phrase_prop {#2} #1 } + { \prop_get:NnN \l__cooking_units_phrase_prop { #2-pl } #1 } + } +\cs_generate_variant:Nn \__cooking_units_cuam_get_phrase_name:NnN { NVN } +\cs_new_protected:Npn \__cooking_units_cuam_print_numerical_input:N #1 + { + \bool_lazy_all:nTF + { + { \l__cooking_units_check_if_phrase_used_bool } + { \g__cooking_units_opt_numeral_bool } + { \l__cooking_units_local_numeral_bool } + }{ + \__cooking_units_int_if_equal_one:nTF {#1} + { + \__cooking_units_translate_one_to_and_check_existance:Nx \l__cooking_units_translation_tmpa_tl + { \l__cooking_units_phrase_number_tl -phrase-gender } + \l__cooking_units_translation_tmpa_tl + } + { \exp_args:NV \__cooking_units_print_numeral:n #1 } + }{ \__cooking_units_print_numerical_input:N #1 } + } +\cs_new:Npn \__cooking_units_cuam_print_correct_unitphrase: + { + \bool_if:NT \l__cooking_units_check_if_phrase_used_bool + { + \l__cooking_units_cuphrase_space_tl + \l__cooking_units_phrase_phrase_tl + } + } +\cs_new:Npn \__cooking_units_cuam_old:n #1 + { + \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N\ % + } {#1} + \__cooking_units_cuam_old_parse:V \l__cooking_units_tmpa_tl + } +\cs_new_protected:Npn \__cooking_units_cuam_old_parse:n #1 + { + \tl_if_in:nVTF {#1} \l__cooking_units_input_range_sign_tl + { + \tl_set:Nn \l__cooking_units_tmpa_tl {#1} + \tl_replace_once:NVn \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } + \__cooking_units_cuam_old_parse_range:V \l__cooking_units_tmpa_tl + }{ + \tl_if_in:nnTF {#1} { / } + { + \tl_if_in:nnTF {#1} { _ } + { \__cooking_units_cuam_old_parse_mixed_frac:www #1 \q_stop } + { \__cooking_units_cuam_old_parse_frac:ww #1 \q_stop } + }{ + \tl_if_in:nnTF {#1} { _ } + { \msg_error:nnn { cooking-units } { missing-slash } {#1} } + { \__cooking_units_cuam_old_parse_scale:n {#1} } + } + } + } +\cs_generate_variant:Nn \__cooking_units_cuam_old_parse:n { V } +\cs_new:Npn \__cooking_units_cuam_old_parse_range:n #1 + { + \__cooking_units_cuam_old_parse_range_aux:ww #1 \q_nil + } +\cs_generate_variant:Nn \__cooking_units_cuam_old_parse_range:n { V } +\cs_new:Npn \__cooking_units_cuam_old_parse_range_aux:ww #1 \q__cooking_units_range #2 \q_nil + { + #1 \l__cooking_units_cunum_range_sign_tl #2 + } +\cs_new:Npn \__cooking_units_cuam_old_parse_scale:n #1 {#1} +\cs_new:Npn \__cooking_units_cuam_old_parse_frac:ww #1/#2 \q_stop + { \__cooking_units_frac:nn {#1} {#2} } +\cs_new:Npn \__cooking_units_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop + { + #1 + \hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { } + \__cooking_units_frac:nn {#2} {#3} + } +\NewDocumentCommand \cufrac { O{} m } + { + \msg_error:nnnn { cooking-units } { obsolete-command } { \cufrac } { \cuam } + \group_begin: + \tl_if_empty:nF {#1} + { \keys_set:nn { cooking-units } {#1} } + \__cooking_units_cufrac:n {#2} + \group_end: + } +\cs_new:Npn \__cooking_units_cufrac:n #1 + { + \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N\ % + } {#1} + \__cooking_units_cufrac_parse:V \l__cooking_units_tmpa_tl + } +\cs_new:Npn \__cooking_units_cufrac_parse:n #1 + { + \tl_if_in:nnTF {#1} { / } + { + \tl_if_in:nnTF {#1} { _ } + { \__cooking_units_cufrac_parse_mixed_frac:www #1 \q_stop } + { \__cooking_units_cufrac_parse_frac:ww #1 \q_stop } + }{ + \tl_if_in:nnTF {#1} { _ } + { \msg_error:nnn { cooking-units } { missing-slash } {#1} } + { \__cooking_units_cufrac_parse_scale:n {#1} } + } + } +\cs_generate_variant:Nn \__cooking_units_cufrac_parse:n { V } +\cs_new:Npn \__cooking_units_cufrac_parse_scale:n #1 {#1} +\cs_new:Npn \__cooking_units_cufrac_parse_frac:ww #1/#2 \q_stop + { \__cooking_units_frac:nn {#1} {#2} } +\cs_new:Npn \__cooking_units_cufrac_parse_mixed_frac:www #1_#2/#3 \q_stop + { + #1 + \hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { } + \__cooking_units_frac:nn {#2} {#3} + } +\NewDocumentCommand \cudefinekeys { m m } + { + \bool_set_false:N \l__cooking_units_single_key_bool + \__cooking_units_cukeys_define_keys_and_single_keys:nn {#1} {#2} + } +\NewDocumentCommand \cudefinesinglekey { m m } + { + \bool_set_true:N \l__cooking_units_single_key_bool + \__cooking_units_cukeys_define_keys_and_single_keys:nn {#1} {#2} + } +\cs_new:Npn \__cooking_units_cukeys_define_keys_and_single_keys:nn #1#2 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \tl_if_blank:nF {#2} + { + \seq_clear:N \l__cooking_units_tmpa_seq + \prop_clear:N \l__cooking_units_tmpa_prop + \bool_if:NTF \l__cooking_units_single_key_bool + { + \__cooking_units_cukeys_parse_and_create_single_key:nn {#1} {#2} + }{ + \fp_set_eq:NN \l__cooking_units_tmpa_fp \c_one_fp + \tl_set:Nn \l__cooking_units_given_unit_tl {#1} + \__cooking_units_cukeys_parse_and_create_keys:nn {#1} + { + {#1} { \c_one_fp } #2 + } + } + } + } +\cs_new:Npn \__cooking_units_cukeys_parse_and_create_keys:nn #1#2 + { + \__cooking_units_cukeys_parse_input:nn #2 + \q_recursion_tail \q_recursion_tail \q_recursion_stop + \__cooking_units_cukeys_create_key_prop:n {#1} + \clist_set_from_seq:NN \l__cooking_units_tmpa_clist \l__cooking_units_tmpa_seq + \__cooking_units_cukeys_define_keys:V \l__cooking_units_tmpa_clist + } +\cs_new:Npn \__cooking_units_cukeys_parse_input: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 } } + \__cooking_units_error_if_unit_not_defined:n {#1} + \seq_put_right:Nn \l__cooking_units_tmpa_seq {#1} + \prop_put:Nnx \l__cooking_units_tmpa_prop {#1} { \fp_eval:n { (#2) / \l__cooking_units_tmpa_fp } } + \__cooking_units_cukeys_parse_input:nn + } +\cs_new:Npn \__cooking_units_cukeys_create_key_prop:n #1 + { + \prop_clear:N \l__cooking_units_tmpb_prop + \prop_put:NnV \l__cooking_units_tmpb_prop { Liste } \l__cooking_units_tmpa_seq + \prop_put:NnV \l__cooking_units_tmpb_prop { prop } \l__cooking_units_tmpa_prop + \prop_put:NnV \l__cooking_units_tmpb_prop { Erstes Ding } \l__cooking_units_given_unit_tl + \seq_map_inline:Nn \l__cooking_units_tmpa_seq + { + \prop_set_eq:cN { l__cooking_units_cukeys_ ##1 _prop } \l__cooking_units_tmpb_prop + \tl_set_eq:cN { l__cooking_units_tmpa_ ##1 _tl } \c_one_fp + \seq_map_inline:Nn \l__cooking_units_tmpa_seq + { + \prop_put:cnx { l__cooking_units_cukeys_ ##1 _prop } + {####1} + { + \fp_eval:n + { + ( \prop_item:Nn \l__cooking_units_tmpa_prop {####1} ) / + ( \prop_item:Nn \l__cooking_units_tmpa_prop {##1} ) + } + } + } + } + } +\cs_new:Npn \__cooking_units_cukeys_define_keys:N #1 + { + \seq_map_inline:Nn \l__cooking_units_tmpa_seq + { + \seq_if_in:NnF \l__cooking_units_list_of_defined_keys_seq {##1} + { \seq_put_right:Nn \l__cooking_units_list_of_defined_keys_seq {##1} } + \keys_define:nn { cooking-units } + { + ##1 .choices:Vn = + \l__cooking_units_tmpa_clist + { + \__cooking_units_cukeys_define_keys_and_single_key_aux:n {##1} + } , ##1 / unknown .code:n= { \seq_set_split:Nnn \l_tmpa_seq { , } {#1} @@ -1095,13 +1794,12 @@ { key-choice-unknown } {##1} {####1} - { \seq_use:Nnnn \l_tmpa_seq { ',' } { ',' } { ' ~ and ~ ' } } + { \seq_use:Nnnn \l_tmpa_seq { ',~ ' } { ',~ ' } { ' ~ and ~ ' } } } , ##1 .default:n = {##1} , ##1 .groups:n = { change-unit } } } - \clist_remove_duplicates:N \l__cooking_units_list_of_defined_keys_clist } \cs_generate_variant:Nn \__cooking_units_cukeys_define_keys:N { V } \cs_new:Npn \__cooking_units_cukeys_define_keys_and_single_key_aux:n #1 @@ -1114,14 +1812,15 @@ } \cs_new:Npn \__cooking_units_cukeys_parse_and_create_single_key:nn #1#2 { - \tl_set_rescan:Nnn \l_tmpa_tl + \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl { \char_set_catcode_letter:N \# % \char_set_catcode_ignore:N\ % } { {#1} { \c_one_fp } #2 } - \__cooking_units_cusinglekeys_parse_input:V \l_tmpa_tl + \__cooking_units_cusinglekeys_parse_input:V \l__cooking_units_tmpa_tl \__cooking_units_cusinglekeys_create_key_prop:n {#1} - \__cooking_units_cukeys_define_singlekey:nV {#1} \l_tmpa_clist + \clist_set_from_seq:NN \l__cooking_units_tmpa_clist \l__cooking_units_tmpa_seq + \__cooking_units_cukeys_define_singlekey:nV {#1} \l__cooking_units_tmpa_clist } \cs_new:Npn \__cooking_units_cusinglekeys_parse_input:n #1 { @@ -1135,27 +1834,28 @@ \quark_if_recursion_tail_stop_do:nn {#2} { \msg_error:nn { cooking-units } { missing-argument } } \__cooking_units_error_if_unit_not_defined:n {#1} - \clist_put_right:Nn \l_tmpa_clist {#1} - \tl_set:Nn \l_tmpa_tl {#2} - \tl_replace_all:NVn \l_tmpa_tl \c__cooking_units_str_hash_one_tl { \l_tmpa_fp } - \prop_put:NnV \l_tmpa_prop {#1} \l_tmpa_tl + \seq_put_right:Nn \l__cooking_units_tmpa_seq {#1} + \tl_set:Nn \l__cooking_units_tmpa_tl {#2} + \tl_replace_all:NVn \l__cooking_units_tmpa_tl \c__cooking_units_input_str_hash_one_tl { \l__cooking_units_tmpa_fp } + \prop_put:NnV \l__cooking_units_tmpa_prop {#1} \l__cooking_units_tmpa_tl \__cooking_units_cusinglekeys_parse_input_aux:nn } \cs_new:Npn \__cooking_units_cusinglekeys_create_key_prop:n #1 { \tl_set_eq:cN { l__cooking_units_tmpa_ #1 _tl } \c_one_fp - \prop_set_eq:cN { l__cooking_units_cukeys_ #1 _prop } \l_tmpa_prop + \prop_set_eq:cN { l__cooking_units_cukeys_ #1 _prop } \l__cooking_units_tmpa_prop \prop_put:cnn { l__cooking_units_cukeys_ #1 _prop } { Erstes Ding } {#1} - \prop_put:cnV { l__cooking_units_cukeys_ #1 _prop } { Liste } \l_tmpa_clist - \prop_put:cnV { l__cooking_units_cukeys_ #1 _prop } { prop } \l_tmpa_prop + \prop_put:cnV { l__cooking_units_cukeys_ #1 _prop } { Liste } \l__cooking_units_tmpa_seq + \prop_put:cnV { l__cooking_units_cukeys_ #1 _prop } { prop } \l__cooking_units_tmpa_prop } \cs_new:Npn \__cooking_units_cukeys_define_singlekey:nN #1#2 { - \clist_put_right:Nn \l__cooking_units_list_of_defined_keys_clist {#1} + \seq_if_in:NnF \l__cooking_units_list_of_defined_keys_seq {#1} + { \seq_put_right:Nn \l__cooking_units_list_of_defined_keys_seq {#1} } \keys_define:nn { cooking-units } { #1 .choices:Vn = - \l_tmpa_clist + \l__cooking_units_tmpa_clist { \__cooking_units_cukeys_define_keys_and_single_key_aux:n {#1} } , @@ -1172,35 +1872,34 @@ #1 .default:n = {#1} , #1 .groups:n = { change-unit } , } - \clist_remove_duplicates:N \l__cooking_units_list_of_defined_keys_clist } \cs_generate_variant:Nn \__cooking_units_cukeys_define_singlekey:nN { nV } \NewDocumentCommand \cuaddkeys { m m } { \bool_set_false:N \l__cooking_units_single_key_bool - \tl_set:Nn \l_tmpa_tl {#1} - \tl_set:Nn \l_tmpb_tl {#2} - \__cooking_units_cukeys_add_keys_or_single_keys:VV \l_tmpa_tl \l_tmpb_tl + \tl_set:Nn \l__cooking_units_tmpa_tl {#1} + \tl_set:Nn \l__cooking_units_tmpb_tl {#2} + \__cooking_units_cukeys_add_keys_or_single_keys:VV \l__cooking_units_tmpa_tl \l__cooking_units_tmpb_tl } \NewDocumentCommand \cuaddsinglekeys { m m } { \bool_set_true:N \l__cooking_units_single_key_bool - \tl_set:Nn \l_tmpa_tl {#1} - \tl_set:Nn \l_tmpb_tl {#2} - \__cooking_units_cukeys_add_keys_or_single_keys:VV \l_tmpa_tl \l_tmpb_tl + \tl_set:Nn \l__cooking_units_tmpa_tl {#1} + \tl_set:Nn \l__cooking_units_tmpb_tl {#2} + \__cooking_units_cukeys_add_keys_or_single_keys:VV \l__cooking_units_tmpa_tl \l__cooking_units_tmpb_tl } \NewDocumentCommand \cuaddtokeys { m m m } { \bool_set_false:N \l__cooking_units_single_key_bool - \tl_set:Nn \l_tmpa_tl {#1} - \tl_set:Nn \l_tmpb_tl { {#2} { \fp_eval:n { \c_one_fp / #3 } } } - \__cooking_units_cukeys_add_keys_or_single_keys:VV \l_tmpa_tl \l_tmpb_tl + \tl_set:Nn \l__cooking_units_tmpa_tl {#1} + \tl_set:Nn \l__cooking_units_tmpb_tl { {#2} { \fp_eval:n { \c_one_fp / (#3) } } } + \__cooking_units_cukeys_add_keys_or_single_keys:VV \l__cooking_units_tmpa_tl \l__cooking_units_tmpb_tl } \cs_new:Npn \__cooking_units_cukeys_add_keys_or_single_keys:nn #1#2 { \__cooking_units_error_if_unit_not_defined:n {#1} - \clist_if_in:NnF \l__cooking_units_list_of_defined_keys_clist {#1} - { \msg_error:nnn { cooking-units } { Key - not - defined } {#1} } + \seq_if_in:NnF \l__cooking_units_list_of_defined_keys_seq {#1} + { \msg_error:nnn { cooking-units } { Key-not-defined } {#1} } \tl_if_blank:nF {#2} { \__cooking_units_cukeys_add_keys_and_single_key_aux:n {#1} @@ -1212,14 +1911,14 @@ \cs_generate_variant:Nn \__cooking_units_cukeys_add_keys_or_single_keys:nn { VV } \cs_new:Npn \__cooking_units_cukeys_add_keys_and_single_key_aux:n #1 { - \prop_get:cnN { l__cooking_units_cukeys_ #1 _prop } { Liste } \l_tmpa_clist - \prop_get:cnN { l__cooking_units_cukeys_ #1 _prop } { prop } \l_tmpa_prop - \prop_get:cnN { l__cooking_units_cukeys_ #1 _prop } { Erstes Ding } \l__cooking_units_tmp_unit_tl - \prop_get:cVN { l__cooking_units_cukeys_ #1 _prop } \l__cooking_units_tmp_unit_tl \l_tmpa_fp + \prop_get:cnN { l__cooking_units_cukeys_ #1 _prop } { Liste } \l__cooking_units_tmpa_seq + \prop_get:cnN { l__cooking_units_cukeys_ #1 _prop } { prop } \l__cooking_units_tmpa_prop + \prop_get:cnN { l__cooking_units_cukeys_ #1 _prop } { Erstes Ding } \l__cooking_units_given_unit_tl + \prop_get:cVN { l__cooking_units_cukeys_ #1 _prop } \l__cooking_units_given_unit_tl \l__cooking_units_tmpa_fp } \NewDocumentCommand \declarecookingunit { o m } { - \clist_if_in:NnTF \g__cooking_units_list_of_defined_units_clist {#2} + \seq_if_in:NnTF \g__cooking_units_list_of_defined_units_seq {#2} { \msg_info:nnn { cooking-units } { redefine-unit } {#2} } { \__cooking_units_new_cooking_unit:nn {#1} {#2} } \__cooking_units_set_cooking_unit:nn {#1} {#2} @@ -1231,7 +1930,7 @@ } \NewDocumentCommand \providecookingunit { o m } { - \clist_if_in:NnF \g__cooking_units_list_of_defined_units_clist {#2} + \seq_if_in:NnF \g__cooking_units_list_of_defined_units_seq {#2} { \__cooking_units_new_cooking_unit:nn {#1} {#2} \__cooking_units_set_cooking_unit:nn {#1} {#2} @@ -1239,10 +1938,10 @@ } \cs_new:Npn \__cooking_units_new_cooking_unit:nn #1#2 { - \clist_if_in:NnTF \g__cooking_units_list_of_defined_units_clist {#2} + \seq_if_in:NnTF \g__cooking_units_list_of_defined_units_seq {#2} { \msg_error:nnn { cooking-units } { unit-already-defined } {#2} } { - \clist_put_right:Nn \g__cooking_units_list_of_defined_units_clist {#2} + \seq_put_right:Nn \g__cooking_units_list_of_defined_units_seq {#2} \tl_new:c { l__cooking_units_tmpa_ #2 _tl } \tl_set_eq:cN { l__cooking_units_tmpa_ #2 _tl } \c_one_fp \clist_new:c { l__cooking_units_predefined_option_#2_clist } @@ -1253,287 +1952,90 @@ { \clist_put_right:cn { l__cooking_units_predefined_option_#2_clist } {##1} }, } \prop_new:c { l__cooking_units_cukeys_ #2 _prop } - \tl_new:c { l__cooking_units_cu_unit_ #2 _tl } + \tl_new:c { l__cooking_units_default_unit_ #2 _tl } } } \cs_new:Npn \__cooking_units_set_cooking_unit:nn #1#2 { \IfNoValueTF {#1} { - \tl_set:cn { l__cooking_units_cu_unit_ #2 _tl } {#2} - \deftranslation { #2 ( cu-unit ) } {#2} + \tl_set:cn { l__cooking_units_default_unit_ #2 _tl } {#2} + \__cooking_units_deftranslation_base:xxn {#2} \c__cooking_units_postfix_unit_tl {#2} }{ - \tl_set:cn { l__cooking_units_cu_unit_ #2 _tl } {#1} - \deftranslation { #2 ( cu-unit ) } {#1} + \tl_set:cn { l__cooking_units_default_unit_ #2 _tl } {#1} + \__cooking_units_deftranslation_base:xxn {#2} \c__cooking_units_postfix_unit_tl {#1} } - } -\NewDocumentCommand \cutext { d<> O{} m m } - { - \group_begin: - \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4} - \bool_if:NTF \l__cooking_units_cutext_to_cunum_bool - { \cunum {#3} {#4} } + \__cooking_units_deftranslation_base:xxn {#2} \c__cooking_units_postfix_unitname_tl { \q__cooking_units_no_translation } + \__cooking_units_deftranslation_base:xxn {#2} \c__cooking_units_postfix_unitname_pl_tl { \q__cooking_units_no_translation } + \__cooking_units_deftranslation_base:xxn {#2} \c__cooking_units_postfix_gender_tl { m } + } +\tl_new:N \l__cooking_units_sanitise_tl +\cs_new_protected:Npn \__cooking_units_sanitise_aux:w #1 \q_mark + { \tl_set:Nn \l__cooking_units_sanitise_tl {#1} } +\group_begin: + \char_set_catcode_active:n { `\< } + \char_set_catcode_active:n { `\> } + \cs_new:Npn \__cooking_units_sanitize_open_arrow: + { + \exp_after:wN \__cooking_units_sanitize_open_arrow_auxi:w \l__cooking_units_sanitise_tl + \q_mark < \q_nil < + \exp_after:wN \__cooking_units_sanitise_aux:w \l__cooking_units_sanitise_tl + } + \cs_new_protected:Npn \__cooking_units_sanitize_open_arrow_auxi:w #1 < + { + \tl_set:Nn \l__cooking_units_sanitise_tl {#1} + \__cooking_units_sanitize_open_arrow_auxii:w + } + \cs_new_protected:Npn \__cooking_units_sanitize_open_arrow_auxii:w #1 < + { + \quark_if_nil:nF {#1} { - \bool_set_false:N \l__cooking_units_cutext_uppercase_word_bool - \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4} + \tl_set:Nx \l__cooking_units_sanitise_tl + { + \exp_not:V \l__cooking_units_sanitise_tl + \token_to_str:N < + \exp_not:n {#1} + } + \exp_after:wN \__cooking_units_sanitize_open_arrow_auxii:w } - \group_end: - } -\NewDocumentCommand \Cutext { d<> O{} m m } - { - \group_begin: - \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4} - \bool_if:NTF \l__cooking_units_cutext_to_cunum_bool - { \cunum {#3} {#4} } + } + \cs_new:Npn \__cooking_units_sanitize_close_arrow: + { + \exp_after:wN \__cooking_units_sanitize_close_arrow_auxi:w \l__cooking_units_sanitise_tl + \q_mark > \q_nil > + \exp_after:wN \__cooking_units_sanitise_aux:w \l__cooking_units_sanitise_tl + } + \cs_new_protected:Npn \__cooking_units_sanitize_close_arrow_auxi:w #1 > + { + \tl_set:Nn \l__cooking_units_sanitise_tl {#1} + \__cooking_units_sanitize_close_arrow_auxii:w + } + \cs_new_protected:Npn \__cooking_units_sanitize_close_arrow_auxii:w #1 > + { + \quark_if_nil:nF {#1} { - \bool_set_true:N \l__cooking_units_cutext_uppercase_word_bool - \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4} + \tl_set:Nx \l__cooking_units_sanitise_tl + { + \exp_not:V \l__cooking_units_sanitise_tl + \token_to_str:N > + \exp_not:n {#1} + } + \exp_after:wN \__cooking_units_sanitize_close_arrow_auxii:w } - \group_end: - } -\cs_new_protected:Npn \__cooking_units_cutext_initialise:nnn #1#2#3 - { - \bool_set_true:N \l__cooking_units_using_cutext_bool - \__cooking_units_initialise_default:nnn {#1} {#2} {#3} - \bool_if:NTF \l__cooking_units_cutext_change_unit_bool - { \__cooking_units_initialise_unit_change:nnn {#1} {#2} {#3} } - { \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_tmp_unit_tl } - \__cooking_units_initialise_after_unit_change:nnn {#1} {#2} {#3} - } -\cs_new:Npn \__cooking_units_cutext:nnnn #1#2#3#4 - { - \bool_if:nTF { \l__cooking_units_cutext_old_bool || !\l__cooking_units_parse_input_bool } - { - \__cooking_units_cutext_default:nnn {#2} {#3} {#4} - \__cooking_units_cutext_print_correct_unitname:nnn {#3} {#4} {#4} - }{ - \__cooking_units_parse_and_evaluate_input:n {#3} - \__cooking_units_cutext_print_correct_unitname:VVV - \l__cooking_units_cutext_tmp_tl \l__cooking_units_option_unit_tl \l__cooking_units_tmp_unit_tl - } - } -\cs_new:Npn \__cooking_units_cutext_default:nnn #1#2#3 - { - \__cooking_units_error_if_unit_not_defined:n {#3} - \bool_if:NT \l__cooking_units_convert_to_eV_bool - { \__cooking_units_convert_to_eV: } - \bool_if:NTF \l__cooking_units_parse_input_bool - { - \tl_set:Nn \l_tmpb_tl {#2} - \tl_if_in:NVTF \l_tmpb_tl \l__cooking_units_input_range_sign_tl - { - \tl_replace_once:NVn \l_tmpb_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } - \__cooking_units_cutext_parse_range:Vn \l_tmpb_tl {#3} - }{ - \__cooking_units_cutext_print_output:Nn \l_tmpb_tl {#3} - } - } - {#2} - } -\cs_new:Npn \__cooking_units_cutext_parse_range:Nn #1 #2 - { - \__cooking_units_cutext_parse_range_aux:nww {#2} #1 \q_stop - } -\cs_generate_variant:Nn \__cooking_units_cutext_parse_range:Nn { V } -\cs_new:Npn \__cooking_units_cutext_parse_range_aux:nww #1 #2 \q__cooking_units_range #3 \q_stop - { - \tl_set:Nn \l__cooking_units_tmpa_tl {#2} - \tl_set:Nn \l__cooking_units_tmpb_tl {#3} - \__cooking_units_cutext_print_output:Nn \l__cooking_units_tmpa_tl {#1} - \tl_use:N \l__cooking_units_cutext_range_sign_tl - \__cooking_units_cutext_print_output:Nn \l__cooking_units_tmpb_tl {#1} - } -\cs_new_protected:Npn \__cooking_units_cutext_print_output:Nn #1#2 - { - \bool_if:NTF \g__cooking_units_load_if_opt_numeral_bool - { - \__cooking_units_if_integer_and_parse:VTF #1 - { - \fp_compare:nNnTF {#1} < { \l__cooking_units_print_numerals_below_int } - { - \fp_compare:nNnTF {#1} = { \c_one_fp } - { - \translatelet \l__cooking_units_translation_tmpa_tl { #2 (cu-unitgender) } - \translatelet \l__cooking_units_translation_tmpa_tl - { one (\l__cooking_units_translation_tmpa_tl) (cu-unitname) } - \bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool - { - \exp_args:Nf \tl_to_uppercase:n { \tl_head:V \l__cooking_units_translation_tmpa_tl } - \tl_tail:V \l__cooking_units_translation_tmpa_tl - } - { \l__cooking_units_translation_tmpa_tl } - }{ - \bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool - { \Numberstringnum {#1} } - { \numberstringnum {#1} } - } - }{ \__cooking_units_print_nummerical_output:N #1 } - }{ \__cooking_units_print_nummerical_output:N #1 } - } - { \__cooking_units_print_nummerical_output:N #1 } - } -\cs_generate_variant:Nn \__cooking_units_cutext_print_output:Nn { NV } -\cs_new:Npn \__cooking_units_cutext_print_correct_unitname:nnn #1#2#3 - { - \l__cooking_units_cutext_space_tl - \bool_if:nTF - { - ! \l__cooking_units_parse_input_bool || - \l__cooking_units_fraction_in_input_bool || - \l__cooking_units_special_sign_bool - } - { \translate { #3 (cu-unitname pl) } } - { - \__cooking_units_if_integer:nTF {#1} - { - \fp_compare:nNnTF {#1} = { \c_one_fp } - { \translate { #2 (cu-unitname) } } - { \translate { #2 (cu-unitname pl) } } - } - { \translate { #2 (cu-unitname pl) } } - } - } -\cs_generate_variant:Nn \__cooking_units_cutext_print_correct_unitname:nnn { VVV } -\NewDocumentCommand \cufrac { O{} m } - { - \msg_error:nnnn { cooking-units } { obsolete-command } { \cufrac } { \cuam } - \group_begin: - \tl_if_empty:nF {#1} - { \keys_set:nn { cooking-units } {#1} } - \__cooking_units_cufrac:n {#2} - \group_end: - } -\cs_new:Npn \__cooking_units_cufrac:n #1 - { - \tl_set_rescan:Nnn \l_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N\ % - } {#1} - \__cooking_units_cufrac_parse:V \l_tmpa_tl - } -\cs_new:Npn \__cooking_units_cufrac_parse:n #1 - { - \tl_if_in:nnTF {#1} { / } - { - \tl_if_in:nnTF {#1} { _ } - { \__cooking_units_cufrac_parse_mixed_frac:www #1 \q_stop } - { \__cooking_units_cufrac_parse_frac:ww #1 \q_stop } - }{ - \tl_if_in:nnTF {#1} { _ } - { \msg_error:nnn { cooking-units } { missing-slash } {#1} } - { \__cooking_units_cufrac_parse_scale:n {#1} } - } - } -\cs_generate_variant:Nn \__cooking_units_cufrac_parse:n { V } -\cs_new:Npn \__cooking_units_cufrac_parse_scale:n #1 {#1} -\cs_new:Npn \__cooking_units_cufrac_parse_frac:ww #1/#2 \q_stop - { \__cooking_units_frac:nn {#1} {#2} } -\cs_new:Npn \__cooking_units_cufrac_parse_mixed_frac:www #1_#2/#3 \q_stop - { - #1 - \hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { } - \__cooking_units_frac:nn {#2} {#3} - } -\tl_new:N \l__cooking_units_cuam_marker_tl -\tl_set:Nn \l__cooking_units_cuam_marker_tl { __cooking_units_cunum } -\tl_new:c { l__cooking_units_tmpa_ \l__cooking_units_cuam_marker_tl _ tl } -\tl_set:cn { l__cooking_units_tmpa_ \l__cooking_units_cuam_marker_tl _ tl } { \c_one_fp } -\clist_new:c { l__cooking_units_predefined_option_ \l__cooking_units_cuam_marker_tl _clist } -\NewDocumentCommand \cuam { d<> O{} m } - { - \group_begin: - \__cooking_units_cuam_initialise:nnn {#1} {#2} {} - \bool_if:NTF \l__cooking_units_parse_input_bool - { - \bool_if:NTF \l__cooking_units_cuam_old_bool - { \__cooking_units_cuam_old:n {#3} } - { \__cooking_units_parse_and_evaluate_input:n {#3} } - } - { \__cooking_units_cunum_do_not_parse:nnn {#3} {} {} } - \group_end: - } -\cs_new_protected:Npn \__cooking_units_cuam_initialise:nnn #1#2#3 - { - \tl_set_eq:NN \l__cooking_units_tmp_unit_tl \l__cooking_units_cuam_marker_tl - \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_cuam_marker_tl - \__cooking_units_initialise_after_unit_change:nnn {#1} {#2} {#3} - } -\cs_new:Npn \__cooking_units_cuam:n #1 - { - \tl_set_rescan:Nnn \l_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N \ % - \char_set_catcode_other:N ? % - } {#1} - \__cooking_units_cuam_parse:V \l_tmpa_tl - } -\cs_new:Npn \__cooking_units_cuam_old:n #1 - { - \tl_set_rescan:Nnn \l_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N\ % - } {#1} - \__cooking_units_cuam_old_parse:V \l_tmpa_tl - } -\cs_new_protected:Npn \__cooking_units_cuam_old_parse:n #1 - { - \tl_if_in:nVTF {#1} \l__cooking_units_input_range_sign_tl - { - \tl_set:Nn \l_tmpa_tl {#1} - \tl_replace_once:NVn \l_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } - \__cooking_units_cuam_old_parse_range:V \l_tmpa_tl - }{ - \tl_if_in:nnTF {#1} { / } - { - \tl_if_in:nnTF {#1} { _ } - { \__cooking_units_cuam_old_parse_mixed_frac:www #1 \q_stop } - { \__cooking_units_cuam_old_parse_frac:ww #1 \q_stop } - }{ - \tl_if_in:nnTF {#1} { _ } - { \msg_error:nnn { cooking-units } { missing-slash } {#1} } - { \__cooking_units_cuam_old_parse_scale:n {#1} } - } - } - } -\cs_generate_variant:Nn \__cooking_units_cuam_old_parse:n { V } -\cs_new:Npn \__cooking_units_cuam_parse_range:n #1 - { - \__cooking_units_cuam_parse_range_aux:ww #1 \q_nil - } -\cs_generate_variant:Nn \__cooking_units_cuam_parse_range:n { V } -\cs_new:Npn \__cooking_units_cuam_parse_range_aux:ww #1 \q__cooking_units_range #2 \q_nil - { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l_tmpa_tl - \__cooking_units_parse_input_and_safe_in:nN {#2} \l_tmpb_tl - \__cooking_units_print_nummerical_output:N \l_tmpa_tl - \l__cooking_units_cunum_range_sign_tl - \__cooking_units_print_nummerical_output:N \l_tmpb_tl - } -\cs_new:Npn \__cooking_units_cuam_old_parse_range:n #1 - { - \__cooking_units_cuam_old_parse_range_aux:ww #1 \q_nil - } -\cs_generate_variant:Nn \__cooking_units_cuam_old_parse_range:n { V } -\cs_new:Npn \__cooking_units_cuam_old_parse_range_aux:ww #1 \q__cooking_units_range #2 \q_nil - { - #1 \l__cooking_units_cunum_range_sign_tl #2 - } -\cs_new:Npn \__cooking_units_cuam_old_parse_scale:n #1 {#1} -\cs_new:Npn \__cooking_units_cuam_old_parse_frac:ww #1/#2 \q_stop - { \__cooking_units_frac:nn {#1} {#2} } -\cs_new:Npn \__cooking_units_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop + } +\group_end: +\cs_new_protected:Npn \__cooking_units_sanitize_arrows:n #1 { - #1 - \hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { } - \__cooking_units_frac:nn {#2} {#3} + \tl_set:Nn \l__cooking_units_sanitise_tl {#1} + \__cooking_units_sanitize_open_arrow: + \__cooking_units_sanitize_close_arrow: } \NewDocumentCommand \cudefinename { m m } { \tl_set:Nn \l__cooking_units_language_tl {#1} - \__cooking_units_cuname_parse_input:n #2 + \__cooking_units_sanitize_arrows:n {#2} + \exp_last_unbraced:NV + \__cooking_units_cuname_parse_input:n \l__cooking_units_sanitise_tl \q_recursion_tail \q_recursion_tail \q_recursion_stop } \cs_new:Npn \__cooking_units_cuname_parse_input:n #1 @@ -1542,7 +2044,7 @@ { \__cooking_units_cuname_parse_unit_symbol:nw {#1} }{ - \clist_if_in:NnTF \g__cooking_units_allowed_unit_phrases_clist {#1} + \clist_if_in:NnTF \g__cooking_units_allowed_special_keys_clist {#1} { \__cooking_units_cuname_parse_input_aux:nn {#1} } { \__cooking_units_cuname_parse_unit_symbol:nw {#1} [ \q_no_value ] } } @@ -1555,11 +2057,14 @@ \__cooking_units_error_if_unit_not_defined:n {#1} \quark_if_no_value:nTF {#2} { - \__cooking_units_deftranslation:Vnv - \l__cooking_units_language_tl { #1 ( cu-unit ) } { l__cooking_units_cu_unit_ #1 _tl } - } - { - \__cooking_units_deftranslation:Vnn \l__cooking_units_language_tl { #1 ( cu-unit ) } {#2} + \__cooking_units_deftranslation_to:Vxxv + \l__cooking_units_language_tl {#1} + \c__cooking_units_postfix_unit_tl + { l__cooking_units_default_unit_ #1 _tl } + }{ + \__cooking_units_deftranslation_to:Vxxn + \l__cooking_units_language_tl {#1} + \c__cooking_units_postfix_unit_tl {#2} } \__cooking_units_cuname_parse_input_aux:nn {#1} } @@ -1568,26 +2073,32 @@ \quark_if_recursion_tail_stop:n {#1} \quark_if_recursion_tail_stop_do:nn {#2} { \msg_error:nn { cooking-units } { missing-argument } } - \clist_if_in:NnF \g__cooking_units_allowed_unit_phrases_clist {#1} + \clist_if_in:NnF \g__cooking_units_allowed_special_keys_clist {#1} { \__cooking_units_error_if_unit_not_defined:n {#1} } - \__cooking_units_deftranslation:Vnn \l__cooking_units_language_tl { #1 ( cu-unitname ) } {#2} + \__cooking_units_deftranslation_to:Vxxn + \l__cooking_units_language_tl {#1} + \c__cooking_units_postfix_unitname_tl {#2} \peek_meaning_ignore_spaces:NTF [ { \__cooking_units_cuname_parse_bracket:nw {#1} } { \__cooking_units_cuname_parse_bracket:nw {#1} [#2] } } \cs_new:Npn \__cooking_units_cuname_parse_bracket:nw #1 [#2] { - \clist_if_in:NnF \g__cooking_units_allowed_unit_phrases_clist {#1} + \clist_if_in:NnF \g__cooking_units_allowed_special_keys_clist {#1} { - \__cooking_units_deftranslation:Vnn \l__cooking_units_language_tl { #1 ( cu-unitname pl ) } {#2} + \__cooking_units_deftranslation_to:Vxxn \l__cooking_units_language_tl {#1} + \c__cooking_units_postfix_unitname_pl_tl {#2} } \peek_meaning_ignore_spaces:NTF < - { \__cooking_units_cuname_parse_arrows:nw {#1} } - { \__cooking_units_cuname_parse_arrows:nw {#1} } + { \__cooking_units_cuname_parse_gender:nw {#1} } + { \__cooking_units_cuname_parse_gender:nw {#1} } } -\cs_new:Npn \__cooking_units_cuname_parse_arrows:nw #1 <#2> +\cs_new:Npn \__cooking_units_cuname_parse_gender:nw #1 <#2> { - \__cooking_units_deftranslation:Vnn \l__cooking_units_language_tl { #1 ( cu-unitgender ) } {#2} + \__cooking_units_check_if_correct_gender_input:n {#2} + \__cooking_units_deftranslation_to:Vxxn + \l__cooking_units_language_tl {#1} + \c__cooking_units_postfix_gender_tl {#2} \__cooking_units_cuname_parse_input:n } \NewDocumentCommand \cudefinesymbol { m m } @@ -1601,15 +2112,120 @@ \quark_if_recursion_tail_stop:n {#1} \quark_if_recursion_tail_stop_do:nn {#2} { \msg_error:nn { cooking-units } { missing-argument } } - \clist_if_in:NnTF \g__cooking_units_allowed_unit_phrases_clist {#1} + \clist_if_in:NnTF \g__cooking_units_allowed_special_keys_clist {#1} { - \__cooking_units_deftranslation:Vnn \l__cooking_units_language_tl { #1 ( cu-unitname ) } {#2} + \__cooking_units_deftranslation_to:Vxxn \l__cooking_units_language_tl {#1} + \c__cooking_units_postfix_unitname_tl {#2} }{ \__cooking_units_error_if_unit_not_defined:n {#1} - \__cooking_units_deftranslation:Vnn \l__cooking_units_language_tl { #1 ( cu-unit ) } {#2} + \__cooking_units_deftranslation_to:Vxxn + \l__cooking_units_language_tl {#1} + \c__cooking_units_postfix_unit_tl {#2} } \__cooking_units_cuprint_define_printed_unit:nn } +\__cooking_units_newtranslation_base:nVn { phrase-list } \c__cooking_units_postfix_phrase_tl { \q__cooking_units_no_translation } +\prg_new_conditional:Npnn \__cooking_units_phrase_list_get_for:NN #1#2 { TF , T , F } + { + \__cooking_units_translate_let:VNxx #2 #1 { phrase-list } \c__cooking_units_postfix_phrase_tl + \tl_if_eq:NNTF #1 \q__cooking_units_no_translation + { \prg_return_false: } + { \prg_return_true: } + } +\prg_new_conditional:Npnn \__cooking_units_if_phrase_list_exists:N #1 { TF , T , F } + { + \__cooking_units_translate_let:Nxx \l_tmpa_tl { phrase-list } \c__cooking_units_postfix_phrase_tl + \tl_if_eq:NNTF \l_tmpa_tl \q__cooking_units_no_translation + { \prg_return_false: } + { \prg_return_true: } + } +\NewDocumentCommand \cudefinephrase { m m } + { + \__cooking_units_cuphrase:nn {#1} {#2} + } +\cs_new:Npn \__cooking_units_cuphrase:nn #1#2 + { + \tl_set:Nn \l__cooking_units_language_tl {#1} + \__cooking_units_phrase_list_get_for:NNTF \l__cooking_units_phrase_prop \l__cooking_units_language_tl + { + \__cooking_units_translate_let:VNxx \l__cooking_units_language_tl \l__cooking_units_phrase_numbers_clist + { phrase-list-list } \c__cooking_units_postfix_phrase_tl + }{ + \prop_clear:N \l__cooking_units_phrase_prop + \clist_clear:N \l__cooking_units_phrase_numbers_clist + } + \__cooking_units_sanitize_arrows:n {#2} + \exp_last_unbraced:NV + \__cooking_units_cuphrase_parse:n \l__cooking_units_sanitise_tl + \q_recursion_tail \q_recursion_tail \q_recursion_stop + \clist_sort:Nn \l__cooking_units_phrase_numbers_clist + { + \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: } + } + } + \__cooking_units_deftranslation_to:VxxV + \l__cooking_units_language_tl { phrase-list } + \c__cooking_units_postfix_phrase_tl + \l__cooking_units_phrase_prop + \__cooking_units_deftranslation_to:VxxV + \l__cooking_units_language_tl { phrase-list-list } + \c__cooking_units_postfix_phrase_tl \l__cooking_units_phrase_numbers_clist + } +\cs_new:Npn \__cooking_units_cuphrase_parse:n #1 + { + \quark_if_recursion_tail_stop:n {#1} + \__cooking_units_if_integer:nF {#1} + { \msg_error:nnn { cooking-units} { phrase-unit-not-an-integer } {#1} } + \peek_meaning_remove_ignore_spaces:NTF * + { + \int_set:Nn \l__cooking_units_tmpa_int {-#1} + \__cooking_units_cuphrase_parse_normal:Vn \l__cooking_units_tmpa_int + }{ + \int_set:Nn \l__cooking_units_tmpa_int {#1} + \__cooking_units_cuphrase_parse_normal:Vn \l__cooking_units_tmpa_int + } + } +\cs_new:Npn \__cooking_units_cuphrase_parse_normal:nn #1#2 + { + \quark_if_recursion_tail_stop_do:nn {#2} + { \msg_error:nn { cooking-units } { missing-argument } } + \prop_put:Nnn \l__cooking_units_phrase_prop {#1} {#2} + \clist_if_in:NnF \l__cooking_units_phrase_numbers_clist {#1} + { \clist_put_right:Nn \l__cooking_units_phrase_numbers_clist {#1} } + \peek_meaning_ignore_spaces:NTF [ + { + \__cooking_units_chuphrase_parse_plural:nw {#1} + }{ + \__cooking_units_chuphrase_parse_plural:nw {#1} [#2] + } + } +\cs_generate_variant:Nn \__cooking_units_cuphrase_parse_normal:nn { V } +\cs_new:Npn \__cooking_units_chuphrase_parse_plural:nw #1 [#2] + { + \prop_put:Nnn \l__cooking_units_phrase_prop { #1-pl } {#2} + \peek_meaning_ignore_spaces:NTF < + { + \__cooking_units_chuphrase_parse_gender:nw {#1} + }{ + \__cooking_units_chuphrase_parse_gender:nw {#1} < m > + } + } +\cs_new:Npn \__cooking_units_chuphrase_parse_gender:nw #1 <#2> + { + \__cooking_units_check_if_correct_gender_input:n {#2} + \__cooking_units_deftranslation_to:Vxxn + \l__cooking_units_language_tl { #1-phrase-gender } + \c__cooking_units_postfix_gender_tl {#2} + \__cooking_units_cuphrase_parse:n + } \NewDocumentCommand \cusetup { m } { \keys_set:nn { cooking-units } {#1} @@ -1619,9 +2235,10 @@ \newcookingunit { g } \newcookingunit { oz } \newcookingunit { lb } +\newcookingunit { stick } \newcookingunit [ \ensuremath{ \__cooking_units_frac:nn { eV } { c^2 } } ] { eVc-2 } -\newcookingunit [ \ensuremath{ {} ^ { \circ } } \kern-\scriptspace C ] { C } \newcookingunit { K } +\newcookingunit [ \ensuremath{ {} ^ { \circ } } \kern-\scriptspace C ] { C } \newcookingunit [ \ensuremath{ {} ^ { \circ } } \kern-\scriptspace F ] { F } \newcookingunit [ \ensuremath{ {} ^ { \circ } } \kern-\scriptspace R\'{e} ] { Re } \newcookingunit { d } @@ -1652,6 +2269,7 @@ \newcookingunit [ csp. ] { csp } %% coffeespoonful \newcookingunit [ dsp. ] { dsp } \newcookingunit [ Msp. ] { Msp } +\DeclareLanguageAlias { AmericanEnglish } { American } \cudefinename { German } { { kg } { Kilogramm } < n > @@ -1698,6 +2316,7 @@ { g } { gramme } { oz } { ounce } { lb } { pound } [ pounds ] + { stick } { stick } [ sticks ] { d } { day } [ days ] { h } { hour } [ hours ] { min } { minute } [ minutes ] @@ -1720,10 +2339,9 @@ { J } { joule } [ joules ] { kJ } { kilojoule } [ kilojoules ] { eV } { electron \space volt } - { Msp } { Messerspitze } [ Messerspitzen ] { pn } [ pinch ] { pinch } [ pinches ] - { EL } [ tsp. ] { tablespoon } [ tablespoons ] - { TL } [ tbsp. ] { teaspoon } [ teaspoons ] + { EL } [ tbsp. ] { tablespoon } [ tablespoons ] + { TL } [ tsp. ] { teaspoon } [ teaspoons ] { dsp } { dessertspoonful } { csp } { coffeespoonful } { ssp } { saltspoonful } @@ -1747,7 +2365,6 @@ { dl } { deciliter } [ deciliters ] { cl } { centiliter } [ centiliters ] { ml } { milliliter } [ milliliters ] - { Msp } { Messerspitze } [ Messerspitzen ] { pn } [ pn. ] { pinch } [ pinches ] } \cudefinename { French } @@ -1792,7 +2409,8 @@ { dag }{ 100 } { g } { 1000 } { oz } { 35.27399 } - { lb } { 2.204 622 6 } %% 2.204 622 6 + { lb } { 2.2046226 } %% 2.204 622 6 + { stick } { 8.81849 } { eVc-2 } { 560958865.0e+27 } %% 560958865.0 +- 3.5 e+27 } \cudefinekeys { d } @@ -1853,6 +2471,10 @@ { F } { #1 * 2.25 + 32 } { eV } { ( #1 * 1.25 + 273.15 ) * \c__cooking_units_kb_eV_fp } } +\cudefinephrase { German } + { + { 12 } { Dutzend } < n > + } \cusetup { set-option-for-F = { round-to-int = true } , -- cgit v1.2.3