diff options
author | Karl Berry <karl@freefriends.org> | 2022-06-07 20:24:08 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2022-06-07 20:24:08 +0000 |
commit | 2c7b923eeb2f36e4fccb572de2df85f598c7b65f (patch) | |
tree | 4f2aa20364eb526f98c2f8183e4270c791f7763c /Master/texmf-dist/source/latex | |
parent | 12bbf07303f5de1dd0b677b009a44635167ec91f (diff) |
cooking-units (7jun22)
git-svn-id: svn://tug.org/texlive/trunk@63504 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex')
-rw-r--r-- | Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx | 351 |
1 files changed, 316 insertions, 35 deletions
diff --git a/Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx b/Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx index 574f2b7fcd8..b953801209b 100644 --- a/Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx +++ b/Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx @@ -59,7 +59,7 @@ Supported Languages * German * English -* French (suboptimal) +* French License ------- @@ -221,14 +221,21 @@ and the derived file cooking-units.sty. cudefinekeys , , cudefinekeychain , cuaddtokeychain , cudeclareunitgroup + , cookingunits_print_fraction:nnn , cookingunits_print_range:nn + , ExplSyntaxOff, ExplSyntaxOn } \NewDocumentCommand \mycs { m } { - \clist_if_in:NnTF \l_cookingunits_list_of_defined_befehlen_clist {#1} + \tl_set_rescan:Nnn \l_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_letter:N \: % + } {#1} + \clist_if_in:NVTF \l_cookingunits_list_of_defined_befehlen_clist \l_tmpa_tl { - \cs_if_exist:cTF {#1} - { \cs{\textcolor{blue}{#1}} } + \cs_if_exist:cTF { \l_tmpa_tl } + { \cs{\textcolor{blue}{ \l_tmpa_tl }} } { \tl_show:n {#1}\mycsERRORII } } { \tl_show:n {#1} \mycsERROR } @@ -806,6 +813,9 @@ and the derived file cooking-units.sty. % \changes {2022/03/26} {2.00a} {Bugfix: |\cuam| prints a unit in case of an error. This also happens with \opt{parse-number=false}.} % \changes {2022/03/26} {2.00a} {Bugfix: Remove \cs{peek_meaning_ignore_spaces:NTF}.} % +% \changes {2022/06/06} {2.01} {Correction of french language. Thanks to Alexis Jeandeau} +% \changes {2022/06/06} {2.01} {Implement a way to define the plural-finding algorithm.} +% \changes {2022/06/06} {2.01} {Add two public commands \cs{cookingunits_print_fraction:nnn} and \cs{cookingunits_print_range:nn}.} % % % @@ -859,7 +869,7 @@ and the derived file cooking-units.sty. % \begin{itemize} % \item German % \item English -% \item French (currently suboptimal\footnote{You can only get limited information from the internet.}) +% \item French % \end{itemize} % Want to contribute a new language or make a correction to an existing one? % See \cref{sec:bug-feed} for more details. Wanna just check the @@ -1066,9 +1076,9 @@ and the derived file cooking-units.sty. % % % +% \section{Good to know stuff} % -% -%\subsection{Rounding temperatures} +% \subsection{Rounding temperatures} % % % By default temperatures are rounded to integers (using \opt{round-precision=0}). @@ -1088,6 +1098,40 @@ and the derived file cooking-units.sty. % \cunum[C=K]{180}{C} \\ % \end{cuexamplecode} % +% +% \subsection{At which point is the plural used?} +% While using \cCutext\ one may wonder which rules are used in order to determine +% if the printed unit is singular or plural. If rules for a specific language are not found +% the default ruleset is used. There are currently two rule sets: One default +% and one if you are using french. +% +% Each set has three seperate rules: one for \enquote{normal} numbers, one for +% ranges and one for fractions. +% +% \subsubsection*{French} +% +% Use singular if: +% \begin{description} +% \item[normal] The absolute value of the number is smaller $2$ +% \item[fraction] The absolute value of the evaluated fraction is smaller $2$. +% (e.g.\ $1\,\sfrac{1}{2} = 1.5$ uses singular, $2\,\sfrac{3}{4} = 2.75$ uses plural). +% \item[range] The absolute value of the second number is smaller $2$. +% (e.g.\ \cuam{1--2}: Take $2$.) +% \end{description} +% +% For sources see \cite{Plural-French-Academia}, \cite{Plural-French-absolute-1} \& +% \cite{Plural-French-absolute-2}\footnote{Thanks a lot to Alexis Jeandeau! I never would +% have imagined that the french language uses the sinfular for everything smaller $2$.}. +% +% \subsubsection*{Default (all other languages)} +% +% Use singular if: +% \begin{description} +% \item[normal] The number is equal to $1$. +% \item[fraction] There is no mixed fraction part and the nominator is equal to $1$. +% \item[range] The second number is equal to $1$. (e.g.\ \cuam{1--2}: Take $2$.) +% \end{description} +% % \section{Predefined units \& some notes} % \label{sec:pred-units} % @@ -1760,7 +1804,8 @@ and the derived file cooking-units.sty. % {dl} {dL} % {cl} {cL} % {ml} {mL} -% {decimal-mark} {.} +% {cutext-range-sign} {~\`{a}~} +% {decimal-mark} {,} % {one(m)} {un} % {one(f)} {une} % {one(n)} {un} @@ -3202,6 +3247,52 @@ and the derived file cooking-units.sty. % % % +% +% +% +% \section{Public Commands} +% +% This section describes some public functions, Their main usage is the printing of +% stuff. They are primtivies used between an \mycs{ExplSyntaxOn} and +% \mycs{ExplSyntaxOff}; for usage in a document you may do the following: +% \begin{lstlisting} +% \ExplSyntaxOn +% \NewDocumentCommand \cuprintfrac { O{} m m } +% { +% \cookingunits_print_fraction:nnn {#1} {#2} {#3} +% } +% \NewDocumentCommand \cuprintrange { m m } +% { +% \cookingunits_print_range:nn {#1} {#2} +% } +% \ExplSyntaxOff +% \end{lstlisting} +% +% +% \begin{function}{\cookingunits_print_fraction:nnn} +% \begin{syntax} +% \mycs{cookingunits_print_fraction:nnn} \marg{mixed-part}\marg{numerator}\marg{denominator} +% \end{syntax} +% \emph{Note:} There is no parsing and processing done in this command, it just +% prints the input. +% +% Uses the internal fraction printing command to print a fraction. \Arg{mixed-part} +% can be empty if no mixed part is needed. +% \end{function} +% +% +% \begin{function}{\cookingunits_print_range:nn} +% \begin{syntax} +% \mycs{cookingunits_print_range:nn} \marg{left-part}\marg{right-part} +% \end{syntax} +% \emph{Note:} There is no parsing and processing done in this command, ist just +% prints the input. +% +% Uses the internal range printing command to print a range (using the same range sign as +% \mycs{cunum} would use) +% \end{function} +% +% %^^A \section{Notes} % %^^A There is a unit called \enquote{Batman}. @@ -3235,8 +3326,7 @@ and the derived file cooking-units.sty. % header). % % Furthermore, as you can see I am not able to speak too many -% languages (german and english to be precise; I managed to add french -% with the help of the internet, which is not optimal) so if you are +% languages (german and english to be precise) so if you are % able to speak a language not yet implemented and would like to help % you can send me the translations known to you. A list of all units % (and their current translations) is given in \cref{sec:Translations}. @@ -3603,8 +3693,8 @@ and the derived file cooking-units.sty. % \begin{macrocode} \ProvidesExplPackage {cooking-units} - {2022/03/26} - {2.00a} + {2022/06/06} + {2.01} {Ein Paket fuer Kocheinheiten} % \end{macrocode} % @@ -4149,7 +4239,7 @@ and the derived file cooking-units.sty. % , \l_@@_pckopt_print_numeral_bool % , \l_@@_lokal_numeral_bool % , \l_@@_phrase_negative_bool -% , \l_@@_cutext_last_amount_equ_one_bool +% , \l_@@_cutext_use_single_bool % , \l_@@_symbol_was_set_by_key_bool % , \l_@@_contains_valid_key_bool % , \l_@@_check_decimal_bool @@ -4184,7 +4274,7 @@ and the derived file cooking-units.sty. \bool_new:N \l_@@_pckopt_print_numeral_bool \bool_new:N \l_@@_lokal_numeral_bool \bool_new:N \l_@@_phrase_negative_bool -\bool_new:N \l_@@_cutext_last_amount_equ_one_bool +\bool_new:N \l_@@_cutext_use_single_bool \bool_new:N \l_@@_symbol_was_set_by_key_bool \bool_new:N \l_@@_contains_valid_key_bool \bool_new:N \l_@@_check_decimal_bool @@ -6579,6 +6669,7 @@ and the derived file cooking-units.sty. \@@_culang_def_base:nnn { name } { decimal-mark } { . } \@@_culang_def_base:nnn { name-pl } { decimal-mark } { \c_@@_no_translation_str } \@@_culang_def_for:nnnn { German } { name-pl } { decimal-mark } { , } +\@@_culang_def_for:nnnn { French } { name-pl } { decimal-mark } { , } % \end{macrocode} % Note that the plural versions just exist for completing the set. % \begin{macrocode} @@ -6599,12 +6690,18 @@ and the derived file cooking-units.sty. \@@_culang_def_for:nnnn { German } { name } { one (f) } { eine } \@@_culang_def_for:nnnn { German } { name } { one (n) } { ein } % \end{macrocode} +% \begin{macrocode} +\@@_culang_def_for:nnnn { French } { name } { one (m) } { un } +\@@_culang_def_for:nnnn { French } { name } { one (f) } { une } +\@@_culang_def_for:nnnn { French } { name } { one (n) } { un } +% \end{macrocode} % % \begin{macrocode} \@@_culang_def_base:nnn { name } { cutext-range-sign } { -- } \@@_culang_def_base:nnn { name-pl } { cutext-range-sign } { \c_@@_no_translation_str } \@@_culang_def_for:nnnn { German } { name } { cutext-range-sign } { ~bis~ } \@@_culang_def_for:nnnn { English } { name } { cutext-range-sign } { ~to~ } +\@@_culang_def_for:nnnn { French } { name } { cutext-range-sign } { ~\`{a}~ } % \end{macrocode} % % @@ -6754,7 +6851,7 @@ and the derived file cooking-units.sty. { \bool_if:NT \l_@@_pckopt_cutext_to_cunum_bool { \@@_set_cmd_type_to:n { cunum } } - \bool_set_false:N \l_@@_cutext_last_amount_equ_one_bool + \bool_set_false:N \l_@@_cutext_use_single_bool } % \end{macrocode} % \end{macro} @@ -7030,12 +7127,17 @@ and the derived file cooking-units.sty. \l_@@_mixed_fraction_tl \l_@@_number_tmpa_tl \l_@@_number_tmpb_tl - \@@_if_print_type_equal:nT { number } + \@@_if_print_type_equal:nTF { number } { \@@_convert_fraction_to_number_in_input:NNN \l_@@_mixed_fraction_tl \l_@@_number_tmpa_tl \l_@@_number_tmpb_tl + }{ + \@@_post_process_fraction_accordingly:NNN + \l_@@_mixed_fraction_tl + \l_@@_number_tmpa_tl + \l_@@_number_tmpb_tl } } % \end{macrocode} @@ -7226,6 +7328,24 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % +% \begin{macro}{ \@@_post_process_fraction_accordingly:NNN } +% Decided to make this into its own command. This post processes fractions +% which is only needed by \cCutext. +% \begin{macrocode} +\cs_new:Npn \@@_post_process_fraction_accordingly:NNN #1#2#3 + { + \tl_case:NnF \l_@@_cmd_type_tl + { + \c_@@_cmd_type_cunum_tl { } + \c_@@_cmd_type_cCutext_tl { \@@_cutext_post_process_fraction_input:NNN #1#2#3 } + \c_@@_cmd_type_cuam_tl { } + }{ + \@@_create_internal_error:nN { post-process-frac } \l_@@_cmd_type_tl + } + } +% \end{macrocode} +% \end{macro} +% % \begin{macro}{ \@@_print_numerical_input:N } % The base printing command for numbers. Makes sure the minus sign % and decimal-mark are correct. @@ -7970,7 +8090,7 @@ and the derived file cooking-units.sty. \bool_if:NTF \l_@@_lokal_numeral_bool { \l_@@_cutext_numeral_space_tl } { \l_@@_cutext_space_tl } - \bool_if:NTF \l_@@_cutext_last_amount_equ_one_bool + \bool_if:NTF \l_@@_cutext_use_single_bool { \@@_culang_print:nV { name } \l_@@_decided_unit_tl } { \@@_culang_print:nV { name-pl } \l_@@_decided_unit_tl } } @@ -8019,8 +8139,15 @@ and the derived file cooking-units.sty. \cs_new:Npn \@@_cutext_post_process_input:NN #1#2 { \@@_if_parse_and_process_type_equal:nTF { range } - { \@@_cutext_check_if_amount_single:N #2 } - { \@@_cutext_check_if_amount_single:N #1 } + { + \@@_culang_let:nnN { pluraltest } { range } \l_@@_translation_tmpa_tl + \use:c { @@_pluraltest_range_ \l_@@_translation_tmpa_tl :NN } #1#2 +% \@@_cutext_check_if_plural_is_needed:N #2 + }{ + \@@_culang_let:nnN { pluraltest } { normal } \l_@@_translation_tmpa_tl + \use:c { @@_pluraltest_normal_ \l_@@_translation_tmpa_tl :N } #1 +% \@@_cutext_check_if_plural_is_needed:N #1 + } \bool_if:NT \l_@@_lokal_numeral_bool { \@@_if_contain_decimals:NNTF #1#2 @@ -8030,18 +8157,29 @@ and the derived file cooking-units.sty. } % \end{macrocode} % \end{macro} -% \begin{macro} { \@@_cutext_check_if_amount_single:N } -% Check if the input is equal to |#1|. Use fp as it is not necessary an integer. -% Set the boolean according to the result. +% \begin{macro} { \@@_cutext_post_process_fraction_input:NNN } % \begin{macrocode} -\cs_new:Npn \@@_cutext_check_if_amount_single:N #1 +\cs_new:Npn \@@_cutext_post_process_fraction_input:NNN #1#2#3 { - \fp_compare:nNnTF {#1} = { 1.0 } - { \bool_set_true:N } { \bool_set_false:N } - \l_@@_cutext_last_amount_equ_one_bool + \@@_culang_let:nnN { pluraltest } { fraction } \l_@@_translation_tmpa_tl + \use:c { @@_pluraltest_fraction_ \l_@@_translation_tmpa_tl :NNN } #1#2#3 } % \end{macrocode} % \end{macro} +% \begin{macro} { \@@_cutext_check_if_plural_is_needed:N } +% Check if the input is equal to |#1|. Use fp as it is not necessary an integer. +% Set the boolean according to the result. +% \begin{macrocode} +%\cs_new:Npn \@@_cutext_check_if_plural_is_needed:N #1 +% { +% \fp_compare:nNnTF {#1} = { 1.0 } +% { \bool_set_true:N } { \bool_set_false:N } +% \l_@@_cutext_use_single_bool +% } +% \end{macrocode} +% \end{macro} +% +% % \begin{macro} { \@@_check_if_integer_can_be_numerals:NN } % At this point we know that we have integers, so check if they are % below |\l_@@_print_numerals_below_int|. If they are, fine. Else, @@ -8128,7 +8266,7 @@ and the derived file cooking-units.sty. % % % Just a helper macro to tidy up the main macro. The first thing to -% do is to check if the nummerical input consits of integers. This +% do is to check if the numerical input consits of integers. This % is done both both numerical values (if a range exists). % Afterwards check if phrases are used and can be used at all. This needs % to be done before the numeral check as it can change the input. @@ -8293,6 +8431,40 @@ and the derived file cooking-units.sty. % % % +% +% \subsection{Public Primitives} +% +% Two public commands. +% \begin{macro}{ \cookingunits_print_fraction:nnn } +% \begin{macrocode} +\cs_new:Npn \cookingunits_print_fraction:nnn #1#2#3 + { + \group_begin: + \@@_set_amount:Nn \l_@@_mixed_fraction_tl {#1} + \@@_set_amount:Nn \l_@@_number_tmpa_tl {#2} + \@@_set_amount:Nn \l_@@_number_tmpb_tl {#3} + \@@_print_fractions:Nnn + \l_@@_mixed_fraction_tl + \l_@@_number_tmpa_tl + \l_@@_number_tmpb_tl + \group_end: + } +% \end{macrocode} +% \end{macro} +% \begin{macro}{ \cookingunits_print_range:nn } +% \begin{macrocode} +\cs_new:Npn \cookingunits_print_range:nn #1#2 + { + \group_begin: + \@@_set_cmd_type_to:n { cunum } + #1 + \@@_print_range_sign: + #2 + \group_end: + } +% \end{macrocode} +% \end{macro} +% % \subsection{\mycs{cucomp}} % % @@ -9511,6 +9683,101 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % +% +% \subsection {Define plural-usage for \cCutext} +% +% \begin{macro}{ pluraltest: normal/range/fraction } +% Some translations used in a second. Define one for \enquote{normal} +% (just a number), \enquote{range} and \enquote{fraction}. +% \begin{macrocode} +\@@_culang_def_base:nnn { pluraltest } { normal } { \c_@@_no_translation_str } +\@@_culang_def_base:nnn { pluraltest } { range } { \c_@@_no_translation_str } +\@@_culang_def_base:nnn { pluraltest } { fraction } { \c_@@_no_translation_str } +% \end{macrocode} +% \end{macro} +% \begin{macro}{ @@_pluraltest_normal_<default>:N, +% @@_pluraltest_range_<default>:NN, +% @@_pluraltest_fraction_<default>:NNN } +% Here we define the default behavior, if no explicit rule is given for a language. +% By default, use the singular only if the value in question is equal to $1$. +% For ranges take the last value, for fractions make sure there are no mixed fractions +% and that the nominator is equal to $1$. +% \begin{macrocode} +\cs_set:cpn { @@_pluraltest_normal_ \c_@@_no_translation_str :N } #1 + { + \fp_compare:nNnTF {#1} = { 1.0 } + { \bool_set_true:N } { \bool_set_false:N } + \l_@@_cutext_use_single_bool + } +\cs_set:cpn { @@_pluraltest_range_ \c_@@_no_translation_str :NN } #1#2 + { + \fp_compare:nNnTF {#2} = { 1.0 } + { \bool_set_true:N } { \bool_set_false:N } + \l_@@_cutext_use_single_bool + } +\cs_set:cpn { @@_pluraltest_fraction_ \c_@@_no_translation_str :NNN } #1#2#3 + { + \tl_if_empty:NTF #1 + { \fp_compare:nNnTF {#2} = { 1.0 } } { \use_ii:nn } + { \bool_set_true:N } { \bool_set_false:N } + \l_@@_cutext_use_single_bool + } +% \end{macrocode} +% \end{macro} +% \begin{macro}{ \@@_pluraltest_define:nn , \@@_pluraltest_define_range:nn , \@@_pluraltest_define_fraction:nn } +% Allow to define a when to use the singular/plural for a given language. +% Nothing more happens here. The default was already defined in the last step. +% \begin{macrocode} +\cs_new:Npn \@@_pluraltest_define:nn #1#2 + { + \@@_culang_def_for:nnnn {#1} { pluraltest } { normal } {#1} + \cs_set:cpn { @@_pluraltest_normal_ #1 :N } ##1 {#2} + } +\cs_new:Npn \@@_pluraltest_define_range:nn #1#2 + { + \@@_culang_def_for:nnnn {#1} { pluraltest } { range } {#1} + \cs_set:cpn { @@_pluraltest_range_ #1 :NN } ##1##2 {#2} + } +\cs_new:Npn \@@_pluraltest_define_fraction:nn #1#2 + { + \@@_culang_def_for:nnnn {#1} { pluraltest } { fraction } {#1} + \cs_set:cpn { @@_pluraltest_fraction_ #1 :NNN } ##1##2##3 {#2} + } +% \end{macrocode} +% \end{macro} +% \begin{macro}{ Pluraltest: French } +% As source see +% \begin{itemize} +% \item \url{https://github.com/Vidabe/cooking-units/pull/29#issue-1190629683} +% \item \url{https://www.dictionnaire-academie.fr/article/A9P2979} +% \end{itemize} +% Note: At this point the minus signs were already removed from fractions; thus +% all their values are positive. +% \begin{macrocode} +\@@_pluraltest_define:nn { French } + { + \fp_compare:nNnTF { \fp_abs:n {#1} } < { 2.0 } + { \bool_set_true:N } { \bool_set_false:N } + \l_@@_cutext_use_single_bool + } +\@@_pluraltest_define_range:nn { French } + { + \fp_compare:nNnTF { \fp_abs:n {#2} } < { 2.0 } + { \bool_set_true:N } { \bool_set_false:N } + \l_@@_cutext_use_single_bool + } +\@@_pluraltest_define_fraction:nn { French } + { + \quark_if_nil:NTF #1 + { \fp_compare:nNnTF { #2/#3 } < { 2.0 } } + { \fp_compare:nNnTF { #1 + #2/#3 } < { 2.0 } } + { \bool_set_true:N } { \bool_set_false:N } + \l_@@_cutext_use_single_bool + } +% \end{macrocode} +% \end{macro} +% +% % \subsection {cudefinesymbol} % % \begin{macro}{ \cudefinesymbol } @@ -10290,8 +10557,8 @@ and the derived file cooking-units.sty. { { kg } { kilogramme } [ kilogrammes ] { dag } { d\'{e}cagramme } [ d\'{e}cagrammes] - { g } { gramme } [ gramme ] - { oz } { once } < f > + { g } { gramme } [ grammes ] + { oz } { once } [ onces ] < f > { lb } { livre } [ livres ] < f > % \end{macrocode} % \begin{macrocode} @@ -10320,19 +10587,19 @@ and the derived file cooking-units.sty. { ml } [ mL ] { millilitre } [ millilitres ] % \end{macrocode} % \begin{macrocode} - { cal } { calorie } [ calorie ] - { kcal } { kilocalorie } [ kilocalories ] + { cal } { calorie } [ calories ] < f > + { kcal } { kilocalorie } [ kilocalories ] < f > { J } { joule } [ joules ] { kJ } { kilojoule } [ kilojoules ] { eV } { \'{e}lectron-volt } [ \'{e}lectron-volts ] % \end{macrocode} % \begin{macrocode} - { pn } { pinc\'{e}e } < f > - { EL } [c.\`{a}.s.] { cuill\`{e}re \space \`{a} \space soupe } < f > - { TL } [c.\`{a}.c.] { cuill\`{e}re \space \`{a} \space caf\'{e} } < f > + { pn } [ pinc\'{e}e ] { pinc\'{e}e } [ pinc\'{e}es ] < f > + { EL } [c.\`{a}.s.] { cuill\`{e}re \space \`{a} \space soupe } [ cuill\`{e}res \space \`{a} \space soupe ] < f > + { TL } [c.\`{a}.c.] { cuill\`{e}re \space \`{a} \space caf\'{e} } [ cuill\`{e}res \space \`{a} \space caf\'{e} ] < f > % \end{macrocode} % \begin{macrocode} - { decimal-mark } { . } + { decimal-mark } { , } { one (m) } { un } { one (f) } { une } { one (n) } { un } @@ -10524,6 +10791,20 @@ and the derived file cooking-units.sty. % % \bibitem{StickSource} \url{https://cooking.stackexchange.com/questions/784/translating-cooking-terms-between-us-uk-au-ca-nz} % +% \bibitem{Plural-French-Academia} +% Dictionnaire de l’Académie française. +% \url{https://www.dictionnaire-academie.fr/article/A9P2979} +% [Last checked: 2022-05-29] +% +% \bibitem{Plural-French-absolute-1} +% \url{https://www.antidote.info/fr/blogue/enquetes/15-gramme-ou-15-grammes} +% [Last checked: 2022-05-29] +% +% \bibitem{Plural-French-absolute-2} +% \url{https://french.stackexchange.com/q/1975} +% [Last checked: 2022-05-29] +% +% % \end{thebibliography} % % |