summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/cooking-units
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2020-01-14 21:51:33 +0000
committerKarl Berry <karl@freefriends.org>2020-01-14 21:51:33 +0000
commitbcd1523ef07b4671135bdc8b1961aa3cfdfcc589 (patch)
treed7ce5496685c7d5e9fed0c993711ee37ba92c088 /Master/texmf-dist/tex/latex/cooking-units
parent6e22c006247027a26bc4392e13189a761a5a775b (diff)
cooking-units (14jan20)
git-svn-id: svn://tug.org/texlive/trunk@53403 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/cooking-units')
-rw-r--r--Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty1159
1 files changed, 725 insertions, 434 deletions
diff --git a/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty b/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
index 5b8bb0d6a80..f0f5dd527d3 100644
--- a/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
+++ b/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
@@ -5,14 +5,14 @@
%% The original source files were:
%%
%% cooking-units.dtx (with options: `package')
-%% Copyright (C) 2016--2018 by Ben Vitecek (current Maintainer)
+%% Copyright (C) 2016--2020 by Ben Vitecek (current Maintainer)
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. The latest version of this license is in:
%%
-%% https://ctan.org/license/lppl1.3c
+%% https://www.latex-project.org/lppl/
%%
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2008-05-04 or later.
@@ -30,8 +30,8 @@
{ \RequirePackage {expl3} }
\ProvidesExplPackage
{cooking-units}
- {2018/09/24}
- {1.45}
+ {2020/01/13}
+ {1.46}
{Ein Paket fuer Kocheinheiten}
\@ifpackagelater { expl3 } { 2018/08/23 }
{ }
@@ -57,11 +57,25 @@
}
\tex_endinput:D
}
+\msg_new:nnnn { cooking-units } { Option-deprecated }
+ {
+ The \ option \ '#1' \ is \ deprecated \ and \ should \ be \
+ replaced \ by \ '#2'.
+ }{
+ Please \ replace \ the \ option.
+ \msg_see_documentation_text:n { cooking-units }
+ }
\bool_new:N \g__cookingunits_opt_numeral_bool
\keys_define:nn { cooking-units }
{
- use-numerals .bool_gset:N = \g__cookingunits_opt_numeral_bool ,
+ use-numerals .code:n =
+ {
+ \msg_warning:nnnn { cooking-units } { Option-deprecated } { use-numerals } { use-fmtcount-numerals }
+ \keys_set:nn { cooking-units } { use-fmtcount-numerals = #1 }
+ } ,
use-numerals .default:n = { false },
+ use-fmtcount-numerals .bool_gset:N = \g__cookingunits_opt_numeral_bool ,
+ use-fmtcount-numerals .default:n = { false },
}
\ProcessKeysOptions { cooking-units }
\bool_if:NT \g__cookingunits_opt_numeral_bool
@@ -70,7 +84,12 @@
}
\keys_define:nn { cooking-units }
{
- use-numerals .code:n = { \msg_error:nnn { cooking-units } { load-time-option } { fmtcount } } ,
+ use-numerals .code:n =
+ {
+ \msg_warning:nnnn { cooking-units } { Option-deprecated } { use-numerals } { use-fmtcount-numerals }
+ \msg_error:nnn { cooking-units } { load-time-option } { fmtcount }
+ } ,
+ use-fmtcount-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 { NVn }
@@ -83,25 +102,26 @@
\cs_generate_variant:Nn \msg_error:nnnn { nnnV }
\cs_generate_variant:Nn \msg_error:nnn { nnV }
\cs_generate_variant:Nn \msg_warning:nnn { nnV }
-\cs_new:Npn \__cookingunits_dim_horizontal:N #1 { \tex_kern:D #1 }
+\cs_generate_variant:Nn \prop_put:Nnn { cnx }
\cs_new_eq:NN \__cookingunits_frac:nn \sfrac
\cs_new_eq:NN \__cookingunits_set_amount:Nn \tl_set:Nn
\cs_new_eq:NN \__cookingunits_set_unit:Nn \tl_set:Nn
-\cs_new:Npn \__cookingunits_print_numeral:n #1 { }
-\cs_new:Npn \__cookingunits_print_Numeral:n #1 { }
+\cs_new:Npn \__cookingunits_print_numeral:n #1
+ { \msg_error:nnn {cooking-units} { define-numeral-function } }
+\cs_new:Npn \__cookingunits_print_Numeral:n #1
+ { \msg_error:nnn {cooking-units} { define-Numeral-function } }
\bool_if:NT \g__cookingunits_opt_numeral_bool
{
\cs_set_eq:NN \__cookingunits_print_numeral:n \numberstringnum
\cs_set_eq:NN \__cookingunits_print_Numeral:n \Numberstringnum
}
\prop_new:N \l__cookingunits_change_unit_prop
+\prop_new:N \g__cookingunits_master_changer_prop
\tl_new:N \l__cookingunits_number_tmpa_tl
\tl_new:N \l__cookingunits_number_tmpb_tl
-\tl_new:N \l__cookingunits_tmpa_tl
-\tl_new:N \l__cookingunits_tmpb_tl
\tl_new:N \l__cookingunits_mixed_fraction_tl
-\tl_new:N \l__cookingunits_given_amount_tl
-\tl_new:N \l__cookingunits_given_unit_tl
+\tl_new:N \l__cookingunits_original_amount_tl
+\tl_new:N \l__cookingunits_original_unit_tl
\tl_new:N \l__cookingunits_option_unit_tl
\tl_new:N \l__cookingunits_language_tl
\tl_new:N \l__cookingunits_cunum_range_sign_tl
@@ -111,7 +131,7 @@
\tl_new:N \l__cookingunits_input_decimal_mark_tl
\tl_new:N \l__cookingunits_input_value_signs_tl
\tl_new:N \l__cookingunits_input_allowed_special_signs_tl
-\tl_new:N \c__cookingunits_input_str_hash_one_tl
+\tl_new:N \g__cookingunits_input_str_hash_one_tl
\tl_new:N \l__cookingunits_input_range_sign_tl
\tl_new:N \l__cookingunits_cutext_space_tl
\tl_new:N \l__cookingunits_cuphrase_space_tl
@@ -122,6 +142,8 @@
\tl_new:N \l__cookingunits_unit_letter_not_allowed_tl
\tl_new:N \l__cookingunits_input_fraction_sign_tl
\tl_new:N \l__cookingunits_input_mixed_fraction_sign_tl
+\tl_new:N \l__cookingunits_list_of_units_tl
+\tl_new:N \l__cookingunits_list_of_values_tl
\tl_new:N \l__cookingunits_cunum_hook_tl
\tl_new:N \l__cookingunits_cutext_hook_tl
\tl_new:N \l__cookingunits_Cutext_hook_tl
@@ -133,10 +155,10 @@
\tl_set:Nn \l__cookingunits_input_decimal_mark_tl { . , }
\tl_set:Nn \l__cookingunits_input_value_signs_tl { + - }
\tl_set:Nn \l__cookingunits_input_allowed_special_signs_tl { ? }
-\tl_set_rescan:Nnn \c__cookingunits_input_str_hash_one_tl
+\tl_gset_rescan:Nnn \g__cookingunits_input_str_hash_one_tl
{ \char_set_catcode_letter:N \# } {#1}
\tl_set:Nn \l__cookingunits_cunum_range_sign_tl { -- }
-\tl_set:Nn \l__cookingunits_cutext_range_sign_tl {}
+\tl_set:Nn \l__cookingunits_cutext_range_sign_tl { }
\tl_set:Nn \l__cookingunits_value_unit_space_tl { \thinspace }
\tl_set:Nn \l__cookingunits_cutext_space_tl { \space }
\tl_set:Nn \l__cookingunits_cuphrase_space_tl { \space }
@@ -177,13 +199,21 @@
\seq_new:N \g__cookingunits_list_of_defined_units_seq
\seq_new:N \g__cookingunits_allowed_special_keys_seq
\seq_new:N \l__cookingunits_phrase_numbers_seq
+\seq_new:N \l__cookingunits_number_of_iterations_seq
+\seq_new:N \l__cookingunits_derivative_unit_list_seq
+\seq_new:N \l__cookingunits_derivative_symbol_list_seq
+\seq_new:N \l__cookingunits_derivative_value_list_seq
+\int_new:N \l__cookingunits_max_depth_int
+\int_new:N \l__cookingunits_curr_depth_int
\seq_new:N \l__cookingunits_temperatures_to_check_seq
\seq_new:N \l__cookingunits_curef_do_not_change_seq
\prop_new:N \l__cookingunits_phrase_prop
\bool_new:N \l__cookingunits_minus_bool
\bool_new:N \l__cookingunits_round_number_bool
\bool_new:N \l__cookingunits_error_bool
+\bool_new:N \l__cookingunits_unit_error_bool
\bool_new:N \l__cookingunits_eval_fractions_bool
+\bool_new:N \l__cookingunits_convert_fractions_bool
\bool_new:N \l__cookingunits_draft_bool
\bool_new:N \l__cookingunits_round_to_int_bool
\bool_new:N \l__cookingunits_special_sign_bool
@@ -191,7 +221,6 @@
\bool_new:N \l__cookingunits_check_temperature_bool
\bool_new:N \l__cookingunits_convert_to_eV_bool
\bool_new:N \l__cookingunits_cutext_uppercase_word_bool
-\bool_new:N \l__cookingunits_error_for_unknown_value_bool
\bool_new:N \l__cookingunits_using_cutext_bool
\bool_new:N \l__cookingunits_cuam_old_bool
\bool_new:N \l__cookingunits_change_number_of_persons_bool
@@ -205,21 +234,20 @@
\bool_new:N \l__cookingunits_lokal_phrase_bool
\bool_new:N \l__cookingunits_print_numeral_bool
\bool_new:N \l__cookingunits_lokal_numeral_bool
-\bool_new:N \l__cookingunits_round_precision_positive_bool
+\bool_new:N \l__cookingunits_round_precision_negative_bool
\bool_new:N \l__cookingunits_fourty_two_bool
\bool_new:N \l__cookingunits_phrase_negative_bool
\bool_new:N \l__cookingunits_range_in_input_bool
\bool_new:N \l__cookingunits_lokal_fraction_bool
\bool_new:N \l__cookingunits_print_fraction_bool
-\bool_new:N \l__cookingunits_lokal_mixed_fraction_bool
\bool_new:N \l__cookingunits_check_decimal_bool
\bool_set_false:N \l__cookingunits_cutext_keep_unit_bool
\bool_set_eq:NN \l__cookingunits_print_numeral_bool \g__cookingunits_opt_numeral_bool
\quark_new:N \q__cookingunits_range
\quark_new:N \q__cookingunits_no_translation
-\quark_new:N \q__cookingunits_decimal
-\quark_new:N \q__cookingunits_fraction
-\quark_new:N \q__cookingunits_mixed_fraction
+\tl_new:N \l__cookingunits_tmpa_tl
+\tl_new:N \l__cookingunits_tmpb_tl
+\tl_new:N \l__cookingunits_tmp_unit_tl
\fp_new:N \l__cookingunits_tmpa_fp
\clist_new:N \l__cookingunits_tmpa_clist
\prop_new:N \l__cookingunits_tmpa_prop
@@ -232,8 +260,8 @@
add-unit-to-group .code:n =
{
\keyval_parse:NNn
- \__cookingunits_unit_group_add_unit_error:n
- \__cookingunits_unit_group_add_unit:nn
+ \__cookingunits_add_to_unit_group_error:n
+ \__cookingunits_add_to_unit_group:nn
{#1}
} ,
add-unit-to-group .default:n = {} ,
@@ -253,18 +281,12 @@
},
erase-all-options .code:n =
{
- \seq_map_inline:Nn \g__cookingunits_list_of_defined_units_seq
- {
- \clist_clear:c { l__cookingunits_predefined_option_ ##1 _clist }
- }
+ \exp_args:Nx \cuclearoptionfor { \seq_use:Nn \g__cookingunits_list_of_defined_units_seq { , } }
},
erase-all-options .value_forbidden:n = { true } ,
erase-all-options-for .code:n =
{
- \keyval_parse:NNn
- \__cookingunits_erase_options_for:n
- \__cookingunits_erase_options_for_error:nn
- {#1}
+ \cuclearoptionfor {#1}
},
erase-all-options-for .value_required:n = { true } ,
cutext-to-cunum .bool_set:N = \l__cookingunits_cutext_to_cunum_bool ,
@@ -373,11 +395,24 @@
{
\int_set:Nn \l__cookingunits_round_precision_int {#1}
\int_compare:nNnTF {#1} < { 0 }
- { \bool_set_false:N \l__cookingunits_round_precision_positive_bool }
- { \bool_set_true:N \l__cookingunits_round_precision_positive_bool }
+ { \bool_set_true:N }
+ { \bool_set_false:N }
+ \l__cookingunits_round_precision_negative_bool
} ,
round-precision .default:n = { 2 } ,
round-to-int .bool_set:N = \l__cookingunits_round_to_int_bool ,
+ round-to-int .choices:nn =
+ { true , false }
+ {
+ \msg_error:nnnn { cooking-units } { Option-deprecated } { round-to-int } { round-precision = 0 }
+ \int_compare:nNnTF { \l_keys_choice_int } = { 1 }
+ {
+ \int_set:Nn \l__cookingunits_round_precision_int { 0 }
+ }{
+
+ }
+ \use:c { bool_set_ \l_keys_choice_tl :N } \l__cookingunits_round_to_int_bool
+ } ,
round-to-int .default:n = { false } ,
round-half .choices:nn =
{ default , commercial }
@@ -391,6 +426,8 @@
round-half .default:n = { default },
eval-fraction .bool_set:N = \l__cookingunits_eval_fractions_bool ,
eval-fraction .default:n = { false } ,
+ convert-fraction .bool_set:N = \l__cookingunits_convert_fractions_bool ,
+ convert-fraction .default:n = { true } ,
fraction-command .code:n = { \cs_set_eq:NN \__cookingunits_frac:nn #1 } ,
fraction-command .default:n = { \sfrac } ,
fraction-inline .code:n = { \cs_set:Npn \__cookingunits_frac:nn ##1##2 {#1} } ,
@@ -428,10 +465,15 @@
convert-to-eV .groups:n = { change-unit } ,
add-natural-unit .code:n =
{
- \__cookingunits_error_if_unit_not_defined:n {#1}
\seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
- \seq_concat:NNN \g__cookingunits_natural_units_seq \g__cookingunits_natural_units_seq \l__cookingunits_tmpa_seq
- \seq_remove_duplicates:N \g__cookingunits_natural_units_seq
+ \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ {
+ \__cookingunits_error_if_unit_not_defined:nF {##1}
+ {
+ \seq_if_in:NnF \g__cookingunits_natural_units_seq {##1}
+ { \seq_gput_right:Nn \g__cookingunits_natural_units_seq {##1} }
+ }
+ }
} ,
add-natural-unit .value_required:n = { true } ,
42 .choice: ,
@@ -453,32 +495,12 @@
cutext-add-hook .code:n = { \tl_put_right:Nn \l__cookingunits_cutext_hook_tl {#1} } ,
Cutext-add-hook .code:n = { \tl_put_right:Nn \l__cookingunits_Cutext_hook_tl {#1} } ,
cuam-add-hook .code:n = { \tl_put_right:Nn \l__cookingunits_cuam_hook_tl {#1} } ,
- curef-add-forbidden-unit .code:n =
- {
- \seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
- \seq_map_inline:Nn \l__cookingunits_tmpa_seq
- {
- \seq_if_in:NnF \l__cookingunits_curef_do_not_change_seq {##1}
- { \seq_put_right:Nn \l__cookingunits_curef_do_not_change_seq {##1} }
- }
- } ,
+ curef-add-forbidden-unit .code:n = { \__cookingunits_add_forbidden_unit:n {#1} } ,
curef-add-forbidden-unit .default:n = { } ,
- curef-remove-forbidden-unit .code:n =
- {
- \seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
- \seq_map_inline:Nn \l__cookingunits_tmpa_seq
- {
- \seq_if_in:NnTF \l__cookingunits_curef_do_not_change_seq {##1}
- { \seq_remove_all:Nn \l__cookingunits_curef_do_not_change_seq {##1} }
- {
- \msg_warning:nnn { cooking-units } { curef-not-inside-list } {##1}
- { \seq_use:Nnnn \l__cookingunits_curef_do_not_change_seq { ',~ ' } { ',~ ' } { ' ~ and ~ ' } }
- }
- }
- } ,
+ curef-remove-forbidden-unit .code:n = { \__cookingunits_remove_forbidden_unit:n {#1} } ,
curef-remove-forbidden-unit .default:n = { } ,
curef-clear-forbidden-units .choice: ,
- curef-clear-forbidden-units/true .code:n = { \seq_clear:N \l__cookingunits_curef_do_not_change_seq } ,
+ curef-clear-forbidden-units/true .code:n = { \__cookingunits_clear_forbidden_unit: } ,
curef-clear-forbidden-units/false .code:n = { } ,
curef-clear-forbidden-units .value_required:n = true,
}
@@ -509,7 +531,7 @@
\msg_new:nnnn { cooking-units } { unknown-unit }
{
The \ unit \ '#1' \ is \ not \ defined. \ Use \
- \newcookingunit ~ (or \ one \ of \ the \ others) \ to \
+ \newcookingunit (or \ one \ of \ the \ others) \ to \
define \ new \ units.
}{
Define \ units \ before \ using \ or \ check \ if \ the \
@@ -567,8 +589,8 @@
}
\msg_new:nnnn { cooking-units } { Key-not-defined }
{
- The \ key \ '#1' \ is \ not \ defined. \ Use \ \cudefinekeys ~ or \
- \cudefinesinglekey ~ to \ define \ keys.
+ The \ key \ '#1' \ is \ not \ defined. \ Use \ \cudefinekeys or \
+ \cudefinesinglekey to \ define \ keys.
}
{
This \ key \ is \ not \ defined, \ perhaps \ you \ misspelled \ it.
@@ -579,8 +601,7 @@
The \ temperature \ '#1' \ is \ too \ low.\ It \ cannot \ be \
below \ the \ absolute \ zero - point \ of \ '#2'. \ Note \ that \
the \ temperatures \
- '\seq_use:Nnnn \l__cookingunits_temperatures_to_check_seq
- { ', ~ ' } { ', ~ ' } { ' ~ and ~ ' }' \
+ '\__cookingunits_seq_use_msg:N \l__cookingunits_temperatures_to_check_seq' \
are \ rounded \ to \ integers \ by \ default.
\\\\
You \ can \ disable \ the \ option \ 'check-temperature' \ to \
@@ -593,8 +614,8 @@
'#3' \ as \ a \ set \ of \ choices \ and \ '#2' \ is \ non \ of \ these.
}{
The \ key \ accepts \ only \ a \ fixed \ set \ of \ choices. \
- You \ can \ add \ new \ choices \ via \ \cuaddkeys, ~ \cuaddsinglekeys ~
- and \ \cuaddtokeys.
+ You \ can \ add \ new \ choices \ via \ \token_to_str:N \cuaddkeys, ~
+ \token_to_str:N \cuaddsinglekeys ~ and \ \token_to_str:N \cuaddtokeys.
\msg_see_documentation_text:n {cooking-units}
}
\msg_new:nnnn { cooking-units } { group-choice-not-allowed }
@@ -610,8 +631,7 @@
{
The \ amount \ '#1' \ is \ not \ known \ at \ line \
\msg_line_number: .
- }
- {
+ }{
You \ used\ a\ special\ sign\ indicating\ that\ the\ true\ amount\ of\ the\
specific\ ingredient\ is\ (was) \ not\ known\ to\ you. This\ message\
reminds\ you\ about\ that\ fact.
@@ -629,8 +649,7 @@
{
The \ option \ '#1' \ is \ only \ available \ as \ a \ load-time-option. \
Please \ set \ it \ as \ a \ package \ option.
- }
- {
+ }{
You \ cannot \ set \ this \ option \ using \ \cusetup ~
but \ only \ as \ a \ package \ option.
\msg_see_documentation_text:n { cooking-units }
@@ -645,16 +664,14 @@
\msg_new:nnnn { cooking-units } { No-Value-given }
{
Please \ input \ a \ value \ for \ the \ key-value \ list \ in \ '#1'
- }
- {
+ }{
Each \ element \ of \ the \ list \ needs \ a \ value.
\msg_see_documentation_text:n { cooking-units }
}
\msg_new:nnnn { cooking-units } { Value-not-allowed }
{
The \ key-list \ in \ '#1' \ does \ not \ take \ a \ value.
- }
- {
+ }{
This \ key-list \ does \ not \ take \ a \ value. \ The \
given \ value \ will \ be \ ignored.
\msg_see_documentation_text:n { cooking-units }
@@ -670,8 +687,7 @@
{
Please \ add \ the \ number \ of \ persons \ this \ recipe \ is \ for \ in \ '#1'. \
Note \ that\ the \ number \ must \ be \ given \ after \ a \ '*'.
- }
- {
+ }{
Write \ 'Schweinsbraten*4' \ to \ create \ the \ label \ 'Schweinsbraten' \
which \ is \ initially \ for \ 4 \ persons.
\msg_see_documentation_text:n { cooking-units }
@@ -680,8 +696,7 @@
{
The \ number \ of \ persons \ the \ recipe \ is \ for \ must \ be \ an \
integer. \ '#1' \ is \ not \ allowed.
- }
- {
+ }{
The \ number \ '#1' \ is \ not \ allowed.
\msg_see_documentation_text:n { cooking-units }
}
@@ -717,20 +732,18 @@
\msg_new:nnnn { cooking-units } { cutext-no-translation-available }
{
For \ the \ unit \ '#1' \ there \ exists \ no \ translation \ to \ be \ used \
- for \ \cutext ~ and \ \Cutext. \
+ for \ \cutext ~ and \ \token_to_str:N \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 }
{
The \ translation \ for \ #1 \ does \ not \ exist.
- Please \ define \ it \ using \ \cudefinename.
- }
- {
+ Please \ define \ it \ using \ \token_to_str:N\cudefinename.
+ }{
And \ you \ may \ send \ me \ the \ translation \ as \ it \ is \
not \ available \ yet.
\msg_see_documentation_text:n { cooking-units }
@@ -739,8 +752,7 @@
{
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 }
}
@@ -762,11 +774,34 @@
}
\msg_new:nnnn { cooking-units } { curef-forbidden-unit }
{
- The \ amount \ of \ '#1' \ cannot \ be \ changed \ using \ cooking-units` \ label \ \& \ ref \ feature.
+ The \ amount \ of \ '#1' \ cannot \ be \ changed \ using \ cooking-units`
+ \ label \ and \ ref \ feature.
}{
You \ can \ remove \ the \ unit \ using \ 'curef-remove-forbidden-unit'.
\msg_see_documentation_text:n { cooking-units }
}
+\msg_new:nnnn { cooking-units } { define-numeral-function }
+ {
+ You \ are \ using \ numerals \ (lowercase) \ without \ the \ load-time \ option \
+ 'use-fmtcount-numerals' \ as \ such \ you \ need \ to \ define \
+ which \ function \ is \ to \ be \ used \ for \ numerals. \ You \ can
+ \ do \ that \ via \ 'numeral-function' \ and \ 'Numeral-function'
+ }{
+ Please \ specify\ which \ function \ should \ be \ used \ to \ print \
+ numerals (lowercase \ and \ uppercase).
+ \msg_see_documentation_text:n { cooking-units }
+ }
+\msg_new:nnnn { cooking-units } { define-Numeral-function }
+ {
+ You \ are \ using \ numerals \ (capitalized) \ without \ the \ load-time \ option \
+ 'use-fmtcount-numerals' \ as \ such \ you \ need \ to \ define \
+ which \ function \ is \ to \ be \ used \ for \ numerals. \ You \ can
+ \ do \ that \ via \ 'numeral-function' \ and \ 'Numeral-function'
+ }{
+ Please \ specify\ which \ function \ should \ be \ used \ to \ print \
+ numerals (lowercase \ and \ uppercase).
+ \msg_see_documentation_text:n { cooking-units }
+ }
\msg_new:nnnn { cooking-units } { 42-is-...-wrong? }
{
You \ requested \ to \ set \ 42 \ to \ 'false'. \ This \ doesn't \ make
@@ -779,21 +814,44 @@
Phew ... \ this \ might \ have \ ended \ disastrous.
\msg_see_documentation_text:n { cooking-units }
}
+\msg_new:nnnn { cooking-units } { empty-amount }
+ {
+ The \ amount \ given \ is \ empty \ ( spaces \ are \ removed ).
+ }{
+ The \ amount \ given \ is \ empty.
+ \msg_see_documentation_text:n { cooking-units }
+ }
+\msg_new:nnnn { cooking-units } { unknown-option }
+ {
+ The \ option \ '#1' \ is \ not \ defined.
+ }{
+ Perhaps \ you \ misspelled \ the \ option.
+ \msg_see_documentation_text:n { cooking-units }
+ }
\msg_new:nnnn { cooking-units } { internal-error }
{
This \ error \ shouldn't \ show. \ This \ means \ I
\ (the \ package \ author) \ screwed
- \ up.
+ \ up. \ The \ error \ code \ is \ '#1'.
}{
Please \ send \ me \ a \ bug \ report.
\msg_see_documentation_text:n { cooking-units }
}
-\cs_new:Npn \__cookingunits_error_if_unit_not_defined:n #1
+\prg_new_protected_conditional:Npnn \__cookingunits_error_if_unit_not_defined:n #1 { TF, T, F }
{
- \seq_if_in:NnF \g__cookingunits_list_of_defined_units_seq {#1}
- { \msg_error:nnn { cooking-units } { unknown-unit } {#1} }
+ \seq_if_in:NnTF \g__cookingunits_list_of_defined_units_seq {#1}
+ { \prg_return_false: }
+ {
+ \msg_error:nnn { cooking-units } { unknown-unit } {#1}
+ \prg_return_true:
+ }
}
-\cs_generate_variant:Nn \__cookingunits_error_if_unit_not_defined:n { V }
+\cs_new:Npn \__cookingunits_error_if_unit_not_defined:n #1
+ { \__cookingunits_error_if_unit_not_defined:nTF {#1} { } { } }
+\cs_generate_variant:Nn \__cookingunits_error_if_unit_not_defined:nTF { V }
+\cs_new:Npn \__cookingunits_seq_use_msg:N #1
+ { \seq_use:Nnnn #1 { ' , ~ ' } { ' , ~ ' } { ' ~ and ~ ' } }
+\cs_generate_variant:Nn \__cookingunits_seq_use_msg:N { c }
\prg_new_protected_conditional:Npnn \__cookingunits_if_integer:n #1 { TF , F }
{
\tl_map_inline:nn {#1}
@@ -838,6 +896,20 @@
{ \prg_return_true: }
{ \prg_return_false: }
}
+\prg_new_conditional:Npnn \__cookingunits_if_gender_error:n #1 { TF }
+ {
+ \str_case:nnTF {#1}
+ {
+ { m } { }
+ { f } { }
+ { n } { }
+ }
+ { \prg_return_false: }
+ {
+ \msg_error:nnn { cooking-units } { unknown-gender } {#1}
+ \prg_return_true:
+ }
+ }
\cs_new:Npn \__cookingunits_check_if_correct_gender_input:n #1
{
\str_case:nnF {#1}
@@ -847,61 +919,63 @@
{ n } { }
} { \msg_error:nnn { cooking-units } { unknown-gender } {#1} }
}
-\cs_new:Npn \__cookingunits_define_unit_group:nn #1#2
+\cs_new:Npn \__cookingunits_define_clear_unit_group:nn #1#2
{
- \seq_new:c { l__cookingunits_group_ #1 _seq }
- \seq_set_from_clist:cn { l__cookingunits_group_ #1 _seq } {#2}
+ \seq_clear_new:c { l__cookingunits_group_ #1 _seq }
\keys_define:nn { cooking-units }
{
#1 .code:n = { \__cookingunits_unit_group_convert_units:nn {#1} {##1} } ,
#1 .groups:n = { change-unit } ,
}
}
-\cs_new:Npn \__cookingunits_error_if_group_not_defined:n #1
+\cs_new:Npn \__cookingunits_add_to_unit_group_error:n #1
+ { \msg_error:nnn { cooking-units } { No-Value-given } { add-unit-to-group } }
+\cs_new:Npn \__cookingunits_add_to_unit_group:nn #1#2
{
- \seq_if_exist:cF { l__cookingunits_group_ #1 _seq }
- { \msg_error:nn { cooking-units} { group-key-unknown } }
- }
-\cs_new:Npn \__cookingunits_unit_group_convert_units:nn #1#2
- {
- \__cookingunits_error_if_group_not_defined:n {#1}
- \__cookingunits_error_if_unit_not_defined:n {#2}
- \seq_if_in:cnTF { l__cookingunits_group_ #1 _seq } {#2}
+ \__cookingunits_error_if_group_not_defined:nF {#1}
{
- \seq_map_inline:cn { l__cookingunits_group_ #1 _seq }
- { \__cookingunits_keys_set:nnn { cooking-units } {##1} {#2} }
- }{
- \msg_error:nnxxx
- { cooking-units }
- { group-choice-not-allowed }
- {#1}
- {#2}
- { \seq_use:cnnn { l__cookingunits_group_ #1 _seq } { ',~ ' } { ',~ ' } { ' ~ and ~ ' } }
+ \clist_map_inline:nn {#2}
+ {
+ \__cookingunits_error_if_unit_not_defined:nF {##1}
+ {
+ \seq_if_in:cnF { l__cookingunits_group_ #1 _seq } {##1}
+ { \seq_put_right:cn { l__cookingunits_group_ #1 _seq } {##1} }
+ }
+ }
}
}
-\__cookingunits_define_unit_group:nn { weight } { kg , dag, g, oz, lb, stick }
-\__cookingunits_define_unit_group:nn { length } { m , dm , cm , mm , in }
-\__cookingunits_define_unit_group:nn { volume } { l , dl , cl , ml }
-\__cookingunits_define_unit_group:nn { temperature } { C , F , K , Re }
-\__cookingunits_define_unit_group:nn { energy } { cal, kcal , J , kJ , eV }
-\__cookingunits_define_unit_group:nn { time } { d , h , min , s }
-\cs_new:Npn \__cookingunits_unit_group_add_unit_error:n #1
+\prg_new_conditional:Npnn \__cookingunits_error_if_group_not_defined:n #1 { F }
{
- \msg_error:nnn { cooking-units } { No-Value-given } { add-unit-to-group }
+ \seq_if_exist:cTF { l__cookingunits_group_ #1 _seq }
+ { \prg_return_false: }
+ {
+ \msg_error:nn { cooking-units} { group-key-unknown }
+ \prg_return_true:
+ }
}
-\cs_new:Npn \__cookingunits_unit_group_add_unit:nn #1#2
+\cs_new:Npn \__cookingunits_unit_group_convert_units:nn #1#2
{
- \__cookingunits_error_if_group_not_defined:n {#1}
- \clist_map_inline:nn {#2}
- {
- \__cookingunits_error_if_unit_not_defined:n {##1}
- \seq_if_in:cnF { l__cookingunits_group_ #1 _seq } {##1}
- { \seq_put_right:cn { l__cookingunits_group_ #1 _seq } {##1} }
- }
+ \__cookingunits_error_if_group_not_defined:nF {#1}
+ {
+ \__cookingunits_error_if_unit_not_defined:nF {#2}
+ {
+ \seq_if_in:cnTF { l__cookingunits_group_ #1 _seq } {#2}
+ {
+ \seq_map_inline:cn { l__cookingunits_group_ #1 _seq }
+ { \__cookingunits_keys_set:nnn { cooking-units } {##1} {#2} }
+ }{
+ \msg_error:nnxxx
+ { cooking-units }
+ { group-choice-not-allowed }
+ {#1} {#2}
+ { \__cookingunits_seq_use_msg:c { l__cookingunits_group_ #1 _seq } }
+ }
+ }
+ }
}
\seq_new:N \g__cookingunits_natural_units_seq
\prop_new:N \g__cookingunits_convert_to_eV_remember_prop
-\seq_set_from_clist:Nn \g__cookingunits_natural_units_seq
+\seq_gset_from_clist:Nn \g__cookingunits_natural_units_seq
{
eV ,
eVc-2 ,
@@ -910,38 +984,37 @@
(chbareV-1)3 ,
}
\cs_new:Npn \__cookingunits_keys_set:nnn #1#2#3
- {
- \keys_set:nn {#1} { #2 = #3 }
- }
+ { \keys_set:nn {#1} { #2 = #3 } }
\cs_generate_variant:Nn \__cookingunits_keys_set:nnn { nVV , nVn }
\cs_new:Npn \__cookingunits_convert_to_eV:
{
- \prop_if_exist:cT { l__cookingunits_cukeys_ \l__cookingunits_given_unit_tl _prop }
+ \tl_set_eq:Nc \l__cookingunits_tmp_unit_tl { l__cookingunits_base_key_unit_ \l__cookingunits_original_unit_tl _tl }
+ \tl_if_empty:NF \l__cookingunits_tmp_unit_tl
{
\prop_get:NVNTF \g__cookingunits_convert_to_eV_remember_prop
- \l__cookingunits_given_unit_tl \l__cookingunits_tmpa_tl
+ \l__cookingunits_original_unit_tl \l__cookingunits_tmpa_tl
+ { \__cookingunits_keys_set:nVV { cooking-units } \l__cookingunits_original_unit_tl \l__cookingunits_tmpa_tl }
{
- \__cookingunits_keys_set:nVV { cooking-units } \l__cookingunits_given_unit_tl \l__cookingunits_tmpa_tl
- }{
- \prop_get:cnNT { l__cookingunits_cukeys_ \l__cookingunits_given_unit_tl _prop } { Liste } \l__cookingunits_tmpa_seq
+ \prop_get:cnNTF { l__cookingunits_cukeys_ \l__cookingunits_tmp_unit_tl _prop } { Liste } \l__cookingunits_tmpa_seq
{
\seq_map_inline:Nn \g__cookingunits_natural_units_seq
{
\seq_if_in:NnT \l__cookingunits_tmpa_seq {##1}
{
\prop_gput:NVn \g__cookingunits_convert_to_eV_remember_prop
- \l__cookingunits_given_unit_tl {##1}
- \__cookingunits_keys_set:nVn { cooking-units } \l__cookingunits_given_unit_tl {##1}
+ \l__cookingunits_original_unit_tl {##1}
+ \__cookingunits_keys_set:nVn { cooking-units } \l__cookingunits_original_unit_tl {##1}
\seq_map_break:
}
}
}
+ { \msg_error:nnn { cooking-units } { internal-error } { convert-to-eV } }
}
}
}
\cs_new:Npn \__cookingunits_tl_eval:Nn #1#2 { \tl_set:Nf #1 { \fp_eval:n {#2} } }
\cs_generate_variant:Nn \__cookingunits_tl_eval:Nn { Nv }
-\prg_new_conditional:Npnn \__cookingunits_change_unit: { TF }
+\prg_new_conditional:Npnn \__cookingunits_change_unit: { TF , T }
{
\bool_lazy_any:nTF
{
@@ -959,50 +1032,36 @@
}
\cs_new:Npn \__cookingunits_temperatures_to_check_define:nn #1#2
{
- \__cookingunits_error_if_unit_not_defined:n {#1}
- \fp_if_exist:cTF { c__cookingunits_ #1 _min_fp }
- { \msg_warning:nnn { cooking-units } { Minimum-already-defined } {#1} }
+ \__cookingunits_error_if_unit_not_defined:nF {#1}
{
- \seq_put_right:Nn \l__cookingunits_temperatures_to_check_seq {#1}
- \fp_const:cn { c__cookingunits_ #1 _min_fp } {#2}
+ \fp_if_exist:cTF { l__cookingunits_ #1 _min_fp }
+ {
+ \fp_set:cn { l__cookingunits_ #1 _min_fp } {#2}
+ }{
+ \seq_put_right:Nn \l__cookingunits_temperatures_to_check_seq {#1}
+ \fp_new:c { l__cookingunits_ #1 _min_fp }
+ \fp_set:cn { l__cookingunits_ #1 _min_fp } {#2}
+ }
}
}
-\cs_new:Npn \__cookingunits_erase_options_for:n #1
- {
- \__cookingunits_error_if_unit_not_defined:n {#1}
- \clist_clear:c { l__cookingunits_predefined_option_ ##1 _clist }
- }
-\cs_new:Npn \__cookingunits_erase_options_for_error:nn #1#2
- {
- \__cookingunits_error_if_unit_not_defined:n {#1}
- \msg_error:nnn { cooking-units } { Value-not-allowed } { erase-all-options-for }
- }
\cs_new:Npn \__cookingunits_set_options_for_error:n #1
{
\__cookingunits_error_if_unit_not_defined:n {#1}
\msg_error:nnn { cooking-units } { No-Value-given } { set-option-for }
}
\cs_new:Npn \__cookingunits_set_options_for:nn #1#2
- {
- \__cookingunits_error_if_unit_not_defined:n {#1}
- \clist_set:cn { l__cookingunits_predefined_option_#1_clist } {#2}
- }
+ { \cusetoptionfor {#1} {#2} }
\cs_new:Npn \__cookingunits_add_options_for_error:n #1
{
\__cookingunits_error_if_unit_not_defined:n {#1}
\msg_error:nnn { cooking-units } { No-Value-given } { add-option-for }
}
\cs_new:Npn \__cookingunits_add_options_for:nn #1#2
- {
- \__cookingunits_error_if_unit_not_defined:n {#1}
- \clist_put_right:cn { l__cookingunits_predefined_option_ #1 _clist } {#2}
- }
+ { \cuaddoptionfor {#1} {#2} }
\cs_new:Npn \__cookingunits_rounding_function:n #1
{
#1
- \bool_if:NTF \l__cookingunits_round_to_int_bool
- { , 0 }
- { , \l__cookingunits_round_precision_int }
+ , \l__cookingunits_round_precision_int
\bool_if:NT \l__cookingunits_round_commercial_bool
{ , #1 }
}
@@ -1054,23 +1113,23 @@
}
\NewDocumentCommand \culabel { m m } { \__cookingunits_culabel:nn {#1} {#2} }
\NewExpandableDocumentCommand \curef { m } { \__cookingunits_curef:n {#1} }
-\cs_new:Npn \__cookingunits_tl_if_in_remove_and_set_bool:NnN #1#2#3
+\cs_new:Npn \__cookingunits_bool_reverse:N #1
{
- \tl_if_in:NnTF #1 {#2}
- {
- \bool_set_true:N #3
- \tl_remove_once:Nn #1 {#2}
- }
- { \bool_set_false:N #3 }
+ \bool_if:NTF #1
+ { \bool_set_false:N }
+ { \bool_set_true:N }
+ #1
}
-\cs_new:Npn \__cookingunits_tl_if_in_remove_and_reverse_bool:NnN #1#2#3
+\cs_new:Npn \__cookingunits_check_minus_remove_and_reverse:NN #1#2
{
- \tl_if_in:NnT #1 {#2}
+ \quark_if_nil:NF #2
{
- \bool_if:NTF #3
- { \bool_set_false:N #3 }
- { \bool_set_true:N #3 }
- \tl_remove_once:Nn #1 {#2}
+ \tl_if_in:NnT #2 { - }
+ {
+ \tl_remove_once:Nn #2 { - }
+ \__cookingunits_bool_reverse:N #1
+ }
+ \__cookingunits_check_minus_remove_and_reverse:NN #1
}
}
\tl_const:Nn \c__cookingunits_postfix_unit_tl { ( cu-unit ) }
@@ -1087,8 +1146,8 @@
{
\declaretranslation {#1} { #2 #3 } {#4}
}
-\cs_generate_variant:Nn \__cookingunits_deftranslation_base:nnn { xx , xxV }
-\cs_generate_variant:Nn \__cookingunits_deftranslation_to:nnnn { Vxxv, VxxV , Vxxn, Vxxx,Vxxo,Vxxf }
+\cs_generate_variant:Nn \__cookingunits_deftranslation_base:nnn { xV }
+\cs_generate_variant:Nn \__cookingunits_deftranslation_to:nnnn { VxVv, VxVV , VxVn }
\cs_new:Npn \__cookingunits_newtranslation_base:nnn #1#2#3
{
\definetranslationfallback { #1 #2 } {#3}
@@ -1160,13 +1219,18 @@
\__cookingunits_newtranslation_to:nnVn { English } { cutext-range-sign } \c__cookingunits_postfix_unitname_tl { ~to~ }
\cs_new_protected:Npn \__cookingunits_initialise_default:n #1
{
- \__cookingunits_set_unit:Nn \l__cookingunits_given_unit_tl {#1}
- \__cookingunits_error_if_unit_not_defined:V \l__cookingunits_given_unit_tl
- \bool_set_false:N \l__cookingunits_special_sign_bool
+ \__cookingunits_set_unit:Nn \l__cookingunits_original_unit_tl {#1}
\bool_set_false:N \l__cookingunits_error_bool
+ \__cookingunits_error_if_unit_not_defined:VTF \l__cookingunits_original_unit_tl
+ {
+ \bool_set_true:N \l__cookingunits_unit_error_bool
+ \cs_set_eq:NN \__cookingunits_print_correct_unit: \__cookingunits_print_default_unit:
+ }
+ { \bool_set_false:N \l__cookingunits_unit_error_bool }
+ \bool_set_false:N \l__cookingunits_special_sign_bool
\bool_set_false:N \l__cookingunits_range_in_input_bool
\bool_set_false:N \l__cookingunits_lokal_fraction_bool
- \bool_set_false:N \l__cookingunits_lokal_mixed_fraction_bool
+ \bool_set_false:N \l__cookingunits_minus_bool
}
\cs_new_protected:Npn \__cookingunits_initialise_unit_change:n #1
{
@@ -1174,19 +1238,19 @@
{ \keys_set_groups:nnn { cooking-units } { change-unit } {#1} }
\bool_if:NT \l__cookingunits_convert_to_eV_bool
{ \__cookingunits_convert_to_eV: }
- \prop_get:NVNF \l__cookingunits_change_unit_prop \l__cookingunits_given_unit_tl \l__cookingunits_option_unit_tl
- { \tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_given_unit_tl }
+ \prop_get:NVNF \l__cookingunits_change_unit_prop \l__cookingunits_original_unit_tl \l__cookingunits_option_unit_tl
+ { \tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_original_unit_tl }
}
\cs_new_protected:Npn \__cookingunits_initialise_after_unit_change:nn #1#2
{
\IfNoValueF {#1}
{ \__cookingunits_reference_label_and_persons:n {#1} }
- \clist_if_empty:cF { l__cookingunits_predefined_option_ \l__cookingunits_option_unit_tl _clist }
+ \clist_if_empty:cF { l__cookingunits_unit_option_ \l__cookingunits_option_unit_tl _clist }
{
\keys_set_filter:nnv
{ cooking-units }
{ change-unit }
- { l__cookingunits_predefined_option_ \l__cookingunits_option_unit_tl _clist }
+ { l__cookingunits_unit_option_ \l__cookingunits_option_unit_tl _clist }
}
\tl_if_empty:nF {#2}
{ \keys_set_filter:nnn { cooking-units } { change-unit } {#2} }
@@ -1194,10 +1258,7 @@
{ \l__cookingunits_calc_because_ref_was_given_bool } { \l__cookingunits_change_number_of_persons_bool }
{ \bool_set_true:N \l__cookingunits_lokal_persons_bool }
{ \bool_set_false:N \l__cookingunits_lokal_persons_bool }
- \bool_lazy_and:nnTF
- { \g__cookingunits_opt_numeral_bool } { \l__cookingunits_print_numeral_bool }
- { \bool_set_true:N \l__cookingunits_lokal_numeral_bool }
- { \bool_set_false:N \l__cookingunits_lokal_numeral_bool }
+ \bool_set_eq:NN \l__cookingunits_lokal_numeral_bool \l__cookingunits_print_numeral_bool
}
\cs_new_protected:Npn \__cookingunits_print_input:N #1 { }
\cs_new_protected:Npn \__cookingunits_print_correct_unit: { }
@@ -1236,13 +1297,13 @@
\tl_replace_once:Nnn #1 { - } \c__cookingunits_minus_tl
#1
}
-\cs_new:Npn \__cookingunits_print_fractions:nnn #1#2#3
+\cs_new:Npn \__cookingunits_print_fractions:Nnn #1#2#3
{
\bool_if:NT \l__cookingunits_minus_bool { \c__cookingunits_minus_tl }
- \tl_if_empty:nF {#1}
+ \tl_if_empty:NF #1
{
#1
- \__cookingunits_dim_horizontal:N \l__cookingunits_mixed_frac_dim
+ \skip_horizontal:N \l__cookingunits_mixed_frac_dim
}
\__cookingunits_frac:nn {#2} {#3}
}
@@ -1262,41 +1323,57 @@
\cs_new:Npn \__cookingunits_create_error:n #1
{
\bool_set_true:N \l__cookingunits_error_bool
- \msg_error:nnV { cooking-units } {#1} \l__cookingunits_given_amount_tl
+ \msg_error:nnV { cooking-units } {#1} \l__cookingunits_original_amount_tl
}
\cs_new:Npn \__cookingunits_create_error_and_stop:n #1
{
\bool_set_true:N \l__cookingunits_error_bool
- \msg_error:nnV { cooking-units } {#1} \l__cookingunits_given_amount_tl
+ \msg_error:nnV { cooking-units } {#1} \l__cookingunits_original_amount_tl
\use_none_delimit_by_q_nil:w
}
\cs_new:Npn \__cookingunits_create_error:nn #1#2
{
\bool_set_true:N \l__cookingunits_error_bool
- \msg_error:nnnV { cooking-units } {#1} {#2} \l__cookingunits_given_amount_tl
+ \msg_error:nnnV { cooking-units } {#1} {#2} \l__cookingunits_original_amount_tl
+ }
+\cs_new:Npn \__cookingunits_process_tmp: { }
+\cs_new:Npn \__cookingunits_process_and_print_input:
+ {
+ \bool_lazy_or:nnTF
+ { \l__cookingunits_error_bool }
+ { \l__cookingunits_unit_error_bool }
+ { \l__cookingunits_original_amount_tl }
+ { \__cookingunits_process_tmp: }
+ }
+\cs_new:Npn \__cookingunits_process_default: { \l__cookingunits_original_amount_tl }
+\cs_new:Npn \__cookingunits_print_default_unit:
+ {
+ \tl_if_empty:NF \l__cookingunits_phantom_tl { \phantom { \l__cookingunits_phantom_tl } }
+ \,\l__cookingunits_original_unit_tl
}
\cs_new:Npn \__cookingunits_parse_input:n #1
{
- \bool_if:NTF \l__cookingunits_fourty_two_bool
- { \tl_clear:N \l__cookingunits_given_amount_tl }
- { \__cookingunits_set_amount:Nn \l__cookingunits_given_amount_tl {#1} }
- \tl_set_rescan:NnV \l__cookingunits_given_amount_tl
+ \__cookingunits_set_amount:Nn \l__cookingunits_original_amount_tl {#1}
+ \tl_set_rescan:NnV \l__cookingunits_original_amount_tl
{
\char_set_catcode_letter:N \_ %
\char_set_catcode_ignore:N \ %
\char_set_catcode_other:N ? %
- } \l__cookingunits_given_amount_tl
- \bool_lazy_or:nnTF
- { \l__cookingunits_draft_bool }
- { \tl_if_empty_p:N \l__cookingunits_given_amount_tl }
+ } \l__cookingunits_original_amount_tl
+ \bool_lazy_any:nTF
{
- \bool_if:NTF \l__cookingunits_fourty_two_bool
- { 42 }
- { \l__cookingunits_given_amount_tl }
+ { \l__cookingunits_fourty_two_bool }
+ { \l__cookingunits_draft_bool }
+ { \tl_if_empty_p:N \l__cookingunits_original_amount_tl }
+ }{
+ \cs_set_eq:NN \__cookingunits_process_tmp: \__cookingunits_process_default:
+ \tl_if_empty:NT \l__cookingunits_original_amount_tl
+ { \msg_error:nnV { cooking-units } { empty-amount } \l__cookingunits_original_amount_tl }
+ \bool_if:NT \l__cookingunits_fourty_two_bool
+ { \tl_set:Nn \l__cookingunits_original_amount_tl { 42 } }
}{
- \tl_set_eq:NN \l__cookingunits_tmpa_tl \l__cookingunits_given_amount_tl
+ \tl_set_eq:NN \l__cookingunits_tmpa_tl \l__cookingunits_original_amount_tl
\__cookingunits_split_input:N \l__cookingunits_tmpa_tl
- \__cookingunits_process_and_print_input:
}
}
\cs_new:Npn \__cookingunits_split_input:N #1
@@ -1312,22 +1389,9 @@
\bool_if:NT \l__cookingunits_range_in_input_bool
{ \__cookingunits_create_error_and_stop:n { fraction-not-allowed-with-range } }
}
- \tl_if_in:NnT #1 { _ }
- {
- \bool_set_true:N \l__cookingunits_lokal_mixed_fraction_bool
- \bool_if:NF \l__cookingunits_lokal_fraction_bool
- { \__cookingunits_create_error_and_stop:n { missing-slash } }
- }
\__cookingunits_split:N #1
\use_none_delimit_by_q_nil:w \q_nil
}
-\cs_new:Npn \__cookingunits_process_tmp: { }
-\cs_new:Npn \__cookingunits_process_and_print_input:
- {
- \bool_if:NTF \l__cookingunits_error_bool
- { \l__cookingunits_given_amount_tl }
- { \__cookingunits_process_tmp: }
- }
\cs_new:Npn \__cookingunits_split:N #1
{
\bool_if:NTF \l__cookingunits_lokal_fraction_bool
@@ -1356,19 +1420,29 @@
}
\cs_new:Npn \__cookingunits_split_fraction:n #1
{
- \bool_if:NTF \l__cookingunits_lokal_mixed_fraction_bool
- {
- \cs_set_eq:NN \__cookingunits_process_tmp: \__cookingunits_process_mixed_fraction_in_input:
- \__cookingunits_split_fraction_mixed:ww
- }{
- \cs_set_eq:NN \__cookingunits_process_tmp: \__cookingunits_process_fraction_in_input:
- \__cookingunits_split_fraction_frac:ww
- }
- #1 \q_stop / \q_recursion_tail \q_stop
- \q_recursion_stop
+ \cs_set_eq:NN \__cookingunits_process_tmp: \__cookingunits_process_generel_fraction_in_input:
+ \__cookingunits_split_fraction_mixed:ww
+ #1 \q_stop / \q_recursion_tail _ \q_nil \q_stop
+ \q_recursion_stop
\bool_lazy_or:nnT
{ \l__cookingunits_lokal_persons_bool }{ \l__cookingunits_eval_fractions_bool }
{ \bool_set_false:N \l__cookingunits_lokal_fraction_bool }
+ \bool_if:NT \l__cookingunits_convert_fractions_bool
+ {
+ \tl_if_eq:NNF \l__cookingunits_original_unit_tl \l__cookingunits_option_unit_tl
+ { \bool_set_false:N \l__cookingunits_lokal_fraction_bool }
+ }
+ }
+\cs_new:Npn \__cookingunits_split_fraction_mixed:ww #1 _ #2 \q_stop
+ {
+ \quark_if_nil:nTF {#2}
+ {
+ \tl_clear:N \l__cookingunits_mixed_fraction_tl
+ \__cookingunits_split_fraction_frac:ww #1 \q_stop
+ }{
+ \__cookingunits_parse_input_and_safe_in:nN {#1} \l__cookingunits_mixed_fraction_tl
+ \__cookingunits_split_fraction_frac:ww #2 \q_stop
+ }
}
\cs_new:Npn \__cookingunits_split_fraction_frac:ww #1 / #2 \q_stop
{
@@ -1378,11 +1452,6 @@
\__cookingunits_parse_input_and_safe_in:nN {#2} \l__cookingunits_number_tmpb_tl
\use_none_delimit_by_q_recursion_stop:w
}
-\cs_new:Npn \__cookingunits_split_fraction_mixed:ww #1 _ #2 \q_stop
- {
- \__cookingunits_parse_input_and_safe_in:nN {#1} \l__cookingunits_mixed_fraction_tl
- \__cookingunits_split_fraction_frac:ww #2 \q_stop
- }
\cs_generate_variant:Nn \__cookingunits_split_number:n { V }
\cs_generate_variant:Nn \__cookingunits_split_range:n { V }
\cs_generate_variant:Nn \__cookingunits_split_fraction:n { V }
@@ -1393,7 +1462,7 @@
\cs_set_eq:NN \__cookingunits_parse:N \__cookingunits_start_loop:N
\tl_map_function:nN {#1} \__cookingunits_parse:N
\bool_if:NTF \l__cookingunits_error_bool
- { \use_none_delimit_by_q_nil:w }
+ { }
{ \tl_set_eq:NN #2 \l__cookingunits_tmpa_tl }
}
\cs_new:Npn \__cookingunits_start_loop:N #1
@@ -1432,7 +1501,11 @@
{ \__cookingunits_create_error:n { Second-fraction-sign-not-allowed } }
{
\tl_if_in:NnTF \l__cookingunits_input_mixed_fraction_sign_tl {#1}
- { \__cookingunits_create_error:n { Second-mixed-fraction-sign-not-allowed } }
+ {
+ \bool_if:NTF \l__cookingunits_lokal_fraction_bool
+ { \__cookingunits_create_error:n { Second-mixed-fraction-sign-not-allowed } }
+ { \__cookingunits_create_error:n { missing-slash } }
+ }
{ \__cookingunits_create_error:nn { Token-not-allowed } {#1} }
}
}
@@ -1461,49 +1534,35 @@
\__cookingunits_post_process_input:NN \l__cookingunits_number_tmpa_tl \l__cookingunits_number_tmpb_tl
\__cookingunits_print_ranges:NN \l__cookingunits_number_tmpa_tl \l__cookingunits_number_tmpb_tl
}
-\cs_new:Npn \__cookingunits_process_fraction_in_input:
+\cs_new:Npn \__cookingunits_process_generel_fraction_in_input:
{
+ \__cookingunits_check_minus_remove_and_reverse:NN
+ \l__cookingunits_mixed_fraction_tl
+ \l__cookingunits_number_tmpa_tl
+ \l__cookingunits_number_tmpb_tl
+ \q_nil
\bool_lazy_or:nnTF
{ \l__cookingunits_lokal_fraction_bool }
{ \l__cookingunits_special_sign_bool }
{
- \__cookingunits_tl_if_in_remove_and_set_bool:NnN \l__cookingunits_number_tmpa_tl { - } \l__cookingunits_minus_bool
- \__cookingunits_tl_if_in_remove_and_reverse_bool:NnN \l__cookingunits_number_tmpb_tl { - } \l__cookingunits_minus_bool
- \__cookingunits_print_fractions:nnn
- { }
- { \l__cookingunits_number_tmpa_tl }
- { \l__cookingunits_number_tmpb_tl }
- }{
- \fp_compare:nNnT { \l__cookingunits_number_tmpb_tl } = { 0 }
- { \msg_error:nnV { cooking-units } { Division-by-zero } \l__cookingunits_given_amount_tl }
- \__cookingunits_tl_eval:Nn \l__cookingunits_number_tmpa_tl
- { \l__cookingunits_number_tmpa_tl / \l__cookingunits_number_tmpb_tl }
- \__cookingunits_process_and_print_number_in_input:N \l__cookingunits_number_tmpa_tl
- }
- }
-\cs_new:Npn \__cookingunits_process_mixed_fraction_in_input:
- {
- \__cookingunits_tl_if_in_remove_and_set_bool:NnN \l__cookingunits_mixed_fraction_tl { - } \l__cookingunits_minus_bool
- \__cookingunits_tl_if_in_remove_and_reverse_bool:NnN \l__cookingunits_number_tmpa_tl { - } \l__cookingunits_minus_bool
- \__cookingunits_tl_if_in_remove_and_reverse_bool:NnN \l__cookingunits_number_tmpb_tl { - } \l__cookingunits_minus_bool
- \bool_lazy_or:nnTF
- { \l__cookingunits_lokal_fraction_bool }
- { \l__cookingunits_special_sign_bool }
- {
- \__cookingunits_print_fractions:nnn
- { \l__cookingunits_mixed_fraction_tl }
+ \bool_if:NT \l__cookingunits_special_sign_bool
+ {
+ \msg_warning:nnV { cooking-units } { amount-not-known } \l__cookingunits_original_amount_tl
+ }
+ \__cookingunits_print_fractions:Nnn
+ \l__cookingunits_mixed_fraction_tl
{ \l__cookingunits_number_tmpa_tl }
{ \l__cookingunits_number_tmpb_tl }
}{
\fp_compare:nNnT { \l__cookingunits_number_tmpb_tl } = { 0 }
- { \msg_error:nnV { cooking-units } { Division-by-zero } \l__cookingunits_given_amount_tl }
+ { \msg_error:nnV { cooking-units } { Division-by-zero } \l__cookingunits_original_amount_tl }
\__cookingunits_tl_eval:Nn \l__cookingunits_number_tmpa_tl
{
- \bool_if:NTF \l__cookingunits_minus_bool
- { - \l__cookingunits_mixed_fraction_tl - }
- { \l__cookingunits_mixed_fraction_tl + }
+ \l__cookingunits_mixed_fraction_tl +
\l__cookingunits_number_tmpa_tl / \l__cookingunits_number_tmpb_tl
}
+ \bool_if:NT \l__cookingunits_minus_bool
+ { \tl_put_left:Nn \l__cookingunits_number_tmpa_tl { - } }
\__cookingunits_process_and_print_number_in_input:N \l__cookingunits_number_tmpa_tl
}
}
@@ -1526,12 +1585,12 @@
\cs_new:Npn \__cookingunits_calculate_input_and_store_in:nN #1#2
{
\fp_set:Nn \l__cookingunits_tmpa_fp {#1}
- \tl_if_in:cnTF { l__cookingunits_unit_change_ \l__cookingunits_given_unit_tl _tl } { \l__cookingunits_tmpa_fp }
+ \tl_if_in:cnTF { l__cookingunits_unit_change_ \l__cookingunits_original_unit_tl _tl } { \l__cookingunits_tmpa_fp }
{
- \__cookingunits_tl_eval:Nv #2 { l__cookingunits_unit_change_ \l__cookingunits_given_unit_tl _tl }
+ \__cookingunits_tl_eval:Nv #2 { l__cookingunits_unit_change_ \l__cookingunits_original_unit_tl _tl }
}{
\__cookingunits_tl_eval:Nn #2
- { \l__cookingunits_tmpa_fp * \tl_use:c { l__cookingunits_unit_change_ \l__cookingunits_given_unit_tl _tl } }
+ { \l__cookingunits_tmpa_fp * \tl_use:c { l__cookingunits_unit_change_ \l__cookingunits_original_unit_tl _tl } }
}
}
\cs_new:Npn \__cookingunits_calc_references:NN #1#2
@@ -1543,7 +1602,7 @@
=
{ \l__cookingunits_local_number_of_persons_int }
{
- \tl_set_eq:NN \l__cookingunits_tmpb_tl \l__cookingunits_given_unit_tl
+ \tl_set_eq:NN \l__cookingunits_tmpb_tl \l__cookingunits_original_unit_tl
\seq_if_in:NVTF \l__cookingunits_curef_do_not_change_seq \l__cookingunits_tmpb_tl
{ \msg_error:nnV { cooking-units } { curef-forbidden-unit } \l__cookingunits_tmpb_tl }
{ \__cookingunits_calc_references_aux:NN #1 #2 }
@@ -1569,18 +1628,12 @@
{
\quark_if_recursion_tail_stop_do:nn {#2}
{
- \bool_lazy_or:nnF
- { \l__cookingunits_round_precision_positive_bool }
- { \l__cookingunits_round_to_int_bool }
+ \bool_if:NT \l__cookingunits_round_precision_negative_bool
{ \bool_set_true:N \l__cookingunits_round_number_bool }
}
\int_compare:nNnT
{ \tl_count:n {#2} } >
- {
- \bool_if:NTF \l__cookingunits_round_to_int_bool
- { 0 }
- { \l__cookingunits_round_precision_int }
- }
+ { \l__cookingunits_round_precision_int }
{ \bool_set_true:N \l__cookingunits_round_number_bool }
\use_none_delimit_by_q_recursion_stop:w
}
@@ -1599,13 +1652,13 @@
\seq_if_in:NVT \l__cookingunits_temperatures_to_check_seq \l__cookingunits_option_unit_tl
{
\fp_compare:vNnT
- { c__cookingunits_ \l__cookingunits_option_unit_tl _min_fp } > {#1}
+ { l__cookingunits_ \l__cookingunits_option_unit_tl _min_fp } > {#1}
{
\msg_error:nnxx { cooking-units }
{ Temperature-too-low }
{ #1 \space \l__cookingunits_option_unit_tl }
{
- \fp_use:c { c__cookingunits_ \l__cookingunits_option_unit_tl _min_fp }
+ \fp_use:c { l__cookingunits_ \l__cookingunits_option_unit_tl _min_fp }
\space \l__cookingunits_option_unit_tl
}
}
@@ -1651,6 +1704,7 @@
\__cookingunits_cunum_initialise:nnnnn {#1} {#2} {#3} {#4} {#5}
\l__cookingunits_cunum_hook_tl
\__cookingunits_parse_input:n {#3}
+ \__cookingunits_process_and_print_input:
\__cookingunits_print_correct_unit:
}
\cs_new_protected:Npn \__cookingunits_cunum_initialise:nnnnn #1#2#3#4#5
@@ -1667,7 +1721,7 @@
\tl_use:N \l__cookingunits_value_unit_space_tl
\__cookingunits_change_unit:TF
{ \__cookingunits_translate:VV \l__cookingunits_option_unit_tl \c__cookingunits_postfix_unit_tl }
- { \__cookingunits_translate:VV \l__cookingunits_given_unit_tl \c__cookingunits_postfix_unit_tl }
+ { \__cookingunits_translate:VV \l__cookingunits_original_unit_tl \c__cookingunits_postfix_unit_tl }
}
\NewDocumentCommand \cutext { d<> O{} m m }
{
@@ -1706,7 +1760,7 @@
\__cookingunits_initialise_default:n {#3}
\__cookingunits_initialise_unit_change:n {#2}
\bool_if:NT \l__cookingunits_cutext_keep_unit_bool
- { \tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_given_unit_tl }
+ { \tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_original_unit_tl }
\__cookingunits_initialise_after_unit_change:nn {#1} {#2}
\bool_if:NT \l__cookingunits_fourty_two_bool
{ \tl_set:Nn \l__cookingunits_cutext_last_value_tl { 42 } }
@@ -1719,7 +1773,10 @@
{ \l__cookingunits_cutext_hook_tl }
\bool_if:NTF \l__cookingunits_cutext_old_bool
{ \__cookingunits_old_cutext:nnn {#2} {#3} {#4} }
- { \__cookingunits_parse_input:n {#3} }
+ {
+ \__cookingunits_parse_input:n {#3}
+ \__cookingunits_process_and_print_input:
+ }
\__cookingunits_print_correct_unit:
}
\cs_new_protected:Npn \__cookingunits_cutext_print_input:Nn #1#2
@@ -1748,7 +1805,7 @@
{
\__cookingunits_change_unit:TF
{ \__cookingunits_cutext_print_input:NV #1 \l__cookingunits_option_unit_tl }
- { \__cookingunits_cutext_print_input:NV #1 \l__cookingunits_given_unit_tl }
+ { \__cookingunits_cutext_print_input:NV #1 \l__cookingunits_original_unit_tl }
}
\cs_new:Npn \__cookingunits_cutext_print_correct_unitname:
{
@@ -1759,13 +1816,13 @@
{ \__cookingunits_translate:VV \l__cookingunits_option_unit_tl \c__cookingunits_postfix_unitname_tl }
{ \__cookingunits_translate:VV \l__cookingunits_option_unit_tl \c__cookingunits_postfix_unitname_pl_tl }
}
- { \__cookingunits_translate:VV \l__cookingunits_given_unit_tl \c__cookingunits_postfix_unitname_pl_tl }
+ { \__cookingunits_translate:VV \l__cookingunits_original_unit_tl \c__cookingunits_postfix_unitname_pl_tl }
}
\cs_new:Npn \__cookingunits_cutext_pre_process_input:NN #1#2
{
\__cookingunits_change_unit:TF
{ \tl_set_eq:NN \l__cookingunits_tmpb_tl \l__cookingunits_option_unit_tl }
- { \tl_set_eq:NN \l__cookingunits_tmpb_tl \l__cookingunits_given_unit_tl }
+ { \tl_set_eq:NN \l__cookingunits_tmpb_tl \l__cookingunits_original_unit_tl }
\__cookingunits_unitname_get:NxF \l__cookingunits_tmpa_tl \l__cookingunits_tmpb_tl
{
\msg_warning:nnx
@@ -1812,7 +1869,7 @@
\tl_const:Nn \c__cookingunits_cuam_marker_tl { __cookingunits_cunum }
\tl_new:c { l__cookingunits_unit_change_ \c__cookingunits_cuam_marker_tl _tl }
\tl_set:cn { l__cookingunits_unit_change_ \c__cookingunits_cuam_marker_tl _tl } { 1.0 }
-\clist_new:c { l__cookingunits_predefined_option_ \c__cookingunits_cuam_marker_tl _clist }
+\clist_new:c { l__cookingunits_unit_option_ \c__cookingunits_cuam_marker_tl _clist }
\NewDocumentCommand \cuam { d<> O{} m }
{
\__cookingunits_if_arrow_grab_until_close_do:nnTF {#3} { }
@@ -1831,13 +1888,14 @@
{ \__cookingunits_cuam_old:n {#3} }
{
\__cookingunits_parse_input:n {#3}
+ \__cookingunits_process_and_print_input:
\__cookingunits_print_correct_unit:
}
}
\cs_new_protected:Npn \__cookingunits_cuam_initialise:nn #1#2
{
\__cookingunits_set_process_and_print_for_cuam:
- \tl_set_eq:NN \l__cookingunits_given_unit_tl \c__cookingunits_cuam_marker_tl
+ \tl_set_eq:NN \l__cookingunits_original_unit_tl \c__cookingunits_cuam_marker_tl
\tl_set_eq:NN \l__cookingunits_option_unit_tl \c__cookingunits_cuam_marker_tl
\bool_set_false:N \l__cookingunits_lokal_phrase_bool
\__cookingunits_initialise_after_unit_change:nn {#1} {#2}
@@ -1982,17 +2040,22 @@
}
\cs_new:Npn \__cookingunits_cukeys_define_keys_and_single_keys:nn #1#2
{
- \__cookingunits_error_if_unit_not_defined:n {#1}
+ \__cookingunits_error_if_unit_not_defined:nTF {#1}
+ { \bool_set_true:N } { \bool_set_false:N }
+ \l__cookingunits_unit_error_bool
\tl_if_blank:nF {#2}
{
+ \prop_gclear:N \g__cookingunits_master_changer_prop
+ \prop_gclear:N \g__cookingunits_convert_to_eV_remember_prop
\seq_clear:N \l__cookingunits_tmpa_seq
\prop_clear:N \l__cookingunits_tmpa_prop
+ \prop_clear_new:c { l__cookingunits_cukeys_ #1 _prop }
\bool_if:NTF \l__cookingunits_single_key_bool
{
\__cookingunits_cukeys_parse_and_create_single_key:nn {#1} {#2}
}{
\fp_set:Nn \l__cookingunits_tmpa_fp { 1.0 }
- \tl_set:Nn \l__cookingunits_given_unit_tl {#1}
+ \tl_set:Nn \l__cookingunits_original_unit_tl {#1}
\__cookingunits_cukeys_parse_and_create_keys:nn {#1}
{
{#1} { 1.0 } #2
@@ -2004,79 +2067,106 @@
{
\__cookingunits_cukeys_parse_input:nn #2
\q_recursion_tail \q_recursion_tail \q_recursion_stop
- \__cookingunits_cukeys_create_key_prop:n {#1}
- \clist_set_from_seq:NN \l__cookingunits_tmpa_clist \l__cookingunits_tmpa_seq
- \__cookingunits_cukeys_define_keys:V \l__cookingunits_tmpa_clist
+ \bool_if:NF \l__cookingunits_unit_error_bool
+ {
+ \__cookingunits_cukeys_create_key_prop:n {#1}
+ \clist_set_from_seq:NN \l__cookingunits_tmpa_clist \l__cookingunits_tmpa_seq
+ \__cookingunits_cukeys_define_keys:V \l__cookingunits_tmpa_clist
+ }
}
+\cs_generate_variant:Nn \__cookingunits_cukeys_parse_and_create_keys:nn { Vn }
\cs_new:Npn \__cookingunits_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 } }
- \__cookingunits_error_if_unit_not_defined:n {#1}
- \seq_put_right:Nn \l__cookingunits_tmpa_seq {#1}
- \prop_put:Nnx \l__cookingunits_tmpa_prop {#1} { \fp_eval:n { (#2) / \l__cookingunits_tmpa_fp } }
+ \__cookingunits_error_if_unit_not_defined:nF {#1}
+ {
+ \seq_if_in:NnF \l__cookingunits_tmpa_seq {#1}
+ { \seq_put_right:Nn \l__cookingunits_tmpa_seq {#1} }
+ \prop_put:Nnx \l__cookingunits_tmpa_prop {#1} { \fp_eval:n { (#2) * \l__cookingunits_tmpa_fp } }
+ }
\__cookingunits_cukeys_parse_input:nn
}
+
\cs_new:Npn \__cookingunits_cukeys_create_key_prop:n #1
{
- \prop_clear:N \l__cookingunits_tmpb_prop
- \prop_put:NnV \l__cookingunits_tmpb_prop { Liste } \l__cookingunits_tmpa_seq
- \prop_put:NnV \l__cookingunits_tmpb_prop { prop } \l__cookingunits_tmpa_prop
- \prop_put:NnV \l__cookingunits_tmpb_prop { Erstes Ding } \l__cookingunits_given_unit_tl
+ \prop_set_eq:cN { l__cookingunits_cukeys_ #1 _prop } \l__cookingunits_tmpa_prop
+ \prop_put:cnV { l__cookingunits_cukeys_ #1 _prop } { Liste } \l__cookingunits_tmpa_seq
\seq_map_inline:Nn \l__cookingunits_tmpa_seq
{
- \prop_set_eq:cN { l__cookingunits_cukeys_ ##1 _prop } \l__cookingunits_tmpb_prop
+ \tl_set_eq:cN { l__cookingunits_base_key_unit_ ##1 _tl } \l__cookingunits_original_unit_tl
\tl_set:cn { l__cookingunits_unit_change_ ##1 _tl } { 1.0 }
- \seq_map_inline:Nn \l__cookingunits_tmpa_seq
- {
- \prop_put:cnx { l__cookingunits_cukeys_ ##1 _prop }
- {####1}
- {
- \fp_eval:n
- {
- ( \prop_item:Nn \l__cookingunits_tmpa_prop {####1} ) /
- ( \prop_item:Nn \l__cookingunits_tmpa_prop {##1} )
- }
- }
- }
}
}
\cs_new:Npn \__cookingunits_cukeys_define_keys:n #1
{
\seq_map_inline:Nn \l__cookingunits_tmpa_seq
{
- \seq_if_in:NnF \l__cookingunits_list_of_defined_keys_seq {##1}
- { \seq_put_right:Nn \l__cookingunits_list_of_defined_keys_seq {##1} }
- \keys_define:nn { cooking-units }
- {
- ##1 .choices:Vn =
- \l__cookingunits_tmpa_clist
- {
- \__cookingunits_cukeys_define_keys_and_single_key_aux:n {##1}
- } ,
- ##1 / unknown .code:n=
- {
- \seq_set_split:Nnn \l_tmpa_seq { , } {#1}
- \msg_error:nnxxx
- { cooking-units }
- { key-choice-unknown }
- {##1}
- {####1}
- { \seq_use:Nnnn \l_tmpa_seq { ',~ ' } { ',~ ' } { ' ~ and ~ ' } }
- } ,
- ##1 .default:n = {##1} ,
- ##1 .groups:n = { change-unit }
- }
+ \__cookingunits_cukeys_keys_define:nn {##1} {#1}
}
}
+\cs_new:Npn \__cookingunits_cukeys_keys_define:nn #1#2
+ {
+ \seq_if_in:NnF \l__cookingunits_list_of_defined_keys_seq {#1}
+ { \seq_put_right:Nn \l__cookingunits_list_of_defined_keys_seq {#1} }
+ \keys_define:nn { cooking-units }
+ {
+ #1 .choices:nn =
+ {#2}
+ {
+ \__cookingunits_cukeys_define_keys_and_single_key_aux:n {#1}
+ } ,
+ #1 / unknown .code:n=
+ {
+ \seq_set_split:Nnn \l_tmpa_seq { , } {#2}
+ \msg_error:nnxxx
+ { cooking-units }
+ { key-choice-unknown }
+ {#1}
+ {##1}
+ { \__cookingunits_seq_use_msg:N \l_tmpa_seq }
+ } ,
+ #1 .default:n = {#1} ,
+ #1 .groups:n = { change-unit }
+ }
+ }
\cs_generate_variant:Nn \__cookingunits_cukeys_define_keys:n { V }
+\prg_new_conditional:Npnn \__cookingunits_prop_get_master:nnN #1#2#3 { F }
+ {
+ \prop_get:NnNTF \g__cookingunits_master_changer_prop { #1 ~->~ #2 } #3
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+\cs_generate_variant:Nn \__cookingunits_prop_get_master:nnNF { nVc }
+\cs_new:Npn \__cookingunits_prop_gput_master:nnn #1#2#3
+ {
+ \prop_gput:Nnn \g__cookingunits_master_changer_prop { #1 ~->~ #2 } {#3}
+ }
+\cs_generate_variant:Nn \__cookingunits_prop_gput_master:nnn { nVV, nVv }
\cs_new:Npn \__cookingunits_cukeys_define_keys_and_single_key_aux:n #1
{
- \prop_get:cVc
- { l__cookingunits_cukeys_#1_prop }
- \l_keys_choice_tl
- { l__cookingunits_unit_change_ #1_tl }
+ \__cookingunits_prop_get_master:nVcF {#1} \l_keys_choice_tl { l__cookingunits_unit_change_ #1_tl }
+ {
+ \prop_if_exist:cTF { l__cookingunits_cukeys_ #1 _prop }
+ {
+ \prop_get:cVc
+ { l__cookingunits_cukeys_ #1 _prop }
+ \l_keys_choice_tl
+ { l__cookingunits_unit_change_ #1_tl }
+ \__cookingunits_prop_gput_master:nVv {#1} \l_keys_choice_tl { l__cookingunits_unit_change_ #1_tl }
+ }{
+ \tl_set_eq:Nc \l__cookingunits_tmpa_tl { l__cookingunits_base_key_unit_ #1 _tl }
+ \prop_set_eq:Nc \l__cookingunits_tmpa_prop { l__cookingunits_cukeys_ \l__cookingunits_tmpa_tl _prop }
+ \__cookingunits_tl_eval:Nn \l__cookingunits_tmpb_tl
+ {
+ (\exp_args:NNV\prop_item:Nn \l__cookingunits_tmpa_prop \l_keys_choice_tl) /
+ (\prop_item:Nn \l__cookingunits_tmpa_prop {#1})
+ }
+ \__cookingunits_prop_gput_master:nVV {#1} \l_keys_choice_tl \l__cookingunits_tmpb_tl
+ \tl_set:cV { l__cookingunits_unit_change_ #1 _tl } \l__cookingunits_tmpb_tl
+ }
+ }
\prop_put:NnV \l__cookingunits_change_unit_prop {#1} \l_keys_choice_tl
}
\cs_new:Npn \__cookingunits_cukeys_parse_and_create_single_key:nn #1#2
@@ -2087,9 +2177,12 @@
\char_set_catcode_ignore:N\ %
} { {#1} { 1.0 } #2 }
\__cookingunits_cusinglekeys_parse_input:V \l__cookingunits_tmpa_tl
- \__cookingunits_cusinglekeys_create_key_prop:n {#1}
- \clist_set_from_seq:NN \l__cookingunits_tmpa_clist \l__cookingunits_tmpa_seq
- \__cookingunits_cukeys_define_singlekey:nV {#1} \l__cookingunits_tmpa_clist
+ \bool_if:NF \l__cookingunits_unit_error_bool
+ {
+ \__cookingunits_cusinglekeys_create_key_prop:n {#1}
+ \clist_set_from_seq:NN \l__cookingunits_tmpa_clist \l__cookingunits_tmpa_seq
+ \__cookingunits_cukeys_define_singlekey:nV {#1} \l__cookingunits_tmpa_clist
+ }
}
\cs_new:Npn \__cookingunits_cusinglekeys_parse_input:n #1
{
@@ -2102,45 +2195,26 @@
\quark_if_recursion_tail_stop:n {#1}
\quark_if_recursion_tail_stop_do:nn {#2}
{ \msg_error:nn { cooking-units } { missing-argument } }
- \__cookingunits_error_if_unit_not_defined:n {#1}
- \seq_put_right:Nn \l__cookingunits_tmpa_seq {#1}
- \tl_set:Nn \l__cookingunits_tmpa_tl {#2}
- \tl_replace_all:NVn \l__cookingunits_tmpa_tl \c__cookingunits_input_str_hash_one_tl { \l__cookingunits_tmpa_fp }
- \prop_put:NnV \l__cookingunits_tmpa_prop {#1} \l__cookingunits_tmpa_tl
+ \__cookingunits_error_if_unit_not_defined:nF {#1}
+ {
+ \seq_if_in:NnF \l__cookingunits_tmpa_seq {#1}
+ { \seq_put_right:Nn \l__cookingunits_tmpa_seq {#1} }
+ \tl_set:Nn \l__cookingunits_tmpa_tl {#2}
+ \tl_replace_all:NVn \l__cookingunits_tmpa_tl \g__cookingunits_input_str_hash_one_tl { \l__cookingunits_tmpa_fp }
+ \prop_put:NnV \l__cookingunits_tmpa_prop {#1} \l__cookingunits_tmpa_tl
+ }
\__cookingunits_cusinglekeys_parse_input_aux:nn
}
\cs_new:Npn \__cookingunits_cusinglekeys_create_key_prop:n #1
{
\tl_set:cn { l__cookingunits_unit_change_ #1 _tl } { 1.0 }
+ \tl_set:cn { l__cookingunits_base_key_unit_ #1 _tl } {#1}
\prop_set_eq:cN { l__cookingunits_cukeys_ #1 _prop } \l__cookingunits_tmpa_prop
- \prop_put:cnn { l__cookingunits_cukeys_ #1 _prop } { Erstes Ding } {#1}
\prop_put:cnV { l__cookingunits_cukeys_ #1 _prop } { Liste } \l__cookingunits_tmpa_seq
- \prop_put:cnV { l__cookingunits_cukeys_ #1 _prop } { prop } \l__cookingunits_tmpa_prop
}
\cs_new:Npn \__cookingunits_cukeys_define_singlekey:nn #1#2
{
- \seq_if_in:NnF \l__cookingunits_list_of_defined_keys_seq {#1}
- { \seq_put_right:Nn \l__cookingunits_list_of_defined_keys_seq {#1} }
- \keys_define:nn { cooking-units }
- {
- #1 .choices:Vn =
- \l__cookingunits_tmpa_clist
- {
- \__cookingunits_cukeys_define_keys_and_single_key_aux:n {#1}
- } ,
- #1 / unknown .code:n=
- {
- \seq_set_split:Nnn \l_tmpa_seq { , } {#2}
- \msg_error:nnxxx
- { cooking-units }
- { key-choice-unknown }
- {#1}
- {##1}
- { \seq_use:Nnnn \l_tmpa_seq { ',' } { ',' } { ' ~ and ~ ' } }
- } ,
- #1 .default:n = {#1} ,
- #1 .groups:n = { change-unit } ,
- }
+ \__cookingunits_cukeys_keys_define:nn {#1} {#2}
}
\cs_generate_variant:Nn \__cookingunits_cukeys_define_singlekey:nn { nV }
\NewDocumentCommand \cuaddkeys { m m }
@@ -2161,24 +2235,27 @@
}
\cs_new:Npn \__cookingunits_cukeys_add_keys_or_single_keys:nn #1#2
{
- \__cookingunits_error_if_unit_not_defined:n {#1}
- \seq_if_in:NnF \l__cookingunits_list_of_defined_keys_seq {#1}
- { \msg_error:nnn { cooking-units } { Key-not-defined } {#1} }
- \tl_if_blank:nF {#2}
+ \__cookingunits_error_if_unit_not_defined:nF {#1}
{
- \__cookingunits_cukeys_add_keys_and_single_key_aux:n {#1}
- \bool_if:NTF \l__cookingunits_single_key_bool
- { \__cookingunits_cukeys_parse_and_create_single_key:nn {#1} {#2} }
- { \__cookingunits_cukeys_parse_and_create_keys:nn {#1} {#2} }
+ \seq_if_in:NnF \l__cookingunits_list_of_defined_keys_seq {#1}
+ { \msg_error:nnn { cooking-units } { Key-not-defined } {#1} }
+ \tl_if_blank:nF {#2}
+ {
+ \prop_gclear:N \g__cookingunits_master_changer_prop
+ \__cookingunits_cukeys_add_keys_and_single_key_aux:n {#1}
+ \bool_if:NTF \l__cookingunits_single_key_bool
+ { \__cookingunits_cukeys_parse_and_create_single_key:nn {#1} {#2} }
+ { \__cookingunits_cukeys_parse_and_create_keys:Vn \l__cookingunits_original_unit_tl {#2} }
+ }
}
}
\cs_generate_variant:Nn \__cookingunits_cukeys_add_keys_or_single_keys:nn { nV }
\cs_new:Npn \__cookingunits_cukeys_add_keys_and_single_key_aux:n #1
{
- \prop_get:cnN { l__cookingunits_cukeys_ #1 _prop } { Liste } \l__cookingunits_tmpa_seq
- \prop_get:cnN { l__cookingunits_cukeys_ #1 _prop } { prop } \l__cookingunits_tmpa_prop
- \prop_get:cnN { l__cookingunits_cukeys_ #1 _prop } { Erstes Ding } \l__cookingunits_given_unit_tl
- \prop_get:cVN { l__cookingunits_cukeys_ #1 _prop } \l__cookingunits_given_unit_tl \l__cookingunits_tmpa_fp
+ \tl_set_eq:Nc \l__cookingunits_original_unit_tl { l__cookingunits_base_key_unit_ #1 _tl }
+ \prop_set_eq:Nc \l__cookingunits_tmpa_prop { l__cookingunits_cukeys_ \l__cookingunits_original_unit_tl _prop }
+ \prop_get:NnN\l__cookingunits_tmpa_prop { Liste } \l__cookingunits_tmpa_seq
+ \prop_get:NnN \l__cookingunits_tmpa_prop {#1} \l__cookingunits_tmpa_fp
}
\NewDocumentCommand \declarecookingunit { o m }
{
@@ -2210,17 +2287,16 @@
\tl_if_in:NnT \l__cookingunits_unit_letter_not_allowed_tl {##1}
{ \msg_error:nnn { cooking-units } { character-not-allowed } {#2} }
}
- \seq_put_right:Nn \g__cookingunits_list_of_defined_units_seq {#2}
+ \seq_gput_right:Nn \g__cookingunits_list_of_defined_units_seq {#2}
\tl_new:c { l__cookingunits_unit_change_ #2 _tl }
\tl_set:cn { l__cookingunits_unit_change_ #2 _tl } { 1.0 }
- \clist_new:c { l__cookingunits_predefined_option_#2_clist }
+ \clist_new:c { l__cookingunits_unit_option_ #2 _clist }
\keys_define:nn { cooking-units }
{
- set-option-for-#2 .clist_set:c = { l__cookingunits_predefined_option_#2_clist } ,
- add-option-for-#2 .code:n =
- { \clist_put_right:cn { l__cookingunits_predefined_option_#2_clist } {##1} },
+ set-option-for-#2 .code:n = { \cusetoptionfor {#2} {##1} } ,
+ add-option-for-#2 .code:n = { \cuaddoptionfor {#2} {##1} },
}
- \prop_new:c { l__cookingunits_cukeys_ #2 _prop }
+ \tl_new:c { l__cookingunits_base_key_unit_ #2 _tl }
\tl_new:c { l__cookingunits_default_unit_ #2 _tl }
}
}
@@ -2229,14 +2305,114 @@
\IfNoValueTF {#1}
{
\tl_set:cn { l__cookingunits_default_unit_ #2 _tl } {#2}
- \__cookingunits_deftranslation_base:xxn {#2} \c__cookingunits_postfix_unit_tl {#2}
+ \__cookingunits_deftranslation_base:xVn {#2} \c__cookingunits_postfix_unit_tl {#2}
}{
\tl_set:cn { l__cookingunits_default_unit_ #2 _tl } {#1}
- \__cookingunits_deftranslation_base:xxn {#2} \c__cookingunits_postfix_unit_tl {#1}
+ \__cookingunits_deftranslation_base:xVn {#2} \c__cookingunits_postfix_unit_tl {#1}
+ }
+ \__cookingunits_deftranslation_base:xVn {#2} \c__cookingunits_postfix_unitname_tl { \q__cookingunits_no_translation }
+ \__cookingunits_deftranslation_base:xVn {#2} \c__cookingunits_postfix_unitname_pl_tl { \q__cookingunits_no_translation }
+ \__cookingunits_deftranslation_base:xVn {#2} \c__cookingunits_postfix_gender_tl { m }
+ }
+\NewDocumentCommand \declarecookingderivatives { m m m m }
+ {
+ \__cookingunits_declare_cooking_derivative:nnnn {#1} {#2} {#3} {#4}
+ }
+\cs_new:Npn \__cookingunits_tl_set_list:Nnn #1#2#3
+ {
+ \__cookingunits_tl_set_list_aux:Nnnnnnnnn #1 {#2} #3
+ \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil
+ \q_recursion_stop
+ }
+\cs_generate_variant:Nn \__cookingunits_tl_set_list:Nnn { NnV, NVV }
+\cs_new:Npn \__cookingunits_tl_set_list_aux:Nnnnnnnnn #1#2#3#4#5#6#7#8#9
+ {
+ \tl_set:Nf #1
+ {
+ \int_case:nn { \l__cookingunits_curr_depth_int }
+ {
+ { 1 } { }
+ { 2 } { {#3} }
+ { 3 } { {#3}{#4} }
+ { 4 } { {#3}{#4}{#5} }
+ { 5 } { {#3}{#4}{#5}{#6} }
+ { 6 } { {#3}{#4}{#5}{#6}{#7} }
+ { 7 } { {#3}{#4}{#5}{#6}{#7}{#8} }
+ { 8 } { {#3}{#4}{#5}{#6}{#7}{#8}{#9} }
+ }
+ {#2}
+ }
+ \use_none_delimit_by_q_recursion_stop:w
+ }
+\cs_new:Npn \__cookingunits_declare_cooking_derivative:nnnn #1#2#3#4
+ {
+ \prop_gclear:N \g__cookingunits_master_changer_prop
+ \seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
+ \seq_clear:N \l__cookingunits_number_of_iterations_seq
+ \seq_clear:N \l__cookingunits_derivative_unit_list_seq
+ \seq_clear:N \l__cookingunits_derivative_symbol_list_seq
+ \seq_clear:N \l__cookingunits_derivative_value_list_seq
+ \int_set:Nn \l__cookingunits_max_depth_int { \seq_count:N \l__cookingunits_tmpa_seq }
+ \int_set:Nn \l__cookingunits_curr_depth_int { 1 }
+ \cs_generate_from_arg_count:NNnn \__cookingunits_tmp_unit_and_symbol_list:w \cs_set:Npn
+ { \l__cookingunits_max_depth_int }
+ {
+ \seq_put_right:Nn \l__cookingunits_derivative_unit_list_seq {#2}
+ \seq_put_right:Nn \l__cookingunits_derivative_symbol_list_seq {#4}
+ }
+ \cs_generate_from_arg_count:NNnn \__cookingunits_tmp_value_list:w \cs_set:Npn
+ { \l__cookingunits_max_depth_int }
+ { \seq_put_right:Nx \l__cookingunits_derivative_value_list_seq { \fp_eval:n {#3} } }
+ \int_step_inline:nn { \l__cookingunits_max_depth_int }
+ {
+ \tl_set_eq:Nc \l__cookingunits_original_unit_tl
+ { l__cookingunits_base_key_unit_ \seq_item:Nn \l__cookingunits_tmpa_seq {##1} _tl }
+ \prop_set_eq:Nc \l__cookingunits_tmpa_prop { l__cookingunits_cukeys_ \l__cookingunits_original_unit_tl _prop }
+ \prop_get:NnN \l__cookingunits_tmpa_prop { Liste } \l__cookingunits_tmpb_seq
+ \int_set:Nn \l__cookingunits_tmpa_int { \seq_count:N \l__cookingunits_tmpb_seq }
+ \seq_put_right:NV \l__cookingunits_number_of_iterations_seq \l__cookingunits_tmpa_int
+ \seq_clear_new:c { l__cookingunits_tmp_ ##1 _seq }
+ \prop_clear_new:c { l__cookingunits_tmp_ ##1 _prop }
+ \seq_set_eq:cN { l__cookingunits_tmp_ ##1 _seq } \l__cookingunits_tmpb_seq
+ \prop_set_eq:cN { l__cookingunits_tmp_ ##1 _prop } \l__cookingunits_tmpa_prop
+ }
+ \seq_map_function:cN
+ { l__cookingunits_tmp_ \int_use:N \l__cookingunits_curr_depth_int _seq }
+ \__cookingunits_seq_step_function:n
+ \seq_get_left:NN \l__cookingunits_derivative_unit_list_seq \l__cookingunits_original_unit_tl
+ \prop_clear_new:c { l__cookingunits_cukeys_ \l__cookingunits_original_unit_tl _prop }
+ \int_zero:N \l__cookingunits_tmpa_int
+ \clist_set_from_seq:NN \l__cookingunits_tmpa_clist \l__cookingunits_derivative_unit_list_seq
+ \seq_map_inline:Nn \l__cookingunits_derivative_unit_list_seq
+ {
+ \int_incr:N \l__cookingunits_tmpa_int
+ \tl_set:Nx \l__cookingunits_tmpa_tl { \seq_item:Nn \l__cookingunits_derivative_symbol_list_seq { \l__cookingunits_tmpa_int } }
+ \exp_after:wN \declarecookingunit \exp_after:wN [ \l__cookingunits_tmpa_tl ] {##1}
+ \prop_put:cnx
+ { l__cookingunits_cukeys_ \l__cookingunits_original_unit_tl _prop }
+ {##1}
+ { \seq_item:Nn \l__cookingunits_derivative_value_list_seq { \l__cookingunits_tmpa_int } }
+ \tl_clear_new:c { l__cookingunits_base_key_unit_ ##1 _tl }
+ \tl_set_eq:cN { l__cookingunits_base_key_unit_ ##1 _tl } \l__cookingunits_original_unit_tl
+ \exp_args:NnV \__cookingunits_cukeys_keys_define:nn {##1} \l__cookingunits_tmpa_clist
+ }
+ }
+\cs_new:Npn \__cookingunits_seq_step_function:n #1
+ {
+ \__cookingunits_tl_set_list:NnV \l__cookingunits_list_of_units_tl {#1} \l__cookingunits_list_of_units_tl
+ \prop_get:cnN { l__cookingunits_tmp_ \int_use:N \l__cookingunits_curr_depth_int _prop } {#1} \l__cookingunits_tmpa_tl
+ \__cookingunits_tl_set_list:NVV \l__cookingunits_list_of_values_tl \l__cookingunits_tmpa_tl \l__cookingunits_list_of_values_tl
+ \int_compare:nNnTF { \l__cookingunits_curr_depth_int } = { \l__cookingunits_max_depth_int }
+ {
+ \exp_after:wN \__cookingunits_tmp_unit_and_symbol_list:w \l__cookingunits_list_of_units_tl
+ \exp_after:wN \__cookingunits_tmp_value_list:w \l__cookingunits_list_of_values_tl
+ }{
+ \int_incr:N \l__cookingunits_curr_depth_int
+ \seq_map_function:cN
+ { l__cookingunits_tmp_ \int_use:N \l__cookingunits_curr_depth_int _seq }
+ \__cookingunits_seq_step_function:n
+ \int_decr:N \l__cookingunits_curr_depth_int
}
- \__cookingunits_deftranslation_base:xxn {#2} \c__cookingunits_postfix_unitname_tl { \q__cookingunits_no_translation }
- \__cookingunits_deftranslation_base:xxn {#2} \c__cookingunits_postfix_unitname_pl_tl { \q__cookingunits_no_translation }
- \__cookingunits_deftranslation_base:xxn {#2} \c__cookingunits_postfix_gender_tl { m }
}
\tl_new:N \l__cookingunits_sanitise_tl
\cs_new_protected:Npn \__cookingunits_sanitise_aux:w #1 \q_mark
@@ -2323,15 +2499,16 @@
\quark_if_recursion_tail_stop:n {#1}
\quark_if_recursion_tail_stop_do:nn {#2}
{ \msg_error:nn { cooking-units } { missing-argument } }
- \__cookingunits_error_if_unit_not_defined:n {#1}
+ \__cookingunits_error_if_unit_not_defined:nT {#1}
+ { \use_none_delimit_by_q_recursion_stop:w }
\quark_if_no_value:nTF {#2}
{
- \__cookingunits_deftranslation_to:Vxxv
+ \__cookingunits_deftranslation_to:VxVv
\l__cookingunits_language_tl {#1}
\c__cookingunits_postfix_unit_tl
{ l__cookingunits_default_unit_ #1 _tl }
}{
- \__cookingunits_deftranslation_to:Vxxn
+ \__cookingunits_deftranslation_to:VxVn
\l__cookingunits_language_tl {#1}
\c__cookingunits_postfix_unit_tl {#2}
}
@@ -2343,8 +2520,11 @@
\quark_if_recursion_tail_stop_do:nn {#2}
{ \msg_error:nn { cooking-units } { missing-argument } }
\seq_if_in:NnF \g__cookingunits_allowed_special_keys_seq {#1}
- { \__cookingunits_error_if_unit_not_defined:n {#1} }
- \__cookingunits_deftranslation_to:Vxxn
+ {
+ \__cookingunits_error_if_unit_not_defined:nT {#1}
+ { \use_none_delimit_by_q_recursion_stop:w }
+ }
+ \__cookingunits_deftranslation_to:VxVn
\l__cookingunits_language_tl {#1}
\c__cookingunits_postfix_unitname_tl {#2}
\peek_meaning_ignore_spaces:NTF [
@@ -2355,7 +2535,7 @@
{
\seq_if_in:NnF \g__cookingunits_allowed_special_keys_seq {#1}
{
- \__cookingunits_deftranslation_to:Vxxn \l__cookingunits_language_tl {#1}
+ \__cookingunits_deftranslation_to:VxVn \l__cookingunits_language_tl {#1}
\c__cookingunits_postfix_unitname_pl_tl {#2}
}
\peek_meaning_ignore_spaces:NTF <
@@ -2364,10 +2544,16 @@
}
\cs_new:Npn \__cookingunits_cuname_parse_gender:nw #1 <#2>
{
- \__cookingunits_check_if_correct_gender_input:n {#2}
- \__cookingunits_deftranslation_to:Vxxn
- \l__cookingunits_language_tl {#1}
- \c__cookingunits_postfix_gender_tl {#2}
+ \__cookingunits_if_gender_error:nTF {#2}
+ {
+ \__cookingunits_deftranslation_to:VxVn
+ \l__cookingunits_language_tl {#1}
+ \c__cookingunits_postfix_gender_tl { m }
+ }{
+ \__cookingunits_deftranslation_to:VxVn
+ \l__cookingunits_language_tl {#1}
+ \c__cookingunits_postfix_gender_tl {#2}
+ }
\__cookingunits_cuname_parse_input:n
}
\NewDocumentCommand \cudefinesymbol { m m }
@@ -2383,13 +2569,15 @@
{ \msg_error:nn { cooking-units } { missing-argument } }
\seq_if_in:NnTF \g__cookingunits_allowed_special_keys_seq {#1}
{
- \__cookingunits_deftranslation_to:Vxxn \l__cookingunits_language_tl {#1}
+ \__cookingunits_deftranslation_to:VxVn \l__cookingunits_language_tl {#1}
\c__cookingunits_postfix_unitname_tl {#2}
}{
- \__cookingunits_error_if_unit_not_defined:n {#1}
- \__cookingunits_deftranslation_to:Vxxn
- \l__cookingunits_language_tl {#1}
- \c__cookingunits_postfix_unit_tl {#2}
+ \__cookingunits_error_if_unit_not_defined:nF {#1}
+ {
+ \__cookingunits_deftranslation_to:VxVn
+ \l__cookingunits_language_tl {#1}
+ \c__cookingunits_postfix_unit_tl {#2}
+ }
}
\__cookingunits_cuprint_define_printed_unit:nn
}
@@ -2443,11 +2631,11 @@
}{ \sort_return_same: }
}
}
- \__cookingunits_deftranslation_to:VxxV
+ \__cookingunits_deftranslation_to:VxVV
\l__cookingunits_language_tl { phrase-prop }
\c__cookingunits_postfix_phrase_tl
\l__cookingunits_phrase_prop
- \__cookingunits_deftranslation_to:VxxV
+ \__cookingunits_deftranslation_to:VxVV
\l__cookingunits_language_tl { phrase-clist }
\c__cookingunits_postfix_phrase_tl \l__cookingunits_phrase_numbers_seq
}
@@ -2492,15 +2680,21 @@
}
\cs_new:Npn \__cookingunits_chuphrase_parse_gender:nw #1 <#2>
{
- \__cookingunits_check_if_correct_gender_input:n {#2}
- \__cookingunits_deftranslation_to:Vxxn
- \l__cookingunits_language_tl { #1-phrase-gender }
- \c__cookingunits_postfix_gender_tl {#2}
+ \__cookingunits_if_gender_error:nTF {#2}
+ {
+ \__cookingunits_deftranslation_to:VxVn
+ \l__cookingunits_language_tl { #1-phrase-gender }
+ \c__cookingunits_postfix_gender_tl { m }
+ }{
+ \__cookingunits_deftranslation_to:VxVn
+ \l__cookingunits_language_tl { #1-phrase-gender }
+ \c__cookingunits_postfix_gender_tl {#2}
+ }
\__cookingunits_cuphrase_parse:n
}
\cs_new:Npn \__cookingunits_old_cutext:nnn #1#2#3
{
- \tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_given_unit_tl
+ \tl_set_eq:NN \l__cookingunits_option_unit_tl \l__cookingunits_original_unit_tl
\__cookingunits_old_cutext_default:nnn {#1} {#2} {#3}
}
\cs_new:Npn \__cookingunits_old_cutext_default:nnn #1#2#3
@@ -2612,7 +2806,7 @@
\cs_new:Npn \__cookingunits_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop
{
#1
- \__cookingunits_dim_horizontal:N \l__cookingunits_mixed_frac_dim
+ \skip_horizontal:N \l__cookingunits_mixed_frac_dim
\__cookingunits_frac:nn {#2} {#3}
}
\NewDocumentCommand \cufrac { O{} m }
@@ -2653,9 +2847,103 @@
\cs_new:Npn \__cookingunits_cufrac_parse_mixed_frac:www #1_#2/#3 \q_stop
{
#1
- \__cookingunits_dim_horizontal:N \l__cookingunits_mixed_frac_dim
+ \skip_horizontal:N \l__cookingunits_mixed_frac_dim
\__cookingunits_frac:nn {#2} {#3}
}
+\cs_new:Npn \__cookingunits_add_forbidden_unit:n #1
+ {
+ \seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
+ \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ {
+ \__cookingunits_error_if_unit_not_defined:nF {##1}
+ {
+ \seq_if_in:NnF \l__cookingunits_curef_do_not_change_seq {##1}
+ { \seq_put_right:Nn \l__cookingunits_curef_do_not_change_seq {##1} }
+ }
+ }
+ }
+\cs_new:Npn \__cookingunits_remove_forbidden_unit:n #1
+ {
+ \seq_set_from_clist:Nn \l__cookingunits_tmpa_seq {#1}
+ \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ {
+ \__cookingunits_error_if_unit_not_defined:nF {##1}
+ {
+ \seq_if_in:NnTF \l__cookingunits_curef_do_not_change_seq {##1}
+ { \seq_remove_all:Nn \l__cookingunits_curef_do_not_change_seq {##1} }
+ {
+ \msg_warning:nnnn { cooking-units } { curef-not-inside-list } {##1}
+ { \__cookingunits_seq_use_msg:N \l__cookingunits_curef_do_not_change_seq }
+ }
+ }
+ }
+ }
+\cs_new:Npn \__cookingunits_clear_forbidden_unit:
+ { \seq_clear:N \l__cookingunits_curef_do_not_change_seq }
+\NewDocumentCommand \cudeclareunitgroup { m m }
+ {
+ \__cookingunits_define_clear_unit_group:nn {#1} {#2}
+ \__cookingunits_add_to_unit_group:nn {#1} {#2}
+ }
+\NewDocumentCommand \cuaddtounitgroup { m m }
+ {
+ \__cookingunits_add_to_unit_group:nn {#1} {#2}
+ }
+\NewDocumentCommand \cuclearunitgroup { m }
+ {
+ \__cookingunits_error_if_group_not_defined:nF {#1}
+ { \__cookingunits_define_clear_unit_group:nn {#1} { } }
+ }
+\NewDocumentCommand \cusetoptionfor { m m }
+ {
+ \__cookingunits_map_trough_valid_unit_options:nnn {#1} {#2}
+ { \clist_set:cn { l__cookingunits_unit_option_ ##1 _clist } {##2} }
+ }
+\NewDocumentCommand \cuaddoptionfor { m m }
+ {
+ \__cookingunits_map_trough_valid_unit_options:nnn {#1} {#2}
+ { \clist_put_right:cn { l__cookingunits_unit_option_ ##1 _clist } {##2} }
+ }
+\NewDocumentCommand \cuclearoptionfor { m }
+ {
+ \__cookingunits_map_trough_valid_unit_options:nnn {#1} { }
+ { \clist_clear:c { l__cookingunits_unit_option_ ##1 _clist } }
+ }
+\cs_new:Npn \__cookingunits_tmp:w { }
+\cs_new:Npn \__cookingunits_map_trough_valid_unit_options:nnn #1#2 #3
+ {
+ \seq_clear:N \l__cookingunits_tmpa_seq
+ \clist_clear:N \l__cookingunits_tmpa_clist
+ \cs_set:Npn \__cookingunits_tmp:w ##1##2 {#3}
+ \clist_map_inline:nn {#1}
+ {
+ \__cookingunits_error_if_unit_not_defined:nF {##1}
+ { \seq_put_right:Nn \l__cookingunits_tmpa_seq {##1} }
+ }
+ \tl_if_empty:nF {#2}
+ { \__cookingunits_unit_options_check_validity:n {#2} }
+ \seq_map_inline:Nn \l__cookingunits_tmpa_seq
+ { \exp_args:NnV \__cookingunits_tmp:w {##1} \l__cookingunits_tmpa_clist }
+ }
+\cs_new:Npn \__cookingunits_unit_options_check_validity:n #1
+ {
+ \keyval_parse:NNn
+ \__cookingunits_unit_options_check_validity_aux_i:n
+ \__cookingunits_unit_options_check_validity_aux_ii:nn
+ {#1}
+ }
+\cs_new:Npn \__cookingunits_unit_options_check_validity_aux_i:n #1
+ {
+ \keys_if_exist:nnTF { cooking-units } {#1}
+ { \clist_put_right:Nn \l__cookingunits_tmpa_clist {#1} }
+ { \msg_error:nnn { cooking-units } { unknown-option } {#1} }
+ }
+\cs_new:Npn \__cookingunits_unit_options_check_validity_aux_ii:nn #1#2
+ {
+ \keys_if_exist:nnTF { cooking-units } {#1}
+ { \clist_put_right:Nn \l__cookingunits_tmpa_clist { #1={#2} } }
+ { \msg_error:nnn { cooking-units } { unknown-option } {#1} }
+ }
\NewDocumentCommand \cusetup { m }
{
\keys_set:nn { cooking-units } {#1}
@@ -2838,9 +3126,9 @@
{
{ dag }{ 100 }
{ g } { 1000 }
- { oz } { 35.27399 }
- { lb } { 2.2046226 } %% 2.204 622 6
- { stick } { 8.81849 }
+ { lb } { 1/0.45359237 }
+ { oz } { 16/0.45359237 }
+ { stick } { 4/0.45359237 }
{ eVc-2 } { 560958865.0e+27 } %% 560958865.0 +- 3.5 e+27
}
\cudefinekeys { d }
@@ -2855,7 +3143,7 @@
{ dm } { 10 }
{ cm } { 100 }
{ mm } { 1000 }
- { in } { 39.370079 }
+ { in } { 36/0.9144 }
{ chbareV-1 } { 5067730.759 } %% 5067730.759 +- 0.070
}
\cudefinekeys { l }
@@ -2905,12 +3193,15 @@
{
{ 12 } { Dutzend } < n >
}
+\cudeclareunitgroup { weight } { kg , dag, g, oz, lb, stick }
+\cudeclareunitgroup { length } { m , dm , cm , mm , in }
+\cudeclareunitgroup { volume } { l , dl , cl , ml }
+\cudeclareunitgroup { temperature } { C , F , K , Re }
+\cudeclareunitgroup { energy } { cal, kcal , J , kJ , eV }
+\cudeclareunitgroup { time } { d , h , min , s }
+\cusetoptionfor { F , C , K , Re } { round-precision = 0 }
\cusetup
{
- set-option-for-F = { round-to-int = true } ,
- set-option-for-C = { round-to-int = true } ,
- set-option-for-K = { round-to-int = true } ,
- set-option-for-Re = { round-to-int = true } ,
curef-add-forbidden-unit = { F , C , K , Re } ,
add-temperature-to-check =
{