diff options
author | Karl Berry <karl@freefriends.org> | 2018-04-30 17:05:54 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-04-30 17:05:54 +0000 |
commit | 2595862e871c121eb470cdd8f5a7a73970e9c398 (patch) | |
tree | bbba94460d3bd4f4dd2541e5a59a6e8080f20053 | |
parent | d628af7b1a32a21730b60108f0a4fd66434d3588 (diff) |
cooking-units (20apr18)
git-svn-id: svn://tug.org/texlive/trunk@47514 c570f23f-e606-0410-a88d-b1316a301751
-rw-r--r-- | Master/texmf-dist/doc/latex/cooking-units/README.md | 5 | ||||
-rw-r--r-- | Master/texmf-dist/doc/latex/cooking-units/cooking-units.pdf | bin | 600842 -> 614258 bytes | |||
-rw-r--r-- | Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx | 3345 | ||||
-rw-r--r-- | Master/texmf-dist/source/latex/cooking-units/cooking-units.ins | 17 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty | 1796 |
5 files changed, 3223 insertions, 1940 deletions
diff --git a/Master/texmf-dist/doc/latex/cooking-units/README.md b/Master/texmf-dist/doc/latex/cooking-units/README.md index 24087ef30d7..9ae432ec6b3 100644 --- a/Master/texmf-dist/doc/latex/cooking-units/README.md +++ b/Master/texmf-dist/doc/latex/cooking-units/README.md @@ -53,10 +53,9 @@ Supported Languages License ------- -This material is subject to the LaTeX Project Public License. See +This material is subject to the LaTeX Project Public License 1.3c or later. See - http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html + https://ctan.org/license/lppl1.3c for the details of that license. -%% diff --git a/Master/texmf-dist/doc/latex/cooking-units/cooking-units.pdf b/Master/texmf-dist/doc/latex/cooking-units/cooking-units.pdf Binary files differindex 0c964502b38..8a0308356e8 100644 --- a/Master/texmf-dist/doc/latex/cooking-units/cooking-units.pdf +++ b/Master/texmf-dist/doc/latex/cooking-units/cooking-units.pdf 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 910c4776e48..5cf667c0dab 100644 --- a/Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx +++ b/Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx @@ -63,9 +63,9 @@ Supported Languages License ------- -This material is subject to the LaTeX Project Public License. See +This material is subject to the LaTeX Project Public License 1.3c or later. See - http://www.ctan.org/tex-archive/help/Catalogue/licenses.lppl.html + https://ctan.org/license/lppl1.3c for the details of that license. @@ -82,16 +82,16 @@ for the details of that license. %\keepsilent \askforoverwritefalse \preamble -Copyright (C) 2016--2017 by Ben Vitecek (current Maintainer) +Copyright (C) 2016--2018 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.3 of this license or (at your option) any later +version 1.3c of this license or (at your option) any later version. The latest version of this license is in: - http://www.latex-project.org/lppl.txt + https://ctan.org/license/lppl1.3c -and version 1.3 or later is part of all distributions of +and version 1.3c or later is part of all distributions of LaTeX version 2008-05-04 or later. This work has the LPPL maintenance status `maintained'. @@ -144,6 +144,20 @@ and the derived file cooking-units.sty. \usepackage{cleveref} \usepackage{mathtools} \usepackage{siunitx} +\usepackage{totalcount} +\usepackage{microtype} + + +\newcounter{CookingUnitsCounter} +\newcounter{cunumCounter} +\newcounter{cuamCounter} +\newcounter{cutextCounter} +\newcounter{CutextCounter} +\DeclareTotalCounter{CookingUnitsCounter} +\DeclareTotalCounter{cunumCounter} +\DeclareTotalCounter{cuamCounter} +\DeclareTotalCounter{cutextCounter} +\DeclareTotalCounter{CutextCounter} \babeltags{myde = ngerman} @@ -185,6 +199,7 @@ and the derived file cooking-units.sty. cuaddtokeys, culabel, curef, + cudefinephrase, } \NewDocumentCommand \mycs { m } @@ -194,6 +209,9 @@ and the derived file cooking-units.sty. { \ERROR } } \newcommand\opt{\texttt} +\newcommand\myunit{\texttt} +\newcommand\mygroup{\texttt} +\newcommand\myaarg[1]{\texttt{<}\meta{#1}\texttt{>}} \newcommand\true{\opt{true}} \newcommand\false{\opt{false}} @@ -214,13 +232,19 @@ and the derived file cooking-units.sty. \texttt {#1} & \tl_use:c { l__cooking_units_default_unit_ #1 _tl } } +\NewDocumentCommand \PrintGroup { m } + { + \mygroup {#1} & + \clist_use:cn { l__cooking_units_group_ #1 _clist } { ,~ } + } %% Allyourwhitespacearebelongtous (too long) %% 42 -\NewDocumentCommand \dothewhitespace { O{ Miep! } } +%% Miep! +\NewDocumentCommand \dothewhitespace { O{ Ducks } } { \textcolor{white} {#1} \\ } @@ -286,7 +310,7 @@ and the derived file cooking-units.sty. { \token_if_parameter:NTF ##1 { - \int_compare:nNnTF { \l_tmpa_int } = { \c_zero } + \int_compare:nNnTF { \l_tmpa_int } = { 0 } { \c_hash_str \int_incr:N \l_tmpa_int @@ -433,7 +457,7 @@ and the derived file cooking-units.sty. \__cooking_units_phrase_list_get_for:NNTF \l_tmpa_prop \l_tmpa_tl { \__cooking_units_translate_let:VNxx \l_tmpa_tl \l_tmpa_clist - { phrase-list-list } \c__cooking_units_postfix_phrase_tl + { phrase-clist } \c__cooking_units_postfix_phrase_tl } { \ERROR } \clist_gput_right:Nn \l_tmpa_clist { THEEND } @@ -508,27 +532,32 @@ and the derived file cooking-units.sty. } \newcookingunit {st} +\newcookingunit [\ensuremath{ {} ^ { \circ } }\kern-\scriptspace R{\text{\o}}] {Ro} \cuaddkeys {lb} { {st} { 1/14 } %% 1 lb are 1/14 st } - - -\newcookingunit [\ensuremath{ {} ^ { \circ } }\kern-\scriptspace R{\text{\o}}] {Ro} - \cuaddsinglekeys {C} { {Ro} { #1*21/40 + 7.5 } } \cusetup { - set-option-for-Ro = { round-to-int = true } + commands-add-hook = {\stepcounter{CookingUnitsCounter}} , + cunum-add-hook = {\stepcounter{cunumCounter}} , + cutext-add-hook = {\stepcounter{cutextCounter}} , + Cutext-add-hook = {\stepcounter{CutextCounter}} , + cuam-add-hook = {\stepcounter{cuamCounter}} , + set-option-for-Ro = { round-to-int = true } , +% add-unit-to-group = { weight = {st} , temperature = {Ro} } } %: \cusetup \cusetup { +% weight=stick, +% 42 = true , % convert-to-eV=true , % cutext-range-sign = {as}, % erase-all-options, @@ -620,17 +649,34 @@ and the derived file cooking-units.sty. % \changes {2017/03/10} {1.11} {Removed things like 'cu-unit' from translate input % and placed them into separate tl's.} % -% \changes {2017/10/23} {1.2} {Replaced \pkg{translator} by \pkg{translations}.} -% \changes {2017/10/23} {1.2} {Added \enquote{phrases}.} -% \changes {2017/10/23} {1.2} {Added unit \enquote{stick} (of butter).} -% \changes {2017/10/23} {1.2} {|<| is not allowed as a special sign anymore.} -% \changes {2017/10/23} {1.2} {New option: \opt{set-cutext-translation-message}.} -% \changes {2017/10/23} {1.2} {New option: \opt{print-numerals}.} -% \changes {2017/10/23} {1.2} {New option: \opt{use-phrases}.} -% \changes {2017/10/23} {1.2} {New option: \opt{phrase-space}.} -% \changes {2017/10/23} {1.2} {New option: \opt{amount-unit-space}.} -% \changes {2017/10/23} {1.2} {Now checks for ranges if both values can be printed as numerals (if activated) (bug fix).} -% \changes {2017/10/23} {1.2} {Reworked quite a lot of code.} +% \changes {2017/10/23} {1.20} {Replaced \pkg{translator} by \pkg{translations}.} +% \changes {2017/10/23} {1.20} {Added \enquote{phrases}.} +% \changes {2017/10/23} {1.20} {Added unit \enquote{stick} (of butter).} +% \changes {2017/10/23} {1.20} {|<| is not allowed as a special sign anymore.} +% \changes {2017/10/23} {1.20} {New option: \opt{set-cutext-translation-message}.} +% \changes {2017/10/23} {1.20} {New option: \opt{print-numerals}.} +% \changes {2017/10/23} {1.20} {New option: \opt{use-phrases}.} +% \changes {2017/10/23} {1.20} {New option: \opt{phrase-space}.} +% \changes {2017/10/23} {1.20} {New option: \opt{amount-unit-space}.} +% \changes {2017/10/23} {1.20} {Now checks for ranges if both values can be printed as numerals (if activated) (bug fix).} +% \changes {2017/10/23} {1.20} {Reworked quite a lot of code.} +% +% \changes {2018/04/20} {1.30} {Allow round precision to be negative.} +% \changes {2018/04/20} {1.30} {Fix argument specifiers.} +% \changes {2018/04/20} {1.30} {Change large portions of code.} +% \changes {2018/04/20} {1.30} {Introduce key-groups (weight, volume, etc.).} +% \changes {2018/04/20} {1.30} {Option: \opt{add-natural-unit}.} +% \changes {2018/04/20} {1.30} {New Option: \opt{42}.} +% \changes {2018/04/20} {1.30} {New options: \opt{expand-both}, \opt{expand-amount}, \opt{expand-unit}.} +% \changes {2018/04/20} {1.30} {New options: \opt{set-option-for} \& \opt{add-option-for}.} +% \changes {2018/04/20} {1.30} {New option: \opt{erase-all-options-for}} +% \changes {2018/04/20} {1.30} {New option: \opt{add-unit-to-group}} +% \changes {2018/04/20} {1.30} {New feature: Hooks} +% \changes {2018/04/20} {1.30} {New parsing algorithm. Hopefully better +% error recovery (if signs for fractions are in wrong order e.g.)} +% \changes {2018/04/20} {1.30} {Add \enquote{Division-by-zero} error.} +% \changes {2018/04/20} {1.30} {Cooking Units-keys are not allowed to contain +% either \enquote{,} or \enquote{/}.} % % % @@ -640,17 +686,14 @@ and the derived file cooking-units.sty. % % % -%% % \GetFileInfo{\jobname.sty} % %\title{The \pkg{\jobname} package^^A %\thanks{This document corresponds to \textsf{Benedikt Vitecek}~\fileversion, dated~\filedate.}} %\author{Ben Vitecek \\ b.vitecek@gmx.at}% -%\date{October 23, 2017}% -% +%\date{2018/04/20}% % % \maketitle -% % % \begin{documentation} % \begin{abstract} @@ -758,10 +801,10 @@ and the derived file cooking-units.sty. % converting): % % \begin{itemize} -% \item \mycs{cunum}\meta{label}\oarg{options}\marg{amount}\oarg{space}\marg{unit-key} -% \item \mycs{cutext}\meta{label}\oarg{options}\marg{amount}\marg{unit-key} -% \item \mycs{Cutext}\meta{label}\oarg{options}\marg{amount}\marg{unit-key} -% \item \mycs{cuam}\meta{label}\oarg{options} \marg{amount} +% \item \mycs{cunum}\myaarg{label}\oarg{options}\marg{amount}\oarg{space}\marg{unit-key} +% \item \mycs{cutext}\myaarg{label}\oarg{options}\marg{amount}\marg{unit-key} +% \item \mycs{Cutext}\myaarg{label}\oarg{options}\marg{amount}\marg{unit-key} +% \item \mycs{cuam}\myaarg{label}\oarg{options} \marg{amount} % \item \mycs{cusetup}\marg{options} % \end{itemize} % @@ -788,7 +831,7 @@ and the derived file cooking-units.sty. % \cunum{2,3}{kg} \\ % \cunum{2--3}{kg} \\ % \cunum{2.5--3.5}{kg} \\ -% \cunum[kg=g]{2.5--3.5}{kg} \\ +% \cunum[kg=g]{2.5--3,5}{kg} \\ % \cunum[C=F]{200}{C} \\ % \cunum[C=F]{180--200}{C} \\ % \cunum{1/2}{m} \\ @@ -801,8 +844,8 @@ and the derived file cooking-units.sty. % \end{cuexamplecode} % % Decimal numbers are automatically rounded to 2 digits after the -% colon, temperatures (\texttt{C}, \texttt{F}, \texttt{K} and -% \texttt{Re}) are automatically rounded to integers.\footnote{You can +% colon, temperatures (\myunit{C}, \myunit{F}, \myunit{K} and +% \myunit{Re}) are automatically rounded to integers.\footnote{You can % -- of course -- change this behavior, see \cref{sec:options}.} % % @@ -867,6 +910,7 @@ and the derived file cooking-units.sty. % \begin{myde} % \begin{cuexamplecode} % \cusetup{use-phrases=true} @ +% \cuam{11} \\ % \cuam{12} \\ % \cuam{13} \\ % \cuam{24} \\ @@ -914,10 +958,9 @@ and the derived file cooking-units.sty. % \cunum{180}{C} & (\cunum[C=F]{180}{C}) & open & fire % \end{cuexamplecode} % -% Now with combination of the option \opt{set-number-of-persons} -% and setting \opt{recalculate-amount} to \opt{true} you can have this recipe +% In combination with the option \opt{set-number-of-persons} +% and \opt{recalculate-amount} you can have this recipe % changed to four persons: -% % \begin{lstlisting} % \culabel{recipe}{2} % %% adding options: @@ -948,7 +991,7 @@ and the derived file cooking-units.sty. % found in \cref{sec:options}. % % -% +%\subsection{Numerals} % \begin{cuinterest}{use-numerals, use-numerals-below, print-numerals} % As seen above, you can use the \emph{package}-option % \opt{use-numerals} to print integers used by \cCutext{} below @@ -962,6 +1005,7 @@ and the derived file cooking-units.sty. % % \end{cuinterest} % +% \subsection{Phrases} % \begin{cuinterest}{use-phrases} % In (I presume) all languages there exist phrases for a given % amount or a number of things (think it is called \enquote{counting measurement}). @@ -1004,10 +1048,31 @@ and the derived file cooking-units.sty. % supported. Furthermore this feature is only available for \mycs{cuam}. % \end{cunote} % -% % \end{cuinterest} % % +%\subsection{Rounding temperatures} +% +% By default temperatures are rounded to integers (using \opt{round-to-int = true}). +% Since 1.30 it is possible to round amounts to a negative precision. +% If you want to round temperatures to the tens see the following +% example (\opt{set-option-for-\meta{unit}} is described in \cref{sec:opt:unit-spec}). +% +% \begin{cuexamplecode} +% \cunum{180}{C} \\ +% \cunum[C=F]{180}{C} \\ +% \cunum[C=Re]{180}{C} \\ +% \cunum[C=K]{180}{C} \\ +% \cusetup{set-option-for-C = { round-precision = -1 } } @ +% \cusetup{set-option-for-F = { round-precision = -1 } } @ +% \cusetup{set-option-for-Re = { round-precision = -1 } } @ +% \cusetup{set-option-for-K = { round-precision = -1 } } @ +% \cunum{180}{C} \\ +% \cunum[C=F]{180}{C} \\ +% \cunum[C=Re]{180}{C} \\ +% \cunum[C=K]{180}{C} \\ +% \end{cuexamplecode} +% % \section{Predefined units \& some notes} % \label{sec:pred-units} % @@ -1039,6 +1104,7 @@ and the derived file cooking-units.sty. % are shown in \cref{sec:Translations}. % Note that \enquote{electron volt} exists just for fun. % } +% \smallskip % \begin{tabular}{ lll @{\hspace{1cm}} lll } % \toprule % description & key & default & description & key & default \\ \midrule @@ -1073,6 +1139,7 @@ and the derived file cooking-units.sty. % (e.g. \enquote{saltspoonful}) may not exist in another language % (like german; at least I never heard of it). So please only use % units known to you.} +% \smallskip % \begin{tabular}{ lll } % \toprule % description & key & symbol \\ \midrule @@ -1082,7 +1149,7 @@ and the derived file cooking-units.sty. % \PrintUnit {dsp} \\ % \PrintUnit {csp} \\ % \PrintUnit {ssp} \\ \addlinespace -% \PrintUnit [Messerpsitze (point of a knife)] {Msp} \\ +% \PrintUnit [Messerspitze (point of a knife)] {Msp} \\ % \bottomrule % \end{tabular} % \label{tab:some-more-units} @@ -1092,6 +1159,7 @@ and the derived file cooking-units.sty. % \centering % \caption{List of (not really) nonsense units (exist just for fun, there will be % no support for those units; unless -- of course -- you really want it).} +% \smallskip % \begin{tabular}{ ll } % \toprule % unit-key & symbol \\ \midrule @@ -1109,8 +1177,12 @@ and the derived file cooking-units.sty. % \section{Defining units} % \label{sec:def-units} % -% New units can be defined using \mycs{declarecookingunit}, -% \mycs{newcookingunit} and \mycs{providecookingunit}: +% New units can be defined using +% \begin{itemize} +% \item \mycs{declarecookingunit} +% \item \mycs{newcookingunit} +% \item \mycs{providecookingunit} +% \end{itemize} % % \begin{function}{\declarecookingunit,\newcookingunit,\providecookingunit} % \begin{syntax} @@ -1160,7 +1232,7 @@ and the derived file cooking-units.sty. % \item \mycs{cuaddtokeys} % \end{itemize} % I apologize for the (name) inconsistency between \mycs{cudefinekeys} and -% \mycs{cudefinesinglekey} (although they are named similarly they work different). +% \mycs{cudefinesinglekey} (although they are named similarly, they work different). % % \begin{function}{\cudefinekeys,\cudefinesinglekey} % \begin{syntax} @@ -1209,16 +1281,16 @@ and the derived file cooking-units.sty. % % This example defines following keys with their respective value: % \begin{itemize} -% \item the key \texttt{kg} with the values \texttt{kg}, \texttt{dag}, -% \texttt{g} and \texttt{oz} -% \item the key \texttt{dag} with the values \texttt{kg}, -% \texttt{dag}, \texttt{g} and \texttt{oz} -% \item the key \texttt{g} with the values \texttt{kg}, \texttt{dag}, -% \texttt{g} and \texttt{oz} -% \item the key \texttt{oz} with the values \texttt{kg}, \texttt{dag}, -% \texttt{g} and \texttt{oz} -% \item the key \texttt{d} with the values \texttt{d}, \texttt{h}, -% \texttt{min} and \texttt{s} +% \item the key \myunit{kg} with the values \myunit{kg}, \myunit{dag}, +% \myunit{g} and \myunit{oz} +% \item the key \myunit{dag} with the values \myunit{kg}, +% \myunit{dag}, \myunit{g} and \myunit{oz} +% \item the key \myunit{g} with the values \myunit{kg}, \myunit{dag}, +% \myunit{g} and \myunit{oz} +% \item the key \myunit{oz} with the values \myunit{kg}, \myunit{dag}, +% \myunit{g} and \myunit{oz} +% \item the key \myunit{d} with the values \myunit{d}, \myunit{h}, +% \myunit{min} and \myunit{s} % \item \dots % \end{itemize} % @@ -1257,8 +1329,8 @@ and the derived file cooking-units.sty. % \end{align*} % with $T_F$ being the input temperature in degree Fahrenheit and % $T_C$ being the same temperature in degree Celsius, etc. Using -% \lstinline|\cudefinesinglekey| the key \texttt{F} with values -% \texttt{C}, \texttt{K} and \texttt{Re} is defined: +% \lstinline|\cudefinesinglekey| the key \myunit{F} with values +% \myunit{C}, \myunit{K} and \myunit{Re} is defined: % % \begin{lstlisting} % \cudefinesinglekey {F} @@ -1269,8 +1341,8 @@ and the derived file cooking-units.sty. % } % \end{lstlisting} % -% This defines the key \texttt{F} with the values \texttt{F}, \texttt{C}, -% \texttt{K} and \texttt{Re}. +% This defines the key \myunit{F} with the values \myunit{F}, \myunit{C}, +% \myunit{K} and \myunit{Re}. % % \end{cuexample} % @@ -1309,7 +1381,7 @@ and the derived file cooking-units.sty. % If the conversion is more complicated use % \lstinline|\cuaddsinglekeys|. It adds \meta{unit-key-2}, etc. as % values to \meta{unit-key-1}. The numerical input can be placed -% using \texttt{\#1} (see \lstinline|\cudefinesinglekey|). This +% using \myunit{\#1} (see \lstinline|\cudefinesinglekey|). This % command neither defines new keys nor does it add values to other % keys than \meta{unit-key-1}. % @@ -1404,11 +1476,11 @@ and the derived file cooking-units.sty. % % \begin{comment} % \begin{cuexample} -% Implementation of \texttt{stick}. From https://cooking.stackexchange.com/questions/784/translating-cooking-terms-between-us-uk-au-ca-nz +% Implementation of \myunit{stick}. From https://cooking.stackexchange.com/questions/784/translating-cooking-terms-between-us-uk-au-ca-nz % we know that % \[ \SI{1}{\stick} = \SI{0.25}{\lb} \] % -% There are two ways to implement \texttt{stick}: +% There are two ways to implement \myunit{stick}: % either use \mycs{cuaddkeys} or \mycs{cuaddtokeys}. % % The easier way (in this case) is \mycs{cuaddtokeys} which is pretty straight forward: @@ -1461,8 +1533,8 @@ and the derived file cooking-units.sty. % \begin{syntax} % \mycs{cudefinename}\marg{Language} % \ \ \{ -% \ \ \ \ \marg{unit-key-1} \oarg{symbol-1} \marg{singular-1} \oarg{plural-1} \meta{gender} -% \ \ \ \ \marg{unit-key-2} \oarg{symbol-2} \marg{singular-2} \oarg{plural-2} \meta{gender} +% \ \ \ \ \marg{unit-key-1} \oarg{symbol-1} \marg{singular-1} \oarg{plural-1} \myaarg{gender} +% \ \ \ \ \marg{unit-key-2} \oarg{symbol-2} \marg{singular-2} \oarg{plural-2} \myaarg{gender} % \ \ \ \ \dots % \ \ \} % \end{syntax} @@ -1578,7 +1650,7 @@ and the derived file cooking-units.sty. % You do it anyway and end up with: % \begin{cuexamplecode} % \cunum{12}{dag} & weed\\ -% \cunum{3}{dag} & nuts\\ +% \cunum{3}[0]{dag} & nuts\\ % \cunum{10}{dag} & duckmeat % \end{cuexamplecode} % @@ -1599,16 +1671,17 @@ and the derived file cooking-units.sty. % % \begin{function}{\cudefinephrase} % \begin{syntax} -% \mycs{cudefinesymbol}\marg{Language} +% \mycs{cudefinephrase}\marg{Language} % \ \ \{ -% \ \marg{integer-1} \marg{phrase-1} \oarg{phrase-1-plural} \meta{gender-1} -% \ \marg{integer-2} * \marg{phrase-2} \oarg{phrase-2-plural} \meta{gender-2} +% \ \marg{integer-1} \marg{phrase-1} \oarg{phrase-1-plural} \myaarg{gender-1} +% \ \marg{integer-2} * \marg{phrase-2} \oarg{phrase-2-plural} \myaarg{gender-2} % \ \dots % \ \ \} % \end{syntax} % -% This command pairs for a given \marg{Language} the number \marg{integer-1} -% with \marg{phrase-1} (plural and gender). The package then checks if the amount +% This command pairs for a given \marg{Language} (see package \pkg{translations}) +% the number \marg{integer-1} +% with \marg{phrase-1} (\& plural and gender). The package then checks if the amount % given in \mycs{cuam} is either this number or a \emph{multiple} of it. % % If the behavior of checking for a multiple is not wanted, you can use the optional @@ -1631,10 +1704,10 @@ and the derived file cooking-units.sty. % \enquote{German}: % % \cudefinephrase {German} -% { +% { % { 60 } {Schock} <n> % { 6 }* {halbes\ Dutzend} <n> -% } +% } % % % \begin{lstlisting} @@ -1645,7 +1718,7 @@ and the derived file cooking-units.sty. % { 6 }* {halbes\ Dutzend} <n> % } % \end{lstlisting} -% Let's just use them (activating the german language): +% Let's just use them (german language activated!): % \begin{myde} % \begin{cuexamplecode} % \cusetup{use-phrases=true} @ @@ -1728,24 +1801,94 @@ and the derived file cooking-units.sty. % \end{function} % % \subsubsection{Unit Specific options} +% \label{sec:opt:unit-spec} % -% \begin{function}{unit} +% \begin{function}{<unit>} % \begin{syntax} % \meta{unit-key-1} = \meta{unit-key-2} % \end{syntax} -% Change unit \meta{unit-key-1} to \meta{unit-key-2} (see +% Change \meta{unit-key-1} to \meta{unit-key-2} (see % \cref{sec:defining-opt} to define new options). % \end{function} +% +% \begin{function}{<group>} +% \begin{syntax} +% \meta{group} = \meta{unit-key} +% \end{syntax} +% Changes each unit contained in \meta{group} to \meta{unit-key} (\meta{unit-key} +% must be part of \meta{group}). +% +% \begin{center} +% \begin{tabular}{ll} +% \toprule +% \meta{group} & default \meta{unit-key}s \\ \midrule +% \PrintGroup{weight} \\ +% \PrintGroup{length} \\ +% \PrintGroup{volume} \\ +% \PrintGroup{temperature} \\ +% \PrintGroup{energy} \\ +% \PrintGroup{time} \\ \bottomrule +% \end{tabular} +% \end{center} +% \end{function} +% +% \begin{cuexamplecode} +% \cusetup{weight=g} @ +% \cunum{1}{kg} \\ +% \cunum{1}{dag} \\ +% \cunum{1}{g} \\ +% \cunum{1}{oz} \\ +% \cunum{1}{lb} \\ +% \cunum{1}{stick} \\ +% \end{cuexamplecode} +% +% +% +% +% \begin{function}{add-unit-to-group} +% \begin{syntax} +% add-unit-to-group = +% \ \{ +% \ \meta{group1} = \marg{unit-key-list}, +% \ \meta{group2} = \marg{unit-key-list}, +% \ \dots +% \ \} +% \end{syntax} +% Adds each \meta{unit-key} in \meta{unit-keys-list} to \meta{group}. +% \end{function} +% \begin{cuexample} +% This example adds the unit \myunit{st} to the group \mygroup{weight} +% and \myunit{Ro} to \mygroup{temperature}. +% \begin{lstlisting} +% \cusetup +% { +% add-unit-to-group = { weight = {st} , temperature = {Ro} } +% } +% \end{lstlisting} +% +% \cusetup{ add-unit-to-group = { weight = {st} } } +% +% \begin{cuexamplecode} +% \cusetup{weight=g} @ +% \cunum{1}{kg} \\ +% \cunum{1}{dag} \\ +% \cunum{1}{g} \\ +% \cunum{1}{oz} \\ +% \cunum{1}{lb} \\ +% \cunum{1}{stick} \\ +% \cunum{1}{st} +% \end{cuexamplecode} +% \end{cuexample} +% % -% \begin{function}{set-option-for-<unit-key>,add-option-for-<unit-key>,erase-all-options} +% \begin{function}{set-option-for-<unit-key>,add-option-for-<unit-key>} % \begin{syntax} -% set-option-for-\meta{unit-key} = \meta{key1=value1,\dots} -% add-option-for-\meta{unit-key} = \meta{key1=value1,\dots} -% erase-all-options +% set-option-for-\meta{unit-key} = \marg{ key1 = value1, \dots\ } +% add-option-for-\meta{unit-key} = \marg{ key1 = value1, \dots\ } % \end{syntax} % Sets and adds \meta{key1=value1,\dots} to a specific % \meta{unit-key}, -% \texttt{erase-all-options} is used to erase all options for all +% \opt{erase-all-options} (see below) is used to erase all options for all % \meta{unit-key}s. % % You may want to attach some options to a special @@ -1754,11 +1897,16 @@ and the derived file cooking-units.sty. % unit). Setting options overwrites old options. Adding options, well % \dots\ adds the options to the old ones. % -% The following rounds the values to integers for \texttt{F}, \texttt{C}, -% \texttt{K} and \texttt{Re}. +% You can \enquote{delete} the options by setting +% an empty value for a specific \meta{unit-key} (or use +% \opt{erase-all-options} (or \opt{erase-all-options-for} ) +% (see below) to erase all options for all \meta{unit-key}s) % % \end{function} % +% \begin{cuexample} +% The following rounds the values to integers for \myunit{F}, \myunit{C}, +% \myunit{K} and \myunit{Re}: % \begin{lstlisting} % \cusetup % { @@ -1769,9 +1917,82 @@ and the derived file cooking-units.sty. % } % \end{lstlisting} % -% You can \enquote{delete} the options by setting -% an empty value for a specific \meta{unit-key} (or use -% \opt{erase-all-options} to erase all options for all \meta{unit-key}s) +%^^A The following code rounds the units to the tens: +%^^A \begin{lstlisting} +%^^A \cusetup +%^^A { +%^^A set-option-for-F = { round-precision = -1 } , +%^^A set-option-for-C = { round-precision = -1 } , +%^^A set-option-for-K = { round-precision = -1 } , +%^^A set-option-for-Re = { round-precision = -1 } +%^^A } +%^^A \end{lstlisting} +% \end{cuexample} +% +% +% \begin{function}{set-option-for, add-option-for} +% \begin{syntax} +% set-option-for = +% \ \{ +% \ \meta{unit-key1} = \marg{keys=vals}, +% \ \meta{unit-key2} = \marg{keys=vals}, +% \ \dots +% \ \} +% add-option-for = +% \ \{ +% \ \meta{unit-key1} = \marg{keys=vals}, +% \ \meta{unit-key2} = \marg{keys=vals}, +% \ \dots +% \ \} +% \end{syntax} +% Sets/adds each \meta{keys=vals} to the specific \meta{unit-key}. Works pretty much +% the same way their \opt{set-option-for-\meta{unit-key}} and +% \opt{add-option-for-\meta{unit-key}} counterparts. +% +% \end{function} +% +% \begin{cuexample} +% The following example does the same as the example above: +% \begin{lstlisting} +% \cusetup +% { +% set-option-for = +% { +% F = { round-to-int = true } , +% C = { round-to-int = true } , +% K = { round-to-int = true } , +% Re = { round-to-int = true } +% } +% } +% \end{lstlisting} +% \end{cuexample} +% +% \begin{function}{erase-all-options, erase-all-options-for} +% \begin{syntax} +% erase-all-options +% erase-all-options-for = \marg{unit-key1, unit-key2, \dots} +% \end{syntax} +% Erase options added to units. \opt{erase-all-options} erases all options +% for \emph{all} \meta{unit-key}s. +% +%^^A If you only want to erase options for specific \meta{unit-key}s, you may +%^^A use \opt{erase-all-options-for}. +% +% \opt{erase-all-options-for} is used to remove added options from +% the specified \meta{unit-key}s. +% +% \end{function} +% +% \begin{cuexample} +% The following code erases all attached options from \myunit{C}, \myunit{F}, +% \myunit{K} and \myunit{Re}: +% +% \begin{lstlisting} +% \cusetup{ erase-all-options-for = {C, F, K, Re} } +% \end{lstlisting} +% \end{cuexample} +% +% % % \subsubsection{Command behavior} % @@ -1808,7 +2029,7 @@ and the derived file cooking-units.sty. % \cutext[kg=g]{1}{kg} \\ % \cutext[kg=g]{1/2}{kg} \\ % \cutext[kg=g]{1--2}{kg} \\ -% \cusetup{cutext-change-unit=false } @ +% \cusetup{cutext-change-unit = false } @ % \cutext[kg=g]{1}{kg} \\ % \cutext[kg=g]{1/2}{kg} \\ % \cutext[kg=g]{1--2}{kg} @@ -1827,12 +2048,78 @@ and the derived file cooking-units.sty. % default. % \end{function} % +% +% +% +% \subsubsection{Hooks} +% +% \begin{function}{commands-add-hook,cunum-add-hook,cutext-add-hook,Cutext-add-hook,cuam-add-hook} +% \begin{syntax} +% commands-add-hook = \marg{code} +% cunum-add-hook = \marg{code} +% cutext-add-hook = \marg{code} +% Cutext-add-hook = \marg{code} +% cuam-add-hook = \marg{code} +% \end{syntax} +% Adds \meta{code} to the respective command (or in case of the first key: +% to \emph{all} commands). The hook is executed +% \emph{after} setting the keys, but \emph{before} parsing and processing the input. +% +% Please be carful with spaces, they will be printed. +% \end{function} +% +% \begin{cuexample} +% You would like to count how often all commands of this package are used. +% Simply add: +% \begin{lstlisting} +% \newcounter{CookingUnitsCounter} %% or however you like it +% \cusetup{commands-add-hook={\stepcounter{CookingUnitsCounter}}} +% %% beware of spaces inside the add-hook keys. +% \end{lstlisting} +% to your preamble. The following table lists how often each command +% is used in this documentation (with help of \pkg{totalcount}): +% +% \begin{center} +% \begin{tabular}{lr} +% \toprule +% command & times \\ \midrule +% \mycs{cunum} & \totalcunumCounters \\ +% \mycs{cutext} & \totalcutextCounters \\ +% \mycs{Cutext} & \totalCutextCounters \\ +% \mycs{cuam} & \totalcuamCounters \\ +% \cmidrule{2-2} +% total & \totalCookingUnitsCounters \\ +% \bottomrule +% \end{tabular} +% \end{center} +% \end{cuexample} +% % \subsubsection{Input and Outputs} % +% +% \begin{function}{expand-both , expand-amount, expand-unit} +% \begin{syntax} +% expand-both = \meta{n/o/f/x} +% expand-amount = \meta{n/o/f/x} +% expand-unit = \meta{n/o/f/x} +% \end{syntax} +% By default the commands \mycs{cunum}, \cCutext{} and \mycs{cunum} +% do \emph{not} expand their input. You can change the expansion behavior of +% the \meta{amount} and/or \meta{unit-key} using the options specified +% above. The meaning of the available values are the same as specified +% in the \LaTeX3\ document \enquote{interface3}. +% +% It is set to \texttt{n} by default. +% +% \end{function} +% +% +% +% % \begin{function}{set-special-sign,add-special-sign} % \begin{syntax} -% set-special-sign = \meta{character(s)} -% add-special-sign = \meta{character(s)} +% set-special-sign = \marg{character(s)} +% add-special-sign = \marg{character(s)} % \end{syntax} % Allows \meta{character(s)} to be used in the first mandatory argument of % \mycs{cunum}, \mycs{cuam}, \cCutext{} without raising an error (you can customize this @@ -1904,6 +2191,7 @@ and the derived file cooking-units.sty. % \mycs{cutext} and \mycs{Cutext} smaller than % \meta{integer}. \meta{integer} is by default 13. Package % \pkg{fmtcount} is used for this purpose. +% You can deactivate the printing of numerals by \opt{print-numerals=false}. % \end{function} % \cusetup{ print-numerals=true } % \begin{cuexamplecode} @@ -1934,10 +2222,10 @@ and the derived file cooking-units.sty. % \begin{syntax} % parse-number = \meta{true/false} % \end{syntax} -% If set to \texttt{false} prints the number of \lstinline!\cunum!, +% If set to \false\ prints the number of \lstinline!\cunum!, % \lstinline!\cutext!, \lstinline!\Cutext! and \mycs{cuam} as they % are (after some \dots\ well \dots\ parsing due to -% \enquote{\lstinline|_|}). Is set to \texttt{true} by default. +% \enquote{\lstinline|_|}). Is set to \true\ by default. % \end{function} % % \begin{cuexamplecode} @@ -1950,7 +2238,7 @@ and the derived file cooking-units.sty. % \cunum{1/2}{kg} \\ % \cunum{1_2/3}{kg} \\ % \cunum{1/2_3}{kg} \\ -% \cunum{qwertzuiop}{kg} \\ +% \cunum{some weird stuff}{kg} \\ % \cutext{1}{kg} \\ % \cutext{100}{kg} \\ % \cutext{gjfak}{kg} \\ @@ -1965,9 +2253,9 @@ and the derived file cooking-units.sty. % % \begin{function}{range-sign} % \begin{syntax} -% range-sign = \meta{string} -% cunum-range-sign = \meta{string} -% cutext-range-sign = \meta{string} +% range-sign = \marg{string} +% cunum-range-sign = \marg{string} +% cutext-range-sign = \marg{string} % \end{syntax} % The second sets the \emph{printed} range sign used in \mycs{cunum} % (and \mycs{cuam}) to \meta{string}, the third sets the printed @@ -2009,8 +2297,9 @@ and the derived file cooking-units.sty. % more information) with their phrase counterpart. This option is set to \false\ by default. % \end{function} % +% \begin{cuexample} % \begin{myde} -% For the German langauge: +% For the German language: % \begin{cuexamplecode} % \cuam{12} \\ % \cuam{12--24} \\ @@ -2019,8 +2308,13 @@ and the derived file cooking-units.sty. % \cuam{12} \\ % \cuam{12--24} \\ % \cuam{36} \\ +% \cusetup{use-phrases=true, print-numerals=true} @ +% \cuam{12} \\ +% \cuam{12--24} \\ +% \cuam{36} \\ % \end{cuexamplecode} % \end{myde} +% \end{cuexample} % % % \subsubsection{Rounding options} @@ -2030,8 +2324,8 @@ and the derived file cooking-units.sty. % round-precision = \meta{integer} % \end{syntax} % Rounds the amount automatically to \meta{integer} digits after the -% colon. Note that units like \texttt{C}, \texttt{F}, \texttt{K} and -% \texttt{Re} are still rounded to integers due to +% colon. Note that units like \myunit{C}, \myunit{F}, \myunit{K} and +% \myunit{Re} are still rounded to integers due to % \texttt{set-option-for-<unit-key>}. % \end{function} % @@ -2048,27 +2342,27 @@ and the derived file cooking-units.sty. % \cunum{12.58}{kg} \\ % \cunum[g=kg]{194}{g} \\ % \cunum[C=F]{200--210}{C} \\ -% \cunum[K=C]{0.0012}{K} +% \cunum[K=C]{0.0012}{K} % \end{cuexamplecode} % -% \begin{comment} % \begin{cunote} +% Also negative numbers are allowed. % \begin{cuexamplecode} % \cusetup{erase-all-options} @ % \cusetup{set-option-for-C={round-precision=-1}} @ -% \cusetup{set-option-for-kg={round-precision=-2}} @ -% \cunum{185}{kg} \\ +% \cusetup{set-option-for-F={round-precision=-1}} @ +% \cunum{-271,2}{C} \\ % \cunum[K=C]{0.0012}{K} \\ -% \cunum{185}{C} +% \cunum{185}{C} \\ +% \cunum[C=F]{180--200}{C} \\ % \end{cuexamplecode} % \end{cunote} -% \end{comment} % % \begin{function}{round-to-int} % \begin{syntax} % round-to-int = \meta{true/false} % \end{syntax} -% Rounds the amount to an integer if set \texttt{true}. +% Rounds the amount to an integer if set \true. % \end{function} % % @@ -2119,8 +2413,8 @@ and the derived file cooking-units.sty. % \begin{syntax} % eval-fraction = \meta{true/false} % \end{syntax} -% This option takes \texttt{true} or \texttt{false} as values. -% If set to \texttt{true} fractions are evaluated. Please note that divisions +% This option takes \true\ or \false\ as values. +% If set to \true\ fractions are evaluated. Please note that divisions % through zero are not allowed. % \end{function} % @@ -2132,6 +2426,7 @@ and the derived file cooking-units.sty. % \cunum{1_1/2}{kg} \\ % \cunum[kg=g]{1_1/2}{kg} \\ % \cunum[kg=g]{-1_1/2}{kg} \\ +% \cunum[kg=g]{1_?/2}{kg} \\ % \end{cuexamplecode} % % \begin{function}{fraction-command} @@ -2162,9 +2457,9 @@ and the derived file cooking-units.sty. % % \begin{function}{fraction-inline} % \begin{syntax} -% fraction-inline = \meta{input containing \#1 and \#2} +% fraction-inline = \marg{input containing \#1 and \#2} % \end{syntax} -% Similar to \texttt{fraction-command} only that you don't have to +% Similar to \opt{fraction-command} only that you don't have to % define a command to alter the output of the fraction. % \end{function} % @@ -2207,7 +2502,7 @@ and the derived file cooking-units.sty. % % \begin{function}{cutext-space} % \begin{syntax} -% cutext-space = \meta{string} +% cutext-space = \marg{string} % \end{syntax} % \meta{string} is inserted between the numeral part and the unit part % when using \cCutext. By default it is set to \cs{space}. Use this option @@ -2230,14 +2525,14 @@ and the derived file cooking-units.sty. % % \begin{function}{phrase-space} % \begin{syntax} -% phrase-space = \meta{string} +% phrase-space = \marg{string} % \end{syntax} % \meta{string} is inserted between the numeral part and the phrase part % while using \mycs{cuam}. By default it is set to \cs{space}. Use this option % if you want to e.g.\ insert an unbreakable space. % \end{function} -% \cusetup{use-phrases=true} % \begin{myde} +% \cusetup{use-phrases=true} % (Switching to german) % \begin{cuexamplecode} % \cuam{12}\\ @@ -2252,12 +2547,12 @@ and the derived file cooking-units.sty. % \cuam{12}\\ % \cuam{144}\\ % \end{cuexamplecode} -% \end{myde} % \cusetup{use-phrases=false} +% \end{myde} % % \begin{function}{amount-unit-space} % \begin{syntax} -% amount-unit-space = \meta{string} +% amount-unit-space = \marg{string} % \end{syntax} % Change the spacing for \mycs{cunum} between the printed amount(s) and % the unit. The default value is |\thinspace|. @@ -2298,8 +2593,9 @@ and the derived file cooking-units.sty. % set-number-of-persons = \meta{integer} % \end{syntax} % With this option you can determine the number of people your recipes -% are. Note that this option only has an effect on those who have a \meta{label} -% given. It is set to \opt{4} by default. +% are for. Note that this option only has an effect on those who have a \meta{label} +% given. It is set to \opt{4} by default. Please also note the use of +% \opt{recalculate-amount}. % \end{function} % \begin{cuexamplecode} % \culabel{anotherrecipe}{2} @ @@ -2337,11 +2633,11 @@ and the derived file cooking-units.sty. % % \begin{function}{label} % \begin{syntax} -% label = \meta{string}*\meta{integer} +% label = \{\meta{string}*\meta{integer}\} % \end{syntax} % The key-value version of \mycs{culabel}. It defines the label \meta{string} % which is originally for \meta{integer} people. Please note that the \texttt{*} -% is mandatory as it separates the string from the integer. Note that each +% is mandatory as it separates the string from the integer. Each % label is defined globally and must be unique. % \end{function} % \begin{cuexamplecode} @@ -2358,7 +2654,7 @@ and the derived file cooking-units.sty. % % \begin{function}{get-label} % \begin{syntax} -% get-label = \meta{label} +% get-label = \marg{label} % \end{syntax} % The key-value version of \mycs{curef}. Note that this key doesn't save the value % inside a macro but rather prints it directly into the document. @@ -2372,10 +2668,14 @@ and the derived file cooking-units.sty. % \curef{Schinken} \\ % \end{cuexamplecode} % +% \begin{cunote} +% \mycs{curef} \emph{is} expendable. +% \end{cunote} +% % % \begin{function}{ref} % \begin{syntax} -% ref = \meta{label} +% ref = \marg{label} % \end{syntax} % Instead of using the first optional arguments of the commands in \cref{sec:commands} % you may use this option. It requires a valid value and throws an error if \meta{label} @@ -2383,7 +2683,7 @@ and the derived file cooking-units.sty. % \end{function} % \begin{cuexamplecode} % \culabel{Kaese}{3} @ -% \cunum<Kaese>[m=dm]{1}{m} \\ +% \cunum<Kaese> [m=dm]{1}{m} \\ % \cunum[ref=Kaese,m=dm]{1}{m} \\ % \cusetup { recalculate-amount = true } @ % \cunum<Kaese>[m=dm]{1}{m} \\ @@ -2397,9 +2697,9 @@ and the derived file cooking-units.sty. % check-temperature = \meta{true/false} % \end{syntax} % Checks if the used temperature is below absolute zero. -% Currently \texttt{C}, \texttt{F}, \texttt{K} and \texttt{Re} are supported. +% Currently \myunit{C}, \myunit{F}, \myunit{K} and \myunit{Re} are supported. % While \lstinline|\cunum{0}{K}| is ok, \lstinline!\cunum{-1}{K}! raises an error, -% same for the others. Is set to \texttt{false} by default. To add new units +% same for the others. Is set to \false\ by default. To add new units % see \opt{add-temperature-to-check}. % \end{function} % @@ -2419,8 +2719,9 @@ and the derived file cooking-units.sty. % % \end{function} % -% For example, this package implements the allowed minimum values for the -% temperatures \texttt{C}, \texttt{F}, \texttt{K} and \texttt{Re} to be checked if +% \begin{cuexample} +% This package implements the allowed minimum values for the +% temperatures \myunit{C}, \myunit{F}, \myunit{K} and \myunit{Re} to be checked if % \opt{check-temperature} is active using: % \begin{lstlisting} % \cusetup @@ -2443,7 +2744,7 @@ and the derived file cooking-units.sty. % add-temperature-to-check = { Ro = -135.90375 } % } % \end{lstlisting} -% +% \end{cuexample} % % % @@ -2453,7 +2754,7 @@ and the derived file cooking-units.sty. % convert-to-eV = \meta{true/false} % \end{syntax} % Converts (nearly) every unit in \cref{tab:def-units} -% to electron volt or the respective derivative. Note that this +% to electron volt or the respective derivative (if possible). Note that this % option is: % a) experimental and probably will forever be and b) just a joke, you are not % supposed to use this units in a cookery book (and as you see this package @@ -2474,6 +2775,50 @@ and the derived file cooking-units.sty. % \cunum{1}{s} % \end{cuexamplecode} % +% \begin{function}{add-natural-unit} +% \begin{syntax} +% add-natural-unit = \meta{unit-key} +% \end{syntax} +% This option adds \meta{unit-key} to the list of units \opt{convert-to-eV} +% uses to determine how a unit is transformed if set to \true. +% \end{function} +% +% +% +% +% \begin{function}{42} +% \begin{syntax} +% 42 = \meta{true/false} +% \end{syntax} +% Take a good guess. +% \end{function} +% +% \begin{cuexamplecode}[\hfill] +% \cusetup{ 42=true } @ +% \cunum{1}{kg} \\ +% \cunum[kg=g]{1}{kg} \\ +% \cunum{1.5}{J} \\ +% \cunum{180}{C} \\ +% \cunum{15}{s} +% \end{cuexamplecode} +% +% +% +% +% +% +% +%^^A \section{Notes} +% +%^^A There is a unit called \enquote{Batman}. +% +% +% +% +% +% +% +% % % % @@ -2487,7 +2832,8 @@ and the derived file cooking-units.sty. % description. If you use mail please add \pkg{cooking-units} % to the e-mail header. GMX has the habit of putting e-mails into the % spam account and adding \pkg{cooking-units} to the header makes -% it easier to recognize those e-mails. +% it easier to recognize those e-mails. It can also take longer of GitHub, +% but I hope I figured out how to get a mail if a new issue is created (by not me). % % Feedback and requests (commands, units, etc.) are also welcome. Please % also add (if possible) an example of the desired output into the @@ -2533,7 +2879,6 @@ and the derived file cooking-units.sty. % % \newpage % \subsection{american} -%^^A Only differences from \enquote{English} are defined. % % \begin{tabular}{ l l l l l } % \toprule @@ -2679,12 +3024,17 @@ and the derived file cooking-units.sty. % % % +% \end{documentation} +% +% +% +% +% +% % % % % -% \end{documentation} -% % \begin{implementation} % % \section{Implementation} @@ -2716,14 +3066,14 @@ and the derived file cooking-units.sty. % \begin{macrocode} \ProvidesExplPackage {cooking-units} - {2017/10/23} - {1.2} + {2018/04/20} + {1.30} {Ein Paket fuer Kocheinheiten} % \end{macrocode} % % Checking if \pkg{expl3} is up-to-date, otherwise abort the loading of the package. % \begin{macrocode} -\@ifpackagelater { expl3 } { 2017/09/18 } +\@ifpackagelater { expl3 } { 2018/02/21 } { } { \PackageError { cooking-units } { Support~package~expl3~too~old } @@ -2793,7 +3143,7 @@ and the derived file cooking-units.sty. % \tl_if_in:nVTF , % \tl_if_in:NVTF , % \tl_if_in:NVT , -% \fp_compare:cNnT , +% \fp_compare:vNnT , % \fp_eval:c , % \prop_get:cVc , % \int_abs:c , @@ -2802,14 +3152,23 @@ and the derived file cooking-units.sty. % \begin{macrocode} \cs_generate_variant:Nn \tl_replace_all:Nnn { NVn } \cs_generate_variant:Nn \tl_replace_once:Nnn { NnV, NVn } -\cs_generate_variant:Nn \tl_if_in:nnTF { nVTF } +\cs_generate_variant:Nn \tl_if_in:nnTF { nV , xn } \cs_generate_variant:Nn \tl_if_in:NnTF { NVTF } \cs_generate_variant:Nn \tl_if_in:NnT { NVT } -\cs_generate_variant:Nn \fp_compare:nNnT { cNnT } -\cs_generate_variant:Nn \fp_eval:n { c } -\cs_generate_variant:Nn \prop_get:cVN { cVc } -\cs_generate_variant:Nn \int_abs:n { c } -\cs_generate_variant:Nn \tl_show:n { x , f } +\cs_generate_variant:Nn \fp_compare:nNnT { vNnT } +\cs_generate_variant:Nn \prop_get:NnN { cVc } +\cs_generate_variant:Nn \tl_set_rescan:Nnn { NnV } +\cs_generate_variant:Nn \msg_error:nnnn { nnnV } +\cs_generate_variant:Nn \msg_error:nnn { nnV } +% \end{macrocode} +% \end{macro} +% +% +% \begin{macro}{ \@@_dim_horizontal:N } +% Using this command (which is essential |\tex_kern:D| until an official +% command exists. +% \begin{macrocode} +\cs_new:Npn \@@_dim_horizontal:N #1 { \tex_kern:D #1 } % \end{macrocode} % \end{macro} % @@ -2821,13 +3180,20 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % +% \begin{macro}{\@@_set_amount:Nn,\@@_set_unit:Nn} +% \begin{macrocode} +\cs_new_eq:NN \@@_set_amount:Nn \tl_set:Nn +\cs_new_eq:NN \@@_set_unit:Nn \tl_set:Nn +% \end{macrocode} +% \end{macro} +% % % \begin{macro}{\@@_print_numeral:n , \@@_print_Numeral:n} % This command is used to print the fractions and can be changed % accordingly. % \begin{macrocode} -\cs_new:Npn \@@_print_numeral:n #1 {} -\cs_new:Npn \@@_print_Numeral:n #1 {} +\cs_new:Npn \@@_print_numeral:n #1 { } +\cs_new:Npn \@@_print_Numeral:n #1 { } \bool_if:NT \g_@@_opt_numeral_bool { \cs_set_eq:NN \@@_print_numeral:n \numberstringnum @@ -2839,9 +3205,9 @@ and the derived file cooking-units.sty. % % \begin{macro}{ \l_@@_change_unit_prop } % Conversions of units are stored within this property list. -% If someone requests that \texttt{kg} should be changed into \texttt{g}, -% \texttt{kg} is stored as a key with the value \texttt{g}. If someone -% then uses the unit \texttt{kg} the value \texttt{g} is restored and the unit +% If someone requests that \myunit{kg} should be changed into \myunit{g}, +% \myunit{kg} is stored as a key with the value \myunit{g}. If someone +% then uses the unit \myunit{kg} the value \myunit{g} is restored and the unit % is changed accordingly. % \begin{macrocode} \prop_new:N \l_@@_change_unit_prop @@ -2868,7 +3234,6 @@ and the derived file cooking-units.sty. % \l_@@_input_allowed_special_signs_tl , % \c_@@_input_str_hash_one_tl , % \l_@@_input_range_sign_tl, -% \l_@@_input_times_persons_sign, % \l_@@_cutext_space_tl, % \l_@@_cuphrase_space_tl, % \l_@@_translation_tmpa_tl, @@ -2882,6 +3247,7 @@ and the derived file cooking-units.sty. \tl_new:N \l_@@_tmpa_tl \tl_new:N \l_@@_tmpb_tl \tl_new:N \l_@@_mixed_fraction_tl +\tl_new:N \l_@@_given_amount_tl \tl_new:N \l_@@_given_unit_tl \tl_new:N \l_@@_option_unit_tl \tl_new:N \l_@@_language_tl @@ -2894,14 +3260,21 @@ and the derived file cooking-units.sty. \tl_new:N \l_@@_input_allowed_special_signs_tl \tl_new:N \c_@@_input_str_hash_one_tl \tl_new:N \l_@@_input_range_sign_tl -\tl_new:N \l_@@_input_times_persons_sign \tl_new:N \l_@@_cutext_space_tl \tl_new:N \l_@@_cuphrase_space_tl \tl_new:N \l_@@_translation_tmpa_tl \tl_new:N \l_@@_cutext_last_value_tl \tl_new:N \l_@@_phantom_tl \tl_new:N \l_@@_phrase_phrase_tl -\tl_new:N \l_@@_unit_key_not_allowed_tl +\tl_new:N \l_@@_unit_letter_not_allowed_tl +\tl_new:N \l_@@_input_fraction_sign_tl +\tl_new:N \l_@@_input_mixed_fraction_sign_tl +% \end{macrocode} +% \begin{macrocode} +\tl_new:N \l_@@_cunum_hook_tl +\tl_new:N \l_@@_cutext_hook_tl +\tl_new:N \l_@@_Cutext_hook_tl +\tl_new:N \l_@@_cuam_hook_tl % \end{macrocode} % \end{macro} % @@ -2911,8 +3284,9 @@ and the derived file cooking-units.sty. % (You will see, I didn't have a better idea) % \begin{macrocode} \tl_set:Nn \l_@@_input_digits_tl { 0123456789 } -\tl_set:Nn \l_@@_input_times_persons_sign { * } \tl_set:Nn \l_@@_input_range_sign_tl { -- } +\tl_set:Nn \l_@@_input_fraction_sign_tl { / } +\tl_set:Nn \l_@@_input_mixed_fraction_sign_tl { _ } \tl_set:Nn \l_@@_input_decimal_mark_tl { . , } \tl_set:Nn \l_@@_input_value_signs_tl { + - } \tl_set:Nn \l_@@_input_allowed_special_signs_tl { ? } @@ -2925,7 +3299,7 @@ and the derived file cooking-units.sty. \tl_set:Nn \l_@@_value_unit_space_tl { \thinspace } \tl_set:Nn \l_@@_cutext_space_tl { \space } \tl_set:Nn \l_@@_cuphrase_space_tl { \space } -\tl_set:Nn \l_@@_unit_key_not_allowed_tl { , / } +\tl_set:Nn \l_@@_unit_letter_not_allowed_tl { , / } % \end{macrocode} % % Flat out stolen from \pkg{siunitx} @@ -2969,18 +3343,11 @@ and the derived file cooking-units.sty. % \end{macro} % % -% \begin{macro}{ \l_@@_significant_figures_plus_one_int } -% Stores the round-precision inside. Not sure if 'significant -% figures' is the correct therm for this. Also computes the number -% plus 1, later I will count the tokens after the colon in a number -% (sorry, can't explain. If you have 123.4567, it gets -% \enquote{4567}, 4 tokens, larger then the number plus 1, needs to -% be rounded). +% \begin{macro}{ \l_@@_round_precision_int } +% Stores the round-precision inside. % \begin{macrocode} -\int_new:N \l_@@_significant_figures_int -\int_new:N \l_@@_significant_figures_plus_one_int -\int_set:Nn \l_@@_significant_figures_int { 2 } -\int_set:Nn \l_@@_significant_figures_plus_one_int { 2 + 1 } +\int_new:N \l_@@_round_precision_int +\int_set:Nn \l_@@_round_precision_int { 2 } % \end{macrocode} % \end{macro} % @@ -2995,22 +3362,22 @@ and the derived file cooking-units.sty. % \end{macro} % % -% \begin{macro}{ \l_@@_number_of_persons_tmpa_int } +% \begin{macro}{ \l_@@_local_number_of_persons_int } % Each recipe defined by \cs{culabel} defines a counter to % store the number of persons the recipe is for. For calculation % the value is retrived and stored inside this temporal counter. % \begin{macrocode} -\int_new:N \l_@@_number_of_persons_tmpa_int +\int_new:N \l_@@_local_number_of_persons_int % \end{macrocode} % \end{macro} % -% \begin{macro}{ \l_@@_calc_for_number_of_persons_int } +% \begin{macro}{ \l_@@_wanted_number_of_persons_int } % Not only the number of persons are recipe is for is needed % for calculation, but also the number of persons you want % the recipe to be. This information is stored here. % \begin{macrocode} -\int_new:N \l_@@_calc_for_number_of_persons_int -\int_set:Nn \l_@@_calc_for_number_of_persons_int { 4 } +\int_new:N \l_@@_wanted_number_of_persons_int +\int_set:Nn \l_@@_wanted_number_of_persons_int { 4 } % \end{macrocode} % \end{macro} % @@ -3057,6 +3424,13 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % +% \begin{macro} { \l_@@_curef_do_not_change_seq } +% This contains the units which shouldn't be changed. +% \begin{macrocode} +\seq_new:N \l_@@_curef_do_not_change_seq +% \end{macrocode} +% \end{macro} +% % \begin{macro} { \l_@@_phrase_prop } % Stores the number and he respective phrase. For example % if \enquote{12} has the phrase \enquote{Dutzend}, this @@ -3066,13 +3440,14 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % +% % \begin{macro} % { % \l_@@_minus_bool, -% \l_@@_round_decimal_part_bool, +% \l_@@_round_number_bool, % \l_@@_error_bool, % \l_@@_eval_fractions_bool, -% \l_@@_parse_input_bool, +% \l_@@_draft_bool, % \l_@@_round_to_int_bool, % \l_@@_special_sign_bool, % \l_@@_single_key_bool, @@ -3082,23 +3457,23 @@ and the derived file cooking-units.sty. % \l_@@_error_for_unknown_value_bool, % \l_@@_using_cutext_bool, % \l_@@_cuam_old_bool, -% \l_@@_calc_for_persons_bool, +% \l_@@_change_number_of_persons_bool, % \l_@@_calc_because_ref_was_given_bool, -% \l_@@_calc_persons_bool, +% \l_@@_lokal_persons_bool, % \l_@@_cutext_to_cunum_bool, % \l_@@_cutext_old_bool, % \l_@@_cutext_change_unit_bool, % \l_@@_round_commercial_bool, % \l_@@_use_phrases_bool, -% \l_@@_check_if_phrase_used_bool +% \l_@@_lokal_phrase_bool % } % Some booleans we need later. % \begin{macrocode} \bool_new:N \l_@@_minus_bool -\bool_new:N \l_@@_round_decimal_part_bool +\bool_new:N \l_@@_round_number_bool \bool_new:N \l_@@_error_bool \bool_new:N \l_@@_eval_fractions_bool -\bool_new:N \l_@@_parse_input_bool +\bool_new:N \l_@@_draft_bool \bool_new:N \l_@@_round_to_int_bool \bool_new:N \l_@@_special_sign_bool \bool_new:N \l_@@_single_key_bool @@ -3108,34 +3483,38 @@ and the derived file cooking-units.sty. \bool_new:N \l_@@_error_for_unknown_value_bool \bool_new:N \l_@@_using_cutext_bool \bool_new:N \l_@@_cuam_old_bool -\bool_new:N \l_@@_calc_for_persons_bool +\bool_new:N \l_@@_change_number_of_persons_bool \bool_new:N \l_@@_calc_because_ref_was_given_bool -\bool_new:N \l_@@_calc_persons_bool +\bool_new:N \l_@@_lokal_persons_bool \bool_new:N \l_@@_cutext_to_cunum_bool \bool_new:N \l_@@_cutext_old_bool \bool_new:N \l_@@_cutext_change_unit_bool \bool_new:N \l_@@_round_commercial_bool \bool_new:N \l_@@_use_phrases_bool -\bool_new:N \l_@@_check_if_phrase_used_bool -\bool_new:N \l_@@_local_numeral_bool +\bool_new:N \l_@@_lokal_phrase_bool +\bool_new:N \l_@@_print_numeral_bool +\bool_new:N \l_@@_lokal_numeral_bool +\bool_new:N \l_@@_round_precision_positive_bool +\bool_new:N \l_@@_fourty_two_bool % \end{macrocode} % % While rewriting the code I searched for those % booleans a lot. % \begin{macrocode} \bool_new:N \l_@@_range_in_input_bool -\bool_new:N \l_@@_fraction_in_input_bool +\bool_new:N \l_@@_lokal_fraction_bool +\bool_new:N \l_@@_print_fraction_bool +\bool_new:N \l_@@_lokal_mixed_fraction_bool \bool_new:N \l_@@_decimal_in_input_bool % \end{macrocode} % \end{macro} % % % -% Setting some of them to \texttt{true} or another boolean respectively. +% Setting some of them to \true\ or another boolean respectively. % \begin{macrocode} -\bool_set_true:N \l_@@_parse_input_bool \bool_set_true:N \l_@@_cutext_change_unit_bool -\bool_set_eq:NN \l_@@_local_numeral_bool \g_@@_opt_numeral_bool +\bool_set_eq:NN \l_@@_print_numeral_bool \g_@@_opt_numeral_bool % \end{macrocode} % % @@ -3147,12 +3526,18 @@ and the derived file cooking-units.sty. %\end{macro} % % \begin{macro}{ \q_@@_no_translation } -% Note the spelling mistake in \enquote{available}. % \begin{macrocode} \quark_new:N \q_@@_no_translation % \end{macrocode} %\end{macro} % +% \begin{macro}{ \q_@@_decimal , \q_@@_frac , \q_@@_mixed_frac } +% \begin{macrocode} +\quark_new:N \q_@@_decimal +\quark_new:N \q_@@_frac +\quark_new:N \q_@@_mixed_frac +% \end{macrocode} +%\end{macro} % % \begin{macro}{ % \l_@@_tmpa_fp , @@ -3161,7 +3546,7 @@ and the derived file cooking-units.sty. % \l_@@_tmpb_prop , % \l_@@_tmpa_seq , % } -% Some temporal stores which are used thoughout the code. +% Some temporal stores which are used throughout the code. % \begin{macrocode} \fp_new:N \l_@@_tmpa_fp \clist_new:N \l_@@_tmpa_clist @@ -3177,175 +3562,202 @@ and the derived file cooking-units.sty. % % \subsection {Keys} % +% % Let's define some keys. % \begin{macrocode} \keys_define:nn { cooking-units } { % \end{macrocode} % -%\begin{macro}{ eval-fraction } -% If set to true the fractions are evaluated. -% \begin{macrocode} - eval-fraction .bool_set:N = \l_@@_eval_fractions_bool , - eval-fraction .default:n = { false } , -% \end{macrocode} -%\end{macro} % -%\begin{macro}{ round-precision } -% Setting the round-precision. Setting those two at once to -% not calculate it every time. +% \begin{macro}{ add-unit-to-group } % \begin{macrocode} - round-precision .code:n = - { - \int_set:Nn \l_@@_significant_figures_int {#1} - \int_set:Nn \l_@@_significant_figures_plus_one_int { #1 + \c_one } + add-unit-to-group .code:n = + { + \keyval_parse:NNn + \@@_unit_group_add_unit_error:n + \@@_unit_group_add_unit:nn + {#1} } , - round-precision .default:n = { 2 } , + add-unit-to-group .default:n = {} , % \end{macrocode} -%\end{macro} +% \end{macro} % -%\begin{macro}{ round-to-int } -% Rounding the results to an integer. +%\begin{macro}{ set-option-for } +% Setting options. % \begin{macrocode} - round-to-int .bool_set:N = \l_@@_round_to_int_bool , - round-to-int .default:n = { false } , + set-option-for .code:n = + { + \keyval_parse:NNn + \@@_set_options_for_error:n + \@@_set_options_for:nn + {#1} + }, % \end{macrocode} -%\end{macro} +% \end{macro} % -%\begin{macro}{ range-sign } -% Setting the printed range sign and make a difference between cunum -% and c(C)utext. +%\begin{macro}{ add-option-for } +% Setting options. % \begin{macrocode} - range-sign .meta:n = - { - cunum-range-sign = {#1} , - cutext-range-sign = {#1} - } , - range-sign .default:n = { -- } , - cunum-range-sign .tl_set:N = \l_@@_cunum_range_sign_tl , - cunum-range-sign .default:n = { -- } , - cutext-range-sign .tl_set:N = \l_@@_cutext_range_sign_tl , - cutext-range-sign .default:n = { -- } , + add-option-for .code:n = + { + \keyval_parse:NNn + \@@_add_options_for_error:n + \@@_add_options_for:nn + {#1} + }, % \end{macrocode} -%\end{macro} +% \end{macro} % -%\begin{macro}{ amount-unit-space } -% Setting the space between the value and the printed unit. +% \begin{macro}{ erase-all-options } +% Erasing all preset options. % \begin{macrocode} - amount-unit-space .tl_set:N = \l_@@_value_unit_space_tl , - amount-unit-space .default:n = { \thinspace } , + erase-all-options .code:n = + { + \seq_map_inline:Nn \g_@@_list_of_defined_units_seq + { + \clist_clear:c { l_@@_predefined_option_ ##1 _clist } + } + }, + erase-all-options .value_forbidden:n = { true } , % \end{macrocode} -%\end{macro} +% \end{macro} % -%\begin{macro}{ fraction-command } -% Setting the fraction command +%\begin{macro}{ erase-all-options-for } +% Erasing options. % \begin{macrocode} - fraction-command .code:n = { \cs_set_eq:NN \@@_frac:nn #1 } , - fraction-command .default:n = { \sfrac } , + erase-all-options-for .code:n = + { + \keyval_parse:NNn + \@@_erase_options_for:n + \@@_erase_options_for_error:nn + {#1} + }, + erase-all-options-for .value_required:n = { true } , % \end{macrocode} -%\end{macro} +% \end{macro} % -%\begin{macro}{ fraction-inline } -% Setting the code inline. +% +% +% +% +% +% \begin{macro}{ cutext-to-cunum } +% Don't want any \mycs{cutext} (or \mycs{Cutext}) in your +% document? Use this option! % \begin{macrocode} - fraction-inline .code:n = { \cs_set:Npn \@@_frac:nn ##1##2 {#1} } , - fraction-inline .default:n = { \sfrac {#1} {#2} } , + cutext-to-cunum .bool_set:N = \l_@@_cutext_to_cunum_bool , + cutext-to-cunum .default:n = { false } , + cutext-to-cunum .groups:n = { change-command } , % \end{macrocode} -%\end{macro} +% \end{macro} % -%\begin{macro}{ mixed-fraction-space } -% Setting the space between the mixed fraction part and the fraction. +% \begin{macro}{ cutext-change-unit } +% Do not wanna change units in \mycs{cutext}? Use this option. % \begin{macrocode} - mixed-fraction-space .dim_set:N = \l_@@_mixed_frac_dim , - mixed-fraction-space .default:n = { 0.1 em } , + cutext-change-unit .bool_set:N = \l_@@_cutext_change_unit_bool , + cutext-change-unit .default:n = { true } , % \end{macrocode} -%\end{macro} +% \end{macro} % -%\begin{macro}{ parse-number } -% Parse the numbers? If no the input is printed as is (after some safetyparsing). +% \begin{macro}{ cuam-version , cutext-version} +% Some keys with horrible option names. Reverts +% the respective command back to its older state (pre v1.10). % \begin{macrocode} - parse-number .bool_set:N = \l_@@_parse_input_bool , - parse-number .default:n= { true } , + cuam-version .choices:nn = + { new , old } + { + \int_case:nn { \l_keys_choice_int } + { + { 1 } { \bool_set_false:N \l_@@_cuam_old_bool } + { 2 } { \bool_set_true:N \l_@@_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_@@_cutext_old_bool } + { 2 } { \bool_set_true:N \l_@@_cutext_old_bool } + } + } , + cutext-version .default:n = { new } , % \end{macrocode} -%\end{macro} +% \end{macro} % -%\begin{macro}{ add-special-sign } -% Adding a (some) special sign(s) which is (are) allowed in the input. +% \begin{macro}{ expand-both , expand-amount, expand-unit } % \begin{macrocode} - add-special-sign .code:n = - { - \str_if_eq:nnTF {#1} { < } - { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } - { \tl_put_right:Nn \l_@@_input_allowed_special_signs_tl {#1} } + expand-both .choices:nn = + { n , o , f , x } + { + \cs_set_eq:Nc \@@_set_unit:Nn { tl_set:N \l_keys_choice_tl } + \cs_set_eq:Nc \@@_set_amount:Nn { tl_set:N \l_keys_choice_tl } } , - add-special-sign .default:n = { } , + expand-both .default:n = { n } , % \end{macrocode} -%\end{macro} -% -%\begin{macro}{ set-special-sign } -% Doing the same as above but also overrides the old signs. % \begin{macrocode} - set-special-sign .code:n = - { - \str_if_eq:nnTF {#1} { < } - { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } - { \tl_set:Nn \l_@@_input_allowed_special_signs_tl {#1} } + expand-amount .choices:nn = + { n , o , f , x } + { + \cs_set_eq:Nc \@@_set_amount:Nn { tl_set:N \l_keys_choice_tl } } , + expand-amount .default:n = { n } , % \end{macrocode} -%\end{macro} -% -% -% \begin{macro}{ input-range-sign } -% Don't wanna use \verb|--| as a range sperator in \mycs{cunum}? -% Use this option. % \begin{macrocode} - input-range-sign .tl_set:N = \l_@@_input_range_sign_tl , - input-range-sign .default:n = { -- } , + expand-unit .choices:nn = + { n , o , f , x } + { + \cs_set_eq:Nc \@@_set_unit:Nn { tl_set:N \l_keys_choice_tl } + } , + expand-unit .default:n = { n } , % \end{macrocode} -%\end{macro} +% \end{macro} % % -%\begin{macro}{ check-temperature } -% Weird option. Checking the temperature, if the temperature is below the absolute zero temperature -% it raises an error. -% \begin{macrocode} - check-temperature .bool_set:N = \l_@@_check_temperature_bool , - check-temperature .default:n = { true } , -% \end{macrocode} % -%\begin{macro}{ add-temperature-to-check } -% Adds a temperature to check for \texttt{check-temperature}. -% It uses the \cs{keyval\_parse:NNn} command as this -% macro is used to parse keys (which is what I need). -% \begin{macrocode} - add-temperature-to-check .code:n = - { - \keyval_parse:NNn - \@@_temperature_to_check_print_error:n - \@@_temperatures_to_check_define:nn - {#1} - }, - temperature-to-check .value_required:n = { true } , -% \end{macrocode} -% \end{macro} % -%\begin{macro}{ convert-to-eV } -% Another weird option, converts pretty much any unit defined by this -% package to electron volt or the respective derivative. -% As this is a unit transfrmation, it needs to be inside the -% group. +% +%\begin{macro}{ set-special-sign } +% Doing the same as above but also overrides the old signs. % \begin{macrocode} - convert-to-eV .bool_set:N = \l_@@_convert_to_eV_bool , - convert-to-eV .default:n = { true } , - convert-to-eV .groups:n = { change-unit } , + set-special-sign .code:n = + { + \tl_map_inline:nn {#1} + { + \str_if_eq:nnT {##1} { < } + { + \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } + \tl_map_break:n { \use_none:nn } + } + } + \use:n { \tl_set:Nn \l_@@_input_allowed_special_signs_tl {#1} } +% \str_if_eq:nnTF {#1} { < } +% { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } +% { \tl_set:Nn \l_@@_input_allowed_special_signs_tl {#1} } + } , % \end{macrocode} %\end{macro} -% -% \begin{macro}{ use-numerals-below } -% Use numerals if the intger is below the integer set by this option. +%\begin{macro}{ add-special-sign } +% Adding a (some) special sign(s) which is (are) allowed in the input. % \begin{macrocode} - use-numerals-below .int_set:N = \l_@@_print_numerals_below_int , - use-numerals-below .default:n = { 13 } , + add-special-sign .code:n = + { + \tl_map_inline:nn {#1} + { + \str_if_eq:nnTF {##1} { < } + { + \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } + }{ + \tl_put_right:Nn \l_@@_input_allowed_special_signs_tl {##1} + } + } +% \str_if_eq:nnTF {#1} { < } +% { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } +% { \tl_put_right:Nn \l_@@_input_allowed_special_signs_tl {#1} } + } , + add-special-sign .default:n = { } , % \end{macrocode} %\end{macro} % @@ -3359,7 +3771,7 @@ and the derived file cooking-units.sty. \msg_redirect_name:nnn { cooking-units } { amount-not-known } { \l_keys_choice_tl } } , - set-unknown-message .default:n = { warning } , + set-unknown-message .default:n = { set-cutext-translation-message } , % \end{macrocode} %\end{macro} % @@ -3377,21 +3789,86 @@ and the derived file cooking-units.sty. %\end{macro} % % -%\begin{macro}{ erase-all-options } -% Erasing all preset options. +% \begin{macro}{ print-numerals } +% A not very good name, but I couldn't think of a better name. % \begin{macrocode} - erase-all-options .code:n = - { - \seq_map_inline:Nn \g_@@_list_of_defined_units_seq - { - \clist_clear:c { l_@@_predefined_option_##1_clist } - } - }, + print-numerals .bool_set:N = \l_@@_print_numeral_bool , + print-numerals .default:n = { true } , +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{ use-numerals-below } +% Use numerals if the integer is below the integer set by this option. +% \begin{macrocode} + use-numerals-below .int_set:N = \l_@@_print_numerals_below_int , + use-numerals-below .default:n = { 13 } , +% \end{macrocode} +%\end{macro} +% +%\begin{macro}{ parse-number } +% Parse the input? If no the input is printed as is (after some safety parsing). +% \begin{macrocode} + parse-number .bool_set_inverse:N = \l_@@_draft_bool , + parse-number .default:n= { true } , +% \end{macrocode} +%\end{macro} +% +%\begin{macro}{ range-sign } +% Setting the printed range sign and make a difference between cunum +% and c(C)utext. +% \begin{macrocode} + range-sign .meta:n = + { + cunum-range-sign = {#1} , + cutext-range-sign = {#1} + } , + range-sign .default:n = { -- } , + cunum-range-sign .tl_set:N = \l_@@_cunum_range_sign_tl , + cunum-range-sign .default:n = { -- } , + cutext-range-sign .tl_set:N = \l_@@_cutext_range_sign_tl , + cutext-range-sign .default:n = { -- } , +% \end{macrocode} +%\end{macro} +% +% \begin{macro}{ use-phrases } +% Do not wanna use phrases in \mycs{cuam}? Use this option! +% \begin{macrocode} + use-phrases .bool_set:N = \l_@@_use_phrases_bool , + use-phrases .default:n = { true } , % \end{macrocode} % \end{macro} % +% +% +% +% +% +%\begin{macro}{ round-precision } +% Setting the round-precision. Setting those two at once to +% not calculate it every time. +% \begin{macrocode} + round-precision .code:n = + { + \int_set:Nn \l_@@_round_precision_int {#1} + \int_compare:nNnTF {#1} < { 0 } + { \bool_set_false:N \l_@@_round_precision_positive_bool } + { \bool_set_true:N \l_@@_round_precision_positive_bool } + } , + round-precision .default:n = { 2 } , +% \end{macrocode} +%\end{macro} +% +%\begin{macro}{ round-to-int } +% Rounding the results to an integer. +% \begin{macrocode} + round-to-int .bool_set:N = \l_@@_round_to_int_bool , + round-to-int .default:n = { false } , +% \end{macrocode} +%\end{macro} +% % \begin{macro}{ round-half } -% Choosing between \enquote{normal} rounding to even and commercial rounding and sets the boolean accordingly. +% Choosing between \enquote{normal} rounding to even +% and commercial rounding and sets the boolean accordingly. % \begin{macrocode} round-half .choices:nn = { default , commercial } @@ -3406,10 +3883,87 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % +%\begin{macro}{ eval-fraction } +% If set to true the fractions are evaluated. +% \begin{macrocode} + eval-fraction .bool_set:N = \l_@@_eval_fractions_bool , + eval-fraction .default:n = { false } , +% \end{macrocode} +%\end{macro} +% +%\begin{macro}{ fraction-command } +% Setting the fraction command +% \begin{macrocode} + fraction-command .code:n = { \cs_set_eq:NN \@@_frac:nn #1 } , + fraction-command .default:n = { \sfrac } , +% \end{macrocode} +%\end{macro} +% +%\begin{macro}{ fraction-inline } +% Setting the code inline. +% \begin{macrocode} + fraction-inline .code:n = { \cs_set:Npn \@@_frac:nn ##1##2 {#1} } , + fraction-inline .default:n = { \sfrac {#1} {#2} } , +% \end{macrocode} +%\end{macro} +% +% +% +% +% +% +%\begin{macro}{ mixed-fraction-space } +% Setting the space between the mixed fraction part and the fraction. +% \begin{macrocode} + mixed-fraction-space .dim_set:N = \l_@@_mixed_frac_dim , + mixed-fraction-space .default:n = { 0.1 em } , +% \end{macrocode} +%\end{macro} +% +% \begin{macro}{ cutext-space } +% The space used in \mycs{cutext} between the number (or numeral) +% and unit. +% \begin{macrocode} + cutext-space .tl_set:N = \l_@@_cutext_space_tl , + cutext-space .default:n = { \space } , +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{ phrase-space } +% Same as before, but for phrases +% \begin{macrocode} + phrase-space .tl_set:N = \l_@@_cuphrase_space_tl , + phrase-space .default:n = { \space } , +% \end{macrocode} +% \end{macro} +% +%\begin{macro}{ amount-unit-space } +% Setting the space between the value and the printed unit. +% \begin{macrocode} + amount-unit-space .tl_set:N = \l_@@_value_unit_space_tl , + amount-unit-space .default:n = { \thinspace } , +% \end{macrocode} +%\end{macro} +% +% +% +% +% +% +% \begin{macro}{ recalculate-amount } +% Setting the number of persons your recipes should be for +% is not enough; it is also needed to tell the package to +% recalculate the amounts. +% \begin{macrocode} + recalculate-amount .bool_set:N = \l_@@_change_number_of_persons_bool , + recalculate-amount .default:n = { false } , +% \end{macrocode} +% \end{macro} +% % \begin{macro}{ set-number-of-persons } % Setting the number of persons the recipe should be for. % \begin{macrocode} - set-number-of-persons .int_set:N = \l_@@_calc_for_number_of_persons_int , + set-number-of-persons .int_set:N = \l_@@_wanted_number_of_persons_int , set-number-of-persons .default:n = { 4 } , % \end{macrocode} % \end{macro} @@ -3437,7 +3991,7 @@ and the derived file cooking-units.sty. % \end{macro} % % \begin{macro}{ ref } -% The <> option for keys. +% The |<>| option for keys. % \begin{macrocode} ref .code:n = { @@ -3447,104 +4001,133 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % -% \begin{macro}{ cuam-version , cutext-version} -% Some keys with horrible option names. Reverts -% the respective command back to its older state (pre v1.10). +% +% +% +% +% +%\begin{macro}{ check-temperature } +% Weird option. Checking the temperature, if the temperature is below the absolute zero temperature +% it raises an error. % \begin{macrocode} - cuam-version .choices:nn = - { new , old } - { - \int_case:nn { \l_keys_choice_int } - { - { 1 } { \bool_set_false:N \l_@@_cuam_old_bool } - { 2 } { \bool_set_true:N \l_@@_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_@@_cutext_old_bool } - { 2 } { \bool_set_true:N \l_@@_cutext_old_bool } - } - } , - cutext-version .default:n = { new } , + check-temperature .bool_set:N = \l_@@_check_temperature_bool , + check-temperature .default:n = { true } , % \end{macrocode} -% \end{macro} % -% \begin{macro}{ recalculate-amount } -% Setting the number of persons your recipes should be for -% is not enough; it is also needed to tell the package to -% recalculate the amounts. +%\begin{macro}{ add-temperature-to-check } +% Adds a temperature to check for \texttt{check-temperature}. +% It uses the \cs{keyval\_parse:NNn} command as this +% macro is used to parse keys (which is what I need). % \begin{macrocode} - recalculate-amount .bool_set:N = \l_@@_calc_for_persons_bool , - recalculate-amount .default:n = { false } , + add-temperature-to-check .code:n = + { + \keyval_parse:NNn + \@@_temperature_to_check_print_error:n + \@@_temperatures_to_check_define:nn + {#1} + }, + temperature-to-check .value_required:n = { true } , % \end{macrocode} -% \end{macro} +% \end{macro} % -% \begin{macro}{ cutext-to-cunum } -% Don't want any \mycs{cutext} (or \mycs{Cutext}) in your -% document? Use this option! +%\begin{macro}{ convert-to-eV } +% Another weird option, converts pretty much any unit defined by this +% package to electron volt or the respective derivative. +% As this is a unit transformation, it needs to be inside the +% group. % \begin{macrocode} - cutext-to-cunum .bool_set:N = \l_@@_cutext_to_cunum_bool , - cutext-to-cunum .default:n = { false } , + convert-to-eV .bool_set:N = \l_@@_convert_to_eV_bool , + convert-to-eV .default:n = { true } , + convert-to-eV .groups:n = { change-unit } , % \end{macrocode} -% \end{macro} +%\end{macro} % -% \begin{macro}{ cutext-space } -% The space used in \mycs{cutext} between the number (or numeral) -% and unit. +% \begin{macro}{ add-natural-unit } % \begin{macrocode} - cutext-space .tl_set:N = \l_@@_cutext_space_tl , - cutext-space .default:n = { \space } , + add-natural-unit .code:n = + { + \@@_error_if_unit_not_defined:n {#1} + \seq_set_from_clist:Nn \l_@@_tmpa_seq {#1} + \seq_concat:NNN \g_@@_natural_units_seq \g_@@_natural_units_seq \l_@@_tmpa_seq + \seq_remove_duplicates:N \g_@@_natural_units_seq + } , + add-natural-unit .value_required:n = { true } , % \end{macrocode} % \end{macro} % -% \begin{macro}{ phrase-space } -% Same as before, but for phrases +% \begin{macro}{ 42 } % \begin{macrocode} - phrase-space .tl_set:N = \l_@@_cuphrase_space_tl , - phrase-space .default:n = { \space } , + 42 .bool_set:N = \l_@@_fourty_two_bool , + 42 .default:n = { true } , % \end{macrocode} % \end{macro} % -% \begin{macro}{ cutext-change-unit } -% Do not wanna change units in \mycs{cutext}? Use this option. +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% +% \begin{macro}{ input-range-sign } +% Don't wanna use \verb|--| as a range sperator in \mycs{cunum}? +% Use this option. % \begin{macrocode} - cutext-change-unit .bool_set:N = \l_@@_cutext_change_unit_bool , - cutext-change-unit .default:n = { true } , + input-range-sign .tl_set:N = \l_@@_input_range_sign_tl , + input-range-sign .default:n = { -- } , % \end{macrocode} -% \end{macro} -% +%\end{macro} % -% \begin{macro}{ use-phrases } -% Do not wanna use phrases in \mycs{cuam}? Use this option! +% \begin{macro}{ numeral-function , Numeral-function } % \begin{macrocode} - use-phrases .bool_set:N = \l_@@_use_phrases_bool , - use-phrases .default:n = { true } , + numeral-function .code:n = { \cs_set_eq:NN \@@_print_numeral:n #1 } , + Numeral-function .code:n = { \cs_set_eq:NN \@@_print_Numeral:n #1 } , % \end{macrocode} % \end{macro} % % % -% \begin{macro}{ print-numerals } -% A not very good name, but I couldn't think of a better name. +% +% \begin{macro}{hooks} % \begin{macrocode} - print-numerals .bool_set:N = \l_@@_local_numeral_bool , - print-numerals .default:n = { true } , + commands-add-hook .meta:n = + { + cunum-add-hook = {#1} , + cutext-add-hook = {#1} , + Cutext-add-hook = {#1} , + cuam-add-hook = {#1} , + } , + cunum-add-hook .code:n = { \tl_put_right:Nn \l_@@_cunum_hook_tl {#1} } , + cutext-add-hook .code:n = { \tl_put_right:Nn \l_@@_cutext_hook_tl {#1} } , + Cutext-add-hook .code:n = { \tl_put_right:Nn \l_@@_Cutext_hook_tl {#1} } , + cuam-add-hook .code:n = { \tl_put_right:Nn \l_@@_cuam_hook_tl {#1} } , % \end{macrocode} % \end{macro} % % -% \begin{macro}{ numeral-function , Numeral-function } % -% \begin{macrocode} - numeral-function .code:n = { \cs_set_eq:NN \@@_print_numeral:n #1 } , - Numeral-function .code:n = { \cs_set_eq:NN \@@_print_Numeral:n #1 } , -% \end{macrocode} -% \end{macro} +% +% +% +% +% +% +% +% +% +% +% % % % @@ -3553,7 +4136,10 @@ and the derived file cooking-units.sty. } % \end{macrocode} % \end{macro} -% +% +% +% +% % % % \subsection {Messages} @@ -3566,7 +4152,7 @@ and the derived file cooking-units.sty. % \begin{macrocode} \msg_new:nnnn { cooking-units } { fraction-not-allowed-with-range } { - 'You' \ cannot \ use \ '/' \ ( and \ '_' )\ in \ combination \ + You \ cannot \ use \ '/' \ ( and \ '_' )\ in \ combination \ with \ '\l_@@_input_range_sign_tl' \ in \ '#1'. }{ You \ cannot \ use \ fractions \ with \ a \ range. @@ -3579,19 +4165,27 @@ and the derived file cooking-units.sty. \msg_new:nnnn { cooking-units } { missing-slash } { You \ cannot \ use \ '_' \ without \ - '/' in '#1'. + '/' \ in \ '#1'. }{ You \ cannot \ have \ a \ mixed \ fraction \ ('_') \ without \ a \ normal \ fraction \ ('/'). \msg_see_documentation_text:n { cooking-units } } +\msg_new:nnnn { cooking-units } { fraction-wrong-order } + { + You \ cannot \ use \ '/' \ before \ '_' \ in \ '#1'. + }{ + You \ can \ only \ use \ '_' \ before \ '/'. + \msg_see_documentation_text:n { cooking-units } + } % \end{macrocode} % Error message if unit is not known to this package. % \begin{macrocode} \msg_new:nnnn { cooking-units } { unknown-unit } { The \ unit \ '#1' \ is \ not \ defined. \ Use \ - \newcookingunit \ to \ define \ new \ units. + \newcookingunit ~ (or \ one \ of \ the \ others) \ to \ + define \ new \ units. }{ Define \ units \ before \ using \ or \ check \ if \ the \ unit-key \ is \ written \ correctly. @@ -3609,10 +4203,22 @@ and the derived file cooking-units.sty. } % \end{macrocode} % +% \begin{macrocode} +\msg_new:nnnn { cooking-units } { character-not-allowed } + { + Unit-keys \ are \ not \ allowed \ to \ either \ contain \ ',' \ or \ '/' \ + in \ '#1'. + }{ + The \ unit-key \ is \ not \ allowed \ to \ contain \ ',' \ or \ '/'. \ + Due \ to \ internal \ reasons. + \msg_see_documentation_text:n {cooking-units} + } +% \end{macrocode} +% % Missing argument in \lstinline|\cudefinesymbols| (et all). % \begin{macrocode} \msg_new:nnnn { cooking-units } { missing-argument } - { There \ is \ an \ missing \ argument. } + { There \ is \ a \ missing \ argument. } { You \ probably \ have \ forgotten \ a \ curly-brace \ pair. \msg_see_documentation_text:n {cooking-units} @@ -3621,13 +4227,13 @@ and the derived file cooking-units.sty. % If fractions are evaluated division by zero is not allowed. % \begin{macrocode} \msg_new:nnnn { cooking-units } { Division-by-zero } - { Division\ by \ zero \ is \ not \ allowed. } + { Division\ by \ zero \ is \ not \ allowed \ in \ '#1'. } { See \ a \ math \ book \ of \ your \ choice \ or \ for \ example \ Wikipedia. } % \end{macrocode} % Showing the not allowed token in the input. Hope this helps. % \begin{macrocode} \msg_new:nnnn { cooking-units } { Token-not-allowed } - { The \ token \ '#1' \ is \ not \ allowed. } + { The \ token \ '#1' \ is \ not \ allowed \ in \ '#2'. } { The \ command \ accepts \ only \ a \ fixed \ number \ of \ tokens. \msg_see_documentation_text:n {cooking-units} @@ -3636,7 +4242,25 @@ and the derived file cooking-units.sty. % A second decimal sign is not allowed (No na net). % \begin{macrocode} \msg_new:nnnn { cooking-units } { Second-decimal-sign-not-allowed } - { A \ second \ decimal \ sign \ is \ not \ allowed. } + { A \ second \ decimal \ sign \ is \ not \ allowed \ in \ '#1'. } + { + Perhaps \ you \ didn't \ type \ it \ correctly. + \msg_see_documentation_text:n {cooking-units} + } +% \end{macrocode} +% +% \begin{macrocode} +\msg_new:nnnn { cooking-units } { Second-fraction-sign-not-allowed } + { A \ second \ fraction \ sign \ is \ not \ allowed \ in \ '#1'. } + { + Perhaps \ you \ didn't \ type \ it \ correctly. + \msg_see_documentation_text:n {cooking-units} + } +% \end{macrocode} +% +% \begin{macrocode} +\msg_new:nnnn { cooking-units } { Second-mixed-fraction-sign-not-allowed } + { A \ second \ mixed \ fraction \ sign \ is \ not \ allowed \ in \ '#1'. } { Perhaps \ you \ didn't \ type \ it \ correctly. \msg_see_documentation_text:n {cooking-units} @@ -3646,8 +4270,8 @@ and the derived file cooking-units.sty. % \begin{macrocode} \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. @@ -3665,7 +4289,7 @@ and the derived file cooking-units.sty. the \ temperatures \ '\seq_use:Nnnn \l_@@_temperatures_to_check_seq { ', ~ ' } { ', ~ ' } { ' ~ and ~ ' }' \ - are \ rounded \ to \ integers. + are \ rounded \ to \ integers \ by \ default. \\\\ You \ can \ disable \ the \ option \ 'check-temperature' \ to \ disable \ this \ error. @@ -3678,11 +4302,22 @@ and the derived file cooking-units.sty. { The \ key \ '#1' \ only \ accepts \ only \ '#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. + \msg_see_documentation_text:n {cooking-units} + } +% \end{macrocode} +% Adding a message for unit-groups. +% \begin{macrocode} +\msg_new:nnnn { cooking-units } { group-choice-not-allowed } { - The \ key \ accepts \ accepts\ only \ a \ fixed \ set \ of \ choices. \ - You \ can \ add \ new \ choices \ via \ \cuaddkeys, \ \cuaddsinglekeys \ - and \ \cuaddtokeys{}. + The \ group \ key \ '#1' \ accepts \ only \ + '#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 \ option \ 'add-unit-to-group'. \msg_see_documentation_text:n {cooking-units} } % \end{macrocode} @@ -3704,6 +4339,17 @@ and the derived file cooking-units.sty. } % \end{macrocode} % +% \begin{macrocode} +\msg_new:nnnn { cooking-units } { group-key-unknown } + { + The \ group \ key \ '#1' \ is \ not \ defined. \ Perhaps + \ you \ misspelled \ it? + }{ + The \ group \ key \ is \ not \ defined. + \msg_see_documentation_text:n { cooking-units } + } +% \end{macrocode} +% % If a load time option is not used as a package option, this % message is shown. % \begin{macrocode} @@ -3713,7 +4359,7 @@ and the derived file cooking-units.sty. Please \ set \ it \ as \ a \ package \ option. } { - You \ cannot \ set \ this \ option \ using \ \cusetup \ + You \ cannot \ set \ this \ option \ using \ \cusetup ~ but \ only \ as \ a \ package \ option. \msg_see_documentation_text:n { cooking-units } } @@ -3724,24 +4370,31 @@ and the derived file cooking-units.sty. \msg_new:nnnn { cooking-units } { obsolete-command } { Command \ #1 is \ obsolete. \ Please \ use \ #2 instead. - } - { + }{ Don't \ use \ this \ old \ command \ ... \msg_see_documentation_text:n { cooking-units } } % \end{macrocode} % -% Error message if a new temperature to check is defined and no -% minimal value is given. % \begin{macrocode} \msg_new:nnnn { cooking-units } { No-Value-given } { - Please \ input \ a \ number \ to \ check \ for \ - 'check-temperature'. + 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 } + } +% \end{macrocode} +% +% \begin{macrocode} +\msg_new:nnnn { cooking-units } { Value-not-allowed } + { + The \ key-list \ in \ '#1' \ does \ not \ take \ a \ value. } { - A \ minimum \ value \ is \ needed \ for \ testing \ if \ - 'check-temperature' \ is \ active. + This \ key-list \ does \ not \ take \ a \ value. \ The \ + given \ value \ will \ be \ ignored. \msg_see_documentation_text:n { cooking-units } } % \end{macrocode} @@ -3751,8 +4404,7 @@ and the derived file cooking-units.sty. \msg_new:nnnn { cooking-units } { Minimum-already-defined } { A \ minimum \ for \ '#1' \ has \ already \ been \ defined. - } - { + }{ You \ cannot \ redefine \ it. \msg_see_documentation_text:n { cooking-units } } @@ -3791,8 +4443,7 @@ and the derived file cooking-units.sty. \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 } } @@ -3804,8 +4455,7 @@ and the derived file cooking-units.sty. { 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 } } @@ -3815,9 +4465,9 @@ and the derived file cooking-units.sty. % \begin{macrocode} \msg_new:nnnn { cooking-units } { redefine-unit } { - The \ unit \ '#1' \ is \ redefined \ by \ \declarecookingunit at \ \msg_line_context: . - } - { + The \ unit \ '#1' \ is \ redefined \ by \ \declarecookingunit ~ at \ + \msg_line_context: . + }{ \msg_see_documentation_text:n { cooking-units } } % \end{macrocode} @@ -3827,36 +4477,35 @@ and the derived file cooking-units.sty. \msg_new:nnnn { cooking-units } { phrase-unit-not-an-integer } { A \ phrase \ must \ be \ an \ integer, \ '#1' \ is \ not \ allowed. - } - { + }{ You \ can \ only \ use \ integers. \msg_see_documentation_text:n { cooking-units } } % \end{macrocode} % % A translation for \cs{cutext} or \cs{Cutext} is not available. For this case -% -- instead of printing the keyname (see \pkg{translations}) -- we fall back +% -- instead of printing the key-name (see \pkg{translations}) -- we fall back % to \cs{cunum}. % \begin{macrocode} -\msg_new:nnnn { cooking-units } { cutext-no-translation-available } %% ToDo +\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 \ \Cutext. \ You \ can \ define \ new \ translations \ for \ a \ given \ language \ using \ - \cudefinename{}. + \cudefinename. } { - \cunum \ is \ used \ instead. + \cunum ~ is \ used \ instead. \msg_see_documentation_text:n { cooking-units } } % \end{macrocode} % % % \begin{macrocode} -\msg_new:nnnn { cooking-units } { Translation-not-available } %% ToDo +\msg_new:nnnn { cooking-units } { Translation-not-available } { The \ translation \ for \ #1 \ does \ not \ exist. - Please \ define \ it \ using \ \cudefinename{}. + Please \ define \ it \ using \ \cudefinename. } { And \ you \ may \ send \ me \ the \ translation \ as \ it \ is \ @@ -3889,6 +4538,18 @@ and the derived file cooking-units.sty. \msg_see_documentation_text:n { cooking-units } } % \end{macrocode} +% +% \begin{macrocode} +\msg_new:nnnn { cooking-units } { internal-error } + { + This \ error \ shouldn't \ show. \ This \ means \ I + \ (the \ package \ author) \ screwed + \ up. + }{ + Please \ send \ me \ a \ bug \ report. + \msg_see_documentation_text:n { cooking-units } + } +% \end{macrocode} % \end{macro} % % \section {Helper Macros} @@ -3916,11 +4577,10 @@ and the derived file cooking-units.sty. % % % -% \begin{macro}{ \@@_if_integer:n , \@@_if_parse_and_integer:n} -% Checking if the input consists only of numbers. Furthermore tests if -% the input should be parsed at all. +% \begin{macro}{ \@@_if_integer:n } +% Checking if the input consists only of numbers. % \begin{macrocode} -\prg_new_protected_conditional:Npnn \@@_if_integer:n #1 { TF , F , T } +\prg_new_protected_conditional:Npnn \@@_if_integer:n #1 { TF , F } { \tl_map_inline:nn {#1} { @@ -3932,36 +4592,42 @@ and the derived file cooking-units.sty. \use_i:nn \prg_return_true: \prg_return_false: } \cs_generate_variant:Nn \@@_if_integer:nTF { V } -\cs_generate_variant:Nn \@@_if_integer:nT { V } \cs_generate_variant:Nn \@@_if_integer:nF { V } -\prg_new_protected_conditional:Npnn \@@_if_parse_and_integer:n #1 { TF } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{ \@@_if_integer:n } +% Checking if the input consists only of numbers. +% \begin{macrocode} +\cs_new:Npn \@@_bool_set_if_integers:NNN #1#2#3 { - \bool_if:NTF \l_@@_parse_input_bool + \@@_if_integer:VTF #2 + { \bool_set_true:N #1 } + { \bool_set_false:N #1 } + \bool_lazy_and:nnT + { \l_@@_range_in_input_bool } {#1} { - \@@_if_integer:nTF {#1} - { \prg_return_true: } - { \prg_return_false: } - } - { \prg_return_false: } + \@@_if_integer:VF #3 + { \bool_set_false:N #1 } + } } -\cs_generate_variant:Nn \@@_if_parse_and_integer:nTF { V } % \end{macrocode} % \end{macro} % % % % \begin{macro}[TF]{ \@@_fp_if_equal_one:n} -% \begin{macro}[TF]{ \@@_int_if_equal_one:n} +% \begin{macro}[TF]{ \@@_int_if_equal_one:n}f % \begin{macrocode} \prg_new_conditional:Npnn \@@_fp_if_equal_one:n #1 { TF } { - \fp_compare:nNnTF {#1} = { \c_one_fp } + \fp_compare:nNnTF {#1} = { 1.0 } { \prg_return_true: } { \prg_return_false: } } \prg_new_conditional:Npnn \@@_int_if_equal_one:n #1 { TF } { - \int_compare:nNnTF {#1} = { \c_one } + \int_compare:nNnTF {#1} = { 1 } { \prg_return_true: } { \prg_return_false: } } @@ -3970,26 +4636,108 @@ and the derived file cooking-units.sty. % % % +% \begin{macro}{} +% \begin{macrocode} +\prg_new_conditional:Npnn \@@_change_cutext_to_cunum:n #1 { TF } + { + \keys_set_groups:nnn { cooking-units } { change-command } {#1} + \bool_if:NTF \l_@@_cutext_to_cunum_bool + { \prg_return_true: } + { \prg_return_false: } + } +% \end{macrocode} +% \end{macro} +% % \begin{macro}{ \@@_check_if_correct_gender_input:n } % \begin{macrocode} \cs_new:Npn \@@_check_if_correct_gender_input:n #1 { \str_case:nnF {#1} { - { m } {} - { f } {} - { n } {} + { m } { } + { f } { } + { n } { } } { \msg_error:nnn { cooking-units } { unknown-gender } {#1} } } % \end{macrocode} % \end{macro} % +% \begin{macro}{\@@_define_unit_group:nn} +% \begin{macrocode} +\cs_new:Npn \@@_define_unit_group:nn #1#2 + { + \clist_new:c { l_@@_group_ #1 _clist } + \clist_set:cn { l_@@_group_ #1 _clist } {#2} + \keys_define:nn { cooking-units } + { + #1 .code:n = { \@@_unit_group_convert_units:nn {#1} {##1} } , + #1 .groups:n = { change-unit } + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_error_if_group_not_defined:n} +% \begin{macrocode} +\cs_new:Npn \@@_error_if_group_not_defined:n #1 + { + \clist_if_exist:cF { l_@@_group_ #1 _clist } + { \msg_error:nn { cooking-units} { group-key-unknown } } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{\@@_unit_group_convert_units:nn} +% \begin{macrocode} +\cs_new:Npn \@@_unit_group_convert_units:nn #1#2 + { + \@@_error_if_group_not_defined:n {#1} + \@@_error_if_unit_not_defined:n {#2} + \clist_if_in:cnTF { l_@@_group_ #1 _clist } {#2} + { + \clist_map_inline:cn { l_@@_group_ #1 _clist } + { \@@_keys_set:nnn { cooking-units } {##1} {#2} } + }{ + \msg_error:nnxxx + { cooking-units } + { group-choice-not-allowed } + {#1} + {#2} + { \clist_use:cnnn { l_@@_group_ #1 _clist } { ',~ ' } { ',~ ' } { ' ~ and ~ ' } } + } + } +\@@_define_unit_group:nn { weight } { kg , dag, g, oz, lb, stick } +\@@_define_unit_group:nn { length } { m , dm , cm , mm , in } +\@@_define_unit_group:nn { volume } { l , dl , cl , ml } +\@@_define_unit_group:nn { temperature } { C , F , K , Re } +\@@_define_unit_group:nn { energy } { cal, kcal , J , kJ , eV } +\@@_define_unit_group:nn { time } { d , h , min , s } +% \end{macrocode} +% \end{macro} % +% \begin{macro}{\@@_unit_group_add_unit_error:n , \@@_unit_group_add_unit:nn } +% \begin{macrocode} +\cs_new:Npn \@@_unit_group_add_unit_error:n #1 + { + \msg_error:nnn { cooking-units } { No-Value-given } { add-unit-to-group } + } +\cs_new:Npn \@@_unit_group_add_unit:nn #1#2 + { + \@@_error_if_group_not_defined:n {#1} + \clist_map_inline:nn {#2} + { + \@@_error_if_unit_not_defined:n {##1} + \clist_if_in:cnF { l_@@_group_ #1 _clist } {##1} + { \clist_put_right:cn { l_@@_group_ #1 _clist } {##1} } + } + } +% \end{macrocode} +% \end{macro} % % \begin{macro}{\@@_convert_to_eV:} % Still work in progress. Will probably forever be. Changes all % predefined units into natural units (except for those who cannot -% be changed, like Msp. for example). +% be changed, like |Msp.| for example). % % \begin{macrocode} \seq_new:N \g_@@_natural_units_seq @@ -4038,15 +4786,34 @@ and the derived file cooking-units.sty. % % % -% \begin{macro}{\@@_tl_set_fp_and_eval:Nn} +% \begin{macro}{\@@_tl_eval:Nn} +% I am using this construction often enough, so \dots\ yeah. +% \begin{macrocode} +\cs_new:Npn \@@_tl_eval:Nn #1#2 { \tl_set:Nf #1 { \fp_eval:n {#2} } } +\cs_generate_variant:Nn \@@_tl_eval:Nn { Nv } +% \end{macrocode} +% \end{macro} +% +% +% +% \begin{macro}{ } % I am using this construction often enough, so \dots\ yeah. % \begin{macrocode} -\cs_new:Npn \@@_tl_set_fp_and_eval:Nn #1#2 - { \tl_set:Nx #1 { \fp_eval:n {#2} } } -\cs_generate_variant:Nn \@@_tl_set_fp_and_eval:Nn { Nc } +\prg_new_conditional:Npnn \@@_change_unit: { TF } + { + \bool_lazy_any:nTF + { + { \l_@@_lokal_fraction_bool } + { \l_@@_special_sign_bool } + { \l_@@_draft_bool } + } + { \prg_return_false: } + { \prg_return_true: } + } % \end{macrocode} % \end{macro} % +% % \begin{macro}{\@@_temperature_to_check_print_error:n,\@@_temperatures_to_check_define:nn} % Commands used in the option \texttt{temperature-to-check}. % If no value is given (first command) it raises an error. If a value @@ -4055,7 +4822,8 @@ and the derived file cooking-units.sty. % \begin{macrocode} \cs_new:Npn \@@_temperature_to_check_print_error:n #1 { - \msg_error:nn { cooking-units } { No-Value-given } + \@@_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { No-Value-given } { add-temperature-to-check } } \cs_new:Npn \@@_temperatures_to_check_define:nn #1#2 { @@ -4070,21 +4838,62 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % +% \begin{macro}{ \@@_erase_options_for:n , \@@_erase_options_for_error:nn } +% \begin{macrocode} +\cs_new:Npn \@@_erase_options_for:n #1 + { + \@@_error_if_unit_not_defined:n {#1} + \clist_clear:c { l_@@_predefined_option_ ##1 _clist } + } +\cs_new:Npn \@@_erase_options_for_error:nn #1#2 + { + \@@_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { Value-not-allowed } { erase-all-options-for } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{ \@@_set_options_for_error:n , \@@_set_options_for:nn } +% \begin{macrocode} +\cs_new:Npn \@@_set_options_for_error:n #1 + { + \@@_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { No-Value-given } { set-option-for } + } +\cs_new:Npn \@@_set_options_for:nn #1#2 + { + \@@_error_if_unit_not_defined:n {#1} + \clist_set:cn { l_@@_predefined_option_#1_clist } {#2} + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{ \@@_add_options_for_error:n , \@@_add_options_for:nn } +% \begin{macrocode} +\cs_new:Npn \@@_add_options_for_error:n #1 + { + \@@_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { No-Value-given } { add-option-for } + } +\cs_new:Npn \@@_add_options_for:nn #1#2 + { + \@@_error_if_unit_not_defined:n {#1} + \clist_put_right:cn { l_@@_predefined_option_ #1 _clist } {#2} + } +% \end{macrocode} +% \end{macro} +% % \begin{macro}{\@@_rounding_function:n} % I think this definition is somewhat stupid, but I don't have a better idea. % \begin{macrocode} \cs_new:Npn \@@_rounding_function:n #1 { #1 - \bool_if:NTF \l_@@_round_commercial_bool - { - , - \bool_if:NTF \l_@@_round_to_int_bool - { \c_zero_fp } - { \l_@@_significant_figures_int } - , #1 - } - { \bool_if:NF \l_@@_round_to_int_bool { , \l_@@_significant_figures_int } } + \bool_if:NTF \l_@@_round_to_int_bool + { , 0 } + { , \l_@@_round_precision_int } + \bool_if:NT \l_@@_round_commercial_bool + { , #1 } } % \end{macrocode} % \end{macro} @@ -4110,18 +4919,18 @@ and the derived file cooking-units.sty. } % \end{macrocode} % -% \begin{macro}{ \@@_culabel:nn , \@@_curef:n } +% \begin{macro}{ \@@_culabel:nn } % \begin{macrocode} \cs_new:Npn \@@_culabel:nn #1#2 { - \int_if_exist:cTF { l_@@_number_of_persons_ #1 _int } + \int_if_exist:cTF { g_@@_number_of_persons_ #1 _int } { \msg_error:nnn { cooking-units } { label-already-defined } {#1} }{ \@@_if_integer:nTF {#2} { - \int_new:c { l_@@_number_of_persons_ #1 _int } - \int_gset:cn { l_@@_number_of_persons_ #1 _int } {#2} + \int_new:c { g_@@_number_of_persons_ #1 _int } + \int_gset:cn { g_@@_number_of_persons_ #1 _int } {#2} } { \msg_error:nnn { cooking-units } { Number-of-persons-is-not-an-integer } {#2} } } @@ -4133,11 +4942,11 @@ and the derived file cooking-units.sty. % \begin{macrocode} \cs_new:Npn \@@_reference_label_and_persons:n #1 { - \int_if_exist:cTF { l_@@_number_of_persons_ #1 _int } + \int_if_exist:cTF { g_@@_number_of_persons_ #1 _int } { \bool_set_true:N \l_@@_calc_because_ref_was_given_bool - \int_set_eq:Nc \l_@@_number_of_persons_tmpa_int - { l_@@_number_of_persons_ #1 _int } + \int_set_eq:Nc \l_@@_local_number_of_persons_int + { g_@@_number_of_persons_ #1 _int } } { \msg_error:nnn { cooking-units } { label-not-defined } {#1} } } @@ -4148,11 +4957,11 @@ and the derived file cooking-units.sty. % \begin{macrocode} \cs_new:Npn \@@_curef:n #1 { - \int_if_exist:cTF { l_@@_number_of_persons_ #1 _int } + \int_if_exist:cTF { g_@@_number_of_persons_ #1 _int } { - \bool_if:NTF \l_@@_calc_for_persons_bool - { \int_use:N \l_@@_calc_for_number_of_persons_int } - { \int_use:c { l_@@_number_of_persons_ #1 _int } } + \bool_if:NTF \l_@@_change_number_of_persons_bool + { \int_use:N \l_@@_wanted_number_of_persons_int } + { \int_use:c { g_@@_number_of_persons_ #1 _int } } }{ \msg_error:nnn { cooking-units } { label-not-defined } {#1} } } % \end{macrocode} @@ -4339,47 +5148,393 @@ and the derived file cooking-units.sty. % \end{macrocode} % % +% \section{General} +% +% This section collects commands which are used by all four main commands +% (\mycs{cunum}, \cCutext, \mycs{cuam}), hence the name. +% +% +% \begin{macro}{\@@_initialise_default:n , +% \@@_initialise_unit_change:n , +% \@@_initialise_after_unit_change:nn +% } +% Functions shared by all initialization functions: +% \begin{macrocode} +\cs_new_protected:Npn \@@_initialise_default:n #1 + { + \@@_set_unit:Nn \l_@@_given_unit_tl {#1} + \@@_error_if_unit_not_defined:V \l_@@_given_unit_tl + \bool_set_false:N \l_@@_special_sign_bool + \bool_set_false:N \l_@@_error_bool + \bool_set_false:N \l_@@_range_in_input_bool + \bool_set_false:N \l_@@_lokal_fraction_bool + \bool_set_false:N \l_@@_lokal_mixed_fraction_bool + } +% \end{macrocode} +% Some units have options added to them. To get those options it is first +% needed to know which unit will be used at all. Therefore units will +% be changed first and afterwards the other options are processed. +% \begin{macrocode} +\cs_new_protected:Npn \@@_initialise_unit_change:n #1 + { + \tl_if_empty:nF {#1} + { + \keys_set_groups:nnn { cooking-units } { change-unit } {#1} + } + \bool_if:NT \l_@@_convert_to_eV_bool { \@@_convert_to_eV: } + \prop_get:NVNF \l_@@_change_unit_prop \l_@@_given_unit_tl \l_@@_option_unit_tl + { + \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_given_unit_tl + } + } +% \end{macrocode} +% \begin{macrocode} +\cs_new_protected:Npn \@@_initialise_after_unit_change:nn #1#2 + { + \IfNoValueF {#1} + { \@@_reference_label_and_persons:n {#1} } + \clist_if_empty:cF { l_@@_predefined_option_ \l_@@_option_unit_tl _clist } + { + \keys_set_filter:nnv + { cooking-units } + { change-unit } + { l_@@_predefined_option_ \l_@@_option_unit_tl _clist } + } + \tl_if_empty:nF {#2} + { \keys_set_filter:nnn { cooking-units } { change-unit } {#2} } + \bool_lazy_and:nnTF + { \l_@@_calc_because_ref_was_given_bool } { \l_@@_change_number_of_persons_bool } + { \bool_set_true:N \l_@@_lokal_persons_bool } + { \bool_set_false:N \l_@@_lokal_persons_bool } + \bool_lazy_and:nnTF + { \g_@@_opt_numeral_bool } { \l_@@_print_numeral_bool } + { \bool_set_true:N \l_@@_lokal_numeral_bool } + { \bool_set_false:N \l_@@_lokal_numeral_bool } + } +% \end{macrocode} +% \end{macro} +% +% +% \begin{macro}{ \@@_print_input:N , \@@_print_correct_unit: , +% \@@_post_process_input:NN , \@@_pre_process_input:NN} +% Wrapper macro for printing the (not)calculated output. Note that if no +% calculation happens in \mycs{cutext} (and \mycs{Cutext}) \cs{l_@@_option_unit_tl} +% is set to \cs{l_@@_given_unit_tl} (the unit given in the second argument of +% \mycs{cutext} or \mycs{Cutext}) by default. +% \begin{macrocode} +\cs_new_protected:Npn \@@_print_input:N #1 { } +\cs_new_protected:Npn \@@_print_correct_unit: { } +\cs_new_protected:Npn \@@_do_not_process_input:NN #1#2 { } +\cs_new_eq:NN \@@_pre_process_input:NN \@@_do_not_process_input:NN +\cs_new_eq:NN \@@_post_process_input:NN \@@_do_not_process_input:NN +% \end{macrocode} +% \end{macro} +% +% \begin{macro} { \@@_set_process_and_print_for_cunum: , +% \@@_set_process_and_print_for_cutext: , +% \@@_set_process_and_print_for_cuam: +% } +% It is handy to set the \enquote{print} and \enquote{process} +% command all in one go. It's also less messy to use. +% \begin{macrocode} +\cs_new_protected:Npn \@@_set_process_and_print_for_cunum: + { + \cs_set_eq:NN \@@_print_input:N \@@_print_numerical_input:N + \cs_set_eq:NN \@@_print_correct_unit: \@@_cunum_print_correct_unit: + \cs_set_eq:NN \@@_pre_process_input:NN \@@_do_not_process_input:NN + \cs_set_eq:NN \@@_post_process_input:NN \@@_do_not_process_input:NN + } +\cs_new_protected:Npn \@@_set_process_and_print_for_cutext: + { + \cs_set_eq:NN \@@_print_input:N \@@_cutext_print_input:N + \cs_set_eq:NN \@@_print_correct_unit: \@@_cutext_print_correct_unitname: + \cs_set_eq:NN \@@_pre_process_input:NN \@@_cutext_pre_process_input:NN + \cs_set_eq:NN \@@_post_process_input:NN \@@_cutext_post_process_input:NN + } +\cs_new_protected:Npn \@@_set_process_and_print_for_cuam: + { + \cs_set_eq:NN \@@_print_input:N \@@_cuam_print_numerical_input:N + \cs_set_eq:NN \@@_print_correct_unit: \@@_cuam_print_correct_unitphrase: + \cs_set_eq:NN \@@_pre_process_input:NN \@@_do_not_process_input:NN + \cs_set_eq:NN \@@_post_process_input:NN \@@_cuam_post_process_input:NN + } +% \end{macrocode} +% \end{macro} +% +% +% +% +% +% \begin{macro}{ \@@_print_numerical_input:N } +% Prints the numerical output (if it is not a fraction). +% +% Changed \lstinline|\l_@@_tmpa_tl| by |\l_@@_translation_tmpa_tl|, it's better that way. +% \begin{macrocode} +\cs_new_protected:Npn \@@_print_numerical_input:N #1 + { + \tl_if_in:NnT #1 { . } + { + \@@_translate_let:Nxx \l_@@_translation_tmpa_tl + { decimal-mark } \c_@@_postfix_unitname_tl + \tl_replace_once:Nnn #1 { . } { \l_@@_translation_tmpa_tl } + } + \tl_replace_once:Nnn #1 { - } \c_@@_minus_tl + #1 + } +% \end{macrocode} +% \end{macro} +% +% +% \begin{macro}{ \@@_print_fractions:nnn } +% The name of this function is the name of the game: It prints fractions. +% Furthermore it sets the boolean \lstinline|fraction_in_input_bool| to true +% so that the correct unit is printed. Instead of \lstinline|\kern| I used the +% \lstinline|\hbox_to_wd:nn| command (I don't have a better idea). +% +% Since v.1.10(alpha) it also prints the minus sign (hopefully correct). +% \begin{macrocode} +\cs_new:Npn \@@_print_fractions:nnn #1#2#3 + { + \bool_if:NT \l_@@_minus_bool { \c_@@_minus_tl } + \tl_if_empty:nF {#1} + { + #1 + \@@_dim_horizontal:N \l_@@_mixed_frac_dim + } + \@@_frac:nn {#2} {#3} + } +% \end{macrocode} +% \end{macro} +% +% +% +% % % % \subsection {Parsing and checking numbers} % -% This section contains macros helping an checking the input. +% This subsection contains macros helping an checking the input. +% +% \begin{macro}{ \@@_parse_input:n } +% Rescans the input to get rid of spaces and to make \_ and ? inactive +% (french with babel makes ? active and changes the definition of it). +% \lstinline|--| is replaced by \lstinline|\q_@@_range| and the input is parsed +% (if not empty). Afterwards the units are printed. +% \begin{macrocode} +\cs_new:Npn \@@_parse_input:n #1 + { + \bool_if:NTF \l_@@_fourty_two_bool + { \tl_clear:N \l_@@_given_amount_tl } + { \@@_set_amount:Nn \l_@@_given_amount_tl {#1} } + \tl_set_rescan:NnV \l_@@_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N \ % + \char_set_catcode_other:N ? % + } \l_@@_given_amount_tl + \bool_lazy_or:nnTF + { \l_@@_draft_bool } + { \tl_if_empty_p:N \l_@@_tmpa_tl } + { + \bool_if:NTF \l_@@_fourty_two_bool + { 42 } + { \l_@@_tmpa_tl } + }{ + \tl_if_in:NVT \l_@@_tmpa_tl \l_@@_input_range_sign_tl + { + \tl_replace_once:NVn \l_@@_tmpa_tl \l_@@_input_range_sign_tl { \q_@@_range } + \bool_set_true:N \l_@@_range_in_input_bool + } + \@@_parsing_amount_input:V \l_@@_tmpa_tl + \@@_split_input: + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{ \@@_parsing_amount_input:n } +% \begin{macrocode} +\cs_new:Npn \@@_parsing_amount_input:n #1 + { + \cs_set_eq:NN \@@_parse:N \@@_start_loop:N + \tl_map_function:nN {#1} \@@_parse:N + } +\cs_generate_variant:Nn \@@_parsing_amount_input:n { V } +% \end{macrocode} +% \end{macro} % -% \begin{macro}{ \@@_parse_input:N, \@@_parse_input:V } -% Splits the input into fractions or ranges (\lstinline|q_@@_range|). +% \begin{macro}{ \@@_split_input:} +% Splits the input into fractions or ranges. % Depending on the input on of the four macros are used. % \begin{macrocode} -\cs_new:Npn \@@_parse_input:N #1 +\cs_new:Npn \@@_split_input: { - \bool_if:NTF \l_@@_range_in_input_bool - { \@@_parse_range_in_input:ww #1 \q_stop } + \bool_if:NTF \l_@@_lokal_fraction_bool + { + \tl_set_eq:NN \l_@@_number_tmpb_tl \l_@@_tmpa_tl + \bool_lazy_or:nnT + { \l_@@_lokal_persons_bool }{ \l_@@_eval_fractions_bool } + { \bool_set_false:N \l_@@_lokal_fraction_bool } + \bool_if:NTF \l_@@_lokal_mixed_fraction_bool + { \@@_parse_mixed_fraction_in_input: } + { \@@_parse_fraction_in_input: } + }{ + \bool_if:NT \l_@@_lokal_mixed_fraction_bool + { \msg_error:nnV { cooking-units } { missing-slash } \l_@@_given_amount_tl } + \bool_if:NTF \l_@@_range_in_input_bool + { + \tl_set_eq:NN \l_@@_number_tmpb_tl \l_@@_tmpa_tl + \@@_parse_range_in_input: + }{ + \tl_set_eq:NN \l_@@_number_tmpa_tl \l_@@_tmpa_tl + \@@_parse_number_in_input: + } + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{ \@@_parse_input_and_safe_in:nN } +% Used to check the input. \lstinline|\l_@@_tmpa_tl| is cleared +% at the beginning. At first it checks if the first token +% is a sign or not. The parsed input is stored into \lstinline|\l_@@_tmpa_tl|. +% \begin{macrocode} +%\cs_new:Npn \@@_parse_input_and_safe_in:nN #1 #2 +% { +% \tl_clear:N \l_@@_tmpa_tl +% \bool_set_false:N \l_@@_decimal_in_input_bool +% \@@_start_loop:Nw #1 \q_stop +% \bool_if:NTF \l_@@_error_bool +% { \tl_set:Nn #2 {#1} } +% { \tl_set_eq:NN #2 \l_@@_tmpa_tl } +% } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{ \@@_start_loop:Nw } +% This function seperates the input into two parts with the first +% part being the first token. This token is checked whetever or not +% it is a sign. If it is a sign it is put into +% \lstinline|\l_@@_tmpa_tl|, if not it is checked normally by +% \lstinline|\@@_parse_input_loop_aux:N|. \#2 (the other +% tokens) is then given to \lstinline|\tl_map_function:nN|. This +% also works if the input only conists of one token with \#2 being +% empty (hopefully). +% \begin{macrocode} +\cs_new:Npn \@@_start_loop:N #1 + { + \tl_clear:N \l_@@_tmpa_tl + \bool_set_false:N \l_@@_decimal_in_input_bool + \cs_set_eq:NN \@@_parse:N \@@_parse_input_loop_aux:N + \tl_if_in:NnTF \l_@@_input_value_signs_tl {#1} + { \tl_put_right:Nn \l_@@_tmpa_tl {#1} } { - \tl_if_in:nnTF {#1} { / } + \tl_map_function:nN {#1} \@@_parse:N + } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro}{ \@@_parse_input_loop_aux:N } +% Parses the input. It also is more or less (more less then more) copied from +% \texttt{siunitx}. Checks if the input consists only of numbers, +% one decimal-sign and the allowed special input. If an allowed +% token is found the boolean \lstinline|\l_@@_special_sign_bool| is +% set to true. +% \begin{macrocode} +\cs_new:Npn \@@_parse_input_loop_aux:N #1 + { + \tl_if_in:NnTF \l_@@_input_digits_tl {#1} + { \tl_put_right:Nn \l_@@_tmpa_tl {#1} } + { + \tl_if_in:NnTF \l_@@_input_decimal_mark_tl {#1} + { + \@@_check_repitition:NN + \q_@@_decimal + \l_@@_decimal_in_input_bool + \tl_put_right:Nn \l_@@_tmpa_tl { . } + }{ + \tl_if_in:NnTF \l_@@_input_allowed_special_signs_tl {#1} + { + \bool_set_true:N \l_@@_special_sign_bool + \tl_put_right:Nn \l_@@_tmpa_tl {#1} + }{ + \bool_if:NTF \l_@@_range_in_input_bool + { + \tl_if_eq:nnTF \q_@@_range {#1} + { + \tl_set_eq:NN \l_@@_number_tmpa_tl \l_@@_tmpa_tl + \cs_set_eq:NN \@@_parse:N \@@_start_loop:N + }{ + \tl_if_in:xnTF + { + \exp_not:V \l_@@_input_fraction_sign_tl + \exp_not:V \l_@@_input_mixed_fraction_sign_tl + } {#1} + { \msg_error:nnV { cooking-units } { fraction-not-allowed-with-range } \l_@@_given_amount_tl } + { \msg_error:nnnV { cooking-units } { Token-not-allowed } {#1} \l_@@_given_amount_tl } + \bool_set_true:N \l_@@_error_bool + \tl_map_break: + } + }{ + \tl_if_in:NnTF \l_@@_input_fraction_sign_tl {#1} + { + \@@_check_repitition:NN + \q_@@_frac + \l_@@_lokal_fraction_bool + \tl_set_eq:NN \l_@@_number_tmpa_tl \l_@@_tmpa_tl + \cs_set_eq:NN \@@_parse:N \@@_start_loop:N + }{ + \tl_if_in:NnTF \l_@@_input_mixed_fraction_sign_tl {#1} + { + \@@_check_repitition:NN + \q_@@_mixed_frac + \l_@@_lokal_mixed_fraction_bool + \bool_if:NT \l_@@_lokal_fraction_bool + { \msg_error:nnV { cooking-units } { fraction-wrong-order } \l_@@_given_amount_tl } + \tl_set_eq:NN \l_@@_mixed_fraction_tl \l_@@_tmpa_tl + \cs_set_eq:NN \@@_parse:N \@@_start_loop:N + }{ + \msg_error:nnnV { cooking-units } { Token-not-allowed } {#1} \l_@@_given_amount_tl + \bool_set_true:N \l_@@_error_bool + \tl_map_break: + } + } + } + } + } + } + } +\cs_new:Npn \@@_check_repitition:NN #1#2 + { + \bool_if:NTF #2 + { + \tl_case:NnTF #1 { - \bool_lazy_or:nnTF - { \l_@@_calc_persons_bool }{ \l_@@_eval_fractions_bool } - { \bool_set_false:N \l_@@_fraction_in_input_bool } - { \bool_set_true:N \l_@@_fraction_in_input_bool } - \tl_if_in:nnTF {#1} { _ } - { \@@_parse_mixed_fraction_in_input:www #1 \q_stop } - { \@@_parse_fraction_in_input:ww #1 \q_stop } + \q_@@_decimal + { \msg_error:nnV { cooking-units } { Second-decimal-sign-not-allowed } \l_@@_given_amount_tl } + \q_@@_frac + { \msg_error:nnV { cooking-units } { Second-fraction-sign-not-allowed } \l_@@_given_amount_tl } + \q_@@_mixed_frac + { \msg_error:nnV { cooking-units } { Second-mixed-fraction-sign-not-allowed } \l_@@_given_amount_tl } } - { \@@_parse_number_in_input:n {#1} } + { \bool_set_true:N \l_@@_error_bool } + { \msg_error:nn { cooking-units } { internal-error } } } + { \bool_set_true:N #2 } } -\cs_generate_variant:Nn \@@_parse_input:N { V } % \end{macrocode} % \end{macro} % -% \begin{macro}{\@@_parse_number_in_input:n} +% +% \begin{macro}{\@@_parse_number_in_input:} % If no fractions and ranges are used this macro activated. % It just checks the input, stores the checked (and a bit % changed) input into a macro. This macro is given to another % function to calculate the input and print it. % \begin{macrocode} -\cs_new:Npn \@@_parse_number_in_input:n #1 +\cs_new:Npn \@@_parse_number_in_input: { - \@@_parse_input_and_safe_in:nN {#1} \l_@@_number_tmpa_tl \@@_process_and_print_number_in_input:N \l_@@_number_tmpa_tl } \cs_new:Npn \@@_process_and_print_number_in_input:N #1 @@ -4392,16 +5547,14 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % -% \begin{macro}{ \@@_parse_range_in_input:ww } +% \begin{macro}{ \@@_parse_range_in_input: } % Is used if a \lstinline|\q_@@_range| is found inside the input. % Seperates the input, checks it and prints it (after calculating % it). Furthermore a boolean is set to true, is used to check for % errors (ergo if fractions are used). % \begin{macrocode} -\cs_new:Npn \@@_parse_range_in_input:ww #1 \q_@@_range #2 \q_stop +\cs_new:Npn \@@_parse_range_in_input: { - \@@_parse_input_and_safe_in:nN {#1} \l_@@_number_tmpa_tl - \@@_parse_input_and_safe_in:nN {#2} \l_@@_number_tmpb_tl \@@_pre_process_input:NN \l_@@_number_tmpa_tl \l_@@_number_tmpb_tl \@@_calculate_and_store_in:N \l_@@_number_tmpa_tl \@@_calculate_and_store_in:N \l_@@_number_tmpb_tl @@ -4415,32 +5568,31 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % -% \begin{macro}{ \@@_parse_fraction_in_input:ww } +% \begin{macro}{ \@@_parse_fraction_in_input: } % If a \lstinline|/| (but no \lstinline|_|) is found inside the input. % Well \dots\ does the same as the functions before. % If fractions should be evaluated the input is \dots\ well, % evaluated and printed. Otherwise the input is given to % another function which prints the fractions. Note that the empty -% argument in \lstinline|\@@_formatiere_fractions:nnn| indicates a +% argument in \lstinline|\@@_print_fractions:nnn| indicates a % \enquote{normal} fraction. % \begin{macrocode} -\cs_new:Npn \@@_parse_fraction_in_input:ww #1/#2 \q_stop +\cs_new:Npn \@@_parse_fraction_in_input: { - \@@_parse_input_and_safe_in:nN {#1} \l_@@_number_tmpa_tl - \@@_parse_input_and_safe_in:nN {#2} \l_@@_number_tmpb_tl -% \bool_if:NTF \l_@@_fraction_in_input_bool \bool_lazy_or:nnTF - { \l_@@_fraction_in_input_bool } + { \l_@@_lokal_fraction_bool } { \l_@@_special_sign_bool } { \@@_tl_if_in_remove_and_set_bool:NnN \l_@@_number_tmpa_tl { - } \l_@@_minus_bool \@@_tl_if_in_remove_and_reverse_bool:NnN \l_@@_number_tmpb_tl { - } \l_@@_minus_bool - \@@_formatiere_fractions:nnn + \@@_print_fractions:nnn { } { \l_@@_number_tmpa_tl } { \l_@@_number_tmpb_tl } }{ - \@@_tl_set_fp_and_eval:Nn \l_@@_number_tmpa_tl + \fp_compare:nNnT { \l_@@_number_tmpb_tl } = { 0 } + { \msg_error:nnV { cooking-units } { Division-by-zero } \l_@@_given_amount_tl } + \@@_tl_eval:Nn \l_@@_number_tmpa_tl { \l_@@_number_tmpa_tl / \l_@@_number_tmpb_tl } \@@_process_and_print_number_in_input:N \l_@@_number_tmpa_tl } @@ -4448,7 +5600,7 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % -% \begin{macro}{ \@@_parse_mixed_fraction_in_input:www } +% \begin{macro}{ \@@_parse_mixed_fraction_in_input: } % The same procedure as last function? The same procedure as every % function! % @@ -4462,24 +5614,23 @@ and the derived file cooking-units.sty. % \end{align} % % \begin{macrocode} -\cs_new:Npn \@@_parse_mixed_fraction_in_input:www #1_#2/#3 \q_stop +\cs_new:Npn \@@_parse_mixed_fraction_in_input: { - \@@_parse_input_and_safe_in:nN {#1} \l_@@_mixed_fraction_tl - \@@_parse_input_and_safe_in:nN {#2} \l_@@_number_tmpa_tl - \@@_parse_input_and_safe_in:nN {#3} \l_@@_number_tmpb_tl \@@_tl_if_in_remove_and_set_bool:NnN \l_@@_mixed_fraction_tl { - } \l_@@_minus_bool \@@_tl_if_in_remove_and_reverse_bool:NnN \l_@@_number_tmpa_tl { - } \l_@@_minus_bool \@@_tl_if_in_remove_and_reverse_bool:NnN \l_@@_number_tmpb_tl { - } \l_@@_minus_bool \bool_lazy_or:nnTF - { \l_@@_fraction_in_input_bool } + { \l_@@_lokal_fraction_bool } { \l_@@_special_sign_bool } { - \@@_formatiere_fractions:nnn + \@@_print_fractions:nnn { \l_@@_mixed_fraction_tl } { \l_@@_number_tmpa_tl } { \l_@@_number_tmpb_tl } }{ - \@@_tl_set_fp_and_eval:Nn \l_@@_number_tmpa_tl + \fp_compare:nNnT { \l_@@_number_tmpb_tl } = { 0 } + { \msg_error:nnV { cooking-units } { Division-by-zero } \l_@@_given_amount_tl } + \@@_tl_eval:Nn \l_@@_number_tmpa_tl { \bool_if:NTF \l_@@_minus_bool { - \l_@@_mixed_fraction_tl - } @@ -4496,91 +5647,6 @@ and the derived file cooking-units.sty. % % % -% \begin{macro}{ \@@_parse_input_and_safe_in:nN } -% Used to check the input. \lstinline|\l_@@_tmpa_tl| is cleared -% at the beginning. At first it checks if the first token -% is a sign or not. The parsed input is stored into \lstinline|\l_@@_tmpa_tl|. -% \begin{macrocode} -\cs_new:Npn \@@_parse_input_and_safe_in:nN #1 #2 - { - \tl_clear:N \l_@@_tmpa_tl - \bool_set_false:N \l_@@_decimal_in_input_bool - \@@_parse_vorzeichen_and_rest:Nw #1 \q_stop - \bool_if:NTF \l_@@_error_bool - { \tl_set:Nn #2 {#1} } - { \tl_set_eq:NN #2 \l_@@_tmpa_tl } - } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{ \@@_parse_vorzeichen_and_rest:Nw } -% This function seperates the input into two parts with the first -% part being the first token. This token is checked whetever or not -% it is a sign. If it is a sign it is put into -% \lstinline|\l_@@_tmpa_tl|, if not it is checked normally by -% \lstinline|\@@_parse_input_for_safety_aux:N|. \#2 (the other -% tokens) is then given to \lstinline|\tl_map_function:nN|. This -% also works if the input only conists of one token with \#2 being -% empty (hopefully). -% \begin{macrocode} -\cs_new:Npn \@@_parse_vorzeichen_and_rest:Nw #1#2 \q_stop - { - \tl_if_in:NnTF \l_@@_input_value_signs_tl {#1} - { \tl_put_right:Nn \l_@@_tmpa_tl {#1} } - { - \tl_map_function:nN {#1} \@@_parse_input_for_safety_aux:N - } - \bool_if:NF \l_@@_error_bool - { \tl_map_function:nN {#2} \@@_parse_input_for_safety_aux:N } - } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{ \@@_parse_input_for_safety_aux:N } -% Parses the input. It also is more or less copied from -% \texttt{siunitx}. Checks if the input consists only of numbers, -% one decimal-sign and the allowed special input. If an allowed -% token is found the boolean \lstinline|\l_@@_special_sign_bool| is -% set to true. -% \begin{macrocode} -\cs_new:Npn \@@_parse_input_for_safety_aux:N #1 - { - \tl_if_in:NnTF \l_@@_input_digits_tl {#1} - { \tl_put_right:Nn \l_@@_tmpa_tl {#1} } - { - \tl_if_in:NnTF \l_@@_input_decimal_mark_tl {#1} - { - \bool_if:NT \l_@@_decimal_in_input_bool - { - \msg_error:nn { cooking-units } - { Second-decimal-sign-not-allowed } - } - \bool_set_true:N \l_@@_decimal_in_input_bool - \tl_put_right:Nn \l_@@_tmpa_tl { . } - }{ - \tl_if_in:NnTF \l_@@_input_allowed_special_signs_tl {#1} - { - \bool_set_true:N \l_@@_special_sign_bool - \tl_put_right:Nn \l_@@_tmpa_tl {#1} - }{ - \bool_if:NTF \l_@@_range_in_input_bool - { - \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} } - } - \bool_set_true:N \l_@@_error_bool - \tl_map_break: - } - } - } - } -% \end{macrocode} -% \end{macro} % % \subsection {Formatiere \& Calculiere} % @@ -4608,8 +5674,11 @@ and the derived file cooking-units.sty. { \l_@@_using_cutext_bool } { ! \l_@@_cutext_change_unit_bool } { \tl_set_eq:NN \l_@@_tmpa_tl #1 } { \@@_calculate_input_and_store_in:nN {#1} \l_@@_tmpa_tl } - \bool_if:NT \l_@@_calc_persons_bool - { \@@_calc_for_number_of_persons_and_store_in:NN \l_@@_tmpa_tl \l_@@_tmpa_tl } + \bool_if:NT \l_@@_lokal_persons_bool + { + \@@_calc_for_number_of_persons_and_store_in:NN + \l_@@_tmpa_tl \l_@@_tmpa_tl + } \@@_round_calculated_input:NV \l_@@_tmpa_tl \l_@@_tmpa_tl \@@_check_temperature_limit:N \l_@@_tmpa_tl } @@ -4619,10 +5688,7 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % -% \begin{macro} -% { -% \@@_calculate_input_and_store_in:nN , -% } +% \begin{macro}{ \@@_calculate_input_and_store_in:nN } % Well \dots\ this function calculates the input. First checks if the % wanted conversion contains a \lstinline|\l_@@_tmpa_fp| (ergo a \#1 in % the key definition). If true the conversion token (which already has @@ -4632,134 +5698,91 @@ and the derived file cooking-units.sty. \cs_new:Npn \@@_calculate_input_and_store_in:nN #1#2 { \fp_set:Nn \l_@@_tmpa_fp {#1} - \tl_if_in:cnTF { l_@@_tmpa_ \l_@@_given_unit_tl _ tl } { \l_@@_tmpa_fp } + \tl_if_in:cnTF { l_@@_tmpa_ \l_@@_given_unit_tl _ tl } { \l_@@_tmpa_fp } { - \@@_tl_set_fp_and_eval:Nc #2 { l_@@_tmpa_ \l_@@_given_unit_tl _ tl } + \@@_tl_eval:Nv #2 { l_@@_tmpa_ \l_@@_given_unit_tl _ tl } }{ - \@@_tl_set_fp_and_eval:Nn #2 + \@@_tl_eval:Nn #2 { \l_@@_tmpa_fp * \tl_use:c { l_@@_tmpa_ \l_@@_given_unit_tl _ tl } } } } % \end{macrocode} % \end{macro} % -% +% \begin{macro}{ \@@_calc_for_number_of_persons_and_store_in:NN } % \begin{macrocode} \cs_new:Npn \@@_calc_for_number_of_persons_and_store_in:NN #1#2 { \int_compare:nNnF - { \l_@@_calc_for_number_of_persons_int } + { \l_@@_wanted_number_of_persons_int } = - { \l_@@_number_of_persons_tmpa_int } + { \l_@@_local_number_of_persons_int } { - \@@_tl_set_fp_and_eval:Nn #1 + \@@_tl_eval:Nn #1 { - \l_@@_calc_for_number_of_persons_int / - \l_@@_number_of_persons_tmpa_int * + \l_@@_wanted_number_of_persons_int / + \l_@@_local_number_of_persons_int * #2 } } } % \end{macrocode} +% \end{macro} % -% -% \begin{macro}{\@@_check_number_for_rounding:n,\@@_check_number_after_dot_aux:w} -% Getting the number after the decimal point. If it doesn't exist -% the boolean is set to false, otherwise it checks how many tokens -% are within the number after the decimal point. If the number of -% tokens is greater than significant\_figures\_plus\_one the bool is -% set to true (which tells the package later that the number should -% be rounded). This should be safe as the input was already checked. +% \begin{macro}{\@@_check_number_for_rounding:n,\@@_check_number_after_dot_aux:ww} +% Check if rounding is needed. The auxilary function splits the number into +% the integer and non-integer part ($12.45$ to $12$ and $45$). +% +% If the non-integer part exists its number of digits $n$ are counted checked +% if it is smaller then $a$, which depends on |\l_@@_round_to_int_bool|. +% % \begin{macrocode} \cs_new:Npn \@@_check_number_for_rounding:n #1 { - \bool_set_false:N \l_@@_round_decimal_part_bool - \@@_check_number_after_dot_aux:w #1 . \q_recursion_tail . + \bool_set_false:N \l_@@_round_number_bool + \@@_check_number_after_dot_aux:ww #1 . \q_recursion_tail . \q_recursion_stop } -\cs_new:Npn \@@_check_number_after_dot_aux:w #1. #2 . +\cs_new:Npn \@@_check_number_after_dot_aux:ww #1 . #2 . { - \quark_if_recursion_tail_stop:n {#2} - \bool_if:NTF \l_@@_round_to_int_bool - { \int_zero:N \l_tmpa_int } - { \int_set_eq:NN \l_tmpa_int \l_@@_significant_figures_plus_one_int } - \int_compare:nNnF - { \tl_count:n {#2} } < { \l_tmpa_int } - { \bool_set_true:N \l_@@_round_decimal_part_bool } + \quark_if_recursion_tail_stop_do:nn {#2} + { + \bool_lazy_or:nnF + { \l_@@_round_precision_positive_bool } + { \l_@@_round_to_int_bool } + { \bool_set_true:N \l_@@_round_number_bool } + } + \int_compare:nNnT + { \tl_count:n {#2} } > + { + \bool_if:NTF \l_@@_round_to_int_bool + { 0 } + { \l_@@_round_precision_int } + } + { \bool_set_true:N \l_@@_round_number_bool } \use_none_delimit_by_q_recursion_stop:w } % \end{macrocode} % \end{macro} % -% \begin{macro}{ \@@_round_calculated_input:NN,\@@_round_calculated_input:NV } +% \begin{macro}{ \@@_round_calculated_input:Nn,\@@_round_calculated_input:NV } % After calculating the numbers are rounded (if needed, safed inside \cs{l_tmpa_bool}). % We test at first if % the input needs to be rounded by comparing the number of tokens after the -% decimal with the number of significant figures plus one. Afterwards the +% decimal with the round precision. Afterwards the % input is expanded and stored in \#1. If rounding needs to be done it happens now. % \begin{macrocode} -\cs_new:Npn \@@_round_calculated_input:NN #1#2 +\cs_new:Npn \@@_round_calculated_input:Nn #1#2 { \@@_check_number_for_rounding:n {#2} - \tl_set:Nx #1 - { - \bool_if:NTF \l_@@_round_decimal_part_bool + \tl_set:Nf #1 + { + \bool_if:NTF \l_@@_round_number_bool { \fp_eval:n { round ( \@@_rounding_function:n {#2} ) } } {#2} } } -\cs_generate_variant:Nn \@@_round_calculated_input:NN { NV } -% \end{macrocode} -% \end{macro} -% -% -% -% -% \begin{macro} -% { \@@_print_input:N , \@@_print_correct_unit: , \@@_post_process_input:NN , \@@_pre_process_input:NN} -% Wrapper macro for printing the (not)calculated output. Note that if no -% calculation happens in \mycs{cutext} (and \mycs{Cutext}) \cs{l_@@_option_unit_tl} -% is set to \cs{l_@@_given_unit_tl} (the unit given in the second argument of -% \mycs{cutext} or \mycs{Cutext}) by default. -% \begin{macrocode} -\cs_new_protected:Npn \@@_print_input:N #1 { } -\cs_new_protected:Npn \@@_print_correct_unit: { } -\cs_new_protected:Npn \@@_do_not_process_input:NN #1#2 { } -\cs_new_eq:NN \@@_pre_process_input:NN \@@_do_not_process_input:NN -\cs_new_eq:NN \@@_post_process_input:NN \@@_do_not_process_input:NN -% \end{macrocode} -% \end{macro} -% -% \begin{macro} -% { -% \@@_set_process_and_print_for_cunum: , -% \@@_set_process_and_print_for_cutext: , -% \@@_set_process_and_print_for_cuam: -% } -% It is handy to set the \enquote{print} and \enquote{process} -% command all in one go. It's also less to use messy. -% \begin{macrocode} -\cs_new_protected:Npn \@@_set_process_and_print_for_cunum: - { - \cs_set_eq:NN \@@_print_input:N \@@_print_numerical_input:N - \cs_set_eq:NN \@@_print_correct_unit: \@@_cunum_print_correct_unit: - \cs_set_eq:NN \@@_pre_process_input:NN \@@_do_not_process_input:NN - \cs_set_eq:NN \@@_post_process_input:NN \@@_do_not_process_input:NN - } -\cs_new_protected:Npn \@@_set_process_and_print_for_cutext: - { - \cs_set_eq:NN \@@_print_input:N \@@_cutext_print_input:N - \cs_set_eq:NN \@@_print_correct_unit: \@@_cutext_print_correct_unitname: - \cs_set_eq:NN \@@_pre_process_input:NN \@@_cutext_pre_process_input:NN - \cs_set_eq:NN \@@_post_process_input:NN \@@_cutext_post_process_input:NN - } -\cs_new_protected:Npn \@@_set_process_and_print_for_cuam: - { - \cs_set_eq:NN \@@_print_input:N \@@_cuam_print_numerical_input:N - \cs_set_eq:NN \@@_print_correct_unit: \@@_cuam_print_correct_unitphrase: - \cs_set_eq:NN \@@_pre_process_input:NN \@@_do_not_process_input:NN - \cs_set_eq:NN \@@_post_process_input:NN \@@_cuam_post_process_input:NN - } +\cs_generate_variant:Nn \@@_round_calculated_input:Nn { NV } % \end{macrocode} % \end{macro} % @@ -4767,54 +5790,14 @@ and the derived file cooking-units.sty. % % % -% \begin{macro}{ \@@_print_numerical_input:N } -% Prints the nummerical output (if it is not a fraction). -% -% Changed \lstinline|\l_@@_tmpa_tl| by |\l_@@_translation_tmpa_tl|, it's better that way. -% \begin{macrocode} -\cs_new_protected:Npn \@@_print_numerical_input:N #1 - { - \tl_if_in:NnT #1 { . } - { - \@@_translate_let:Nxx \l_@@_translation_tmpa_tl - { decimal-mark } \c_@@_postfix_unitname_tl - \tl_replace_once:Nnn #1 { . } { \l_@@_translation_tmpa_tl } - } - \tl_if_in:NnT #1 { - } - { \tl_replace_once:NnV #1 { - } \c_@@_minus_tl } - #1 - } -% \end{macrocode} -% \end{macro} -% -% -% \begin{macro}{ \@@_formatiere_fractions:nnn } -% The name of this function is the name of the game: It prints fractions. -% Furthermore it sets the boolean \lstinline|fraction_in_input_bool| to true -% so that the correct unit is printed. Instead of \lstinline|\kern| I used the -% \lstinline|\hbox_to_wd:nn| command (I don't have a better idea). % -% Since v.1.10(alpha) it also prints the minus sign (hopefully correct). -% \begin{macrocode} -\cs_new:Npn \@@_formatiere_fractions:nnn #1#2#3 - { - \bool_if:NT \l_@@_minus_bool { \c_@@_minus_tl } - \tl_if_empty:nF {#1} - { - #1 - \hbox_to_wd:nn { \l_@@_mixed_frac_dim } { } - } - \@@_frac:nn {#2} {#3} - } -% \end{macrocode} -% \end{macro} % % -% \begin{macro}{\@@_check_temperature_limit:n} +% \begin{macro}{\@@_check_temperature_limit:N} % If \lstinline|check_temperature_bool| is set to true it now checks % if the value is below the absolute temperature. \lstinline|\clist_if_in:nVT| -% is needed due to \texttt{Re}, a \lstinline|\tl_if_in:nVT| would also check for \texttt{R} -% and \texttt{e} instead of only \texttt{Re}. +% is needed due to \myunit{Re}, a \lstinline|\tl_if_in:nVT| would also check for \myunit{R} +% and \myunit{e} instead of only \myunit{Re}. % \begin{macrocode} \cs_new:Npn \@@_check_temperature_limit:N #1 { @@ -4822,7 +5805,7 @@ and the derived file cooking-units.sty. { \seq_if_in:NVT \l_@@_temperatures_to_check_seq \l_@@_option_unit_tl { - \fp_compare:cNnT + \fp_compare:vNnT { c_@@_ \l_@@_option_unit_tl _min_fp } > {#1} { \msg_error:nnxx { cooking-units } @@ -4867,7 +5850,7 @@ and the derived file cooking-units.sty. \str_if_eq:nnTF {#1} { < } { \tl_if_in:NoT \l_@@_input_allowed_special_signs_tl { < } - { \msg_error:nn {cooking-units} { <-not-allowed-as-special-sign } } + { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } \tl_clear:N \l_@@_tmpa_tl \tl_put_right:Nx \l_@@_tmpa_tl { \tl_to_str:N < } \@@_grab_arrows_for_safety_do_afterwards:nN @@ -4904,7 +5887,8 @@ and the derived file cooking-units.sty. \cs_new:Npn \@@_cunum:nnnnn #1#2#3#4#5 { \@@_cunum_initialise:nnnnn {#1} {#2} {#3} {#4} {#5} - \@@_cunum_parse_numerical_input:n {#3} + \l_@@_cunum_hook_tl + \@@_parse_input:n {#3} \@@_print_correct_unit: } % \end{macrocode} @@ -4926,121 +5910,15 @@ and the derived file cooking-units.sty. { \@@_set_process_and_print_for_cunum: \tl_set:Nn \l_@@_phantom_tl {#4} - \@@_initialise_default:nnn {#1} {#2} {#5} - \@@_initialise_unit_change:nnn {#1} {#2} {#5} + \@@_initialise_default:n {#5} + \@@_initialise_unit_change:n {#2} \@@_initialise_after_unit_change:nn {#1} {#2} } % \end{macrocode} % \end{macro} % -% \begin{macro}{ \@@_initialise_default:n } -% Function shared by all initialization functions: -% \begin{macrocode} -\cs_new_protected:Npn \@@_initialise_default:nnn #1#2#3 - { - \tl_set:Nn \l_@@_given_unit_tl {#3} - \@@_error_if_unit_not_defined:V \l_@@_given_unit_tl - \bool_set_false:N \l_@@_special_sign_bool - \bool_set_false:N \l_@@_error_bool - \bool_set_false:N \l_@@_range_in_input_bool - \bool_set_false:N \l_@@_fraction_in_input_bool - } -% \end{macrocode} -% Some units have options added to them. To get those options it is first -% needed to know which unit will be used at all. Therefore units will -% be changed first and afterwards the other options are processed. -% \begin{macrocode} -\cs_new_protected:Npn \@@_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_@@_convert_to_eV_bool { \@@_convert_to_eV: } - \prop_get:NVNF \l_@@_change_unit_prop \l_@@_given_unit_tl \l_@@_option_unit_tl - { - \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_given_unit_tl - } - } -% \end{macrocode} -% \begin{macrocode} -\cs_new_protected:Npn \@@_initialise_after_unit_change:nn #1#2 - { - \IfNoValueF {#1} - { \@@_reference_label_and_persons:n {#1} } - \clist_if_empty:cF { l_@@_predefined_option_ \l_@@_option_unit_tl _clist } - { - \keys_set_filter:nnv - { cooking-units } - { change-unit } - { l_@@_predefined_option_ \l_@@_option_unit_tl _clist } - } - \tl_if_empty:nF {#2} - { \keys_set_filter:nnn { cooking-units } { change-unit } {#2} } - \bool_lazy_and:nnTF - { \l_@@_calc_because_ref_was_given_bool } { \l_@@_calc_for_persons_bool } - { \bool_set_true:N \l_@@_calc_persons_bool } - { \bool_set_false:N \l_@@_calc_persons_bool } - } -% \end{macrocode} -% \end{macro} -% -% -% -% \begin{macrocode} -\cs_new:Npn \@@_cunum_parse_numerical_input:n #1 - { - \bool_if:NTF \l_@@_parse_input_bool - { \@@_parse_and_evaluate_input:n {#1} } - { \@@_do_not_parse:n {#1} } - } -% \end{macrocode} -% -% % % -% \begin{macro}{ \@@_do_not_parse:n } -% If the input shoudn't be parsed this function is used to print the -% input without error messages (mostly concerning the \_). Spaces are still ignored. -% \begin{macrocode} -\cs_new:Npn \@@_do_not_parse:n #1 - { - \tl_set_rescan:Nnn \l_@@_number_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N \ % - } {#1} - \l_@@_number_tmpa_tl - } -% \end{macrocode} -% \end{macro} -% -% \begin{macro}{ \@@_parse_and_evaluate_input:n } -% Rescans the input to get rid of spaces and to make \_ and ? inactive -% (french with babel makes ? active and changes the definition of it). -% \lstinline|--| is replaced by \lstinline|\q_@@_range| and the input is parsed -% (if not empty). Afterwards the units are printed. -% \begin{macrocode} -\cs_new:Npn \@@_parse_and_evaluate_input: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} - \tl_if_empty:NF \l_@@_tmpa_tl - { - \tl_if_in:NVT \l_@@_tmpa_tl \l_@@_input_range_sign_tl - { - \tl_replace_once:NVn \l_@@_tmpa_tl \l_@@_input_range_sign_tl { \q_@@_range } - \bool_set_true:N \l_@@_range_in_input_bool - } - \@@_parse_input:V \l_@@_tmpa_tl - } - } -% \end{macrocode} -% \end{macro} % % \begin{macro}{ \@@_cunum_print_correct_unit: } % The invisible space is added by a \lstinline|\phantom|, afterwards @@ -5053,14 +5931,9 @@ and the derived file cooking-units.sty. { \tl_if_empty:NF \l_@@_phantom_tl { \phantom { \l_@@_phantom_tl } } \tl_use:N \l_@@_value_unit_space_tl - \bool_lazy_any:nTF - { - { \l_@@_fraction_in_input_bool } - { \l_@@_special_sign_bool } - { ! \l_@@_parse_input_bool } - } - { \@@_translate:xx \l_@@_given_unit_tl \c_@@_postfix_unit_tl } + \@@_change_unit:TF { \@@_translate:xx \l_@@_option_unit_tl \c_@@_postfix_unit_tl } + { \@@_translate:xx \l_@@_given_unit_tl \c_@@_postfix_unit_tl } } % \end{macrocode} % \end{macro} @@ -5078,9 +5951,12 @@ and the derived file cooking-units.sty. { \cutext } { \group_begin: - \@@_cutext_initialise:nnn {#1} {#2} {#4} - \bool_set_false:N \l_@@_cutext_uppercase_word_bool - \@@_cutext_do:nnnn {#1} {#2} {#3} {#4} + \@@_change_cutext_to_cunum:nTF {#2} + { \@@_cunum:nnnnn {#1} {#2} {#3} { } {#4} } + { + \bool_set_false:N \l_@@_cutext_uppercase_word_bool + \@@_cutext:nnnn {#1} {#2} {#3} {#4} + } \group_end: } } @@ -5093,9 +5969,12 @@ and the derived file cooking-units.sty. { \Cutext } { \group_begin: - \@@_cutext_initialise:nnn {#1} {#2} {#4} - \bool_set_true:N \l_@@_cutext_uppercase_word_bool - \@@_cutext_do:nnnn {#1} {#2} {#3} {#4} + \@@_change_cutext_to_cunum:nTF {#2} + { \@@_cunum:nnnnn {#1} {#2} {#3} { } {#4} } + { + \bool_set_true:N \l_@@_cutext_uppercase_word_bool + \@@_cutext:nnnn {#1} {#2} {#3} {#4} + } \group_end: } } @@ -5106,75 +5985,39 @@ and the derived file cooking-units.sty. { \bool_set_true:N \l_@@_using_cutext_bool \@@_set_process_and_print_for_cutext: - \@@_initialise_default:nnn {#1} {#2} {#3} + \@@_initialise_default:n {#3} \bool_if:NTF \l_@@_cutext_change_unit_bool - { \@@_initialise_unit_change:nnn {#1} {#2} {#3} } + { \@@_initialise_unit_change:n {#2} } { \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_given_unit_tl } \@@_initialise_after_unit_change:nn {#1} {#2} + \bool_if:NT \l_@@_fourty_two_bool + { \tl_set:Nn \l_@@_cutext_last_value_tl { 42 } } } % \end{macrocode} % -% Besser benennen. -% \begin{macrocode} -\cs_new:Npn \@@_cutext_do:nnnn #1#2#3#4 - { - \bool_if:NTF \l_@@_cutext_to_cunum_bool - { \cunum <#1> [#2] {#3} {#4} } - { - \@@_cutext:nnnn {#1} {#2} {#3} {#4} - } - } -% \end{macrocode} -% -% \begin{macrocode} % #1: label, #2: Options, #3: Values, #4: unit +% \begin{macrocode} \cs_new:Npn \@@_cutext:nnnn #1#2#3#4 { - \bool_if:NTF \l_@@_parse_input_bool - { - \bool_if:NTF \l_@@_cutext_old_bool - { - \@@_old_cutext_default:nnn {#2} {#3} {#4} - \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_given_unit_tl - \@@_cutext_print_correct_unitname: - }{ - \@@_parse_and_evaluate_input:n {#3} - \@@_print_correct_unit: - } - }{ - \@@_do_not_parse:n {#3} - \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_given_unit_tl - \@@_cutext_print_correct_unitname: - } + \@@_cutext_initialise:nnn {#1} {#2} {#4} + \bool_if:NTF \l_@@_cutext_uppercase_word_bool + { \l_@@_Cutext_hook_tl } + { \l_@@_cutext_hook_tl } + \bool_if:NTF \l_@@_cutext_old_bool + { \@@_old_cutext:nnn {#2} {#3} {#4} } + { \@@_parse_input:n {#3} } + \@@_print_correct_unit: } % \end{macrocode} % % -% \begin{macro} {\@@_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:N} -% \begin{macrocode} -\prg_new_conditional:Npnn \@@_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:N #1 { TF } - { - \bool_lazy_and:nnTF - { \g_@@_opt_numeral_bool } - { \l_@@_local_numeral_bool } - { - \@@_if_parse_and_integer:VTF #1 - { - \int_compare:nNnTF {#1} < { \l_@@_print_numerals_below_int } - { \prg_return_true: } - { \prg_return_false: } - }{ \prg_return_false: } - }{ \prg_return_false: } - } -% \end{macrocode} -% \end{macro} % % \begin{macro} {\@@_cutext_print_input:Nn , \@@_cutext_print_input:NV} % \changes {2016/06/11} {0.99} {New.} % \begin{macrocode} \cs_new_protected:Npn \@@_cutext_print_input:Nn #1#2 { - \@@_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:NTF #1 + \bool_if:NTF \l_@@_lokal_numeral_bool { \@@_int_if_equal_one:nTF {#1} { @@ -5195,7 +6038,11 @@ and the derived file cooking-units.sty. } \cs_generate_variant:Nn \@@_cutext_print_input:Nn { NV } \cs_new_protected:Npn \@@_cutext_print_input:N #1 - { \@@_cutext_print_input:NV #1 \l_@@_option_unit_tl } + { + \@@_change_unit:TF + { \@@_cutext_print_input:NV #1 \l_@@_option_unit_tl } + { \@@_cutext_print_input:NV #1 \l_@@_given_unit_tl } + } % \end{macrocode} % \end{macro} % @@ -5203,56 +6050,22 @@ and the derived file cooking-units.sty. \cs_new:Npn \@@_cutext_print_correct_unitname: { \l_@@_cutext_space_tl - \bool_lazy_any:nTF - { - { \l_@@_fraction_in_input_bool } - { \l_@@_special_sign_bool } - { ! \l_@@_parse_input_bool } - } - { \@@_translate:xx \l_@@_given_unit_tl \c_@@_postfix_unitname_pl_tl } + \@@_change_unit:TF { \@@_fp_if_equal_one:nTF { \l_@@_cutext_last_value_tl } { \@@_translate:xx \l_@@_option_unit_tl \c_@@_postfix_unitname_tl } { \@@_translate:xx \l_@@_option_unit_tl \c_@@_postfix_unitname_pl_tl } } + { \@@_translate:xx \l_@@_given_unit_tl \c_@@_postfix_unitname_pl_tl } } % \end{macrocode} % % \begin{macrocode} \cs_new:Npn \@@_cutext_pre_process_input:NN #1#2 { - \@@_cutext_check_unitname_consequences:NN #1#2 - } -\cs_new:Npn \@@_cutext_post_process_input:NN #1#2 - { - \bool_if:NTF \l_@@_range_in_input_bool - { - \tl_set_eq:NN \l_@@_cutext_last_value_tl #2 - \bool_if:NT \g_@@_opt_numeral_bool - { - \bool_lazy_and:nnF - { \fp_compare_p:nNn {#1} < { \l_@@_print_numerals_below_int } } - { \fp_compare_p:nNn {#2} < { \l_@@_print_numerals_below_int } } - { \bool_set_false:N \l_@@_local_numeral_bool } - } - } - { \tl_set_eq:NN \l_@@_cutext_last_value_tl #1 } - } -% \end{macrocode} -% -% It doesn't matter if I check if the singular or the plural translation exists, -% as the plural one exists if the singular exists and vice versa. -% \begin{macrocode} -\cs_new:Npn \@@_cutext_check_unitname_consequences:NN #1#2 - { - \bool_lazy_any:nTF - { - { \l_@@_fraction_in_input_bool } - { \l_@@_special_sign_bool } - { ! \l_@@_parse_input_bool } - } + \@@_change_unit:TF + { \tl_set_eq:NN \l_@@_tmpb_tl \l_@@_option_unit_tl } { \tl_set_eq:NN \l_@@_tmpb_tl \l_@@_given_unit_tl } - { \tl_set_eq:NN \l_@@_tmpb_tl \l_@@_option_unit_tl } \@@_unitname_get:NxF \l_@@_tmpa_tl \l_@@_tmpb_tl { \msg_warning:nnx @@ -5267,54 +6080,58 @@ and the derived file cooking-units.sty. % % % -% -% -% -% \begin{macro} { \@@_old_cutext_default:nnn } -% \changes {2016/06/11} {0.98a} { New command } % \begin{macrocode} -\cs_new:Npn \@@_old_cutext_default:nnn #1#2#3 +\cs_new:Npn \@@_cutext_post_process_input:NN #1#2 { - \bool_if:NTF \l_@@_parse_input_bool + \bool_if:NF \l_@@_special_sign_bool { - \tl_set:Nn \l_@@_cutext_last_value_tl {#2} - \tl_if_in:NVTF \l_@@_cutext_last_value_tl \l_@@_input_range_sign_tl - { - \tl_replace_once:NVn \l_@@_cutext_last_value_tl - \l_@@_input_range_sign_tl { \q_@@_range } - \@@_old_cutext_parse_range:Vn \l_@@_cutext_last_value_tl {#3} - }{ - \@@_cutext_print_input:Nn \l_@@_cutext_last_value_tl {#3} - } + \@@_cutext_post_process_input_aux:NN #1#2 } - {#2} } % \end{macrocode} -% \end{macro} -% % \begin{macrocode} -\cs_new:Npn \@@_old_cutext_parse_range:Nn #1 #2 +\cs_new:Npn \@@_cutext_post_process_input_aux:NN #1#2 { - \@@_old_cutext_parse_range_aux:nww {#2} #1 \q_stop + \@@_bool_set_if_integers:NNN \l_@@_tmpa_bool #1 #2 + \bool_if:NTF \l_@@_range_in_input_bool + { \tl_set_eq:NN \l_@@_cutext_last_value_tl #2 } + { \tl_set_eq:NN \l_@@_cutext_last_value_tl #1 } + \bool_if:NT \l_@@_lokal_numeral_bool + { \@@_cutext_post_process_input_numerals:NN #1#2 } } -\cs_generate_variant:Nn \@@_old_cutext_parse_range:Nn { V } -\cs_new:Npn \@@_old_cutext_parse_range_aux:nww #1 #2 \q_@@_range #3 \q_stop +\cs_new:Npn \@@_cutext_post_process_input_numerals:NN #1#2 { - \tl_set:Nn \l_@@_tmpa_tl {#2} - \tl_set:Nn \l_@@_cutext_last_value_tl {#3} - \@@_cutext_print_input:Nn \l_@@_tmpa_tl {#1} - \tl_use:N \l_@@_cutext_range_sign_tl - \@@_cutext_print_input:Nn \l_@@_cutext_last_value_tl {#1} + \bool_if:NTF \l_@@_tmpa_bool + { + \bool_if:NTF \l_@@_range_in_input_bool + { + \bool_lazy_and:nnF + { \int_compare_p:nNn {#1} < { \l_@@_print_numerals_below_int } } + { \int_compare_p:nNn {#2} < { \l_@@_print_numerals_below_int } } + { \bool_set_false:N \l_@@_lokal_numeral_bool } + }{ + \int_compare:nNnF {#1} < { \l_@@_print_numerals_below_int } + { \bool_set_false:N \l_@@_lokal_numeral_bool } + } + } + { \bool_set_false:N \l_@@_lokal_numeral_bool } } % \end{macrocode} % % +% +% +% +% +% +% +% % \section{cuam} % % \begin{macrocode} \tl_const:Nn \c_@@_cuam_marker_tl { @@_cunum } \tl_new:c { l_@@_tmpa_ \c_@@_cuam_marker_tl _ tl } -\tl_set:cn { l_@@_tmpa_ \c_@@_cuam_marker_tl _ tl } { \c_one_fp } +\tl_set:cn { l_@@_tmpa_ \c_@@_cuam_marker_tl _ tl } { 1.0 } \clist_new:c { l_@@_predefined_option_ \c_@@_cuam_marker_tl _clist } % \end{macrocode} % @@ -5328,6 +6145,7 @@ and the derived file cooking-units.sty. { \group_begin: \@@_cuam_initialise:nn {#1} {#2} + \l_@@_cuam_hook_tl \@@_cuam:n {#3} \group_end: } @@ -5338,16 +6156,12 @@ and the derived file cooking-units.sty. % \begin{macrocode} \cs_new:Npn \@@_cuam:n #1 { - \bool_if:NTF \l_@@_parse_input_bool - { - \bool_if:NTF \l_@@_cuam_old_bool - { \@@_cuam_old:n {#1} } - { - \@@_parse_and_evaluate_input:n {#1} - \@@_print_correct_unit: - } - } - { \@@_do_not_parse:n {#1} } + \bool_if:NTF \l_@@_cuam_old_bool + { \@@_cuam_old:n {#1} } + { + \@@_parse_input:n {#1} + \@@_print_correct_unit: + } } % \end{macrocode} % @@ -5357,103 +6171,97 @@ and the derived file cooking-units.sty. \@@_set_process_and_print_for_cuam: \tl_set_eq:NN \l_@@_given_unit_tl \c_@@_cuam_marker_tl \tl_set_eq:NN \l_@@_option_unit_tl \c_@@_cuam_marker_tl + \bool_set_false:N \l_@@_lokal_phrase_bool \@@_initialise_after_unit_change:nn {#1} {#2} } % \end{macrocode} % -% I should redo this command \dots\ later +% Important thing is: This whole process must not acticate if a +% special sign is in the input. This is due to mathematical comparisons. % \begin{macrocode} \cs_new_protected:Npn \@@_cuam_post_process_input:NN #1#2 { - \@@_if_integer:VTF #1 - { \bool_set_true:N \l_@@_tmpa_bool } - { \bool_set_false:N \l_@@_tmpa_bool } - \bool_lazy_and:nnT - { \l_@@_range_in_input_bool } { \l_@@_tmpa_bool } - { - \@@_if_integer:VTF #2 - { \bool_set_true:N \l_@@_tmpa_bool } - { \bool_set_false:N \l_@@_tmpa_bool } - } + \bool_if:NF \l_@@_special_sign_bool + { \@@_cuam_post_process_input_aux:NN #1 #2 } + } +% \end{macrocode} +% +% 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 +% 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. +% \begin{macrocode} +\cs_new:Npn \@@_cuam_post_process_input_aux:NN #1#2 + { + \@@_bool_set_if_integers:NNN \l_@@_tmpa_bool #1 #2 \bool_lazy_and:nnT { \l_@@_use_phrases_bool } { \l_@@_tmpa_bool } { - \@@_if_phrase_list_exists:NT \l_@@_phrase_prop - { - \@@_translate_let:Nxx \l_@@_phrase_numbers_clist - { phrase-list-list } \c_@@_postfix_phrase_tl - \@@_cuam_process_input_aux:NNN #1 \l_@@_tmpa_int \l_@@_phrase_number_tl - \bool_if:NT \l_@@_check_if_phrase_used_bool - { - \bool_if:NTF \l_@@_range_in_input_bool - { - \@@_cuam_process_input_aux:NNN #2 \l_@@_tmpb_int \l_@@_tmpb_tl - \bool_lazy_and:nnTF - { \l_@@_check_if_phrase_used_bool } - { \tl_if_eq_p:NN \l_@@_phrase_number_tl \l_@@_tmpb_tl } - { \bool_set_true:N \l_@@_check_if_phrase_used_bool } - { \bool_set_false:N \l_@@_check_if_phrase_used_bool } - \bool_if:NT \l_@@_check_if_phrase_used_bool - { - \tl_set:NV #1 \l_@@_tmpa_int - \tl_set:NV #2 \l_@@_tmpb_int - \@@_cuam_get_phrase_name:NVN - \l_@@_phrase_phrase_tl \l_@@_phrase_number_tl \l_@@_tmpb_int - } - }{ - \tl_set:NV #1 \l_@@_tmpa_int - \@@_cuam_get_phrase_name:NVN - \l_@@_phrase_phrase_tl \l_@@_phrase_number_tl \l_@@_tmpa_int - } - } - } + \@@_cuam_post_process_input_phrases:NN #1#2 } - \bool_lazy_and:nnT - { \g_@@_opt_numeral_bool } { \l_@@_local_numeral_bool } + \bool_if:NT \l_@@_lokal_numeral_bool { - \bool_set_eq:NN \l_@@_local_numeral_bool \l_@@_tmpa_bool - \bool_if:NT \l_@@_local_numeral_bool - { - \bool_if:NTF \l_@@_range_in_input_bool - { - \bool_lazy_and:nnF - { \int_compare_p:nNn {#1} < { \l_@@_print_numerals_below_int } } - { \int_compare_p:nNn {#2} < { \l_@@_print_numerals_below_int } } - { \bool_set_false:N \l_@@_local_numeral_bool } - }{ - \int_compare:nNnF {#1} < { \l_@@_print_numerals_below_int } - { \bool_set_false:N \l_@@_local_numeral_bool } - } - } + \@@_cuam_post_process_input_numerals:NN #1#2 } } % \end{macrocode} % +% This command is more or less straightforward. Does a list of phrases exist +% for the current language? If yes, parse the input and check if phrases are used. +% It is important for ranges to check both values and then decide if phrases +% are used or not. % \begin{macrocode} -\prg_new_conditional:Npnn \@@_cuam_check_if_larger:nn #1#2 { F } +\cs_new:Npn \@@_cuam_post_process_input_phrases:NN #1#2 { - \int_compare:nNnTF {#1} > {#2} - { \prg_return_true: } - { \prg_return_false: } + \@@_get_phrase_for_current_langauge:NNT + \l_@@_phrase_prop + \l_@@_phrase_numbers_clist + { + \@@_cuam_post_process_input_phrases_aux:NNN + #1 \l_@@_tmpa_int \l_@@_phrase_number_tl + \bool_if:NT \l_@@_lokal_phrase_bool + { + \bool_if:NTF \l_@@_range_in_input_bool + { + \@@_cuam_post_process_input_phrases_aux:NNN + #2 \l_@@_tmpb_int \l_@@_tmpb_tl + \bool_lazy_and:nnF + { \l_@@_lokal_phrase_bool } + { \tl_if_eq_p:NN \l_@@_phrase_number_tl \l_@@_tmpb_tl } + { \bool_set_false:N \l_@@_lokal_phrase_bool } + \bool_if:NT \l_@@_lokal_phrase_bool + { + \tl_set:NV #1 \l_@@_tmpa_int + \tl_set:NV #2 \l_@@_tmpb_int + \@@_cuam_get_phrase_name:NVN + \l_@@_phrase_phrase_tl \l_@@_phrase_number_tl \l_@@_tmpb_int + } + }{ + \tl_set:NV #1 \l_@@_tmpa_int + \@@_cuam_get_phrase_name:NVN + \l_@@_phrase_phrase_tl \l_@@_phrase_number_tl \l_@@_tmpa_int + } + } + } } % \end{macrocode} -% % \begin{macrocode} -\cs_new:Npn \@@_cuam_process_input_aux:NNN #1#2#3 +\cs_new:Npn \@@_cuam_post_process_input_phrases_aux:NNN #1#2#3 { - \bool_set_false:N \l_@@_check_if_phrase_used_bool + \bool_set_false:N \l_@@_lokal_phrase_bool \clist_map_inline:Nn \l_@@_phrase_numbers_clist { - \@@_cuam_check_if_larger:nnF { \int_abs:n {##1} } {#1} + \int_compare:nNnF { \int_abs:n {##1} } > {#1} { - \int_compare:nNnTF {##1} < { \c_zero } - { \int_set_eq:NN \l_tmpa_int \c_one } + \int_compare:nNnTF {##1} < { 0 } + { \int_set:Nn \l_tmpa_int { 1 } } { \int_set:Nn \l_tmpa_int { \int_div_truncate:nn {#1} {##1} } } \int_compare:nNnT { \int_abs:n {##1} * \l_tmpa_int } = {#1} { \int_set_eq:NN #2 \l_tmpa_int \tl_set:Nn #3 {##1} - \bool_set_true:N \l_@@_check_if_phrase_used_bool + \bool_set_true:N \l_@@_lokal_phrase_bool \clist_map_break: } } @@ -5468,15 +6276,46 @@ and the derived file cooking-units.sty. \cs_generate_variant:Nn \@@_cuam_get_phrase_name:NnN { NVN } % \end{macrocode} % +% +% Processing numerals. This function only happens if numerals are used +% and because numerals have to be integers I can set the numeral boolean +% false if there is no integer. +% +% Furthermore, due to knowing that we have integers we can use +% |\int_compare_p:nNn| instead of the |fp|-equivalent. +% \begin{macrocode} +\cs_new:Npn \@@_cuam_post_process_input_numerals:NN #1#2 + { + \bool_if:NTF \l_@@_tmpa_bool + { + \bool_if:NTF \l_@@_range_in_input_bool + { + \bool_lazy_and:nnF + { \int_compare_p:nNn {#1} < { \l_@@_print_numerals_below_int } } + { \int_compare_p:nNn {#2} < { \l_@@_print_numerals_below_int } } + { \bool_set_false:N \l_@@_lokal_numeral_bool } + }{ + \int_compare:nNnF {#1} < { \l_@@_print_numerals_below_int } + { \bool_set_false:N \l_@@_lokal_numeral_bool } + } + } + { \bool_set_false:N \l_@@_lokal_numeral_bool } + } +% \end{macrocode} +% +% +% Note: This command checks if \emph{both} a phrase and a numeral is +% used to decide whetever or not to print numerals. This is due to +% the $1$ being dependent (in some languages) depending on the gender +% of the following word. Currently testing only |\l_@@_lokal_numeral_bool| doesn't +% work due to the $1$ having a special parsing. % \begin{macrocode} \cs_new_protected:Npn \@@_cuam_print_numerical_input:N #1 { - \bool_lazy_all:nTF + \bool_lazy_and:nnTF + { \l_@@_lokal_phrase_bool } + { \l_@@_lokal_numeral_bool } { - { \l_@@_check_if_phrase_used_bool } - { \g_@@_opt_numeral_bool } - { \l_@@_local_numeral_bool } - }{ \@@_int_if_equal_one:nTF {#1} { \@@_translate_one_to_and_check_existance:Nx \l_@@_translation_tmpa_tl @@ -5491,7 +6330,7 @@ and the derived file cooking-units.sty. % \begin{macrocode} \cs_new:Npn \@@_cuam_print_correct_unitphrase: { - \bool_if:NT \l_@@_check_if_phrase_used_bool + \bool_if:NT \l_@@_lokal_phrase_bool { \l_@@_cuphrase_space_tl \l_@@_phrase_phrase_tl @@ -5501,121 +6340,8 @@ and the derived file cooking-units.sty. % % % -% \begin{macro}{\@@_cuam_old:n} -% \begin{macrocode} -\cs_new:Npn \@@_cuam_old:n #1 - { - \tl_set_rescan:Nnn \l_@@_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N\ % - } {#1} - \@@_cuam_old_parse:V \l_@@_tmpa_tl - } -% \end{macrocode} -% \end{macro} -% -% \begin{macrocode} -\cs_new_protected:Npn \@@_cuam_old_parse:n #1 - { - \tl_if_in:nVTF {#1} \l_@@_input_range_sign_tl - { - \tl_set:Nn \l_@@_tmpa_tl {#1} - \tl_replace_once:NVn \l_@@_tmpa_tl \l_@@_input_range_sign_tl { \q_@@_range } - \@@_cuam_old_parse_range:V \l_@@_tmpa_tl - }{ - \tl_if_in:nnTF {#1} { / } - { - \tl_if_in:nnTF {#1} { _ } - { \@@_cuam_old_parse_mixed_frac:www #1 \q_stop } - { \@@_cuam_old_parse_frac:ww #1 \q_stop } - }{ - \tl_if_in:nnTF {#1} { _ } - { \msg_error:nnn { cooking-units } { missing-slash } {#1} } - { \@@_cuam_old_parse_scale:n {#1} } - } - } - } -\cs_generate_variant:Nn \@@_cuam_old_parse:n { V } -% \end{macrocode} -% -% \begin{macrocode} -\cs_new:Npn \@@_cuam_old_parse_range:n #1 - { - \@@_cuam_old_parse_range_aux:ww #1 \q_nil - } -\cs_generate_variant:Nn \@@_cuam_old_parse_range:n { V } -\cs_new:Npn \@@_cuam_old_parse_range_aux:ww #1 \q_@@_range #2 \q_nil - { - #1 \l_@@_cunum_range_sign_tl #2 - } -% \end{macrocode} -% -% -% \begin{macrocode} -\cs_new:Npn \@@_cuam_old_parse_scale:n #1 {#1} -% \end{macrocode} -% -% \begin{macrocode} -\cs_new:Npn \@@_cuam_old_parse_frac:ww #1/#2 \q_stop - { \@@_frac:nn {#1} {#2} } -% \end{macrocode} -% -% \begin{macrocode} -\cs_new:Npn \@@_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop - { - #1 - \hbox_to_wd:nn { \l_@@_mixed_frac_dim } { } - \@@_frac:nn {#2} {#3} - } -% \end{macrocode} % -% \section {cufrac} % -% Obsolete. -% \begin{macrocode} -\NewDocumentCommand \cufrac { O{} m } - { - \msg_error:nnnn { cooking-units } { obsolete-command } { \cufrac } { \cuam } - \group_begin: - \tl_if_empty:nF {#1} - { \keys_set:nn { cooking-units } {#1} } - \@@_cufrac:n {#2} - \group_end: - } -\cs_new:Npn \@@_cufrac:n #1 - { - \tl_set_rescan:Nnn \l_@@_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N\ % - } {#1} - \@@_cufrac_parse:V \l_@@_tmpa_tl - } -\cs_new:Npn \@@_cufrac_parse:n #1 - { - \tl_if_in:nnTF {#1} { / } - { - \tl_if_in:nnTF {#1} { _ } - { \@@_cufrac_parse_mixed_frac:www #1 \q_stop } - { \@@_cufrac_parse_frac:ww #1 \q_stop } - }{ - \tl_if_in:nnTF {#1} { _ } - { \msg_error:nnn { cooking-units } { missing-slash } {#1} } - { \@@_cufrac_parse_scale:n {#1} } - } - } -\cs_generate_variant:Nn \@@_cufrac_parse:n { V } -\cs_new:Npn \@@_cufrac_parse_scale:n #1 {#1} -\cs_new:Npn \@@_cufrac_parse_frac:ww #1/#2 \q_stop - { \@@_frac:nn {#1} {#2} } -\cs_new:Npn \@@_cufrac_parse_mixed_frac:www #1_#2/#3 \q_stop - { - #1 - \hbox_to_wd:nn { \l_@@_mixed_frac_dim } { } - \@@_frac:nn {#2} {#3} - } -% \end{macrocode} % % \section {cukeys} % @@ -5660,11 +6386,11 @@ and the derived file cooking-units.sty. { \@@_cukeys_parse_and_create_single_key:nn {#1} {#2} }{ - \fp_set_eq:NN \l_@@_tmpa_fp \c_one_fp + \fp_set:Nn \l_@@_tmpa_fp { 1.0 } \tl_set:Nn \l_@@_given_unit_tl {#1} \@@_cukeys_parse_and_create_keys:nn {#1} { - {#1} { \c_one_fp } #2 + {#1} { 1.0 } #2 } } } @@ -5729,11 +6455,11 @@ and the derived file cooking-units.sty. % \end{align*} % % Therefore the property list for \lstinline|kg| contains the keys and values: -% \texttt{kg}=\texttt{1} -% \texttt{dag}=\texttt{100}, \texttt{g}=\texttt{1000} and \texttt{oz}= \texttt{35.27399}. +% \myunit{kg}=\myunit{1} +% \myunit{dag}=\myunit{100}, \myunit{g}=\myunit{1000} and \myunit{oz}= \myunit{35.27399}. % -% For the next unit (\texttt{dag} in this case) a new property list is created, relation above -% stored inside etc. The condition now is that \texttt{dag}=\texttt{1}, therefore every number +% For the next unit (\myunit{dag} in this case) a new property list is created, relation above +% stored inside etc. The condition now is that \myunit{dag}=\texttt{1}, therefore every number % is divided the the number \texttt{100}: % % \begin{align*} @@ -5743,7 +6469,7 @@ and the derived file cooking-units.sty. % \SI{1}{\deka\gram}&= \SI{0.3527399}{\oz} % \end{align*} % -% Same for \texttt{g}: +% Same for \myunit{g}: % % \begin{align*} % \SI{1}{\g}&= \SI{0.001}{\kg} \\ @@ -5752,7 +6478,7 @@ and the derived file cooking-units.sty. % \SI{1}{\g}&= \SI{0.03527399}{oz} % \end{align*} % -% and \texttt{oz} +% and \myunit{oz} % % \begin{align*} % \SI{1}{oz}&= \SI{0.0283495}{\kg} \\ @@ -5771,7 +6497,7 @@ and the derived file cooking-units.sty. \seq_map_inline:Nn \l_@@_tmpa_seq { \prop_set_eq:cN { l_@@_cukeys_ ##1 _prop } \l_@@_tmpb_prop - \tl_set_eq:cN { l_@@_tmpa_ ##1 _tl } \c_one_fp + \tl_set:cn { l_@@_tmpa_ ##1 _tl } { 1.0 } \seq_map_inline:Nn \l_@@_tmpa_seq { \prop_put:cnx { l_@@_cukeys_ ##1 _prop } @@ -5789,11 +6515,11 @@ and the derived file cooking-units.sty. % \end{macrocode} % \end{macro} % -% \begin{macro}{ \@@_cukeys_define_keys:N , \@@_cukeys_define_keys:V } +% \begin{macro}{ \@@_cukeys_define_keys:n , \@@_cukeys_define_keys:V } % Defining the keys: It maps through the list of unit-keys and creates a % unit-key respectively. % \begin{macrocode} -\cs_new:Npn \@@_cukeys_define_keys:N #1 +\cs_new:Npn \@@_cukeys_define_keys:n #1 { \seq_map_inline:Nn \l_@@_tmpa_seq { @@ -5821,7 +6547,7 @@ and the derived file cooking-units.sty. } } } -\cs_generate_variant:Nn \@@_cukeys_define_keys:N { V } +\cs_generate_variant:Nn \@@_cukeys_define_keys:n { V } % \end{macrocode} % \end{macro} % @@ -5847,7 +6573,7 @@ and the derived file cooking-units.sty. { \char_set_catcode_letter:N \# % \char_set_catcode_ignore:N\ % - } { {#1} { \c_one_fp } #2 } + } { {#1} { 1.0 } #2 } \@@_cusinglekeys_parse_input:V \l_@@_tmpa_tl \@@_cusinglekeys_create_key_prop:n {#1} \clist_set_from_seq:NN \l_@@_tmpa_clist \l_@@_tmpa_seq @@ -5880,7 +6606,7 @@ and the derived file cooking-units.sty. % \begin{macrocode} \cs_new:Npn \@@_cusinglekeys_create_key_prop:n #1 { - \tl_set_eq:cN { l_@@_tmpa_ #1 _tl } \c_one_fp + \tl_set:cn { l_@@_tmpa_ #1 _tl } { 1.0 } \prop_set_eq:cN { l_@@_cukeys_ #1 _prop } \l_@@_tmpa_prop \prop_put:cnn { l_@@_cukeys_ #1 _prop } { Erstes Ding } {#1} \prop_put:cnV { l_@@_cukeys_ #1 _prop } { Liste } \l_@@_tmpa_seq @@ -5889,7 +6615,7 @@ and the derived file cooking-units.sty. % \end{macrocode} % % \begin{macrocode} -\cs_new:Npn \@@_cukeys_define_singlekey:nN #1#2 +\cs_new:Npn \@@_cukeys_define_singlekey:nn #1#2 { \seq_if_in:NnF \l_@@_list_of_defined_keys_seq {#1} { \seq_put_right:Nn \l_@@_list_of_defined_keys_seq {#1} } @@ -5914,7 +6640,7 @@ and the derived file cooking-units.sty. #1 .groups:n = { change-unit } , } } -\cs_generate_variant:Nn \@@_cukeys_define_singlekey:nN { nV } +\cs_generate_variant:Nn \@@_cukeys_define_singlekey:nn { nV } % \end{macrocode} % % @@ -5947,7 +6673,7 @@ and the derived file cooking-units.sty. { \bool_set_false:N \l_@@_single_key_bool \tl_set:Nn \l_@@_tmpa_tl {#1} - \tl_set:Nn \l_@@_tmpb_tl { {#2} { \fp_eval:n { \c_one_fp / (#3) } } } + \tl_set:Nn \l_@@_tmpb_tl { {#2} { \fp_eval:n { 1.0 / (#3) } } } \@@_cukeys_add_keys_or_single_keys:VV \l_@@_tmpa_tl \l_@@_tmpb_tl } % \end{macrocode} @@ -6017,9 +6743,14 @@ and the derived file cooking-units.sty. \seq_if_in:NnTF \g_@@_list_of_defined_units_seq {#2} { \msg_error:nnn { cooking-units } { unit-already-defined } {#2} } { + \tl_map_inline:nn {#2} + { + \tl_if_in:NnT \l_@@_unit_letter_not_allowed_tl {##1} + { \msg_error:nnn { cooking-units } { character-not-allowed } {#2} } + } \seq_put_right:Nn \g_@@_list_of_defined_units_seq {#2} \tl_new:c { l_@@_tmpa_ #2 _tl } - \tl_set_eq:cN { l_@@_tmpa_ #2 _tl } \c_one_fp + \tl_set:cn { l_@@_tmpa_ #2 _tl } { 1.0 } \clist_new:c { l_@@_predefined_option_#2_clist } \keys_define:nn { cooking-units } { @@ -6051,7 +6782,7 @@ and the derived file cooking-units.sty. % % \section {Names} % -% +% Stolen from \pkg{l3keys.dtx} % \begin{macrocode} \tl_new:N \l_@@_sanitise_tl \cs_new_protected:Npn \@@_sanitise_aux:w #1 \q_mark @@ -6248,23 +6979,26 @@ and the derived file cooking-units.sty. % % % \begin{macrocode} -\@@_newtranslation_base:nVn { phrase-list } \c_@@_postfix_phrase_tl { \q_@@_no_translation } +\@@_newtranslation_base:nVn { phrase-prop } \c_@@_postfix_phrase_tl { \q_@@_no_translation } % \end{macrocode} % % \begin{macrocode} -\prg_new_conditional:Npnn \@@_phrase_list_get_for:NN #1#2 { TF , T , F } +\prg_new_conditional:Npnn \@@_phrase_list_get_for:NN #1#2 { TF } { - \@@_translate_let:VNxx #2 #1 { phrase-list } \c_@@_postfix_phrase_tl + \@@_translate_let:VNxx #2 #1 { phrase-prop } \c_@@_postfix_phrase_tl \tl_if_eq:NNTF #1 \q_@@_no_translation { \prg_return_false: } { \prg_return_true: } } -\prg_new_conditional:Npnn \@@_if_phrase_list_exists:N #1 { TF , T , F } +\prg_new_conditional:Npnn \@@_get_phrase_for_current_langauge:NN #1#2 { T } { - \@@_translate_let:Nxx \l_tmpa_tl { phrase-list } \c_@@_postfix_phrase_tl - \tl_if_eq:NNTF \l_tmpa_tl \q_@@_no_translation + \@@_translate_let:Nxx #1 { phrase-prop } \c_@@_postfix_phrase_tl + \tl_if_eq:NNTF #1 \q_@@_no_translation { \prg_return_false: } - { \prg_return_true: } + { + \@@_translate_let:Nxx #2 { phrase-clist } \c_@@_postfix_phrase_tl + \prg_return_true: + } } % \end{macrocode} % \begin{macrocode} @@ -6280,7 +7014,7 @@ and the derived file cooking-units.sty. \@@_phrase_list_get_for:NNTF \l_@@_phrase_prop \l_@@_language_tl { \@@_translate_let:VNxx \l_@@_language_tl \l_@@_phrase_numbers_clist - { phrase-list-list } \c_@@_postfix_phrase_tl + { phrase-clist } \c_@@_postfix_phrase_tl }{ \prop_clear:N \l_@@_phrase_prop \clist_clear:N \l_@@_phrase_numbers_clist @@ -6309,11 +7043,11 @@ and the derived file cooking-units.sty. % \end{macrocode} % \begin{macrocode} \@@_deftranslation_to:VxxV - \l_@@_language_tl { phrase-list } + \l_@@_language_tl { phrase-prop } \c_@@_postfix_phrase_tl \l_@@_phrase_prop \@@_deftranslation_to:VxxV - \l_@@_language_tl { phrase-list-list } + \l_@@_language_tl { phrase-clist } \c_@@_postfix_phrase_tl \l_@@_phrase_numbers_clist } % \end{macrocode} @@ -6378,6 +7112,224 @@ and the derived file cooking-units.sty. } % \end{macrocode} % +% +% +% +% \subsection{Old stuff} +% +% \begin{macro} { } +% \begin{macrocode} +\cs_new:Npn \@@_old_cutext:nnn #1#2#3 + { + \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_given_unit_tl + \@@_old_cutext_default:nnn {#1} {#2} {#3} + } +% \end{macrocode} +% \end{macro} +% +% +% +% \begin{macro} { \@@_old_cutext_default:nnn } +% \changes {2016/06/11} {0.98a} { New command } +% \begin{macrocode} +\cs_new:Npn \@@_old_cutext_default:nnn #1#2#3 + { + \bool_if:NTF \l_@@_draft_bool + {#2} + { + \tl_set:Nn \l_@@_cutext_last_value_tl {#2} + \tl_if_in:NVTF \l_@@_cutext_last_value_tl \l_@@_input_range_sign_tl + { + \tl_replace_once:NVn \l_@@_cutext_last_value_tl + \l_@@_input_range_sign_tl { \q_@@_range } + \@@_old_cutext_parse_range:Vn \l_@@_cutext_last_value_tl {#3} + }{ + \@@_old_cutext_print_input:Nn \l_@@_cutext_last_value_tl {#3} + } + } + } +% \end{macrocode} +% \begin{macrocode} +\cs_new_protected:Npn \@@_old_cutext_print_input:Nn #1#2 + { + \@@_old_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:NTF #1 + { + \@@_int_if_equal_one:nTF {#1} + { + \@@_translate_one_to_and_check_existance:Nx \l_@@_translation_tmpa_tl {#2} + \bool_if:NTF \l_@@_cutext_uppercase_word_bool + { + \exp_args:Nx \tl_upper_case:n { \tl_head:V \l_@@_translation_tmpa_tl } + \tl_tail:V \l_@@_translation_tmpa_tl + } + { \l_@@_translation_tmpa_tl } + }{ + \bool_if:NTF \l_@@_cutext_uppercase_word_bool + { \@@_print_Numeral:n {#1} } + { \@@_print_numeral:n {#1} } + } + } + { \@@_print_numerical_input:N #1 } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macro} {\@@_old_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:N} +% \begin{macrocode} +\prg_new_conditional:Npnn \@@_old_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:N #1 { TF } + { + \bool_if:NTF \l_@@_lokal_numeral_bool + { + \@@_if_integer:VTF #1 + { + \int_compare:nNnTF {#1} < { \l_@@_print_numerals_below_int } + { \prg_return_true: } + { \prg_return_false: } + }{ \prg_return_false: } + }{ \prg_return_false: } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macrocode} +\cs_new:Npn \@@_old_cutext_parse_range:nn #1 #2 + { + \@@_old_cutext_parse_range_aux:nww {#2} #1 \q_stop + } +\cs_generate_variant:Nn \@@_old_cutext_parse_range:nn { V } +\cs_new:Npn \@@_old_cutext_parse_range_aux:nww #1 #2 \q_@@_range #3 \q_stop + { + \tl_set:Nn \l_@@_tmpa_tl {#2} + \tl_set:Nn \l_@@_cutext_last_value_tl {#3} + \@@_old_cutext_print_input:Nn \l_@@_tmpa_tl {#1} + \tl_use:N \l_@@_cutext_range_sign_tl + \@@_old_cutext_print_input:Nn \l_@@_cutext_last_value_tl {#1} + } +% \end{macrocode} +% +% +% \begin{macro}{\@@_cuam_old:n} +% \begin{macrocode} +\cs_new:Npn \@@_cuam_old:n #1 + { + \tl_set_rescan:Nnn \l_@@_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N\ % + } {#1} + \bool_if:NTF \l_@@_draft_bool + { \l_@@_tmpa_tl } + { \@@_cuam_old_parse:V \l_@@_tmpa_tl } + } +% \end{macrocode} +% \end{macro} +% +% \begin{macrocode} +\cs_new_protected:Npn \@@_cuam_old_parse:n #1 + { + \tl_if_in:nVTF {#1} \l_@@_input_range_sign_tl + { + \tl_set:Nn \l_@@_tmpa_tl {#1} + \tl_replace_once:NVn \l_@@_tmpa_tl \l_@@_input_range_sign_tl { \q_@@_range } + \@@_cuam_old_parse_range:V \l_@@_tmpa_tl + }{ + \tl_if_in:nnTF {#1} { / } + { + \tl_if_in:nnTF {#1} { _ } + { \@@_cuam_old_parse_mixed_frac:www #1 \q_stop } + { \@@_cuam_old_parse_frac:ww #1 \q_stop } + }{ + \tl_if_in:nnTF {#1} { _ } + { \msg_error:nnn { cooking-units } { missing-slash } {#1} } + { \@@_cuam_old_parse_scale:n {#1} } + } + } + } +\cs_generate_variant:Nn \@@_cuam_old_parse:n { V } +% \end{macrocode} +% +% \begin{macrocode} +\cs_new:Npn \@@_cuam_old_parse_range:n #1 + { + \@@_cuam_old_parse_range_aux:ww #1 \q_nil + } +\cs_generate_variant:Nn \@@_cuam_old_parse_range:n { V } +\cs_new:Npn \@@_cuam_old_parse_range_aux:ww #1 \q_@@_range #2 \q_nil + { + #1 \l_@@_cunum_range_sign_tl #2 + } +% \end{macrocode} +% +% +% \begin{macrocode} +\cs_new:Npn \@@_cuam_old_parse_scale:n #1 {#1} +% \end{macrocode} +% +% \begin{macrocode} +\cs_new:Npn \@@_cuam_old_parse_frac:ww #1/#2 \q_stop + { \@@_frac:nn {#1} {#2} } +% \end{macrocode} +% +% \begin{macrocode} +\cs_new:Npn \@@_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop + { + #1 + \@@_dim_horizontal:N \l_@@_mixed_frac_dim + \@@_frac:nn {#2} {#3} + } +% \end{macrocode} +% +% +% \subsubsection {cufrac} +% +% Obsolete. +% \begin{macrocode} +\NewDocumentCommand \cufrac { O{} m } + { + \msg_error:nnnn { cooking-units } { obsolete-command } { \cufrac } { \cuam } + \group_begin: + \tl_if_empty:nF {#1} + { \keys_set:nn { cooking-units } {#1} } + \@@_cufrac:n {#2} + \group_end: + } +\cs_new:Npn \@@_cufrac:n #1 + { + \tl_set_rescan:Nnn \l_@@_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N\ % + } {#1} + \@@_cufrac_parse:V \l_@@_tmpa_tl + } +\cs_new:Npn \@@_cufrac_parse:n #1 + { + \tl_if_in:nnTF {#1} { / } + { + \tl_if_in:nnTF {#1} { _ } + { \@@_cufrac_parse_mixed_frac:www #1 \q_stop } + { \@@_cufrac_parse_frac:ww #1 \q_stop } + }{ + \tl_if_in:nnTF {#1} { _ } + { \msg_error:nnn { cooking-units } { missing-slash } {#1} } + { \@@_cufrac_parse_scale:n {#1} } + } + } +\cs_generate_variant:Nn \@@_cufrac_parse:n { V } +\cs_new:Npn \@@_cufrac_parse_scale:n #1 {#1} +\cs_new:Npn \@@_cufrac_parse_frac:ww #1/#2 \q_stop + { \@@_frac:nn {#1} {#2} } +\cs_new:Npn \@@_cufrac_parse_mixed_frac:www #1_#2/#3 \q_stop + { + #1 + \@@_dim_horizontal:N \l_@@_mixed_frac_dim + \@@_frac:nn {#2} {#3} + } +% \end{macrocode} +% +% +% +% % \subsection {cusetup} % % \begin{macrocode} @@ -6769,6 +7721,7 @@ and the derived file cooking-units.sty. F = -459.67 , Re = -218.52 } , + round-precision = 2 , } % \end{macrocode} % diff --git a/Master/texmf-dist/source/latex/cooking-units/cooking-units.ins b/Master/texmf-dist/source/latex/cooking-units/cooking-units.ins index da756d8a345..d023c107e9b 100644 --- a/Master/texmf-dist/source/latex/cooking-units/cooking-units.ins +++ b/Master/texmf-dist/source/latex/cooking-units/cooking-units.ins @@ -5,16 +5,16 @@ %% The original source files were: %% %% cooking-units.dtx (with options: `install') -%% Copyright (C) 2016--2017 by Ben Vitecek (current Maintainer) +%% Copyright (C) 2016--2018 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.3 of this license or (at your option) any later +%% version 1.3c of this license or (at your option) any later %% version. The latest version of this license is in: %% -%% http://www.latex-project.org/lppl.txt +%% https://ctan.org/license/lppl1.3c %% -%% and version 1.3 or later is part of all distributions of +%% and version 1.3c or later is part of all distributions of %% LaTeX version 2008-05-04 or later. %% %% This work has the LPPL maintenance status `maintained'. @@ -25,16 +25,16 @@ \input l3docstrip.tex \askforoverwritefalse \preamble -Copyright (C) 2016--2017 by Ben Vitecek (current Maintainer) +Copyright (C) 2016--2018 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.3 of this license or (at your option) any later +version 1.3c of this license or (at your option) any later version. The latest version of this license is in: -http://www.latex-project.org/lppl.txt +https://ctan.org/license/lppl1.3c -and version 1.3 or later is part of all distributions of +and version 1.3c or later is part of all distributions of LaTeX version 2008-05-04 or later. This work has the LPPL maintenance status `maintained'. @@ -49,7 +49,6 @@ and the derived file cooking-units.sty. \file{\jobname.sty}{\from{\jobname.dtx}{package}} } \endbatchfile -%% \endinput %% %% End of file `cooking-units.ins'. 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 466ca5b3b63..7e53a0129f6 100644 --- a/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty +++ b/Master/texmf-dist/tex/latex/cooking-units/cooking-units.sty @@ -5,16 +5,16 @@ %% The original source files were: %% %% cooking-units.dtx (with options: `package') -%% Copyright (C) 2016--2017 by Ben Vitecek (current Maintainer) +%% Copyright (C) 2016--2018 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.3 of this license or (at your option) any later +%% version 1.3c of this license or (at your option) any later %% version. The latest version of this license is in: %% -%% http://www.latex-project.org/lppl.txt +%% https://ctan.org/license/lppl1.3c %% -%% and version 1.3 or later is part of all distributions of +%% and version 1.3c or later is part of all distributions of %% LaTeX version 2008-05-04 or later. %% %% This work has the LPPL maintenance status `maintained'. @@ -22,7 +22,6 @@ %% This work consists of the files README.md, cooking-units.dtx and cooking-units.ins %% and the derived file cooking-units.sty. %% -%% \@ifpackageloaded {xparse} { } { \RequirePackage {xparse} } @@ -31,10 +30,10 @@ { \RequirePackage {expl3} } \ProvidesExplPackage {cooking-units} - {2017/10/23} - {1.2} + {2018/04/20} + {1.30} {Ein Paket fuer Kocheinheiten} -\@ifpackagelater { expl3 } { 2017/09/18 } +\@ifpackagelater { expl3 } { 2018/02/21 } { } { \PackageError { cooking-units } { Support~package~expl3~too~old } @@ -75,17 +74,20 @@ } \cs_generate_variant:Nn \tl_replace_all:Nnn { NVn } \cs_generate_variant:Nn \tl_replace_once:Nnn { NnV, NVn } -\cs_generate_variant:Nn \tl_if_in:nnTF { nVTF } +\cs_generate_variant:Nn \tl_if_in:nnTF { nV , xn } \cs_generate_variant:Nn \tl_if_in:NnTF { NVTF } \cs_generate_variant:Nn \tl_if_in:NnT { NVT } -\cs_generate_variant:Nn \fp_compare:nNnT { cNnT } -\cs_generate_variant:Nn \fp_eval:n { c } -\cs_generate_variant:Nn \prop_get:cVN { cVc } -\cs_generate_variant:Nn \int_abs:n { c } -\cs_generate_variant:Nn \tl_show:n { x , f } +\cs_generate_variant:Nn \fp_compare:nNnT { vNnT } +\cs_generate_variant:Nn \prop_get:NnN { cVc } +\cs_generate_variant:Nn \tl_set_rescan:Nnn { NnV } +\cs_generate_variant:Nn \msg_error:nnnn { nnnV } +\cs_generate_variant:Nn \msg_error:nnn { nnV } +\cs_new:Npn \__cooking_units_dim_horizontal:N #1 { \tex_kern:D #1 } \cs_new_eq:NN \__cooking_units_frac:nn \sfrac -\cs_new:Npn \__cooking_units_print_numeral:n #1 {} -\cs_new:Npn \__cooking_units_print_Numeral:n #1 {} +\cs_new_eq:NN \__cooking_units_set_amount:Nn \tl_set:Nn +\cs_new_eq:NN \__cooking_units_set_unit:Nn \tl_set:Nn +\cs_new:Npn \__cooking_units_print_numeral:n #1 { } +\cs_new:Npn \__cooking_units_print_Numeral:n #1 { } \bool_if:NT \g__cooking_units_opt_numeral_bool { \cs_set_eq:NN \__cooking_units_print_numeral:n \numberstringnum @@ -97,6 +99,7 @@ \tl_new:N \l__cooking_units_tmpa_tl \tl_new:N \l__cooking_units_tmpb_tl \tl_new:N \l__cooking_units_mixed_fraction_tl +\tl_new:N \l__cooking_units_given_amount_tl \tl_new:N \l__cooking_units_given_unit_tl \tl_new:N \l__cooking_units_option_unit_tl \tl_new:N \l__cooking_units_language_tl @@ -109,17 +112,23 @@ \tl_new:N \l__cooking_units_input_allowed_special_signs_tl \tl_new:N \c__cooking_units_input_str_hash_one_tl \tl_new:N \l__cooking_units_input_range_sign_tl -\tl_new:N \l__cooking_units_input_times_persons_sign \tl_new:N \l__cooking_units_cutext_space_tl \tl_new:N \l__cooking_units_cuphrase_space_tl \tl_new:N \l__cooking_units_translation_tmpa_tl \tl_new:N \l__cooking_units_cutext_last_value_tl \tl_new:N \l__cooking_units_phantom_tl \tl_new:N \l__cooking_units_phrase_phrase_tl -\tl_new:N \l__cooking_units_unit_key_not_allowed_tl +\tl_new:N \l__cooking_units_unit_letter_not_allowed_tl +\tl_new:N \l__cooking_units_input_fraction_sign_tl +\tl_new:N \l__cooking_units_input_mixed_fraction_sign_tl +\tl_new:N \l__cooking_units_cunum_hook_tl +\tl_new:N \l__cooking_units_cutext_hook_tl +\tl_new:N \l__cooking_units_Cutext_hook_tl +\tl_new:N \l__cooking_units_cuam_hook_tl \tl_set:Nn \l__cooking_units_input_digits_tl { 0123456789 } -\tl_set:Nn \l__cooking_units_input_times_persons_sign { * } \tl_set:Nn \l__cooking_units_input_range_sign_tl { -- } +\tl_set:Nn \l__cooking_units_input_fraction_sign_tl { / } +\tl_set:Nn \l__cooking_units_input_mixed_fraction_sign_tl { _ } \tl_set:Nn \l__cooking_units_input_decimal_mark_tl { . , } \tl_set:Nn \l__cooking_units_input_value_signs_tl { + - } \tl_set:Nn \l__cooking_units_input_allowed_special_signs_tl { ? } @@ -130,7 +139,7 @@ \tl_set:Nn \l__cooking_units_value_unit_space_tl { \thinspace } \tl_set:Nn \l__cooking_units_cutext_space_tl { \space } \tl_set:Nn \l__cooking_units_cuphrase_space_tl { \space } -\tl_set:Nn \l__cooking_units_unit_key_not_allowed_tl { , / } +\tl_set:Nn \l__cooking_units_unit_letter_not_allowed_tl { , / } \AtBeginDocument { \cs_if_free:cT { T@TS1 } { @@ -155,27 +164,26 @@ } \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_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_round_precision_int +\int_set:Nn \l__cooking_units_round_precision_int { 2 } \int_new:N \l__cooking_units_print_numerals_below_int \int_set:Nn \l__cooking_units_print_numerals_below_int { 13 } -\int_new:N \l__cooking_units_number_of_persons_tmpa_int -\int_new:N \l__cooking_units_calc_for_number_of_persons_int -\int_set:Nn \l__cooking_units_calc_for_number_of_persons_int { 4 } +\int_new:N \l__cooking_units_local_number_of_persons_int +\int_new:N \l__cooking_units_wanted_number_of_persons_int +\int_set:Nn \l__cooking_units_wanted_number_of_persons_int { 4 } \int_new:N \l__cooking_units_phrase_number_tl \seq_new:N \l__cooking_units_list_of_defined_keys_seq \seq_new:N \g__cooking_units_list_of_defined_units_seq \clist_new:N \g__cooking_units_allowed_special_keys_clist \clist_new:N \l__cooking_units_phrase_numbers_clist \seq_new:N \l__cooking_units_temperatures_to_check_seq +\seq_new:N \l__cooking_units_curef_do_not_change_seq \prop_new:N \l__cooking_units_phrase_prop \bool_new:N \l__cooking_units_minus_bool -\bool_new:N \l__cooking_units_round_decimal_part_bool +\bool_new:N \l__cooking_units_round_number_bool \bool_new:N \l__cooking_units_error_bool \bool_new:N \l__cooking_units_eval_fractions_bool -\bool_new:N \l__cooking_units_parse_input_bool +\bool_new:N \l__cooking_units_draft_bool \bool_new:N \l__cooking_units_round_to_int_bool \bool_new:N \l__cooking_units_special_sign_bool \bool_new:N \l__cooking_units_single_key_bool @@ -185,24 +193,31 @@ \bool_new:N \l__cooking_units_error_for_unknown_value_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_change_number_of_persons_bool \bool_new:N \l__cooking_units_calc_because_ref_was_given_bool -\bool_new:N \l__cooking_units_calc_persons_bool +\bool_new:N \l__cooking_units_lokal_persons_bool \bool_new:N \l__cooking_units_cutext_to_cunum_bool \bool_new:N \l__cooking_units_cutext_old_bool \bool_new:N \l__cooking_units_cutext_change_unit_bool \bool_new:N \l__cooking_units_round_commercial_bool \bool_new:N \l__cooking_units_use_phrases_bool -\bool_new:N \l__cooking_units_check_if_phrase_used_bool -\bool_new:N \l__cooking_units_local_numeral_bool +\bool_new:N \l__cooking_units_lokal_phrase_bool +\bool_new:N \l__cooking_units_print_numeral_bool +\bool_new:N \l__cooking_units_lokal_numeral_bool +\bool_new:N \l__cooking_units_round_precision_positive_bool +\bool_new:N \l__cooking_units_fourty_two_bool \bool_new:N \l__cooking_units_range_in_input_bool -\bool_new:N \l__cooking_units_fraction_in_input_bool +\bool_new:N \l__cooking_units_lokal_fraction_bool +\bool_new:N \l__cooking_units_print_fraction_bool +\bool_new:N \l__cooking_units_lokal_mixed_fraction_bool \bool_new:N \l__cooking_units_decimal_in_input_bool -\bool_set_true:N \l__cooking_units_parse_input_bool \bool_set_true:N \l__cooking_units_cutext_change_unit_bool -\bool_set_eq:NN \l__cooking_units_local_numeral_bool \g__cooking_units_opt_numeral_bool +\bool_set_eq:NN \l__cooking_units_print_numeral_bool \g__cooking_units_opt_numeral_bool \quark_new:N \q__cooking_units_range \quark_new:N \q__cooking_units_no_translation +\quark_new:N \q__cooking_units_decimal +\quark_new:N \q__cooking_units_frac +\quark_new:N \q__cooking_units_mixed_frac \fp_new:N \l__cooking_units_tmpa_fp \clist_new:N \l__cooking_units_tmpa_clist \prop_new:N \l__cooking_units_tmpa_prop @@ -212,73 +227,120 @@ \int_new:N \l__cooking_units_tmpb_int \keys_define:nn { cooking-units } { - eval-fraction .bool_set:N = \l__cooking_units_eval_fractions_bool , - eval-fraction .default:n = { false } , - round-precision .code:n = + add-unit-to-group .code:n = { - \int_set:Nn \l__cooking_units_significant_figures_int {#1} - \int_set:Nn \l__cooking_units_significant_figures_plus_one_int { #1 + \c_one } + \keyval_parse:NNn + \__cooking_units_unit_group_add_unit_error:n + \__cooking_units_unit_group_add_unit:nn + {#1} } , - round-precision .default:n = { 2 } , - round-to-int .bool_set:N = \l__cooking_units_round_to_int_bool , - round-to-int .default:n = { false } , - range-sign .meta:n = + add-unit-to-group .default:n = {} , + set-option-for .code:n = { - cunum-range-sign = {#1} , - cutext-range-sign = {#1} + \keyval_parse:NNn + \__cooking_units_set_options_for_error:n + \__cooking_units_set_options_for:nn + {#1} + }, + add-option-for .code:n = + { + \keyval_parse:NNn + \__cooking_units_add_options_for_error:n + \__cooking_units_add_options_for:nn + {#1} + }, + erase-all-options .code:n = + { + \seq_map_inline:Nn \g__cooking_units_list_of_defined_units_seq + { + \clist_clear:c { l__cooking_units_predefined_option_ ##1 _clist } + } + }, + erase-all-options .value_forbidden:n = { true } , + erase-all-options-for .code:n = + { + \keyval_parse:NNn + \__cooking_units_erase_options_for:n + \__cooking_units_erase_options_for_error:nn + {#1} + }, + erase-all-options-for .value_required:n = { true } , + cutext-to-cunum .bool_set:N = \l__cooking_units_cutext_to_cunum_bool , + cutext-to-cunum .default:n = { false } , + cutext-to-cunum .groups:n = { change-command } , + cutext-change-unit .bool_set:N = \l__cooking_units_cutext_change_unit_bool , + cutext-change-unit .default: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 } + } } , - range-sign .default:n = { -- } , - cunum-range-sign .tl_set:N = \l__cooking_units_cunum_range_sign_tl , - cunum-range-sign .default:n = { -- } , - cutext-range-sign .tl_set:N = \l__cooking_units_cutext_range_sign_tl , - cutext-range-sign .default:n = { -- } , - amount-unit-space .tl_set:N = \l__cooking_units_value_unit_space_tl , - amount-unit-space .default:n = { \thinspace } , - fraction-command .code:n = { \cs_set_eq:NN \__cooking_units_frac:nn #1 } , - fraction-command .default:n = { \sfrac } , - fraction-inline .code:n = { \cs_set:Npn \__cooking_units_frac:nn ##1##2 {#1} } , - fraction-inline .default:n = { \sfrac {#1} {#2} } , - mixed-fraction-space .dim_set:N = \l__cooking_units_mixed_frac_dim , - mixed-fraction-space .default:n = { 0.1 em } , - parse-number .bool_set:N = \l__cooking_units_parse_input_bool , - parse-number .default:n= { true } , - add-special-sign .code:n = + cuam-version .default:n = { new } , + cutext-version .choices:nn = + { new , old } { - \str_if_eq:nnTF {#1} { < } - { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } - { \tl_put_right:Nn \l__cooking_units_input_allowed_special_signs_tl {#1} } + \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 } + } } , - add-special-sign .default:n = { } , + cutext-version .default:n = { new } , + expand-both .choices:nn = + { n , o , f , x } + { + \cs_set_eq:Nc \__cooking_units_set_unit:Nn { tl_set:N \l_keys_choice_tl } + \cs_set_eq:Nc \__cooking_units_set_amount:Nn { tl_set:N \l_keys_choice_tl } + } , + expand-both .default:n = { n } , + expand-amount .choices:nn = + { n , o , f , x } + { + \cs_set_eq:Nc \__cooking_units_set_amount:Nn { tl_set:N \l_keys_choice_tl } + } , + expand-amount .default:n = { n } , + expand-unit .choices:nn = + { n , o , f , x } + { + \cs_set_eq:Nc \__cooking_units_set_unit:Nn { tl_set:N \l_keys_choice_tl } + } , + expand-unit .default:n = { n } , set-special-sign .code:n = { - \str_if_eq:nnTF {#1} { < } - { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } - { \tl_set:Nn \l__cooking_units_input_allowed_special_signs_tl {#1} } + \tl_map_inline:nn {#1} + { + \str_if_eq:nnT {##1} { < } + { + \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } + \tl_map_break:n { \use_none:nn } + } + } + \use:n { \tl_set:Nn \l__cooking_units_input_allowed_special_signs_tl {#1} } } , - input-range-sign .tl_set:N = \l__cooking_units_input_range_sign_tl , - input-range-sign .default:n = { -- } , - check-temperature .bool_set:N = \l__cooking_units_check_temperature_bool , - check-temperature .default:n = { true } , - add-temperature-to-check .code:n = + add-special-sign .code:n = { - \keyval_parse:NNn - \__cooking_units_temperature_to_check_print_error:n - \__cooking_units_temperatures_to_check_define:nn - {#1} - }, - temperature-to-check .value_required:n = { true } , - convert-to-eV .bool_set:N = \l__cooking_units_convert_to_eV_bool , - convert-to-eV .default:n = { true } , - convert-to-eV .groups:n = { change-unit } , - use-numerals-below .int_set:N = \l__cooking_units_print_numerals_below_int , - use-numerals-below .default:n = { 13 } , + \tl_map_inline:nn {#1} + { + \str_if_eq:nnTF {##1} { < } + { + \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } + }{ + \tl_put_right:Nn \l__cooking_units_input_allowed_special_signs_tl {##1} + } + } + } , + add-special-sign .default:n = { } , set-unknown-message .choices:nn = { error , warning , none } { \msg_redirect_name:nnn { cooking-units } { amount-not-known } { \l_keys_choice_tl } } , - set-unknown-message .default:n = { warning } , + set-unknown-message .default:n = { set-cutext-translation-message } , set-cutext-translation-message .choices:nn = { error , warning , none } { @@ -286,13 +348,34 @@ { \l_keys_choice_tl } } , set-cutext-translation-message .default:n = { warning } , - erase-all-options .code:n = + print-numerals .bool_set:N = \l__cooking_units_print_numeral_bool , + print-numerals .default:n = { true } , + use-numerals-below .int_set:N = \l__cooking_units_print_numerals_below_int , + use-numerals-below .default:n = { 13 } , + parse-number .bool_set_inverse:N = \l__cooking_units_draft_bool , + parse-number .default:n= { true } , + range-sign .meta:n = { - \seq_map_inline:Nn \g__cooking_units_list_of_defined_units_seq - { - \clist_clear:c { l__cooking_units_predefined_option_##1_clist } - } - }, + cunum-range-sign = {#1} , + cutext-range-sign = {#1} + } , + range-sign .default:n = { -- } , + cunum-range-sign .tl_set:N = \l__cooking_units_cunum_range_sign_tl , + cunum-range-sign .default:n = { -- } , + cutext-range-sign .tl_set:N = \l__cooking_units_cutext_range_sign_tl , + cutext-range-sign .default:n = { -- } , + use-phrases .bool_set:N = \l__cooking_units_use_phrases_bool , + use-phrases .default:n = { true } , + round-precision .code:n = + { + \int_set:Nn \l__cooking_units_round_precision_int {#1} + \int_compare:nNnTF {#1} < { 0 } + { \bool_set_false:N \l__cooking_units_round_precision_positive_bool } + { \bool_set_true:N \l__cooking_units_round_precision_positive_bool } + } , + round-precision .default:n = { 2 } , + round-to-int .bool_set:N = \l__cooking_units_round_to_int_bool , + round-to-int .default:n = { false } , round-half .choices:nn = { default , commercial } { @@ -303,7 +386,23 @@ } }, round-half .default:n = { default }, - set-number-of-persons .int_set:N = \l__cooking_units_calc_for_number_of_persons_int , + eval-fraction .bool_set:N = \l__cooking_units_eval_fractions_bool , + eval-fraction .default:n = { false } , + fraction-command .code:n = { \cs_set_eq:NN \__cooking_units_frac:nn #1 } , + fraction-command .default:n = { \sfrac } , + fraction-inline .code:n = { \cs_set:Npn \__cooking_units_frac:nn ##1##2 {#1} } , + fraction-inline .default:n = { \sfrac {#1} {#2} } , + mixed-fraction-space .dim_set:N = \l__cooking_units_mixed_frac_dim , + mixed-fraction-space .default:n = { 0.1 em } , + cutext-space .tl_set:N = \l__cooking_units_cutext_space_tl , + cutext-space .default:n = { \space } , + phrase-space .tl_set:N = \l__cooking_units_cuphrase_space_tl , + phrase-space .default:n = { \space } , + amount-unit-space .tl_set:N = \l__cooking_units_value_unit_space_tl , + amount-unit-space .default:n = { \thinspace } , + recalculate-amount .bool_set:N = \l__cooking_units_change_number_of_persons_bool , + recalculate-amount .default:n = { false } , + set-number-of-persons .int_set:N = \l__cooking_units_wanted_number_of_persons_int , set-number-of-persons .default:n = { 4 } , label .code:n = { @@ -320,46 +419,48 @@ \__cooking_units_reference_label_and_persons:n {#1} } , ref .value_required:n = { true } , - cuam-version .choices:nn = - { new , old } + check-temperature .bool_set:N = \l__cooking_units_check_temperature_bool , + check-temperature .default:n = { true } , + add-temperature-to-check .code:n = { - \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 } + \keyval_parse:NNn + \__cooking_units_temperature_to_check_print_error:n + \__cooking_units_temperatures_to_check_define:nn + {#1} + }, + temperature-to-check .value_required:n = { true } , + convert-to-eV .bool_set:N = \l__cooking_units_convert_to_eV_bool , + convert-to-eV .default:n = { true } , + convert-to-eV .groups:n = { change-unit } , + add-natural-unit .code:n = { - \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 } - } + \__cooking_units_error_if_unit_not_defined:n {#1} + \seq_set_from_clist:Nn \l__cooking_units_tmpa_seq {#1} + \seq_concat:NNN \g__cooking_units_natural_units_seq \g__cooking_units_natural_units_seq \l__cooking_units_tmpa_seq + \seq_remove_duplicates:N \g__cooking_units_natural_units_seq } , - 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 } , - phrase-space .tl_set:N = \l__cooking_units_cuphrase_space_tl , - phrase-space .default:n = { \space } , - cutext-change-unit .bool_set:N = \l__cooking_units_cutext_change_unit_bool , - cutext-change-unit .default:n = { true } , - use-phrases .bool_set:N = \l__cooking_units_use_phrases_bool , - use-phrases .default:n = { true } , - print-numerals .bool_set:N = \l__cooking_units_local_numeral_bool , - print-numerals .default:n = { true } , + add-natural-unit .value_required:n = { true } , + 42 .bool_set:N = \l__cooking_units_fourty_two_bool , + 42 .default:n = { true } , + input-range-sign .tl_set:N = \l__cooking_units_input_range_sign_tl , + input-range-sign .default:n = { -- } , numeral-function .code:n = { \cs_set_eq:NN \__cooking_units_print_numeral:n #1 } , Numeral-function .code:n = { \cs_set_eq:NN \__cooking_units_print_Numeral:n #1 } , + commands-add-hook .meta:n = + { + cunum-add-hook = {#1} , + cutext-add-hook = {#1} , + Cutext-add-hook = {#1} , + cuam-add-hook = {#1} , + } , + cunum-add-hook .code:n = { \tl_put_right:Nn \l__cooking_units_cunum_hook_tl {#1} } , + cutext-add-hook .code:n = { \tl_put_right:Nn \l__cooking_units_cutext_hook_tl {#1} } , + Cutext-add-hook .code:n = { \tl_put_right:Nn \l__cooking_units_Cutext_hook_tl {#1} } , + cuam-add-hook .code:n = { \tl_put_right:Nn \l__cooking_units_cuam_hook_tl {#1} } , } \msg_new:nnnn { cooking-units } { fraction-not-allowed-with-range } { - 'You' \ cannot \ use \ '/' \ ( and \ '_' )\ in \ combination \ + You \ cannot \ use \ '/' \ ( and \ '_' )\ in \ combination \ with \ '\l__cooking_units_input_range_sign_tl' \ in \ '#1'. }{ You \ cannot \ use \ fractions \ with \ a \ range. @@ -368,16 +469,24 @@ \msg_new:nnnn { cooking-units } { missing-slash } { You \ cannot \ use \ '_' \ without \ - '/' in '#1'. + '/' \ in \ '#1'. }{ You \ cannot \ have \ a \ mixed \ fraction \ ('_') \ without \ a \ normal \ fraction \ ('/'). \msg_see_documentation_text:n { cooking-units } } +\msg_new:nnnn { cooking-units } { fraction-wrong-order } + { + You \ cannot \ use \ '/' \ before \ '_' \ in \ '#1'. + }{ + You \ can \ only \ use \ '_' \ before \ '/'. + \msg_see_documentation_text:n { cooking-units } + } \msg_new:nnnn { cooking-units } { unknown-unit } { The \ unit \ '#1' \ is \ not \ defined. \ Use \ - \newcookingunit \ to \ define \ new \ units. + \newcookingunit ~ (or \ one \ of \ the \ others) \ to \ + define \ new \ units. }{ Define \ units \ before \ using \ or \ check \ if \ the \ unit-key \ is \ written \ correctly. @@ -390,31 +499,52 @@ key \ for \ a \ new \ unit. \msg_see_documentation_text:n {cooking-units} } +\msg_new:nnnn { cooking-units } { character-not-allowed } + { + Unit-keys \ are \ not \ allowed \ to \ either \ contain \ ',' \ or \ '/' \ + in \ '#1'. + }{ + The \ unit-key \ is \ not \ allowed \ to \ contain \ ',' \ or \ '/'. \ + Due \ to \ internal \ reasons. + \msg_see_documentation_text:n {cooking-units} + } \msg_new:nnnn { cooking-units } { missing-argument } - { There \ is \ an \ missing \ argument. } + { There \ is \ a \ 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 } - { Division\ by \ zero \ is \ not \ allowed. } + { Division\ by \ zero \ is \ not \ allowed \ in \ '#1'. } { See \ a \ math \ book \ of \ your \ choice \ or \ for \ example \ Wikipedia. } \msg_new:nnnn { cooking-units } { Token-not-allowed } - { The \ token \ '#1' \ is \ not \ allowed. } + { The \ token \ '#1' \ is \ not \ allowed \ in \ '#2'. } { 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 } - { A \ second \ decimal \ sign \ is \ not \ allowed. } + { A \ second \ decimal \ sign \ is \ not \ allowed \ in \ '#1'. } + { + Perhaps \ you \ didn't \ type \ it \ correctly. + \msg_see_documentation_text:n {cooking-units} + } +\msg_new:nnnn { cooking-units } { Second-fraction-sign-not-allowed } + { A \ second \ fraction \ sign \ is \ not \ allowed \ in \ '#1'. } + { + Perhaps \ you \ didn't \ type \ it \ correctly. + \msg_see_documentation_text:n {cooking-units} + } +\msg_new:nnnn { cooking-units } { Second-mixed-fraction-sign-not-allowed } + { A \ second \ mixed \ fraction \ sign \ is \ not \ allowed \ in \ '#1'. } { Perhaps \ you \ didn't \ type \ it \ correctly. \msg_see_documentation_text:n {cooking-units} } \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. @@ -427,7 +557,7 @@ the \ temperatures \ '\seq_use:Nnnn \l__cooking_units_temperatures_to_check_seq { ', ~ ' } { ', ~ ' } { ' ~ and ~ ' }' \ - are \ rounded \ to \ integers. + are \ rounded \ to \ integers \ by \ default. \\\\ You \ can \ disable \ the \ option \ 'check-temperature' \ to \ disable \ this \ error. @@ -437,11 +567,19 @@ { The \ key \ '#1' \ only \ accepts \ only \ '#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. + \msg_see_documentation_text:n {cooking-units} } +\msg_new:nnnn { cooking-units } { group-choice-not-allowed } { - The \ key \ accepts \ accepts\ only \ a \ fixed \ set \ of \ choices. \ - You \ can \ add \ new \ choices \ via \ \cuaddkeys, \ \cuaddsinglekeys \ - and \ \cuaddtokeys{}. + The \ group \ key \ '#1' \ accepts \ only \ + '#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 \ option \ 'add-unit-to-group'. \msg_see_documentation_text:n {cooking-units} } \msg_new:nnnn { cooking-units } { amount-not-known } @@ -455,39 +593,52 @@ reminds\ you\ about\ that\ fact. \msg_see_documentation_text:n {cooking-units} } +\msg_new:nnnn { cooking-units } { group-key-unknown } + { + The \ group \ key \ '#1' \ is \ not \ defined. \ Perhaps + \ you \ misspelled \ it? + }{ + The \ group \ key \ is \ not \ defined. + \msg_see_documentation_text:n { cooking-units } + } \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. } { - You \ cannot \ set \ this \ option \ using \ \cusetup \ + You \ cannot \ set \ this \ option \ using \ \cusetup ~ but \ only \ as \ a \ package \ option. \msg_see_documentation_text:n { cooking-units } } \msg_new:nnnn { cooking-units } { obsolete-command } { Command \ #1 is \ obsolete. \ Please \ use \ #2 instead. - } - { + }{ Don't \ use \ this \ old \ command \ ... \msg_see_documentation_text:n { cooking-units } } \msg_new:nnnn { cooking-units } { No-Value-given } { - Please \ input \ a \ number \ to \ check \ for \ - 'check-temperature'. + Please \ input \ a \ value \ for \ the \ key-value \ list \ in \ '#1' } { - A \ minimum \ value \ is \ needed \ for \ testing \ if \ - 'check-temperature' \ is \ active. + Each \ element \ of \ the \ list \ needs \ a \ value. \msg_see_documentation_text:n { cooking-units } } -\msg_new:nnnn { cooking-units } { Minimum-already-defined } +\msg_new:nnnn { cooking-units } { Value-not-allowed } { - A \ minimum \ for \ '#1' \ has \ already \ been \ defined. + 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 } + } +\msg_new:nnnn { cooking-units } { Minimum-already-defined } + { + A \ minimum \ for \ '#1' \ has \ already \ been \ defined. + }{ You \ cannot \ redefine \ it. \msg_see_documentation_text:n { cooking-units } } @@ -513,8 +664,7 @@ \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 } } @@ -522,41 +672,39 @@ { 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: . - } - { + The \ unit \ '#1' \ is \ redefined \ by \ \declarecookingunit ~ at \ + \msg_line_context: . + }{ \msg_see_documentation_text:n { cooking-units } } \msg_new:nnnn { cooking-units } { phrase-unit-not-an-integer } { A \ phrase \ must \ be \ an \ integer, \ '#1' \ is \ not \ allowed. - } - { + }{ You \ can \ only \ use \ integers. \msg_see_documentation_text:n { cooking-units } } -\msg_new:nnnn { cooking-units } { cutext-no-translation-available } %% ToDo +\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 \ \Cutext. \ You \ can \ define \ new \ translations \ for \ a \ given \ language \ using \ - \cudefinename{}. + \cudefinename. } { - \cunum \ is \ used \ instead. + \cunum ~ is \ used \ instead. \msg_see_documentation_text:n { cooking-units } } -\msg_new:nnnn { cooking-units } { Translation-not-available } %% ToDo +\msg_new:nnnn { cooking-units } { Translation-not-available } { The \ translation \ for \ #1 \ does \ not \ exist. - Please \ define \ it \ using \ \cudefinename{}. + Please \ define \ it \ using \ \cudefinename. } { And \ you \ may \ send \ me \ the \ translation \ as \ it \ is \ @@ -580,13 +728,22 @@ Please \ remove \ spaces \ if \ there \ are \ some. \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. + }{ + Please \ send \ me \ a \ bug \ report. + \msg_see_documentation_text:n { cooking-units } + } \cs_new:Npn \__cooking_units_error_if_unit_not_defined:n #1 { \seq_if_in:NnF \g__cooking_units_list_of_defined_units_seq {#1} { \msg_error:nnn { cooking-units } { unknown-unit } {#1} } } \cs_generate_variant:Nn \__cooking_units_error_if_unit_not_defined:n { V } -\prg_new_protected_conditional:Npnn \__cooking_units_if_integer:n #1 { TF , F , T } +\prg_new_protected_conditional:Npnn \__cooking_units_if_integer:n #1 { TF , F } { \tl_map_inline:nn {#1} { @@ -598,28 +755,35 @@ \use_i:nn \prg_return_true: \prg_return_false: } \cs_generate_variant:Nn \__cooking_units_if_integer:nTF { V } -\cs_generate_variant:Nn \__cooking_units_if_integer:nT { V } \cs_generate_variant:Nn \__cooking_units_if_integer:nF { V } -\prg_new_protected_conditional:Npnn \__cooking_units_if_parse_and_integer:n #1 { TF } +\cs_new:Npn \__cooking_units_bool_set_if_integers:NNN #1#2#3 { - \bool_if:NTF \l__cooking_units_parse_input_bool + \__cooking_units_if_integer:VTF #2 + { \bool_set_true:N #1 } + { \bool_set_false:N #1 } + \bool_lazy_and:nnT + { \l__cooking_units_range_in_input_bool } {#1} { - \__cooking_units_if_integer:nTF {#1} - { \prg_return_true: } - { \prg_return_false: } + \__cooking_units_if_integer:VF #3 + { \bool_set_false:N #1 } } - { \prg_return_false: } } -\cs_generate_variant:Nn \__cooking_units_if_parse_and_integer:nTF { V } \prg_new_conditional:Npnn \__cooking_units_fp_if_equal_one:n #1 { TF } { - \fp_compare:nNnTF {#1} = { \c_one_fp } + \fp_compare:nNnTF {#1} = { 1.0 } { \prg_return_true: } { \prg_return_false: } } \prg_new_conditional:Npnn \__cooking_units_int_if_equal_one:n #1 { TF } { - \int_compare:nNnTF {#1} = { \c_one } + \int_compare:nNnTF {#1} = { 1 } + { \prg_return_true: } + { \prg_return_false: } + } +\prg_new_conditional:Npnn \__cooking_units_change_cutext_to_cunum:n #1 { TF } + { + \keys_set_groups:nnn { cooking-units } { change-command } {#1} + \bool_if:NTF \l__cooking_units_cutext_to_cunum_bool { \prg_return_true: } { \prg_return_false: } } @@ -627,11 +791,63 @@ { \str_case:nnF {#1} { - { m } {} - { f } {} - { n } {} + { m } { } + { f } { } + { n } { } } { \msg_error:nnn { cooking-units } { unknown-gender } {#1} } } +\cs_new:Npn \__cooking_units_define_unit_group:nn #1#2 + { + \clist_new:c { l__cooking_units_group_ #1 _clist } + \clist_set:cn { l__cooking_units_group_ #1 _clist } {#2} + \keys_define:nn { cooking-units } + { + #1 .code:n = { \__cooking_units_unit_group_convert_units:nn {#1} {##1} } , + #1 .groups:n = { change-unit } + } + } +\cs_new:Npn \__cooking_units_error_if_group_not_defined:n #1 + { + \clist_if_exist:cF { l__cooking_units_group_ #1 _clist } + { \msg_error:nn { cooking-units} { group-key-unknown } } + } +\cs_new:Npn \__cooking_units_unit_group_convert_units:nn #1#2 + { + \__cooking_units_error_if_group_not_defined:n {#1} + \__cooking_units_error_if_unit_not_defined:n {#2} + \clist_if_in:cnTF { l__cooking_units_group_ #1 _clist } {#2} + { + \clist_map_inline:cn { l__cooking_units_group_ #1 _clist } + { \__cooking_units_keys_set:nnn { cooking-units } {##1} {#2} } + }{ + \msg_error:nnxxx + { cooking-units } + { group-choice-not-allowed } + {#1} + {#2} + { \clist_use:cnnn { l__cooking_units_group_ #1 _clist } { ',~ ' } { ',~ ' } { ' ~ and ~ ' } } + } + } +\__cooking_units_define_unit_group:nn { weight } { kg , dag, g, oz, lb, stick } +\__cooking_units_define_unit_group:nn { length } { m , dm , cm , mm , in } +\__cooking_units_define_unit_group:nn { volume } { l , dl , cl , ml } +\__cooking_units_define_unit_group:nn { temperature } { C , F , K , Re } +\__cooking_units_define_unit_group:nn { energy } { cal, kcal , J , kJ , eV } +\__cooking_units_define_unit_group:nn { time } { d , h , min , s } +\cs_new:Npn \__cooking_units_unit_group_add_unit_error:n #1 + { + \msg_error:nnn { cooking-units } { No-Value-given } { add-unit-to-group } + } +\cs_new:Npn \__cooking_units_unit_group_add_unit:nn #1#2 + { + \__cooking_units_error_if_group_not_defined:n {#1} + \clist_map_inline:nn {#2} + { + \__cooking_units_error_if_unit_not_defined:n {##1} + \clist_if_in:cnF { l__cooking_units_group_ #1 _clist } {##1} + { \clist_put_right:cn { l__cooking_units_group_ #1 _clist } {##1} } + } + } \seq_new:N \g__cooking_units_natural_units_seq \prop_new:N \g__cooking_units_convert_to_eV_remember_prop \seq_set_split:Nnn \g__cooking_units_natural_units_seq { , } @@ -672,12 +888,23 @@ } } } -\cs_new:Npn \__cooking_units_tl_set_fp_and_eval:Nn #1#2 - { \tl_set:Nx #1 { \fp_eval:n {#2} } } -\cs_generate_variant:Nn \__cooking_units_tl_set_fp_and_eval:Nn { Nc } +\cs_new:Npn \__cooking_units_tl_eval:Nn #1#2 { \tl_set:Nf #1 { \fp_eval:n {#2} } } +\cs_generate_variant:Nn \__cooking_units_tl_eval:Nn { Nv } +\prg_new_conditional:Npnn \__cooking_units_change_unit: { TF } + { + \bool_lazy_any:nTF + { + { \l__cooking_units_lokal_fraction_bool } + { \l__cooking_units_special_sign_bool } + { \l__cooking_units_draft_bool } + } + { \prg_return_false: } + { \prg_return_true: } + } \cs_new:Npn \__cooking_units_temperature_to_check_print_error:n #1 { - \msg_error:nn { cooking-units } { No-Value-given } + \__cooking_units_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { No-Value-given } { add-temperature-to-check } } \cs_new:Npn \__cooking_units_temperatures_to_check_define:nn #1#2 { @@ -689,18 +916,44 @@ \fp_const:cn { c__cooking_units_ #1 _min_fp } {#2} } } +\cs_new:Npn \__cooking_units_erase_options_for:n #1 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \clist_clear:c { l__cooking_units_predefined_option_ ##1 _clist } + } +\cs_new:Npn \__cooking_units_erase_options_for_error:nn #1#2 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { Value-not-allowed } { erase-all-options-for } + } +\cs_new:Npn \__cooking_units_set_options_for_error:n #1 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { No-Value-given } { set-option-for } + } +\cs_new:Npn \__cooking_units_set_options_for:nn #1#2 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \clist_set:cn { l__cooking_units_predefined_option_#1_clist } {#2} + } +\cs_new:Npn \__cooking_units_add_options_for_error:n #1 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \msg_error:nnn { cooking-units } { No-Value-given } { add-option-for } + } +\cs_new:Npn \__cooking_units_add_options_for:nn #1#2 + { + \__cooking_units_error_if_unit_not_defined:n {#1} + \clist_put_right:cn { l__cooking_units_predefined_option_ #1 _clist } {#2} + } \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 } } + \bool_if:NTF \l__cooking_units_round_to_int_bool + { , 0 } + { , \l__cooking_units_round_precision_int } + \bool_if:NT \l__cooking_units_round_commercial_bool + { , #1 } } \cs_new:Npn \__cooking_units_label_and_persons:n #1 { @@ -717,35 +970,35 @@ } \cs_new:Npn \__cooking_units_culabel:nn #1#2 { - \int_if_exist:cTF { l__cooking_units_number_of_persons_ #1 _int } + \int_if_exist:cTF { g__cooking_units_number_of_persons_ #1 _int } { \msg_error:nnn { cooking-units } { label-already-defined } {#1} }{ \__cooking_units_if_integer:nTF {#2} { - \int_new:c { l__cooking_units_number_of_persons_ #1 _int } - \int_gset:cn { l__cooking_units_number_of_persons_ #1 _int } {#2} + \int_new:c { g__cooking_units_number_of_persons_ #1 _int } + \int_gset:cn { g__cooking_units_number_of_persons_ #1 _int } {#2} } { \msg_error:nnn { cooking-units } { Number-of-persons-is-not-an-integer } {#2} } } } \cs_new:Npn \__cooking_units_reference_label_and_persons:n #1 { - \int_if_exist:cTF { l__cooking_units_number_of_persons_ #1 _int } + \int_if_exist:cTF { g__cooking_units_number_of_persons_ #1 _int } { \bool_set_true:N \l__cooking_units_calc_because_ref_was_given_bool - \int_set_eq:Nc \l__cooking_units_number_of_persons_tmpa_int - { l__cooking_units_number_of_persons_ #1 _int } + \int_set_eq:Nc \l__cooking_units_local_number_of_persons_int + { g__cooking_units_number_of_persons_ #1 _int } } { \msg_error:nnn { cooking-units } { label-not-defined } {#1} } } \cs_new:Npn \__cooking_units_curef:n #1 { - \int_if_exist:cTF { l__cooking_units_number_of_persons_ #1 _int } + \int_if_exist:cTF { g__cooking_units_number_of_persons_ #1 _int } { - \bool_if:NTF \l__cooking_units_calc_for_persons_bool - { \int_use:N \l__cooking_units_calc_for_number_of_persons_int } - { \int_use:c { l__cooking_units_number_of_persons_ #1 _int } } + \bool_if:NTF \l__cooking_units_change_number_of_persons_bool + { \int_use:N \l__cooking_units_wanted_number_of_persons_int } + { \int_use:c { g__cooking_units_number_of_persons_ #1 _int } } }{ \msg_error:nnn { cooking-units } { label-not-defined } {#1} } } \NewDocumentCommand \culabel { m m } { \__cooking_units_culabel:nn {#1} {#2} } @@ -849,28 +1102,249 @@ \__cooking_units_newtranslation_to:nnVn { German } { one (m) } \c__cooking_units_postfix_unitname_tl { ein } \__cooking_units_newtranslation_to:nnVn { German } { one (f) } \c__cooking_units_postfix_unitname_tl { eine } \__cooking_units_newtranslation_to:nnVn { German } { one (n) } \c__cooking_units_postfix_unitname_tl { ein } -\cs_new:Npn \__cooking_units_parse_input:N #1 +\cs_new_protected:Npn \__cooking_units_initialise_default:n #1 { - \bool_if:NTF \l__cooking_units_range_in_input_bool - { \__cooking_units_parse_range_in_input:ww #1 \q_stop } + \__cooking_units_set_unit:Nn \l__cooking_units_given_unit_tl {#1} + \__cooking_units_error_if_unit_not_defined:V \l__cooking_units_given_unit_tl + \bool_set_false:N \l__cooking_units_special_sign_bool + \bool_set_false:N \l__cooking_units_error_bool + \bool_set_false:N \l__cooking_units_range_in_input_bool + \bool_set_false:N \l__cooking_units_lokal_fraction_bool + \bool_set_false:N \l__cooking_units_lokal_mixed_fraction_bool + } +\cs_new_protected:Npn \__cooking_units_initialise_unit_change:n #1 + { + \tl_if_empty:nF {#1} { - \tl_if_in:nnTF {#1} { / } + \keys_set_groups:nnn { cooking-units } { change-unit } {#1} + } + \bool_if:NT \l__cooking_units_convert_to_eV_bool { \__cooking_units_convert_to_eV: } + \prop_get:NVNF \l__cooking_units_change_unit_prop \l__cooking_units_given_unit_tl \l__cooking_units_option_unit_tl + { + \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl + } + } +\cs_new_protected:Npn \__cooking_units_initialise_after_unit_change:nn #1#2 + { + \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 } + { + \keys_set_filter:nnv + { cooking-units } + { change-unit } + { l__cooking_units_predefined_option_ \l__cooking_units_option_unit_tl _clist } + } + \tl_if_empty:nF {#2} + { \keys_set_filter:nnn { cooking-units } { change-unit } {#2} } + \bool_lazy_and:nnTF + { \l__cooking_units_calc_because_ref_was_given_bool } { \l__cooking_units_change_number_of_persons_bool } + { \bool_set_true:N \l__cooking_units_lokal_persons_bool } + { \bool_set_false:N \l__cooking_units_lokal_persons_bool } + \bool_lazy_and:nnTF + { \g__cooking_units_opt_numeral_bool } { \l__cooking_units_print_numeral_bool } + { \bool_set_true:N \l__cooking_units_lokal_numeral_bool } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + } +\cs_new_protected:Npn \__cooking_units_print_input:N #1 { } +\cs_new_protected:Npn \__cooking_units_print_correct_unit: { } +\cs_new_protected:Npn \__cooking_units_do_not_process_input:NN #1#2 { } +\cs_new_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN +\cs_new_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_do_not_process_input:NN +\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cunum: + { + \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_print_numerical_input:N + \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cunum_print_correct_unit: + \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN + \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_do_not_process_input:NN + } +\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cutext: + { + \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_cutext_print_input:N + \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cutext_print_correct_unitname: + \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_cutext_pre_process_input:NN + \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_cutext_post_process_input:NN + } +\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cuam: + { + \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_cuam_print_numerical_input:N + \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cuam_print_correct_unitphrase: + \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN + \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_cuam_post_process_input:NN + } +\cs_new_protected:Npn \__cooking_units_print_numerical_input:N #1 + { + \tl_if_in:NnT #1 { . } + { + \__cooking_units_translate_let:Nxx \l__cooking_units_translation_tmpa_tl + { decimal-mark } \c__cooking_units_postfix_unitname_tl + \tl_replace_once:Nnn #1 { . } { \l__cooking_units_translation_tmpa_tl } + } + \tl_replace_once:Nnn #1 { - } \c__cooking_units_minus_tl + #1 + } +\cs_new:Npn \__cooking_units_print_fractions:nnn #1#2#3 + { + \bool_if:NT \l__cooking_units_minus_bool { \c__cooking_units_minus_tl } + \tl_if_empty:nF {#1} + { + #1 + \__cooking_units_dim_horizontal:N \l__cooking_units_mixed_frac_dim + } + \__cooking_units_frac:nn {#2} {#3} + } +\cs_new:Npn \__cooking_units_parse_input:n #1 + { + \bool_if:NTF \l__cooking_units_fourty_two_bool + { \tl_clear:N \l__cooking_units_given_amount_tl } + { \__cooking_units_set_amount:Nn \l__cooking_units_given_amount_tl {#1} } + \tl_set_rescan:NnV \l__cooking_units_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N \ % + \char_set_catcode_other:N ? % + } \l__cooking_units_given_amount_tl + \bool_lazy_or:nnTF + { \l__cooking_units_draft_bool } + { \tl_if_empty_p:N \l__cooking_units_tmpa_tl } + { + \bool_if:NTF \l__cooking_units_fourty_two_bool + { 42 } + { \l__cooking_units_tmpa_tl } + }{ + \tl_if_in:NVT \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { - \bool_lazy_or:nnTF - { \l__cooking_units_calc_persons_bool }{ \l__cooking_units_eval_fractions_bool } - { \bool_set_false:N \l__cooking_units_fraction_in_input_bool } - { \bool_set_true:N \l__cooking_units_fraction_in_input_bool } - \tl_if_in:nnTF {#1} { _ } - { \__cooking_units_parse_mixed_fraction_in_input:www #1 \q_stop } - { \__cooking_units_parse_fraction_in_input:ww #1 \q_stop } + \tl_replace_once:NVn \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } + \bool_set_true:N \l__cooking_units_range_in_input_bool + } + \__cooking_units_parsing_amount_input:V \l__cooking_units_tmpa_tl + \__cooking_units_split_input: + } + } +\cs_new:Npn \__cooking_units_parsing_amount_input:n #1 + { + \cs_set_eq:NN \__cooking_units_parse:N \__cooking_units_start_loop:N + \tl_map_function:nN {#1} \__cooking_units_parse:N + } +\cs_generate_variant:Nn \__cooking_units_parsing_amount_input:n { V } +\cs_new:Npn \__cooking_units_split_input: + { + \bool_if:NTF \l__cooking_units_lokal_fraction_bool + { + \tl_set_eq:NN \l__cooking_units_number_tmpb_tl \l__cooking_units_tmpa_tl + \bool_lazy_or:nnT + { \l__cooking_units_lokal_persons_bool }{ \l__cooking_units_eval_fractions_bool } + { \bool_set_false:N \l__cooking_units_lokal_fraction_bool } + \bool_if:NTF \l__cooking_units_lokal_mixed_fraction_bool + { \__cooking_units_parse_mixed_fraction_in_input: } + { \__cooking_units_parse_fraction_in_input: } + }{ + \bool_if:NT \l__cooking_units_lokal_mixed_fraction_bool + { \msg_error:nnV { cooking-units } { missing-slash } \l__cooking_units_given_amount_tl } + \bool_if:NTF \l__cooking_units_range_in_input_bool + { + \tl_set_eq:NN \l__cooking_units_number_tmpb_tl \l__cooking_units_tmpa_tl + \__cooking_units_parse_range_in_input: + }{ + \tl_set_eq:NN \l__cooking_units_number_tmpa_tl \l__cooking_units_tmpa_tl + \__cooking_units_parse_number_in_input: + } + } + } +\cs_new:Npn \__cooking_units_start_loop:N #1 + { + \tl_clear:N \l__cooking_units_tmpa_tl + \bool_set_false:N \l__cooking_units_decimal_in_input_bool + \cs_set_eq:NN \__cooking_units_parse:N \__cooking_units_parse_input_loop_aux:N + \tl_if_in:NnTF \l__cooking_units_input_value_signs_tl {#1} + { \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} } + { + \tl_map_function:nN {#1} \__cooking_units_parse:N + } + } +\cs_new:Npn \__cooking_units_parse_input_loop_aux:N #1 + { + \tl_if_in:NnTF \l__cooking_units_input_digits_tl {#1} + { \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} } + { + \tl_if_in:NnTF \l__cooking_units_input_decimal_mark_tl {#1} + { + \__cooking_units_check_repitition:NN + \q__cooking_units_decimal + \l__cooking_units_decimal_in_input_bool + \tl_put_right:Nn \l__cooking_units_tmpa_tl { . } + }{ + \tl_if_in:NnTF \l__cooking_units_input_allowed_special_signs_tl {#1} + { + \bool_set_true:N \l__cooking_units_special_sign_bool + \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} + }{ + \bool_if:NTF \l__cooking_units_range_in_input_bool + { + \tl_if_eq:nnTF \q__cooking_units_range {#1} + { + \tl_set_eq:NN \l__cooking_units_number_tmpa_tl \l__cooking_units_tmpa_tl + \cs_set_eq:NN \__cooking_units_parse:N \__cooking_units_start_loop:N + }{ + \tl_if_in:xnTF + { + \exp_not:V \l__cooking_units_input_fraction_sign_tl + \exp_not:V \l__cooking_units_input_mixed_fraction_sign_tl + } {#1} + { \msg_error:nnV { cooking-units } { fraction-not-allowed-with-range } \l__cooking_units_given_amount_tl } + { \msg_error:nnnV { cooking-units } { Token-not-allowed } {#1} \l__cooking_units_given_amount_tl } + \bool_set_true:N \l__cooking_units_error_bool + \tl_map_break: + } + }{ + \tl_if_in:NnTF \l__cooking_units_input_fraction_sign_tl {#1} + { + \__cooking_units_check_repitition:NN + \q__cooking_units_frac + \l__cooking_units_lokal_fraction_bool + \tl_set_eq:NN \l__cooking_units_number_tmpa_tl \l__cooking_units_tmpa_tl + \cs_set_eq:NN \__cooking_units_parse:N \__cooking_units_start_loop:N + }{ + \tl_if_in:NnTF \l__cooking_units_input_mixed_fraction_sign_tl {#1} + { + \__cooking_units_check_repitition:NN + \q__cooking_units_mixed_frac + \l__cooking_units_lokal_mixed_fraction_bool + \bool_if:NT \l__cooking_units_lokal_fraction_bool + { \msg_error:nnV { cooking-units } { fraction-wrong-order } \l__cooking_units_given_amount_tl } + \tl_set_eq:NN \l__cooking_units_mixed_fraction_tl \l__cooking_units_tmpa_tl + \cs_set_eq:NN \__cooking_units_parse:N \__cooking_units_start_loop:N + }{ + \msg_error:nnnV { cooking-units } { Token-not-allowed } {#1} \l__cooking_units_given_amount_tl + \bool_set_true:N \l__cooking_units_error_bool + \tl_map_break: + } + } + } + } + } + } + } +\cs_new:Npn \__cooking_units_check_repitition:NN #1#2 + { + \bool_if:NTF #2 + { + \tl_case:NnTF #1 + { + \q__cooking_units_decimal + { \msg_error:nnV { cooking-units } { Second-decimal-sign-not-allowed } \l__cooking_units_given_amount_tl } + \q__cooking_units_frac + { \msg_error:nnV { cooking-units } { Second-fraction-sign-not-allowed } \l__cooking_units_given_amount_tl } + \q__cooking_units_mixed_frac + { \msg_error:nnV { cooking-units } { Second-mixed-fraction-sign-not-allowed } \l__cooking_units_given_amount_tl } } - { \__cooking_units_parse_number_in_input:n {#1} } + { \bool_set_true:N \l__cooking_units_error_bool } + { \msg_error:nn { cooking-units } { internal-error } } } + { \bool_set_true:N #2 } } -\cs_generate_variant:Nn \__cooking_units_parse_input:N { V } -\cs_new:Npn \__cooking_units_parse_number_in_input:n #1 +\cs_new:Npn \__cooking_units_parse_number_in_input: { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_number_tmpa_tl \__cooking_units_process_and_print_number_in_input:N \l__cooking_units_number_tmpa_tl } \cs_new:Npn \__cooking_units_process_and_print_number_in_input:N #1 @@ -880,10 +1354,8 @@ \__cooking_units_post_process_input:NN #1 \q_no_value \__cooking_units_print_input:N #1 } -\cs_new:Npn \__cooking_units_parse_range_in_input:ww #1 \q__cooking_units_range #2 \q_stop +\cs_new:Npn \__cooking_units_parse_range_in_input: { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_number_tmpa_tl - \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_number_tmpb_tl \__cooking_units_pre_process_input:NN \l__cooking_units_number_tmpa_tl \l__cooking_units_number_tmpb_tl \__cooking_units_calculate_and_store_in:N \l__cooking_units_number_tmpa_tl \__cooking_units_calculate_and_store_in:N \l__cooking_units_number_tmpb_tl @@ -894,44 +1366,43 @@ { \tl_use:N \l__cooking_units_cunum_range_sign_tl } \__cooking_units_print_input:N \l__cooking_units_number_tmpb_tl } -\cs_new:Npn \__cooking_units_parse_fraction_in_input:ww #1/#2 \q_stop +\cs_new:Npn \__cooking_units_parse_fraction_in_input: { - \__cooking_units_parse_input_and_safe_in:nN {#1} \l__cooking_units_number_tmpa_tl - \__cooking_units_parse_input_and_safe_in:nN {#2} \l__cooking_units_number_tmpb_tl \bool_lazy_or:nnTF - { \l__cooking_units_fraction_in_input_bool } + { \l__cooking_units_lokal_fraction_bool } { \l__cooking_units_special_sign_bool } { \__cooking_units_tl_if_in_remove_and_set_bool:NnN \l__cooking_units_number_tmpa_tl { - } \l__cooking_units_minus_bool \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_number_tmpb_tl { - } \l__cooking_units_minus_bool - \__cooking_units_formatiere_fractions:nnn + \__cooking_units_print_fractions:nnn { } { \l__cooking_units_number_tmpa_tl } { \l__cooking_units_number_tmpb_tl } }{ - \__cooking_units_tl_set_fp_and_eval:Nn \l__cooking_units_number_tmpa_tl + \fp_compare:nNnT { \l__cooking_units_number_tmpb_tl } = { 0 } + { \msg_error:nnV { cooking-units } { Division-by-zero } \l__cooking_units_given_amount_tl } + \__cooking_units_tl_eval:Nn \l__cooking_units_number_tmpa_tl { \l__cooking_units_number_tmpa_tl / \l__cooking_units_number_tmpb_tl } \__cooking_units_process_and_print_number_in_input:N \l__cooking_units_number_tmpa_tl } } -\cs_new:Npn \__cooking_units_parse_mixed_fraction_in_input:www #1_#2/#3 \q_stop +\cs_new:Npn \__cooking_units_parse_mixed_fraction_in_input: { - \__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_number_tmpa_tl - \__cooking_units_parse_input_and_safe_in:nN {#3} \l__cooking_units_number_tmpb_tl \__cooking_units_tl_if_in_remove_and_set_bool:NnN \l__cooking_units_mixed_fraction_tl { - } \l__cooking_units_minus_bool \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_number_tmpa_tl { - } \l__cooking_units_minus_bool \__cooking_units_tl_if_in_remove_and_reverse_bool:NnN \l__cooking_units_number_tmpb_tl { - } \l__cooking_units_minus_bool \bool_lazy_or:nnTF - { \l__cooking_units_fraction_in_input_bool } + { \l__cooking_units_lokal_fraction_bool } { \l__cooking_units_special_sign_bool } { - \__cooking_units_formatiere_fractions:nnn + \__cooking_units_print_fractions:nnn { \l__cooking_units_mixed_fraction_tl } { \l__cooking_units_number_tmpa_tl } { \l__cooking_units_number_tmpb_tl } }{ - \__cooking_units_tl_set_fp_and_eval:Nn \l__cooking_units_number_tmpa_tl + \fp_compare:nNnT { \l__cooking_units_number_tmpb_tl } = { 0 } + { \msg_error:nnV { cooking-units } { Division-by-zero } \l__cooking_units_given_amount_tl } + \__cooking_units_tl_eval:Nn \l__cooking_units_number_tmpa_tl { \bool_if:NTF \l__cooking_units_minus_bool { - \l__cooking_units_mixed_fraction_tl - } @@ -941,61 +1412,6 @@ \__cooking_units_process_and_print_number_in_input:N \l__cooking_units_number_tmpa_tl } } -\cs_new:Npn \__cooking_units_parse_input_and_safe_in:nN #1 #2 - { - \tl_clear:N \l__cooking_units_tmpa_tl - \bool_set_false:N \l__cooking_units_decimal_in_input_bool - \__cooking_units_parse_vorzeichen_and_rest:Nw #1 \q_stop - \bool_if:NTF \l__cooking_units_error_bool - { \tl_set:Nn #2 {#1} } - { \tl_set_eq:NN #2 \l__cooking_units_tmpa_tl } - } -\cs_new:Npn \__cooking_units_parse_vorzeichen_and_rest:Nw #1#2 \q_stop - { - \tl_if_in:NnTF \l__cooking_units_input_value_signs_tl {#1} - { \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} } - { - \tl_map_function:nN {#1} \__cooking_units_parse_input_for_safety_aux:N - } - \bool_if:NF \l__cooking_units_error_bool - { \tl_map_function:nN {#2} \__cooking_units_parse_input_for_safety_aux:N } - } -\cs_new:Npn \__cooking_units_parse_input_for_safety_aux:N #1 - { - \tl_if_in:NnTF \l__cooking_units_input_digits_tl {#1} - { \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} } - { - \tl_if_in:NnTF \l__cooking_units_input_decimal_mark_tl {#1} - { - \bool_if:NT \l__cooking_units_decimal_in_input_bool - { - \msg_error:nn { cooking-units } - { Second-decimal-sign-not-allowed } - } - \bool_set_true:N \l__cooking_units_decimal_in_input_bool - \tl_put_right:Nn \l__cooking_units_tmpa_tl { . } - }{ - \tl_if_in:NnTF \l__cooking_units_input_allowed_special_signs_tl {#1} - { - \bool_set_true:N \l__cooking_units_special_sign_bool - \tl_put_right:Nn \l__cooking_units_tmpa_tl {#1} - }{ - \bool_if:NTF \l__cooking_units_range_in_input_bool - { - \tl_if_in:nnTF { / _ } {#1} - { \msg_error:nnn { cooking-units } { fraction-not-allowed-with-range } {#1} } - { \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} } - } - \bool_set_true:N \l__cooking_units_error_bool - \tl_map_break: - } - } - } - } \cs_new:Npn \__cooking_units_calculate_and_store_in:N #1 { \bool_if:NF \l__cooking_units_error_bool @@ -1009,8 +1425,11 @@ { \l__cooking_units_using_cutext_bool } { ! \l__cooking_units_cutext_change_unit_bool } { \tl_set_eq:NN \l__cooking_units_tmpa_tl #1 } { \__cooking_units_calculate_input_and_store_in:nN {#1} \l__cooking_units_tmpa_tl } - \bool_if:NT \l__cooking_units_calc_persons_bool - { \__cooking_units_calc_for_number_of_persons_and_store_in:NN \l__cooking_units_tmpa_tl \l__cooking_units_tmpa_tl } + \bool_if:NT \l__cooking_units_lokal_persons_bool + { + \__cooking_units_calc_for_number_of_persons_and_store_in:NN + \l__cooking_units_tmpa_tl \l__cooking_units_tmpa_tl + } \__cooking_units_round_calculated_input:NV \l__cooking_units_tmpa_tl \l__cooking_units_tmpa_tl \__cooking_units_check_temperature_limit:N \l__cooking_units_tmpa_tl } @@ -1020,112 +1439,72 @@ \cs_new:Npn \__cooking_units_calculate_input_and_store_in:nN #1#2 { \fp_set:Nn \l__cooking_units_tmpa_fp {#1} - \tl_if_in:cnTF { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } { \l__cooking_units_tmpa_fp } + \tl_if_in:cnTF { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } { \l__cooking_units_tmpa_fp } { - \__cooking_units_tl_set_fp_and_eval:Nc #2 { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } + \__cooking_units_tl_eval:Nv #2 { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } }{ - \__cooking_units_tl_set_fp_and_eval:Nn #2 + \__cooking_units_tl_eval:Nn #2 { \l__cooking_units_tmpa_fp * \tl_use:c { l__cooking_units_tmpa_ \l__cooking_units_given_unit_tl _ tl } } } } \cs_new:Npn \__cooking_units_calc_for_number_of_persons_and_store_in:NN #1#2 { \int_compare:nNnF - { \l__cooking_units_calc_for_number_of_persons_int } + { \l__cooking_units_wanted_number_of_persons_int } = - { \l__cooking_units_number_of_persons_tmpa_int } + { \l__cooking_units_local_number_of_persons_int } { - \__cooking_units_tl_set_fp_and_eval:Nn #1 + \__cooking_units_tl_eval:Nn #1 { - \l__cooking_units_calc_for_number_of_persons_int / - \l__cooking_units_number_of_persons_tmpa_int * + \l__cooking_units_wanted_number_of_persons_int / + \l__cooking_units_local_number_of_persons_int * #2 } } } \cs_new:Npn \__cooking_units_check_number_for_rounding:n #1 { - \bool_set_false:N \l__cooking_units_round_decimal_part_bool - \__cooking_units_check_number_after_dot_aux:w #1 . \q_recursion_tail . + \bool_set_false:N \l__cooking_units_round_number_bool + \__cooking_units_check_number_after_dot_aux:ww #1 . \q_recursion_tail . \q_recursion_stop } -\cs_new:Npn \__cooking_units_check_number_after_dot_aux:w #1. #2 . +\cs_new:Npn \__cooking_units_check_number_after_dot_aux:ww #1 . #2 . { - \quark_if_recursion_tail_stop:n {#2} - \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:nNnF - { \tl_count:n {#2} } < { \l_tmpa_int } - { \bool_set_true:N \l__cooking_units_round_decimal_part_bool } + \quark_if_recursion_tail_stop_do:nn {#2} + { + \bool_lazy_or:nnF + { \l__cooking_units_round_precision_positive_bool } + { \l__cooking_units_round_to_int_bool } + { \bool_set_true:N \l__cooking_units_round_number_bool } + } + \int_compare:nNnT + { \tl_count:n {#2} } > + { + \bool_if:NTF \l__cooking_units_round_to_int_bool + { 0 } + { \l__cooking_units_round_precision_int } + } + { \bool_set_true:N \l__cooking_units_round_number_bool } \use_none_delimit_by_q_recursion_stop:w } -\cs_new:Npn \__cooking_units_round_calculated_input:NN #1#2 +\cs_new:Npn \__cooking_units_round_calculated_input:Nn #1#2 { \__cooking_units_check_number_for_rounding:n {#2} - \tl_set:Nx #1 + \tl_set:Nf #1 { - \bool_if:NTF \l__cooking_units_round_decimal_part_bool + \bool_if:NTF \l__cooking_units_round_number_bool { \fp_eval:n { round ( \__cooking_units_rounding_function:n {#2} ) } } {#2} } } -\cs_generate_variant:Nn \__cooking_units_round_calculated_input:NN { NV } -\cs_new_protected:Npn \__cooking_units_print_input:N #1 { } -\cs_new_protected:Npn \__cooking_units_print_correct_unit: { } -\cs_new_protected:Npn \__cooking_units_do_not_process_input:NN #1#2 { } -\cs_new_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN -\cs_new_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_do_not_process_input:NN -\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cunum: - { - \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_print_numerical_input:N - \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cunum_print_correct_unit: - \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN - \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_do_not_process_input:NN - } -\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cutext: - { - \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_cutext_print_input:N - \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cutext_print_correct_unitname: - \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_cutext_pre_process_input:NN - \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_cutext_post_process_input:NN - } -\cs_new_protected:Npn \__cooking_units_set_process_and_print_for_cuam: - { - \cs_set_eq:NN \__cooking_units_print_input:N \__cooking_units_cuam_print_numerical_input:N - \cs_set_eq:NN \__cooking_units_print_correct_unit: \__cooking_units_cuam_print_correct_unitphrase: - \cs_set_eq:NN \__cooking_units_pre_process_input:NN \__cooking_units_do_not_process_input:NN - \cs_set_eq:NN \__cooking_units_post_process_input:NN \__cooking_units_cuam_post_process_input:NN - } -\cs_new_protected:Npn \__cooking_units_print_numerical_input:N #1 - { - \tl_if_in:NnT #1 { . } - { - \__cooking_units_translate_let:Nxx \l__cooking_units_translation_tmpa_tl - { decimal-mark } \c__cooking_units_postfix_unitname_tl - \tl_replace_once:Nnn #1 { . } { \l__cooking_units_translation_tmpa_tl } - } - \tl_if_in:NnT #1 { - } - { \tl_replace_once:NnV #1 { - } \c__cooking_units_minus_tl } - #1 - } -\cs_new:Npn \__cooking_units_formatiere_fractions:nnn #1#2#3 - { - \bool_if:NT \l__cooking_units_minus_bool { \c__cooking_units_minus_tl } - \tl_if_empty:nF {#1} - { - #1 - \hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { } - } - \__cooking_units_frac:nn {#2} {#3} - } +\cs_generate_variant:Nn \__cooking_units_round_calculated_input:Nn { NV } \cs_new:Npn \__cooking_units_check_temperature_limit:N #1 { \bool_if:NT \l__cooking_units_check_temperature_bool { \seq_if_in:NVT \l__cooking_units_temperatures_to_check_seq \l__cooking_units_option_unit_tl { - \fp_compare:cNnT + \fp_compare:vNnT { c__cooking_units_ \l__cooking_units_option_unit_tl _min_fp } > {#1} { \msg_error:nnxx { cooking-units } @@ -1155,7 +1534,7 @@ \str_if_eq:nnTF {#1} { < } { \tl_if_in:NoT \l__cooking_units_input_allowed_special_signs_tl { < } - { \msg_error:nn {cooking-units} { <-not-allowed-as-special-sign } } + { \msg_error:nn { cooking-units } { <-not-allowed-as-special-sign } } \tl_clear:N \l__cooking_units_tmpa_tl \tl_put_right:Nx \l__cooking_units_tmpa_tl { \tl_to_str:N < } \__cooking_units_grab_arrows_for_safety_do_afterwards:nN @@ -1176,101 +1555,25 @@ \cs_new:Npn \__cooking_units_cunum:nnnnn #1#2#3#4#5 { \__cooking_units_cunum_initialise:nnnnn {#1} {#2} {#3} {#4} {#5} - \__cooking_units_cunum_parse_numerical_input:n {#3} + \l__cooking_units_cunum_hook_tl + \__cooking_units_parse_input:n {#3} \__cooking_units_print_correct_unit: } \cs_new_protected:Npn \__cooking_units_cunum_initialise:nnnnn #1#2#3#4#5 { \__cooking_units_set_process_and_print_for_cunum: \tl_set:Nn \l__cooking_units_phantom_tl {#4} - \__cooking_units_initialise_default:nnn {#1} {#2} {#5} - \__cooking_units_initialise_unit_change:nnn {#1} {#2} {#5} + \__cooking_units_initialise_default:n {#5} + \__cooking_units_initialise_unit_change:n {#2} \__cooking_units_initialise_after_unit_change:nn {#1} {#2} } -\cs_new_protected:Npn \__cooking_units_initialise_default:nnn #1#2#3 - { - \tl_set:Nn \l__cooking_units_given_unit_tl {#3} - \__cooking_units_error_if_unit_not_defined:V \l__cooking_units_given_unit_tl - \bool_set_false:N \l__cooking_units_special_sign_bool - \bool_set_false:N \l__cooking_units_error_bool - \bool_set_false:N \l__cooking_units_range_in_input_bool - \bool_set_false:N \l__cooking_units_fraction_in_input_bool - } -\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:NVNF \l__cooking_units_change_unit_prop \l__cooking_units_given_unit_tl \l__cooking_units_option_unit_tl - { - \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl - } - } -\cs_new_protected:Npn \__cooking_units_initialise_after_unit_change:nn #1#2 - { - \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 } - { - \keys_set_filter:nnv - { cooking-units } - { change-unit } - { l__cooking_units_predefined_option_ \l__cooking_units_option_unit_tl _clist } - } - \tl_if_empty:nF {#2} - { \keys_set_filter:nnn { cooking-units } { change-unit } {#2} } - \bool_lazy_and:nnTF - { \l__cooking_units_calc_because_ref_was_given_bool } { \l__cooking_units_calc_for_persons_bool } - { \bool_set_true:N \l__cooking_units_calc_persons_bool } - { \bool_set_false:N \l__cooking_units_calc_persons_bool } - } -\cs_new:Npn \__cooking_units_cunum_parse_numerical_input:n #1 - { - \bool_if:NTF \l__cooking_units_parse_input_bool - { \__cooking_units_parse_and_evaluate_input:n {#1} } - { \__cooking_units_do_not_parse:n {#1} } - } -\cs_new:Npn \__cooking_units_do_not_parse:n #1 - { - \tl_set_rescan:Nnn \l__cooking_units_number_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N \ % - } {#1} - \l__cooking_units_number_tmpa_tl - } -\cs_new:Npn \__cooking_units_parse_and_evaluate_input:n #1 - { - \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N \ % - \char_set_catcode_other:N ? % - } {#1} - \tl_if_empty:NF \l__cooking_units_tmpa_tl - { - \tl_if_in:NVT \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl - { - \tl_replace_once:NVn \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } - \bool_set_true:N \l__cooking_units_range_in_input_bool - } - \__cooking_units_parse_input:V \l__cooking_units_tmpa_tl - } - } \cs_new:Npn \__cooking_units_cunum_print_correct_unit: { \tl_if_empty:NF \l__cooking_units_phantom_tl { \phantom { \l__cooking_units_phantom_tl } } \tl_use:N \l__cooking_units_value_unit_space_tl - \bool_lazy_any:nTF - { - { \l__cooking_units_fraction_in_input_bool } - { \l__cooking_units_special_sign_bool } - { ! \l__cooking_units_parse_input_bool } - } - { \__cooking_units_translate:xx \l__cooking_units_given_unit_tl \c__cooking_units_postfix_unit_tl } + \__cooking_units_change_unit:TF { \__cooking_units_translate:xx \l__cooking_units_option_unit_tl \c__cooking_units_postfix_unit_tl } + { \__cooking_units_translate:xx \l__cooking_units_given_unit_tl \c__cooking_units_postfix_unit_tl } } \NewDocumentCommand \cutext { d<> O{} m m } { @@ -1278,9 +1581,12 @@ { \cutext } { \group_begin: - \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4} - \bool_set_false:N \l__cooking_units_cutext_uppercase_word_bool - \__cooking_units_cutext_do:nnnn {#1} {#2} {#3} {#4} + \__cooking_units_change_cutext_to_cunum:nTF {#2} + { \__cooking_units_cunum:nnnnn {#1} {#2} {#3} { } {#4} } + { + \bool_set_false:N \l__cooking_units_cutext_uppercase_word_bool + \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4} + } \group_end: } } @@ -1290,9 +1596,12 @@ { \Cutext } { \group_begin: - \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4} - \bool_set_true:N \l__cooking_units_cutext_uppercase_word_bool - \__cooking_units_cutext_do:nnnn {#1} {#2} {#3} {#4} + \__cooking_units_change_cutext_to_cunum:nTF {#2} + { \__cooking_units_cunum:nnnnn {#1} {#2} {#3} { } {#4} } + { + \bool_set_true:N \l__cooking_units_cutext_uppercase_word_bool + \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4} + } \group_end: } } @@ -1300,56 +1609,28 @@ { \bool_set_true:N \l__cooking_units_using_cutext_bool \__cooking_units_set_process_and_print_for_cutext: - \__cooking_units_initialise_default:nnn {#1} {#2} {#3} + \__cooking_units_initialise_default:n {#3} \bool_if:NTF \l__cooking_units_cutext_change_unit_bool - { \__cooking_units_initialise_unit_change:nnn {#1} {#2} {#3} } + { \__cooking_units_initialise_unit_change:n {#2} } { \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl } \__cooking_units_initialise_after_unit_change:nn {#1} {#2} - } -\cs_new:Npn \__cooking_units_cutext_do:nnnn #1#2#3#4 - { - \bool_if:NTF \l__cooking_units_cutext_to_cunum_bool - { \cunum <#1> [#2] {#3} {#4} } - { - \__cooking_units_cutext:nnnn {#1} {#2} {#3} {#4} - } + \bool_if:NT \l__cooking_units_fourty_two_bool + { \tl_set:Nn \l__cooking_units_cutext_last_value_tl { 42 } } } \cs_new:Npn \__cooking_units_cutext:nnnn #1#2#3#4 { - \bool_if:NTF \l__cooking_units_parse_input_bool - { - \bool_if:NTF \l__cooking_units_cutext_old_bool - { - \__cooking_units_old_cutext_default:nnn {#2} {#3} {#4} - \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl - \__cooking_units_cutext_print_correct_unitname: - }{ - \__cooking_units_parse_and_evaluate_input:n {#3} - \__cooking_units_print_correct_unit: - } - }{ - \__cooking_units_do_not_parse:n {#3} - \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl - \__cooking_units_cutext_print_correct_unitname: - } - } -\prg_new_conditional:Npnn \__cooking_units_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:N #1 { TF } - { - \bool_lazy_and:nnTF - { \g__cooking_units_opt_numeral_bool } - { \l__cooking_units_local_numeral_bool } - { - \__cooking_units_if_parse_and_integer:VTF #1 - { - \int_compare:nNnTF {#1} < { \l__cooking_units_print_numerals_below_int } - { \prg_return_true: } - { \prg_return_false: } - }{ \prg_return_false: } - }{ \prg_return_false: } + \__cooking_units_cutext_initialise:nnn {#1} {#2} {#4} + \bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool + { \l__cooking_units_Cutext_hook_tl } + { \l__cooking_units_cutext_hook_tl } + \bool_if:NTF \l__cooking_units_cutext_old_bool + { \__cooking_units_old_cutext:nnn {#2} {#3} {#4} } + { \__cooking_units_parse_input:n {#3} } + \__cooking_units_print_correct_unit: } \cs_new_protected:Npn \__cooking_units_cutext_print_input:Nn #1#2 { - \__cooking_units_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:NTF #1 + \bool_if:NTF \l__cooking_units_lokal_numeral_bool { \__cooking_units_int_if_equal_one:nTF {#1} { @@ -1370,52 +1651,27 @@ } \cs_generate_variant:Nn \__cooking_units_cutext_print_input:Nn { NV } \cs_new_protected:Npn \__cooking_units_cutext_print_input:N #1 - { \__cooking_units_cutext_print_input:NV #1 \l__cooking_units_option_unit_tl } + { + \__cooking_units_change_unit:TF + { \__cooking_units_cutext_print_input:NV #1 \l__cooking_units_option_unit_tl } + { \__cooking_units_cutext_print_input:NV #1 \l__cooking_units_given_unit_tl } + } \cs_new:Npn \__cooking_units_cutext_print_correct_unitname: { \l__cooking_units_cutext_space_tl - \bool_lazy_any:nTF - { - { \l__cooking_units_fraction_in_input_bool } - { \l__cooking_units_special_sign_bool } - { ! \l__cooking_units_parse_input_bool } - } - { \__cooking_units_translate:xx \l__cooking_units_given_unit_tl \c__cooking_units_postfix_unitname_pl_tl } + \__cooking_units_change_unit:TF { \__cooking_units_fp_if_equal_one:nTF { \l__cooking_units_cutext_last_value_tl } { \__cooking_units_translate:xx \l__cooking_units_option_unit_tl \c__cooking_units_postfix_unitname_tl } { \__cooking_units_translate:xx \l__cooking_units_option_unit_tl \c__cooking_units_postfix_unitname_pl_tl } } + { \__cooking_units_translate:xx \l__cooking_units_given_unit_tl \c__cooking_units_postfix_unitname_pl_tl } } \cs_new:Npn \__cooking_units_cutext_pre_process_input:NN #1#2 { - \__cooking_units_cutext_check_unitname_consequences:NN #1#2 - } -\cs_new:Npn \__cooking_units_cutext_post_process_input:NN #1#2 - { - \bool_if:NTF \l__cooking_units_range_in_input_bool - { - \tl_set_eq:NN \l__cooking_units_cutext_last_value_tl #2 - \bool_if:NT \g__cooking_units_opt_numeral_bool - { - \bool_lazy_and:nnF - { \fp_compare_p:nNn {#1} < { \l__cooking_units_print_numerals_below_int } } - { \fp_compare_p:nNn {#2} < { \l__cooking_units_print_numerals_below_int } } - { \bool_set_false:N \l__cooking_units_local_numeral_bool } - } - } - { \tl_set_eq:NN \l__cooking_units_cutext_last_value_tl #1 } - } -\cs_new:Npn \__cooking_units_cutext_check_unitname_consequences:NN #1#2 - { - \bool_lazy_any:nTF - { - { \l__cooking_units_fraction_in_input_bool } - { \l__cooking_units_special_sign_bool } - { ! \l__cooking_units_parse_input_bool } - } - { \tl_set_eq:NN \l__cooking_units_tmpb_tl \l__cooking_units_given_unit_tl } + \__cooking_units_change_unit:TF { \tl_set_eq:NN \l__cooking_units_tmpb_tl \l__cooking_units_option_unit_tl } + { \tl_set_eq:NN \l__cooking_units_tmpb_tl \l__cooking_units_given_unit_tl } \__cooking_units_unitname_get:NxF \l__cooking_units_tmpa_tl \l__cooking_units_tmpb_tl { \msg_warning:nnx @@ -1426,38 +1682,42 @@ \__cooking_units_set_process_and_print_for_cunum: } } -\cs_new:Npn \__cooking_units_old_cutext_default:nnn #1#2#3 +\cs_new:Npn \__cooking_units_cutext_post_process_input:NN #1#2 { - \bool_if:NTF \l__cooking_units_parse_input_bool + \bool_if:NF \l__cooking_units_special_sign_bool { - \tl_set:Nn \l__cooking_units_cutext_last_value_tl {#2} - \tl_if_in:NVTF \l__cooking_units_cutext_last_value_tl \l__cooking_units_input_range_sign_tl - { - \tl_replace_once:NVn \l__cooking_units_cutext_last_value_tl - \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } - \__cooking_units_old_cutext_parse_range:Vn \l__cooking_units_cutext_last_value_tl {#3} - }{ - \__cooking_units_cutext_print_input:Nn \l__cooking_units_cutext_last_value_tl {#3} - } + \__cooking_units_cutext_post_process_input_aux:NN #1#2 } - {#2} } -\cs_new:Npn \__cooking_units_old_cutext_parse_range:Nn #1 #2 +\cs_new:Npn \__cooking_units_cutext_post_process_input_aux:NN #1#2 { - \__cooking_units_old_cutext_parse_range_aux:nww {#2} #1 \q_stop + \__cooking_units_bool_set_if_integers:NNN \l__cooking_units_tmpa_bool #1 #2 + \bool_if:NTF \l__cooking_units_range_in_input_bool + { \tl_set_eq:NN \l__cooking_units_cutext_last_value_tl #2 } + { \tl_set_eq:NN \l__cooking_units_cutext_last_value_tl #1 } + \bool_if:NT \l__cooking_units_lokal_numeral_bool + { \__cooking_units_cutext_post_process_input_numerals:NN #1#2 } } -\cs_generate_variant:Nn \__cooking_units_old_cutext_parse_range:Nn { V } -\cs_new:Npn \__cooking_units_old_cutext_parse_range_aux:nww #1 #2 \q__cooking_units_range #3 \q_stop +\cs_new:Npn \__cooking_units_cutext_post_process_input_numerals:NN #1#2 { - \tl_set:Nn \l__cooking_units_tmpa_tl {#2} - \tl_set:Nn \l__cooking_units_cutext_last_value_tl {#3} - \__cooking_units_cutext_print_input:Nn \l__cooking_units_tmpa_tl {#1} - \tl_use:N \l__cooking_units_cutext_range_sign_tl - \__cooking_units_cutext_print_input:Nn \l__cooking_units_cutext_last_value_tl {#1} + \bool_if:NTF \l__cooking_units_tmpa_bool + { + \bool_if:NTF \l__cooking_units_range_in_input_bool + { + \bool_lazy_and:nnF + { \int_compare_p:nNn {#1} < { \l__cooking_units_print_numerals_below_int } } + { \int_compare_p:nNn {#2} < { \l__cooking_units_print_numerals_below_int } } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + }{ + \int_compare:nNnF {#1} < { \l__cooking_units_print_numerals_below_int } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + } + } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } } \tl_const:Nn \c__cooking_units_cuam_marker_tl { __cooking_units_cunum } \tl_new:c { l__cooking_units_tmpa_ \c__cooking_units_cuam_marker_tl _ tl } -\tl_set:cn { l__cooking_units_tmpa_ \c__cooking_units_cuam_marker_tl _ tl } { \c_one_fp } +\tl_set:cn { l__cooking_units_tmpa_ \c__cooking_units_cuam_marker_tl _ tl } { 1.0 } \clist_new:c { l__cooking_units_predefined_option_ \c__cooking_units_cuam_marker_tl _clist } \NewDocumentCommand \cuam { d<> O{} m } { @@ -1466,115 +1726,94 @@ { \group_begin: \__cooking_units_cuam_initialise:nn {#1} {#2} + \l__cooking_units_cuam_hook_tl \__cooking_units_cuam:n {#3} \group_end: } } \cs_new:Npn \__cooking_units_cuam:n #1 { - \bool_if:NTF \l__cooking_units_parse_input_bool - { - \bool_if:NTF \l__cooking_units_cuam_old_bool - { \__cooking_units_cuam_old:n {#1} } - { - \__cooking_units_parse_and_evaluate_input:n {#1} - \__cooking_units_print_correct_unit: - } - } - { \__cooking_units_do_not_parse:n {#1} } + \bool_if:NTF \l__cooking_units_cuam_old_bool + { \__cooking_units_cuam_old:n {#1} } + { + \__cooking_units_parse_input:n {#1} + \__cooking_units_print_correct_unit: + } } \cs_new_protected:Npn \__cooking_units_cuam_initialise:nn #1#2 { \__cooking_units_set_process_and_print_for_cuam: \tl_set_eq:NN \l__cooking_units_given_unit_tl \c__cooking_units_cuam_marker_tl \tl_set_eq:NN \l__cooking_units_option_unit_tl \c__cooking_units_cuam_marker_tl + \bool_set_false:N \l__cooking_units_lokal_phrase_bool \__cooking_units_initialise_after_unit_change:nn {#1} {#2} } \cs_new_protected:Npn \__cooking_units_cuam_post_process_input:NN #1#2 { - \__cooking_units_if_integer:VTF #1 - { \bool_set_true:N \l__cooking_units_tmpa_bool } - { \bool_set_false:N \l__cooking_units_tmpa_bool } + \bool_if:NF \l__cooking_units_special_sign_bool + { \__cooking_units_cuam_post_process_input_aux:NN #1 #2 } + } +\cs_new:Npn \__cooking_units_cuam_post_process_input_aux:NN #1#2 + { + \__cooking_units_bool_set_if_integers:NNN \l__cooking_units_tmpa_bool #1 #2 \bool_lazy_and:nnT - { \l__cooking_units_range_in_input_bool } { \l__cooking_units_tmpa_bool } + { \l__cooking_units_use_phrases_bool } { \l__cooking_units_tmpa_bool } { - \__cooking_units_if_integer:VTF #2 - { \bool_set_true:N \l__cooking_units_tmpa_bool } - { \bool_set_false:N \l__cooking_units_tmpa_bool } + \__cooking_units_cuam_post_process_input_phrases:NN #1#2 } - \bool_lazy_and:nnT - { \l__cooking_units_use_phrases_bool } { \l__cooking_units_tmpa_bool } + \bool_if:NT \l__cooking_units_lokal_numeral_bool + { + \__cooking_units_cuam_post_process_input_numerals:NN #1#2 + } + } +\cs_new:Npn \__cooking_units_cuam_post_process_input_phrases:NN #1#2 + { + \__cooking_units_get_phrase_for_current_langauge:NNT + \l__cooking_units_phrase_prop + \l__cooking_units_phrase_numbers_clist { - \__cooking_units_if_phrase_list_exists:NT \l__cooking_units_phrase_prop + \__cooking_units_cuam_post_process_input_phrases_aux:NNN + #1 \l__cooking_units_tmpa_int \l__cooking_units_phrase_number_tl + \bool_if:NT \l__cooking_units_lokal_phrase_bool { - \__cooking_units_translate_let:Nxx \l__cooking_units_phrase_numbers_clist - { phrase-list-list } \c__cooking_units_postfix_phrase_tl - \__cooking_units_cuam_process_input_aux:NNN #1 \l__cooking_units_tmpa_int \l__cooking_units_phrase_number_tl - \bool_if:NT \l__cooking_units_check_if_phrase_used_bool + \bool_if:NTF \l__cooking_units_range_in_input_bool { - \bool_if:NTF \l__cooking_units_range_in_input_bool + \__cooking_units_cuam_post_process_input_phrases_aux:NNN + #2 \l__cooking_units_tmpb_int \l__cooking_units_tmpb_tl + \bool_lazy_and:nnF + { \l__cooking_units_lokal_phrase_bool } + { \tl_if_eq_p:NN \l__cooking_units_phrase_number_tl \l__cooking_units_tmpb_tl } + { \bool_set_false:N \l__cooking_units_lokal_phrase_bool } + \bool_if:NT \l__cooking_units_lokal_phrase_bool { - \__cooking_units_cuam_process_input_aux:NNN #2 \l__cooking_units_tmpb_int \l__cooking_units_tmpb_tl - \bool_lazy_and:nnTF - { \l__cooking_units_check_if_phrase_used_bool } - { \tl_if_eq_p:NN \l__cooking_units_phrase_number_tl \l__cooking_units_tmpb_tl } - { \bool_set_true:N \l__cooking_units_check_if_phrase_used_bool } - { \bool_set_false:N \l__cooking_units_check_if_phrase_used_bool } - \bool_if:NT \l__cooking_units_check_if_phrase_used_bool - { - \tl_set:NV #1 \l__cooking_units_tmpa_int - \tl_set:NV #2 \l__cooking_units_tmpb_int - \__cooking_units_cuam_get_phrase_name:NVN - \l__cooking_units_phrase_phrase_tl \l__cooking_units_phrase_number_tl \l__cooking_units_tmpb_int - } - }{ - \tl_set:NV #1 \l__cooking_units_tmpa_int - \__cooking_units_cuam_get_phrase_name:NVN - \l__cooking_units_phrase_phrase_tl \l__cooking_units_phrase_number_tl \l__cooking_units_tmpa_int + \tl_set:NV #1 \l__cooking_units_tmpa_int + \tl_set:NV #2 \l__cooking_units_tmpb_int + \__cooking_units_cuam_get_phrase_name:NVN + \l__cooking_units_phrase_phrase_tl \l__cooking_units_phrase_number_tl \l__cooking_units_tmpb_int } + }{ + \tl_set:NV #1 \l__cooking_units_tmpa_int + \__cooking_units_cuam_get_phrase_name:NVN + \l__cooking_units_phrase_phrase_tl \l__cooking_units_phrase_number_tl \l__cooking_units_tmpa_int } } } - \bool_lazy_and:nnT - { \g__cooking_units_opt_numeral_bool } { \l__cooking_units_local_numeral_bool } - { - \bool_set_eq:NN \l__cooking_units_local_numeral_bool \l__cooking_units_tmpa_bool - \bool_if:NT \l__cooking_units_local_numeral_bool - { - \bool_if:NTF \l__cooking_units_range_in_input_bool - { - \bool_lazy_and:nnF - { \int_compare_p:nNn {#1} < { \l__cooking_units_print_numerals_below_int } } - { \int_compare_p:nNn {#2} < { \l__cooking_units_print_numerals_below_int } } - { \bool_set_false:N \l__cooking_units_local_numeral_bool } - }{ - \int_compare:nNnF {#1} < { \l__cooking_units_print_numerals_below_int } - { \bool_set_false:N \l__cooking_units_local_numeral_bool } - } - } - } } -\prg_new_conditional:Npnn \__cooking_units_cuam_check_if_larger:nn #1#2 { F } +\cs_new:Npn \__cooking_units_cuam_post_process_input_phrases_aux:NNN #1#2#3 { - \int_compare:nNnTF {#1} > {#2} - { \prg_return_true: } - { \prg_return_false: } - } -\cs_new:Npn \__cooking_units_cuam_process_input_aux:NNN #1#2#3 - { - \bool_set_false:N \l__cooking_units_check_if_phrase_used_bool + \bool_set_false:N \l__cooking_units_lokal_phrase_bool \clist_map_inline:Nn \l__cooking_units_phrase_numbers_clist { - \__cooking_units_cuam_check_if_larger:nnF { \int_abs:n {##1} } {#1} + \int_compare:nNnF { \int_abs:n {##1} } > {#1} { - \int_compare:nNnTF {##1} < { \c_zero } - { \int_set_eq:NN \l_tmpa_int \c_one } + \int_compare:nNnTF {##1} < { 0 } + { \int_set:Nn \l_tmpa_int { 1 } } { \int_set:Nn \l_tmpa_int { \int_div_truncate:nn {#1} {##1} } } \int_compare:nNnT { \int_abs:n {##1} * \l_tmpa_int } = {#1} { \int_set_eq:NN #2 \l_tmpa_int \tl_set:Nn #3 {##1} - \bool_set_true:N \l__cooking_units_check_if_phrase_used_bool + \bool_set_true:N \l__cooking_units_lokal_phrase_bool \clist_map_break: } } @@ -1587,14 +1826,29 @@ { \prop_get:NnN \l__cooking_units_phrase_prop { #2-pl } #1 } } \cs_generate_variant:Nn \__cooking_units_cuam_get_phrase_name:NnN { NVN } +\cs_new:Npn \__cooking_units_cuam_post_process_input_numerals:NN #1#2 + { + \bool_if:NTF \l__cooking_units_tmpa_bool + { + \bool_if:NTF \l__cooking_units_range_in_input_bool + { + \bool_lazy_and:nnF + { \int_compare_p:nNn {#1} < { \l__cooking_units_print_numerals_below_int } } + { \int_compare_p:nNn {#2} < { \l__cooking_units_print_numerals_below_int } } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + }{ + \int_compare:nNnF {#1} < { \l__cooking_units_print_numerals_below_int } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + } + } + { \bool_set_false:N \l__cooking_units_lokal_numeral_bool } + } \cs_new_protected:Npn \__cooking_units_cuam_print_numerical_input:N #1 { - \bool_lazy_all:nTF + \bool_lazy_and:nnTF + { \l__cooking_units_lokal_phrase_bool } + { \l__cooking_units_lokal_numeral_bool } { - { \l__cooking_units_check_if_phrase_used_bool } - { \g__cooking_units_opt_numeral_bool } - { \l__cooking_units_local_numeral_bool } - }{ \__cooking_units_int_if_equal_one:nTF {#1} { \__cooking_units_translate_one_to_and_check_existance:Nx \l__cooking_units_translation_tmpa_tl @@ -1606,101 +1860,12 @@ } \cs_new:Npn \__cooking_units_cuam_print_correct_unitphrase: { - \bool_if:NT \l__cooking_units_check_if_phrase_used_bool + \bool_if:NT \l__cooking_units_lokal_phrase_bool { \l__cooking_units_cuphrase_space_tl \l__cooking_units_phrase_phrase_tl } } -\cs_new:Npn \__cooking_units_cuam_old:n #1 - { - \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N\ % - } {#1} - \__cooking_units_cuam_old_parse:V \l__cooking_units_tmpa_tl - } -\cs_new_protected:Npn \__cooking_units_cuam_old_parse:n #1 - { - \tl_if_in:nVTF {#1} \l__cooking_units_input_range_sign_tl - { - \tl_set:Nn \l__cooking_units_tmpa_tl {#1} - \tl_replace_once:NVn \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } - \__cooking_units_cuam_old_parse_range:V \l__cooking_units_tmpa_tl - }{ - \tl_if_in:nnTF {#1} { / } - { - \tl_if_in:nnTF {#1} { _ } - { \__cooking_units_cuam_old_parse_mixed_frac:www #1 \q_stop } - { \__cooking_units_cuam_old_parse_frac:ww #1 \q_stop } - }{ - \tl_if_in:nnTF {#1} { _ } - { \msg_error:nnn { cooking-units } { missing-slash } {#1} } - { \__cooking_units_cuam_old_parse_scale:n {#1} } - } - } - } -\cs_generate_variant:Nn \__cooking_units_cuam_old_parse:n { V } -\cs_new:Npn \__cooking_units_cuam_old_parse_range:n #1 - { - \__cooking_units_cuam_old_parse_range_aux:ww #1 \q_nil - } -\cs_generate_variant:Nn \__cooking_units_cuam_old_parse_range:n { V } -\cs_new:Npn \__cooking_units_cuam_old_parse_range_aux:ww #1 \q__cooking_units_range #2 \q_nil - { - #1 \l__cooking_units_cunum_range_sign_tl #2 - } -\cs_new:Npn \__cooking_units_cuam_old_parse_scale:n #1 {#1} -\cs_new:Npn \__cooking_units_cuam_old_parse_frac:ww #1/#2 \q_stop - { \__cooking_units_frac:nn {#1} {#2} } -\cs_new:Npn \__cooking_units_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop - { - #1 - \hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { } - \__cooking_units_frac:nn {#2} {#3} - } -\NewDocumentCommand \cufrac { O{} m } - { - \msg_error:nnnn { cooking-units } { obsolete-command } { \cufrac } { \cuam } - \group_begin: - \tl_if_empty:nF {#1} - { \keys_set:nn { cooking-units } {#1} } - \__cooking_units_cufrac:n {#2} - \group_end: - } -\cs_new:Npn \__cooking_units_cufrac:n #1 - { - \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl - { - \char_set_catcode_letter:N \_ % - \char_set_catcode_ignore:N\ % - } {#1} - \__cooking_units_cufrac_parse:V \l__cooking_units_tmpa_tl - } -\cs_new:Npn \__cooking_units_cufrac_parse:n #1 - { - \tl_if_in:nnTF {#1} { / } - { - \tl_if_in:nnTF {#1} { _ } - { \__cooking_units_cufrac_parse_mixed_frac:www #1 \q_stop } - { \__cooking_units_cufrac_parse_frac:ww #1 \q_stop } - }{ - \tl_if_in:nnTF {#1} { _ } - { \msg_error:nnn { cooking-units } { missing-slash } {#1} } - { \__cooking_units_cufrac_parse_scale:n {#1} } - } - } -\cs_generate_variant:Nn \__cooking_units_cufrac_parse:n { V } -\cs_new:Npn \__cooking_units_cufrac_parse_scale:n #1 {#1} -\cs_new:Npn \__cooking_units_cufrac_parse_frac:ww #1/#2 \q_stop - { \__cooking_units_frac:nn {#1} {#2} } -\cs_new:Npn \__cooking_units_cufrac_parse_mixed_frac:www #1_#2/#3 \q_stop - { - #1 - \hbox_to_wd:nn { \l__cooking_units_mixed_frac_dim } { } - \__cooking_units_frac:nn {#2} {#3} - } \NewDocumentCommand \cudefinekeys { m m } { \bool_set_false:N \l__cooking_units_single_key_bool @@ -1722,11 +1887,11 @@ { \__cooking_units_cukeys_parse_and_create_single_key:nn {#1} {#2} }{ - \fp_set_eq:NN \l__cooking_units_tmpa_fp \c_one_fp + \fp_set:Nn \l__cooking_units_tmpa_fp { 1.0 } \tl_set:Nn \l__cooking_units_given_unit_tl {#1} \__cooking_units_cukeys_parse_and_create_keys:nn {#1} { - {#1} { \c_one_fp } #2 + {#1} { 1.0 } #2 } } } @@ -1758,7 +1923,7 @@ \seq_map_inline:Nn \l__cooking_units_tmpa_seq { \prop_set_eq:cN { l__cooking_units_cukeys_ ##1 _prop } \l__cooking_units_tmpb_prop - \tl_set_eq:cN { l__cooking_units_tmpa_ ##1 _tl } \c_one_fp + \tl_set:cn { l__cooking_units_tmpa_ ##1 _tl } { 1.0 } \seq_map_inline:Nn \l__cooking_units_tmpa_seq { \prop_put:cnx { l__cooking_units_cukeys_ ##1 _prop } @@ -1773,7 +1938,7 @@ } } } -\cs_new:Npn \__cooking_units_cukeys_define_keys:N #1 +\cs_new:Npn \__cooking_units_cukeys_define_keys:n #1 { \seq_map_inline:Nn \l__cooking_units_tmpa_seq { @@ -1801,7 +1966,7 @@ } } } -\cs_generate_variant:Nn \__cooking_units_cukeys_define_keys:N { V } +\cs_generate_variant:Nn \__cooking_units_cukeys_define_keys:n { V } \cs_new:Npn \__cooking_units_cukeys_define_keys_and_single_key_aux:n #1 { \prop_get:cVc @@ -1816,7 +1981,7 @@ { \char_set_catcode_letter:N \# % \char_set_catcode_ignore:N\ % - } { {#1} { \c_one_fp } #2 } + } { {#1} { 1.0 } #2 } \__cooking_units_cusinglekeys_parse_input:V \l__cooking_units_tmpa_tl \__cooking_units_cusinglekeys_create_key_prop:n {#1} \clist_set_from_seq:NN \l__cooking_units_tmpa_clist \l__cooking_units_tmpa_seq @@ -1842,13 +2007,13 @@ } \cs_new:Npn \__cooking_units_cusinglekeys_create_key_prop:n #1 { - \tl_set_eq:cN { l__cooking_units_tmpa_ #1 _tl } \c_one_fp + \tl_set:cn { l__cooking_units_tmpa_ #1 _tl } { 1.0 } \prop_set_eq:cN { l__cooking_units_cukeys_ #1 _prop } \l__cooking_units_tmpa_prop \prop_put:cnn { l__cooking_units_cukeys_ #1 _prop } { Erstes Ding } {#1} \prop_put:cnV { l__cooking_units_cukeys_ #1 _prop } { Liste } \l__cooking_units_tmpa_seq \prop_put:cnV { l__cooking_units_cukeys_ #1 _prop } { prop } \l__cooking_units_tmpa_prop } -\cs_new:Npn \__cooking_units_cukeys_define_singlekey:nN #1#2 +\cs_new:Npn \__cooking_units_cukeys_define_singlekey:nn #1#2 { \seq_if_in:NnF \l__cooking_units_list_of_defined_keys_seq {#1} { \seq_put_right:Nn \l__cooking_units_list_of_defined_keys_seq {#1} } @@ -1873,7 +2038,7 @@ #1 .groups:n = { change-unit } , } } -\cs_generate_variant:Nn \__cooking_units_cukeys_define_singlekey:nN { nV } +\cs_generate_variant:Nn \__cooking_units_cukeys_define_singlekey:nn { nV } \NewDocumentCommand \cuaddkeys { m m } { \bool_set_false:N \l__cooking_units_single_key_bool @@ -1892,7 +2057,7 @@ { \bool_set_false:N \l__cooking_units_single_key_bool \tl_set:Nn \l__cooking_units_tmpa_tl {#1} - \tl_set:Nn \l__cooking_units_tmpb_tl { {#2} { \fp_eval:n { \c_one_fp / (#3) } } } + \tl_set:Nn \l__cooking_units_tmpb_tl { {#2} { \fp_eval:n { 1.0 / (#3) } } } \__cooking_units_cukeys_add_keys_or_single_keys:VV \l__cooking_units_tmpa_tl \l__cooking_units_tmpb_tl } \cs_new:Npn \__cooking_units_cukeys_add_keys_or_single_keys:nn #1#2 @@ -1941,9 +2106,14 @@ \seq_if_in:NnTF \g__cooking_units_list_of_defined_units_seq {#2} { \msg_error:nnn { cooking-units } { unit-already-defined } {#2} } { + \tl_map_inline:nn {#2} + { + \tl_if_in:NnT \l__cooking_units_unit_letter_not_allowed_tl {##1} + { \msg_error:nnn { cooking-units } { character-not-allowed } {#2} } + } \seq_put_right:Nn \g__cooking_units_list_of_defined_units_seq {#2} \tl_new:c { l__cooking_units_tmpa_ #2 _tl } - \tl_set_eq:cN { l__cooking_units_tmpa_ #2 _tl } \c_one_fp + \tl_set:cn { l__cooking_units_tmpa_ #2 _tl } { 1.0 } \clist_new:c { l__cooking_units_predefined_option_#2_clist } \keys_define:nn { cooking-units } { @@ -2124,20 +2294,23 @@ } \__cooking_units_cuprint_define_printed_unit:nn } -\__cooking_units_newtranslation_base:nVn { phrase-list } \c__cooking_units_postfix_phrase_tl { \q__cooking_units_no_translation } -\prg_new_conditional:Npnn \__cooking_units_phrase_list_get_for:NN #1#2 { TF , T , F } +\__cooking_units_newtranslation_base:nVn { phrase-prop } \c__cooking_units_postfix_phrase_tl { \q__cooking_units_no_translation } +\prg_new_conditional:Npnn \__cooking_units_phrase_list_get_for:NN #1#2 { TF } { - \__cooking_units_translate_let:VNxx #2 #1 { phrase-list } \c__cooking_units_postfix_phrase_tl + \__cooking_units_translate_let:VNxx #2 #1 { phrase-prop } \c__cooking_units_postfix_phrase_tl \tl_if_eq:NNTF #1 \q__cooking_units_no_translation { \prg_return_false: } { \prg_return_true: } } -\prg_new_conditional:Npnn \__cooking_units_if_phrase_list_exists:N #1 { TF , T , F } +\prg_new_conditional:Npnn \__cooking_units_get_phrase_for_current_langauge:NN #1#2 { T } { - \__cooking_units_translate_let:Nxx \l_tmpa_tl { phrase-list } \c__cooking_units_postfix_phrase_tl - \tl_if_eq:NNTF \l_tmpa_tl \q__cooking_units_no_translation + \__cooking_units_translate_let:Nxx #1 { phrase-prop } \c__cooking_units_postfix_phrase_tl + \tl_if_eq:NNTF #1 \q__cooking_units_no_translation { \prg_return_false: } - { \prg_return_true: } + { + \__cooking_units_translate_let:Nxx #2 { phrase-clist } \c__cooking_units_postfix_phrase_tl + \prg_return_true: + } } \NewDocumentCommand \cudefinephrase { m m } { @@ -2149,7 +2322,7 @@ \__cooking_units_phrase_list_get_for:NNTF \l__cooking_units_phrase_prop \l__cooking_units_language_tl { \__cooking_units_translate_let:VNxx \l__cooking_units_language_tl \l__cooking_units_phrase_numbers_clist - { phrase-list-list } \c__cooking_units_postfix_phrase_tl + { phrase-clist } \c__cooking_units_postfix_phrase_tl }{ \prop_clear:N \l__cooking_units_phrase_prop \clist_clear:N \l__cooking_units_phrase_numbers_clist @@ -2172,11 +2345,11 @@ } } \__cooking_units_deftranslation_to:VxxV - \l__cooking_units_language_tl { phrase-list } + \l__cooking_units_language_tl { phrase-prop } \c__cooking_units_postfix_phrase_tl \l__cooking_units_phrase_prop \__cooking_units_deftranslation_to:VxxV - \l__cooking_units_language_tl { phrase-list-list } + \l__cooking_units_language_tl { phrase-clist } \c__cooking_units_postfix_phrase_tl \l__cooking_units_phrase_numbers_clist } \cs_new:Npn \__cooking_units_cuphrase_parse:n #1 @@ -2226,6 +2399,164 @@ \c__cooking_units_postfix_gender_tl {#2} \__cooking_units_cuphrase_parse:n } +\cs_new:Npn \__cooking_units_old_cutext:nnn #1#2#3 + { + \tl_set_eq:NN \l__cooking_units_option_unit_tl \l__cooking_units_given_unit_tl + \__cooking_units_old_cutext_default:nnn {#1} {#2} {#3} + } +\cs_new:Npn \__cooking_units_old_cutext_default:nnn #1#2#3 + { + \bool_if:NTF \l__cooking_units_draft_bool + {#2} + { + \tl_set:Nn \l__cooking_units_cutext_last_value_tl {#2} + \tl_if_in:NVTF \l__cooking_units_cutext_last_value_tl \l__cooking_units_input_range_sign_tl + { + \tl_replace_once:NVn \l__cooking_units_cutext_last_value_tl + \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } + \__cooking_units_old_cutext_parse_range:Vn \l__cooking_units_cutext_last_value_tl {#3} + }{ + \__cooking_units_old_cutext_print_input:Nn \l__cooking_units_cutext_last_value_tl {#3} + } + } + } +\cs_new_protected:Npn \__cooking_units_old_cutext_print_input:Nn #1#2 + { + \__cooking_units_old_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:NTF #1 + { + \__cooking_units_int_if_equal_one:nTF {#1} + { + \__cooking_units_translate_one_to_and_check_existance:Nx \l__cooking_units_translation_tmpa_tl {#2} + \bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool + { + \exp_args:Nx \tl_upper_case:n { \tl_head:V \l__cooking_units_translation_tmpa_tl } + \tl_tail:V \l__cooking_units_translation_tmpa_tl + } + { \l__cooking_units_translation_tmpa_tl } + }{ + \bool_if:NTF \l__cooking_units_cutext_uppercase_word_bool + { \__cooking_units_print_Numeral:n {#1} } + { \__cooking_units_print_numeral:n {#1} } + } + } + { \__cooking_units_print_numerical_input:N #1 } + } +\prg_new_conditional:Npnn \__cooking_units_old_cutext_if_numeral_is_int_and_parse_and_smaller_then_print_numerals:N #1 { TF } + { + \bool_if:NTF \l__cooking_units_lokal_numeral_bool + { + \__cooking_units_if_integer:VTF #1 + { + \int_compare:nNnTF {#1} < { \l__cooking_units_print_numerals_below_int } + { \prg_return_true: } + { \prg_return_false: } + }{ \prg_return_false: } + }{ \prg_return_false: } + } +\cs_new:Npn \__cooking_units_old_cutext_parse_range:nn #1 #2 + { + \__cooking_units_old_cutext_parse_range_aux:nww {#2} #1 \q_stop + } +\cs_generate_variant:Nn \__cooking_units_old_cutext_parse_range:nn { V } +\cs_new:Npn \__cooking_units_old_cutext_parse_range_aux:nww #1 #2 \q__cooking_units_range #3 \q_stop + { + \tl_set:Nn \l__cooking_units_tmpa_tl {#2} + \tl_set:Nn \l__cooking_units_cutext_last_value_tl {#3} + \__cooking_units_old_cutext_print_input:Nn \l__cooking_units_tmpa_tl {#1} + \tl_use:N \l__cooking_units_cutext_range_sign_tl + \__cooking_units_old_cutext_print_input:Nn \l__cooking_units_cutext_last_value_tl {#1} + } +\cs_new:Npn \__cooking_units_cuam_old:n #1 + { + \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N\ % + } {#1} + \bool_if:NTF \l__cooking_units_draft_bool + { \l__cooking_units_tmpa_tl } + { \__cooking_units_cuam_old_parse:V \l__cooking_units_tmpa_tl } + } +\cs_new_protected:Npn \__cooking_units_cuam_old_parse:n #1 + { + \tl_if_in:nVTF {#1} \l__cooking_units_input_range_sign_tl + { + \tl_set:Nn \l__cooking_units_tmpa_tl {#1} + \tl_replace_once:NVn \l__cooking_units_tmpa_tl \l__cooking_units_input_range_sign_tl { \q__cooking_units_range } + \__cooking_units_cuam_old_parse_range:V \l__cooking_units_tmpa_tl + }{ + \tl_if_in:nnTF {#1} { / } + { + \tl_if_in:nnTF {#1} { _ } + { \__cooking_units_cuam_old_parse_mixed_frac:www #1 \q_stop } + { \__cooking_units_cuam_old_parse_frac:ww #1 \q_stop } + }{ + \tl_if_in:nnTF {#1} { _ } + { \msg_error:nnn { cooking-units } { missing-slash } {#1} } + { \__cooking_units_cuam_old_parse_scale:n {#1} } + } + } + } +\cs_generate_variant:Nn \__cooking_units_cuam_old_parse:n { V } +\cs_new:Npn \__cooking_units_cuam_old_parse_range:n #1 + { + \__cooking_units_cuam_old_parse_range_aux:ww #1 \q_nil + } +\cs_generate_variant:Nn \__cooking_units_cuam_old_parse_range:n { V } +\cs_new:Npn \__cooking_units_cuam_old_parse_range_aux:ww #1 \q__cooking_units_range #2 \q_nil + { + #1 \l__cooking_units_cunum_range_sign_tl #2 + } +\cs_new:Npn \__cooking_units_cuam_old_parse_scale:n #1 {#1} +\cs_new:Npn \__cooking_units_cuam_old_parse_frac:ww #1/#2 \q_stop + { \__cooking_units_frac:nn {#1} {#2} } +\cs_new:Npn \__cooking_units_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop + { + #1 + \__cooking_units_dim_horizontal:N \l__cooking_units_mixed_frac_dim + \__cooking_units_frac:nn {#2} {#3} + } +\NewDocumentCommand \cufrac { O{} m } + { + \msg_error:nnnn { cooking-units } { obsolete-command } { \cufrac } { \cuam } + \group_begin: + \tl_if_empty:nF {#1} + { \keys_set:nn { cooking-units } {#1} } + \__cooking_units_cufrac:n {#2} + \group_end: + } +\cs_new:Npn \__cooking_units_cufrac:n #1 + { + \tl_set_rescan:Nnn \l__cooking_units_tmpa_tl + { + \char_set_catcode_letter:N \_ % + \char_set_catcode_ignore:N\ % + } {#1} + \__cooking_units_cufrac_parse:V \l__cooking_units_tmpa_tl + } +\cs_new:Npn \__cooking_units_cufrac_parse:n #1 + { + \tl_if_in:nnTF {#1} { / } + { + \tl_if_in:nnTF {#1} { _ } + { \__cooking_units_cufrac_parse_mixed_frac:www #1 \q_stop } + { \__cooking_units_cufrac_parse_frac:ww #1 \q_stop } + }{ + \tl_if_in:nnTF {#1} { _ } + { \msg_error:nnn { cooking-units } { missing-slash } {#1} } + { \__cooking_units_cufrac_parse_scale:n {#1} } + } + } +\cs_generate_variant:Nn \__cooking_units_cufrac_parse:n { V } +\cs_new:Npn \__cooking_units_cufrac_parse_scale:n #1 {#1} +\cs_new:Npn \__cooking_units_cufrac_parse_frac:ww #1/#2 \q_stop + { \__cooking_units_frac:nn {#1} {#2} } +\cs_new:Npn \__cooking_units_cufrac_parse_mixed_frac:www #1_#2/#3 \q_stop + { + #1 + \__cooking_units_dim_horizontal:N \l__cooking_units_mixed_frac_dim + \__cooking_units_frac:nn {#2} {#3} + } \NewDocumentCommand \cusetup { m } { \keys_set:nn { cooking-units } {#1} @@ -2488,6 +2819,7 @@ F = -459.67 , Re = -218.52 } , + round-precision = 2 , } \endinput %% |