summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-11-14 22:34:47 +0000
committerKarl Berry <karl@freefriends.org>2016-11-14 22:34:47 +0000
commitcd08665896fd28bcf3597c5e45969b3a5209a794 (patch)
treeeabe5723e4820e527a6e5610837e7e749e71c5d0 /Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
parent96679398651343a7668086d8a4bab8b66986be81 (diff)
cooking-units (14nov16)
git-svn-id: svn://tug.org/texlive/trunk@42507 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty')
-rw-r--r--Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty698
1 files changed, 512 insertions, 186 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 efbc1d03db3..701f8c3a718 100644
--- a/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
+++ b/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty
@@ -30,8 +30,8 @@
{ \RequirePackage {expl3} }
\ProvidesExplPackage
{cooking-units}
- {2016/10/19}
- {1.04}
+ {2016/11/13}
+ {1.10}
{Ein Paket fuer Kocheinheiten}
\@ifpackagelater { expl3 } { 2016/05/18 }
{ }
@@ -70,6 +70,9 @@
\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_new_eq:NN \__cooking_units_frac:nn \sfrac
\prop_new:N \l__cooking_units_change_unit_prop
\tl_new:N \l__cooking_units_tmpa_tl
@@ -87,16 +90,24 @@
\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_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_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_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
{ \char_set_catcode_letter:N \# } {#1}
+\tl_set:Nn \l__cooking_units_cutext_space_tl { \space }
\AtBeginDocument {
\cs_if_free:cT { T@TS1 }
{
@@ -121,12 +132,15 @@
}
\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_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
@@ -144,7 +158,17 @@
\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_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_set_true:N \l__cooking_units_parse_input_bool
+\bool_set_true:N \l__cooking_units_cutext_change_unit_bool
\quark_new:N \q__cooking_units_range
\clist_gset:Nn \g__cooking_units_allowed_unit_phrases_clist
{
@@ -161,7 +185,7 @@
\newtranslation [ to=German ] { one (m) (cu-unitname) } { ein }
\newtranslation [ to=German ] { one (f) (cu-unitname) } { eine }
\newtranslation [ to=German ] { one (n) (cu-unitname) } { ein }
-\keys_define:nn { cooking - units }
+\keys_define:nn { cooking-units }
{
eval-fraction .bool_set:N = \l__cooking_units_eval_fractions_bool ,
eval-fraction .default:n = { false } ,
@@ -230,20 +254,58 @@
round-half .choices:nn =
{ default , commercial }
{
- \cs_set:Npx \__cooking_units_round_setup:n ####1
+ \int_case:nn { \l_keys_choice_int }
{
- \exp_not:N \l__cooking_units_significant_figures_int
- \int_case:nn { \l_keys_choice_int }
- {
- { 1 } { }
- { 2 } { \exp_not:N, ####1 }
- }
+ { 1 } { \bool_set_false:N \l__cooking_units_round_commercial_bool }
+ { 2 } { \bool_set_true:N \l__cooking_units_round_commercial_bool }
}
},
round-half .default:n = { default },
- label .code:n = { \label{cooking-units-#1} } ,
- for-persons .int_set:N = \l__cooking_units_number_of_persons_int ,
- for-persons .default:n = { 4 } ,
+ set-number-of-persons .int_set:N = \l__cooking_units_calc_for_number_of_persons_int ,
+ set-number-of-persons .default:n = { 4 } ,
+ label .code:n =
+ {
+ \__cooking_units_label_and_persons:n {#1}
+ } ,
+ label .value_required:n = { true } ,
+ get-label .code:n =
+ {
+ \__cooking_units_curef:n {#1}
+ } ,
+ label .value_required:n = { true } ,
+ ref .code:n =
+ {
+ \__cooking_units_reference_label_and_persons:n {#1}
+ } ,
+ ref .value_required:n = { true } ,
+ cuam-version .choices:nn =
+ { new , old }
+ {
+ \int_case:nn { \l_keys_choice_int }
+ {
+ { 1 } { \bool_set_false:N \l__cooking_units_cuam_old_bool }
+ { 2 } { \bool_set_true:N \l__cooking_units_cuam_old_bool }
+ }
+ } ,
+ cuam-version .default:n = { new } ,
+ cutext-version .choices:nn =
+ { new , old }
+ {
+ \int_case:nn { \l_keys_choice_int }
+ {
+ { 1 } { \bool_set_false:N \l__cooking_units_cutext_old_bool }
+ { 2 } { \bool_set_true:N \l__cooking_units_cutext_old_bool }
+ }
+ } ,
+ cutext-version .default:n = { new } ,
+ recalculate-amount .bool_set:N = \l__cooking_units_calc_for_persons_bool ,
+ recalculate-amount .default:n = { false } ,
+ cutext-to-cunum .bool_set:N = \l__cooking_units_cutext_to_cunum_bool ,
+ cutext-to-cunum .default:n = { false } ,
+ cutext-space .tl_set:N = \l__cooking_units_cutext_space_tl ,
+ cutext-space .default:n = { \space } ,
+ cutext-change-unit .bool_set:N = \l__cooking_units_cutext_change_unit_bool ,
+ cutext-change-unit .default:n = { true } ,
}
\msg_new:nnnn { cooking-units } { fraction-not-allowed-with-range }
{
@@ -271,35 +333,35 @@
unit-key \ is \ written \ correctly.
\msg_see_documentation_text:n { cooking-units }
}
-\msg_new:nnnn { cooking - units } { unit-already-defined }
+\msg_new:nnnn { cooking-units } { unit-already-defined }
{ The\ unit \ '#1' \ is \ already \ defined. }
{
The \ unit-key \ is \ already \ defined. \ Please \ use \ a \ different \
key \ for \ a \ new \ unit.
\msg_see_documentation_text:n {cooking-units}
}
-\msg_new:nnnn { cooking - units } { missing-argument }
+\msg_new:nnnn { cooking-units } { missing-argument }
{ There \ is \ an \ missing \ argument. }
{
You \ probably \ have \ forgotten \ a \ curly-brace \ pair.
\msg_see_documentation_text:n {cooking-units}
}
-\msg_new:nnnn { cooking - units } { Division-by-zero }
+\msg_new:nnnn { cooking-units } { Division-by-zero }
{ Division\ by \ zero \ is \ not \ allowed. }
{ See \ a \ math \ book \ of \ your \ choice \ or \ for \ example \ Wikipedia. }
-\msg_new:nnnn { cooking - units } { Token-not-allowed }
+\msg_new:nnnn { cooking-units } { Token-not-allowed }
{ The \ token \ '#1' \ is \ not \ allowed. }
{
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.
@@ -308,7 +370,7 @@
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-to-low }
{
The \ temperature \ '#1' \ is \ to \ low.\ It \ cannot \ be \
below \ the \ absolute \ zero - point \ of \ '#2'. \ Note \ that \
@@ -319,7 +381,7 @@
disable \ this \ error.
}
{ See \ for \ example \ Wikipedia. }
-\msg_new:nnnn { cooking - units } { key-choice-unknown }
+\msg_new:nnnn { cooking-units } { key-choice-unknown }
{
The \ key \ '#1' \ only \ accepts \ only \
'#3' \ as \ a \ set \ of \ choices \ and \ '#2' \ is \ non \ of \ these.
@@ -330,7 +392,7 @@
and \ \cuaddtokeys.
\msg_see_documentation_text:n {cooking-units}
}
-\msg_new:nnnn { cooking - units } { amount-not-known }
+\msg_new:nnnn { cooking-units } { amount-not-known }
{
The \ amount \ of \ #1 \ is \ not \ known \ at \ line \
\msg_line_number: .
@@ -341,7 +403,7 @@
reminds\ you\ about\ that\ fact.
\msg_see_documentation_text:n {cooking-units}
}
-\msg_new:nnnn { cooking - units } { load-time-option }
+\msg_new:nnnn { cooking-units } { load-time-option }
{
The \ option \ '#1' \ is \ only \ available \ as \ a \ load-time-option. \
Please \ set \ it \ as \ a \ package \ option.
@@ -351,7 +413,7 @@
but \ only \ as \ a \ package \ option.
\msg_see_documentation_text:n { cooking-units }
}
-\msg_new:nnnn { cooking - units } { obsolete-command }
+\msg_new:nnnn { cooking-units } { obsolete-command }
{
Command \ #1 is \ obsolete. \ Please \ use \ #2 instead.
}
@@ -359,7 +421,7 @@
Don't \ use \ this \ old \ command \ ...
\msg_see_documentation_text:n { cooking-units }
}
-\msg_new:nnnn { cooking - units } { No-Value-given }
+\msg_new:nnnn { cooking-units } { No-Value-given }
{
Please \ input \ a \ number \ to \ check \ for \
'check-temperature'.
@@ -369,7 +431,7 @@
'check-temperature' \ is \ active.
\msg_see_documentation_text:n { cooking-units }
}
-\msg_new:nnnn { cooking - units } { Minimum-already-defined }
+\msg_new:nnnn { cooking-units } { Minimum-already-defined }
{
A \ minimum \ for \ '#1' \ has \ already \ been \ defined.
}
@@ -377,24 +439,73 @@
You \ cannot \ redefine \ it.
\msg_see_documentation_text:n { cooking-units }
}
+\msg_new:nnnn { cooking-units } { Number-of-persons-missing }
+ {
+ 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 }
+ }
+\msg_new:nnnn { cooking-units } { Number-of-persons-is-not-an-integer }
+ {
+ The \ number \ of \ persons \ the \ recipe \ is \ for \ must \ be \ an \
+ integer.
+ }
+ {
+ The \ number \ '#1' \ is \ not \ allowed.
+ \msg_see_documentation_text:n { cooking-units }
+ }
+\msg_new:nnnn { cooking-units } { label-already-defined }
+ {
+ The \ label \ '#1' \ has \ already \ been \ defined.
+ }
+ {
+ Each \ label \ must \ be \ unique.
+ \msg_see_documentation_text:n { cooking-units }
+ }
+\msg_new:nnnn { cooking-units } { label-not-defined }
+ {
+ The \ label \ is \ not \ defined. \ Please \ note \ that \ a \ label
+ \ has \ to \ defined \ before \ it \ is \ referenced.
+ }
+ {
+ Define \ the \ label \ before \ using \ it.
+ \msg_see_documentation_text:n { cooking-units }
+ }
+\msg_new:nnnn { cooking-units } { redefine-unit }
+ {
+ The \ unit \ '#1' \ is \ redefined \ by \ \declarecookingunit at \ \msg_line_context: .
+ }
+ {
+ \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}
{ \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_and_parse:n #1 { TF }
+\prg_new_protected_conditional:Npnn \__cooking_units_if_integer:n #1 { TF }
{
- \bool_if:NTF \l__cooking_units_parse_input_bool
+ \tl_map_inline:nn {#1}
{
- \tl_map_inline:nn {#1}
+ \tl_if_in:NnF \l__cooking_units_input_digits_tl {##1}
{
- \tl_if_in:NnF \l__cooking_units_input_digits_tl {##1}
- {
- \tl_map_break:n { \use_iii:nnn }
- }
+ \tl_map_break:n { \use_iii:nnn }
}
- \use_i:nn \prg_return_true: \prg_return_false:
+ }
+ \use_i:nn \prg_return_true: \prg_return_false:
+ }
+\prg_new_protected_conditional:Npnn \__cooking_units_if_integer_and_parse:n #1 { TF }
+ {
+ \bool_if:NTF \l__cooking_units_parse_input_bool
+ {
+ \__cooking_units_if_integer:nTF {#1}
+ { \prg_return_true: }
+ { \prg_return_false: }
}
{ \prg_return_false: }
}
@@ -430,21 +541,17 @@
cl= (chbareV-1)3 ,
ml= (chbareV-1)3 ,
}
- \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_filter:nnv
- { cooking-units }
- { change-unit }
- { l__cooking_units_predefined_option_ \l__cooking_units_option_unit_tl _clist }
}
\cs_new:Npn \__cooking_units_deftranslation:Nnn #1#2#3
{
- \deftranslation [ to=#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
+ {
+ \tl_set:Nf #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
{
\msg_error:nn { cooking-units } { No-Value-given }
@@ -453,13 +560,103 @@
{
\__cooking_units_error_if_unit_not_defined:n {#1}
\fp_if_exist:cTF { c__cooking_units_ #1 _min_fp }
- { \msg_error:nnn { cooking-units } { Minimum-already-defined } {#1} }
+ { \msg_warning:nnn { cooking-units } { Minimum-already-defined } {#1} }
{
\clist_put_right:Nn \l__cooking_units_temperatures_to_check_clist {#1}
\fp_const:cn { c__cooking_units_ #1 _min_fp } {#2}
}
}
-\cs_new:Npn \__cooking_units_round_setup:n #1 { \l__cooking_units_significant_figures_int }
+\cs_new:Npn \__cooking_units_rounding_function:n #1
+ {
+ #1
+ \bool_if:NTF \l__cooking_units_round_commercial_bool
+ {
+ \bool_if:NTF \l__cooking_units_round_to_int_bool
+ { , \c_zero_fp }
+ { , \l__cooking_units_significant_figures_int }
+ , #1
+ }
+ { \bool_if:NF \l__cooking_units_round_to_int_bool { , \l__cooking_units_significant_figures_int } }
+ }
+\cs_new:Npn \__cooking_units_label_and_persons:n #1
+ {
+ \tl_if_in:nnTF {#1} { @ }
+ {
+ \__cooking_units_label_and_persons_for_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}
+ }
+ }
+ }
+\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} }
+ }
+\cs_new:Npn \__cooking_units_culabel:nnn #1#2#3
+ {
+ \int_if_exist:cTF { l__cooking_units_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 }
+ }
+ { \msg_error:nnn { cooking-units } { Number-of-persons-is-not-an-integer } {#2} }
+ }
+ }
+\cs_new:Npn \__cooking_units_curef:n #1
+ {
+ \int_if_exist:cTF { l__cooking_units_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 } }
+ }{ \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} }
+\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
+ }
+ }
+\cs_new:Npn \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN #1#2#3
+ {
+ \tl_if_in:NnT #1 {#2}
+ {
+ \bool_if:NTF #3
+ { \bool_set_false:N #3 }
+ { \bool_set_true:N #3 }
+ \tl_remove_once:Nn #1 {#2}
+ }
+ }
\cs_new:Npn \__cooking_units_cunum_parse_input:N #1
{
\bool_if:NTF \l__cooking_units_parse_range_bool
@@ -485,19 +682,27 @@
\__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
- \tl_use:N \l__cooking_units_cunum_range_sign_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
}
\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_eval_fractions_bool
+ \bool_if:nTF
+ {
+ \l__cooking_units_calc_persons_tmp_bool ||
+ \l__cooking_units_eval_fractions_bool
+ }
{
\__cooking_units_calculate_and_print_input:n
{ \l__cooking_units_tmpa_tl / \l__cooking_units_tmpb_tl }
}{
- \__cooking_units_formatiere_fractions:nnn
+ \__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
{ }
{ \l__cooking_units_tmpa_tl }
{ \l__cooking_units_tmpb_tl }
@@ -508,19 +713,23 @@
\__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
- \bool_if:NTF \l__cooking_units_eval_fractions_bool
+ \__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_calculate_and_print_input:n
{
- \l__cooking_units_mixed_fraction_tl
- \fp_compare:nNnTF
- { \l__cooking_units_mixed_fraction_tl } < { \c_zero_fp }
- { - }
- { + }
+ \bool_if:NTF \l_tmpb_bool
+ { - \l__cooking_units_mixed_fraction_tl - }
+ { \l__cooking_units_mixed_fraction_tl + }
\l__cooking_units_tmpa_tl / \l__cooking_units_tmpb_tl
}
}{
- \__cooking_units_formatiere_fractions:nnn
+ \__cooking_units_formatiere_fractions:nNN
{ \l__cooking_units_mixed_fraction_tl }
{ \l__cooking_units_tmpa_tl }
{ \l__cooking_units_tmpb_tl }
@@ -570,8 +779,7 @@
\tl_if_in:nnTF { / _ } {#1}
{ \msg_error:nnn { cooking-units } { fraction-not-allowed-with-range } {#1} }
{ \msg_error:nnn { cooking-units } { Token-not-allowed } {#1} }
- }
- {
+ }{
\tl_if_in:nnTF { _ } {#1}
{ \msg_error:nnn { cooking-units } { missing-slash } {#1} }
{ \msg_error:nnn { cooking-units } { Token-not-allowed } {#1} }
@@ -593,10 +801,16 @@
\msg_warning:nnx { cooking-units } { amount-not-known } \l_tmpa_tl
}
{
- \__cooking_units_calculate_input_and_store_in:nN {#1} \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
}
- \__cooking_units_print_nummerical_output:N \l_tmpa_tl
+ \__cooking_units_print_output:N \l_tmpa_tl
}
}
\cs_generate_variant:Nn \__cooking_units_calculate_and_print_input:n { N }
@@ -605,23 +819,27 @@
\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 }
{
- \tl_set:Nf #2
- {
- \fp_eval:c { 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_tmp_unit_tl _ tl }
}{
- \tl_set:Nf #2
+ \__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 } }
+ }
+ }
+\cs_new:Npn \__cooking_units_calc_for_number_of_persons_and_store_in:NN #1#2
+ {
+ \int_compare:nNnF
+ { \l__cooking_units_calc_for_number_of_persons_int }
+ =
+ { \l__cooking_units_persons_tmp_int }
+ {
+ \__cooking_units_tl_set_fp_and_eval:Nn #1
{
- \fp_eval:n
- {
- \l_tmpa_fp *
- \tl_use:c { l__cooking_units_tmpa_ \l__cooking_units_tmp_unit_tl _ tl }
- }
+ \l__cooking_units_calc_for_number_of_persons_int /
+ \l__cooking_units_persons_tmp_int *
+ #2
}
}
- \__cooking_units_round_calculated_input:NV #2 #2
}
-\cs_generate_variant:Nn \__cooking_units_calculate_input_and_store_in:nN { V }
\cs_new:Npn \__cooking_units_check_number_after_dot:n #1
{
\__cooking_units_check_number_after_dot_aux:w #1 . \q_recursion_tail .
@@ -630,33 +848,46 @@
\cs_new:Npn \__cooking_units_check_number_after_dot_aux:w #1. #2 .
{
\quark_if_recursion_tail_stop:n {#2}
- \int_compare:nNnF
- { \tl_count:n {#2} } < { \l__cooking_units_significant_figures_plus_one_int }
+ \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
+ { \tl_count:n {#2} } < { \l_tmpa_int }
+ { \bool_set_false:N \l_tmpa_bool }
{ \bool_set_true:N \l_tmpa_bool }
\use_none_delimit_by_q_recursion_stop:w
}
\cs_new:Npn \__cooking_units_round_calculated_input:NN #1#2
{
- \bool_set_false:N \l_tmpa_bool
\__cooking_units_check_number_after_dot:n {#2}
\tl_set:Nf #1
{
- \bool_if:NTF \l__cooking_units_round_to_int_bool
- {
- \fp_eval:n { round (#2) }
- }{
- \bool_if:NTF \l_tmpa_bool
- {
- \fp_eval:n { round( #2 , \__cooking_units_round_setup:n {#2} ) }
- }
- {#2}
- }
+ \bool_if:NTF \l_tmpa_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:Npn \__cooking_units_formatiere_fractions:nnn #1#2#3
+\cs_new_protected:Npn \__cooking_units_print_output:N #1
+ {
+ \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_new_protected:Npn \__cooking_units_print_nummerical_output: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
+ #1
+ }
+\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 }
\tl_if_empty:nF {#1}
{
#1
@@ -684,47 +915,56 @@
}
}
}
-\cs_new_protected:Npn \__cooking_units_print_nummerical_output:N #1
- {
-%% \l_@@_tmpa_tl is sehr gefaehrlich hier.
- \translatelet \l__cooking_units_tmpa_tl { decimal-mark ( cu-unitname ) }
- \tl_replace_once:NnV #1 { . } \l__cooking_units_tmpa_tl
- \tl_replace_once:NnV #1 { - } \c__cooking_units_minus_tl
- #1
- }
-\NewDocumentCommand \cunum { O{} m O{} m }
+\NewDocumentCommand \cunum { d<> O{} m O{} m }
{
\group_begin:
- \__cooking_units_cunum_initialise:nnnn {#1} {#2} {#3} {#4}
+ \__cooking_units_cunum_initialise:nnnnn {#1} {#2} {#3} {#4} {#5}
\bool_if:NTF \l__cooking_units_parse_input_bool
- { \__cooking_units_cunum:nnVV {#2} {#3} \l__cooking_units_option_unit_tl \l__cooking_units_tmp_unit_tl }
- { \__cooking_units_cunum_do_not_parse:nnn {#2} {#3} {#4} }
+ { \__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:
}
-\cs_new_protected:Npn \__cooking_units_cunum_initialise:nnnn #1#2#3#4
+\cs_new_protected:Npn \__cooking_units_cunum_initialise:nnnnn #1#2#3#4#5
+ {
+ \__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}
+ }
+\cs_new_protected:Npn \__cooking_units_initialise_default:nnn #1#2#3
{
- \tl_set:Nn \l__cooking_units_tmp_unit_tl {#4}
+ \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_if_empty:nF {#1}
- { \keys_set_groups:nnn { cooking-units } { change-unit } {#1} }
- \bool_if:NTF \l__cooking_units_convert_to_eV_bool
+ \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
+ }
+\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 }
+ }
+\cs_new_protected:Npn \__cooking_units_initialise_after_unit_change:nnn #1#2#3
+ {
+ \IfNoValueF {#1}
+ { \__cooking_units_reference_label_and_persons:n {#1} }
+ \clist_if_empty:cF { l__cooking_units_predefined_option_ \l__cooking_units_option_unit_tl _clist }
{
- \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_filter:nnv
{ cooking-units }
{ change-unit }
{ l__cooking_units_predefined_option_ \l__cooking_units_option_unit_tl _clist }
- \tl_if_empty:nF {#1}
- { \keys_set_filter:nnn { cooking-units } { change-unit } {#1} }
}
- \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
+ \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 }
}
\cs_new:Npn \__cooking_units_cunum_do_not_parse:nnn #1#2#3
{
@@ -734,9 +974,8 @@
\char_set_catcode_ignore:N \ %
} {#1}
\l_tmpa_tl
- \__cooking_units_cunum_print_correct_unit:nnn {#2} {#3} {#3}
}
-\cs_new:Npn \__cooking_units_cunum:nnNN #1#2#3#4
+\cs_new:Npn \__cooking_units_parse_and_evaluate_input:n #1
{
\tl_set_rescan:Nnn \l_tmpa_tl
{
@@ -753,32 +992,32 @@
}
\__cooking_units_cunum_parse_input:V \l_tmpa_tl
}
- \__cooking_units_cunum_print_correct_unit:nnn {#2} {#3} {#4}
}
-\cs_generate_variant:Nn \__cooking_units_cunum:nnNN { nnVV }
\cs_new:Npn \__cooking_units_cunum_print_correct_unit:nnn #1#2#3
{
\tl_if_empty:nF {#1} { \phantom {#1} }
\tl_use:N \l__cooking_units_value_unit_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-unit ) } }
{ \translate { #2 ( cu-unit ) } }
}
+\cs_generate_variant:Nn \__cooking_units_cunum_print_correct_unit:nnn { nVV }
\NewDocumentCommand \cudefinekeys { m m }
{
\bool_set_false:N \l__cooking_units_single_key_bool
- \cukeys_define_keys_and_single_keys:nn {#1} {#2}
+ \__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
- \cukeys_define_keys_and_single_keys:nn {#1} {#2}
+ \__cooking_units_cukeys_define_keys_and_single_keys:nn {#1} {#2}
}
-\cs_new:Npn \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}
@@ -978,9 +1217,25 @@
\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
}
+\NewDocumentCommand \declarecookingunit { o m }
+ {
+ \clist_if_in:NnTF \g__cooking_units_list_of_defined_units_clist {#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}
+ }
\NewDocumentCommand \newcookingunit { o m }
{
\__cooking_units_new_cooking_unit:nn {#1} {#2}
+ \__cooking_units_set_cooking_unit:nn {#1} {#2}
+ }
+\NewDocumentCommand \providecookingunit { o m }
+ {
+ \clist_if_in:NnF \g__cooking_units_list_of_defined_units_clist {#2}
+ {
+ \__cooking_units_new_cooking_unit:nn {#1} {#2}
+ \__cooking_units_set_cooking_unit:nn {#1} {#2}
+ }
}
\cs_new:Npn \__cooking_units_new_cooking_unit:nn #1#2
{
@@ -991,7 +1246,7 @@
\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 }
- \keys_define:nn { cooking - units }
+ \keys_define:nn { cooking-units }
{
set-option-for-#2 .clist_set:c = { l__cooking_units_predefined_option_#2_clist } ,
add-option-for-#2 .code:n =
@@ -999,37 +1254,67 @@
}
\prop_new:c { l__cooking_units_cukeys_ #2 _prop }
\tl_new:c { l__cooking_units_cu_unit_ #2 _tl }
- \IfNoValueTF {#1}
- {
- \tl_set:cn { l__cooking_units_cu_unit_ #2 _tl } {#2}
- \newtranslation { #2 ( cu-unit ) } {#2}
- }{
- \tl_set:cn { l__cooking_units_cu_unit_ #2 _tl } {#1}
- \newtranslation { #2 ( cu-unit ) } {#1}
- }
}
}
-\NewDocumentCommand \cutext { O{} m m }
+\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_cu_unit_ #2 _tl } {#1}
+ \deftranslation { #2 ( cu-unit ) } {#1}
+ }
+ }
+\NewDocumentCommand \cutext { d<> O{} m m }
{
\group_begin:
- \bool_set_false:N \l__cooking_units_cutext_uppercase_word_bool
- \__cooking_units_cutext_default:nnn {#1} {#2} {#3}
- \__cooking_units_cutext_print_correct_unitname:nn {#2} {#3}
+ \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4}
+ \bool_if:NTF \l__cooking_units_cutext_to_cunum_bool
+ { \cunum {#3} {#4} }
+ {
+ \bool_set_false:N \l__cooking_units_cutext_uppercase_word_bool
+ \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4}
+ }
\group_end:
}
-\NewDocumentCommand \Cutext { O{} m m }
+\NewDocumentCommand \Cutext { d<> O{} m m }
{
\group_begin:
- \bool_set_true:N \l__cooking_units_cutext_uppercase_word_bool
- \__cooking_units_cutext_default:nnn {#1} {#2} {#3}
- \__cooking_units_cutext_print_correct_unitname:nn {#2} {#3}
+ \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4}
+ \bool_if:NTF \l__cooking_units_cutext_to_cunum_bool
+ { \cunum {#3} {#4} }
+ {
+ \bool_set_true:N \l__cooking_units_cutext_uppercase_word_bool
+ \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4}
+ }
\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}
- \tl_if_empty:nF {#1}
- { \keys_set:nn { cooking-units } {#1} }
\bool_if:NT \l__cooking_units_convert_to_eV_bool
{ \__cooking_units_convert_to_eV: }
\bool_if:NTF \l__cooking_units_parse_input_bool
@@ -1040,7 +1325,7 @@
\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_nummerical_output:Nn \l_tmpb_tl {#3}
+ \__cooking_units_cutext_print_output:Nn \l_tmpb_tl {#3}
}
}
{#2}
@@ -1054,18 +1339,11 @@
{
\tl_set:Nn \l__cooking_units_tmpa_tl {#2}
\tl_set:Nn \l__cooking_units_tmpb_tl {#3}
- \__cooking_units_cutext_print_nummerical_output:Nn \l__cooking_units_tmpa_tl {#1}
+ \__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_nummerical_output:Nn \l__cooking_units_tmpb_tl {#1}
- }
-\cs_new:Npn \__cooking_units_cutext_just_print_number_correctly:N #1
- {
- \translatelet \l_tmpa_tl { decimal-mark ( cu-unitname ) }
- \tl_replace_once:NnV #1 { . } \l_tmpa_tl
- \tl_replace_once:NnV #1 { - } \c__cooking_units_minus_tl
- #1
+ \__cooking_units_cutext_print_output:Nn \l__cooking_units_tmpb_tl {#1}
}
-\cs_new_protected:Npn \__cooking_units_cutext_print_nummerical_output:Nn #1#2
+\cs_new_protected:Npn \__cooking_units_cutext_print_output:Nn #1#2
{
\bool_if:NTF \g__cooking_units_load_if_opt_numeral_bool
{
@@ -1075,36 +1353,47 @@
{
\fp_compare:nNnTF {#1} = { \c_one_fp }
{
- \translatelet \l_tmpa_tl { #2 (cu-unitgender) }
- \translatelet \l_tmpa_tl { one (\l_tmpa_tl) (cu-unitname) }
+ \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_tmpa_tl }
- \tl_tail:V \l_tmpa_tl
+ \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_tmpa_tl }
+ { \l__cooking_units_translation_tmpa_tl }
}{
\bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool
{ \Numberstringnum {#1} }
{ \numberstringnum {#1} }
}
- }{ \__cooking_units_cutext_just_print_number_correctly:N #1 }
- }{ \__cooking_units_cutext_just_print_number_correctly:N #1 }
+ }{ \__cooking_units_print_nummerical_output:N #1 }
+ }{ \__cooking_units_print_nummerical_output:N #1 }
}
- { \__cooking_units_cutext_just_print_number_correctly:N #1 }
+ { \__cooking_units_print_nummerical_output:N #1 }
}
-\cs_new:Npn \__cooking_units_cutext_print_correct_unitname:nn #1#2
+\cs_generate_variant:Nn \__cooking_units_cutext_print_output:Nn { NV }
+\cs_new:Npn \__cooking_units_cutext_print_correct_unitname:nnn #1#2#3
{
- \space
- \__cooking_units_if_integer_and_parse:nTF {#1}
+ \l__cooking_units_cutext_space_tl
+ \bool_if:nTF
{
- \fp_compare:nNnTF {#1} = { \c_one_fp }
- { \translate { #2 (cu-unitname) } }
+ ! \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) } }
- }{
- \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 }
@@ -1146,59 +1435,96 @@
\hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { }
\__cooking_units_frac:nn {#2} {#3}
}
-\NewDocumentCommand \cuam { s O{} m }
+\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:
- \tl_if_empty:nF {#2}
- { \keys_set:nn { cooking-units } {#2} }
- \IfBooleanTF {#1}
- { \__cooking_units_cuam_star:n {#3} }
- { \__cooking_units_cuam_star:n {#3} }
+ \__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:Npn \__cooking_units_cuam_star:n #1
+\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_star_parse:V \l_tmpa_tl
+ \__cooking_units_cuam_old_parse:V \l_tmpa_tl
}
-\cs_new_protected:Npn \__cooking_units_cuam_star_parse:n #1
+\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_star_parse_range:V \l_tmpa_tl
+ \__cooking_units_cuam_old_parse_range:V \l_tmpa_tl
}{
\tl_if_in:nnTF {#1} { / }
{
\tl_if_in:nnTF {#1} { _ }
- { \__cooking_units_cuam_star_parse_mixed_frac:www #1 \q_stop }
- { \__cooking_units_cuam_star_parse_frac:ww #1 \q_stop }
+ { \__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_star_parse_scale:n {#1} }
+ { \__cooking_units_cuam_old_parse_scale:n {#1} }
}
}
}
-\cs_generate_variant:Nn \__cooking_units_cuam_star_parse:n { V }
-\cs_new:Npn \__cooking_units_cuam_star_parse_range: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_star_parse_range_aux:ww #1 \q_nil
+ \__cooking_units_cuam_old_parse_range_aux:ww #1 \q_nil
}
-\cs_generate_variant:Nn \__cooking_units_cuam_star_parse_range:n { V }
-\cs_new:Npn \__cooking_units_cuam_star_parse_range_aux:ww #1 \q__cooking_units_range #2 \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_star_parse_scale:n #1 {#1}
-\cs_new:Npn \__cooking_units_cuam_star_parse_frac:ww #1/#2 \q_stop
+\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_star_parse_mixed_frac:www #1_#2/#3 \q_stop
+\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 } { }