summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/cooking-units
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2016-11-14 22:34:47 +0000
committerKarl Berry <karl@freefriends.org>2016-11-14 22:34:47 +0000
commitcd08665896fd28bcf3597c5e45969b3a5209a794 (patch)
treeeabe5723e4820e527a6e5610837e7e749e71c5d0 /Master/texmf-dist/source/latex/cooking-units
parent96679398651343a7668086d8a4bab8b66986be81 (diff)
cooking-units (14nov16)
git-svn-id: svn://tug.org/texlive/trunk@42507 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/source/latex/cooking-units')
-rw-r--r--Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx1666
1 files changed, 1239 insertions, 427 deletions
diff --git a/Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx b/Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx
index 9824d98e6c7..06a8db58f74 100644
--- a/Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx
+++ b/Master/texmf-dist/source/latex/cooking-units/cooking-units.dtx
@@ -158,13 +158,40 @@ and the derived file cooking-units.sty.
\labelformat{table}{table~#1}
\labelformat{section}{section~#1}
-\newcommand\mycs[1]{\cs{\textcolor{blue}{#1}}}
+\ExplSyntaxOn
+
+\clist_new:N \l_cooking_units_list_of_defined_befehlen_clist
+\clist_set:Nn \l_cooking_units_list_of_defined_befehlen_clist
+ {
+ cunum,
+ cutext,
+ Cutext,
+ cuam,
+ newcookingunit,
+ declarecookingunit,
+ providecookingunit,
+ cudefinename,
+ cudefinesymbol,
+ cusetup,
+ cudefinekeys,
+ cudefinesinglekey,
+ cuaddkeys,
+ cuaddsinglekeys,
+ cuaddtokeys,
+ culabel,
+ curef,
+ }
+
+\NewDocumentCommand \mycs { m }
+ {
+ \clist_if_in:NnTF \l_cooking_units_list_of_defined_befehlen_clist {#1}
+ { \cs{\textcolor{blue}{#1}} }
+ { \ERROR }
+ }
\newcommand\opt{\texttt}
\newcommand\true{\opt{true}}
\newcommand\false{\opt{false}}
-\ExplSyntaxOn
-
\NewDocumentCommand \PrintUnit { m }
{
\translate{ #1 (cu-unitname) } & #1 & \translate{ #1 ( cu-unit ) }
@@ -181,13 +208,14 @@ and the derived file cooking-units.sty.
{
\textcolor{white} {#1} \\
}
-
+\newcommand\eatthewhitespace{}
\NewEnviron { cuexamplecode }[1][]
{
\begin{center}
\begin{minipage}{0.4\linewidth}
\tl_replace_all:Nnn \BODY { @ } { \dothewhitespace }
- \tl_replace_all:Nnn \BODY { ! } { }
+ \tl_replace_all:Nnn \BODY { ! } { }
+ \tl_replace_all:Nnn \BODY { & } { \ignorespaces }
\BODY
\end{minipage}
@@ -199,6 +227,8 @@ and the derived file cooking-units.sty.
{
\char_set_catcode_other:N \{ %
\char_set_catcode_other:N \} %
+ \char_set_catcode_other:N \_ %
+ \char_set_catcode_other:N \~ %
% \char_set_catcode_other:N \# %
}
{ \BODY }
@@ -218,20 +248,23 @@ and the derived file cooking-units.sty.
\textbackslash \textcolor{blue}{\l_tmpb_tl}
}
}
- {
+ {
\bool_if:nTF
{
- \tl_if_eq_p:NN ##1 @ ||
- \tl_if_eq_p:NN ##1 !
+ \str_if_eq_p:nn {##1} { @ } ||
+ \str_if_eq_p:nn {##1} { ! } ||
+ \str_if_eq_p:nn {##1} { & }
+ }
+ {
+ \str_if_eq:nnTF {##1} { & } { \space } { \\ }
}
- { \\ }
{
\token_if_active:NTF ##1
- { \string ##1 }
+ {##1}
{
\token_if_parameter:NTF ##1
{
- \int_compare:nTF { \l_tmpa_int == 0 }
+ \int_compare:nNnTF { \l_tmpa_int } = { \c_zero }
{
\c_hash_str
\int_incr:N \l_tmpa_int
@@ -340,6 +373,8 @@ and the derived file cooking-units.sty.
\ExplSyntaxOff
+\newcommand\cCutext{\mycs{cutext} and \mycs{Cutext}}
+
\lstset
{
basicstyle = \ttfamily,
@@ -355,6 +390,8 @@ and the derived file cooking-units.sty.
Cutext,
cuam,
newcookingunit,
+ declarecookingunit,
+ providecookingunit,
cudefinename,
cudefinesymbol,
cusetup,
@@ -363,20 +400,24 @@ and the derived file cooking-units.sty.
cuaddkeys,
cuaddsinglekeys,
cuaddtokeys,
+ culabel,
+ curef,
}
}
\newcookingunit {st}
-\cuaddkeys {lb} %% adding t to g (could also add to kg, dag and oz)
+\cuaddkeys {lb}
{
{st} { 1/14 } %% 1 lb are 1/14 st
}
-
+
+
\newcookingunit [\ensuremath{ {} ^ { \circ } }\kern-\scriptspace R{\o}] {Ro}
+
\cuaddsinglekeys {C}
{
- {Ro} { #1*21/40 + 7.5}
+ {Ro} { #1*21/40 + 7.5 }
}
\cusetup
{
@@ -437,7 +478,7 @@ and the derived file cooking-units.sty.
% \changes {2016/09/03} {1.01} {Added units 'ssp', 'csp', 'dsp'}
% \changes {2016/09/03} {1.01} {English unit: litre (and only litre) uses the curly l \protect\ensuremath{\protect\ell} now }
% \changes {2016/09/03} {1.01} {British English: 'pinch' is written in full}
-% \changes {2016/09/03} {1.01} {Separated Messerpsitze and pinch}
+% \changes {2016/09/03} {1.01} {Separated Messerspitze and pinch}
% \changes {2016/09/05} {1.02} {Replaced \cs{cufrac} by \cs{cuam}}
% \changes {2016/09/05} {1.02} {New message: 'obsolete-command'}
% \changes {2016/09/09} {1.02a} {Changed name from \cs{@@_parse_fraction_in_input:www} to \cs{@@_parse_mixed_fraction_in_input:www}}
@@ -448,7 +489,7 @@ and the derived file cooking-units.sty.
% \changes {2016/09/09} {1.02d} {Add 'single' to property list of singlekeys.}
% \changes {2016/09/16} {1.02e} {Only use \cs{phantom} if the argument (for \cs{phantom}) is not empty.}
% \changes {2016/09/09} {1.02i} {Delete 'single' from property lists of singlekeys cause it is not as safe as I thought.}
-% \changes {2016/09/09} {1.02f} {Corrected mistake: 'ELektronenvolt' (note upperacse L) to 'Elektronenvolt' in german.}
+% \changes {2016/09/09} {1.02f} {Corrected mistake: 'ELektronenvolt' (note uppercase L) to 'Elektronenvolt' in german.}
% \changes {2016/09/26} {1.03} {New option (and needed macros): add-temperature-to-check.}
% \changes {2016/09/26} {1.03a} {\cs{cuaddsinglekeys} now tests if the unit exists (it didn't before).}
% \changes {2016/09/26} {1.03b} {Replaced \cs{prop_clear_new:c} by \cs{prop_clear:c}.}
@@ -458,6 +499,18 @@ and the derived file cooking-units.sty.
% \changes {2016/10/19} {1.04} {'convert-to-eV' now also as optional argument available.}
% \changes {2016/10/19} {1.04} {Option 'load-time-option' now spells 'available' correct.}
% \changes {2016/10/19} {1.04} {Update of documentation.}
+% \changes {2016/10/28} {1.10alpha} {Start implementation of \enquote{Change recipe from $n$ to $m$ persons.}.}
+% \changes {2016/10/28} {1.10alpha} {\cs{cutext} (and \cs{Cutext}) and \cs{cuam} now parse their input like \cs{cunum}. This is needed as they also need to be changed.}
+% \changes {2016/10/29} {1.10alpha} {Tiding code: Now every command is separated into a \enquote{calc} function, a \enquote{print numeric value} and a \enquote{print unit} (if there) function. At least, that's the plan.}
+% \changes {2016/10/30} {1.10} {Fractions should now deal correctly with minus signs.}
+% \changes {2016/11/07} {1.10} {Finished writing v1.10.}
+% \changes {2016/11/13} {1.10} {Change amounts for specific number of persons.}
+% \changes {2016/11/13} {1.10} {\cs{cutext}, \cs{Cutext} and \cs{cuam} check their input, allows conversion of units.}
+% \changes {2016/11/13} {1.10} {New commands: \cs{culabel} and \cs{curef}.}
+% \changes {2016/11/13} {1.10} {New commands: \cs{declarecookingunit} and \cs{providecookingunit}.}
+% \changes {2016/11/13} {1.10} {New options: \opt{cutext-to-cunum}, \opt{cutext-change-unit} and \opt{cutext-space}.}
+% \changes {2016/11/13} {1.10} {New options: \opt{cuam-version} and \opt{cutext-version}}
+% \changes {2016/11/13} {1.10} {New options: \opt{recalculate-amount} and \opt{set-number-of-persons}, \opt{label}, \opt{get-label}, \opt{ref}.}
%
%
% \GetFileInfo{\jobname.sty}
@@ -471,11 +524,11 @@ and the derived file cooking-units.sty.
%
%
% \begin{documentation}
-%
-%
% \begin{abstract}
-% This package enables user to globally format units and to switch
-% between them. It should be used for light-hearted things like
+% This package enables user to globally format units, to switch
+% between them and since v1.10 you can also change your recipes for a given
+% number of persons.
+% It should be used for light-hearted things like
% cookery books (and not e.g. scientific texts).\footnote{I did hide some
% grammatical and spelling errors for easter egg hunters \Winkey.}
% \end{abstract}
@@ -539,17 +592,19 @@ and the derived file cooking-units.sty.
% \item French (currently suboptimal\footnote{You can only get limited information from the internet.})
% \end{itemize}
% Have another language to add or a correction of an existing one?
-% See \vref{sec:bug-feed} for more details.
+% See \vref{sec:bug-feed} for more details. Wanna just check the existing
+% translations? See \vref{sec:Translations}.
%
% \section {The Commands}
+% \label{sec:commands}
%
% This package offers the following commands for unit printing (and converting):
%
% \begin{itemize}
-% \item \mycs{cunum}\oarg{options}\marg{amount}\oarg{space}\marg{unit-key}
-% \item \mycs{cutext}\oarg{options}\marg{amount}\marg{unit-key}
-% \item \mycs{Cutext}\oarg{options}\marg{amount}\marg{unit-key}
-% \item \mycs{cuam}\oarg{options} \marg{amount}
+% \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}
% \end{itemize}
%
% Numbers and units are printed using \mycs{cunum}. The numerical part
@@ -564,7 +619,9 @@ and the derived file cooking-units.sty.
% customize this behavior, see \vref{sec:options}}. \oarg{space} adds
% a space between the number and the unit using \lstinline|\phantom|.
%
-% For a list of predefined units have a look at \vref{tab:def-units}.
+% For a list of predefined units have a look at \vref{tab:def-units}.
+%
+% \meta{label} is explained in \vref{sec:labeletref}.
%
%
% \begin{cuexamplecode}
@@ -590,13 +647,16 @@ and the derived file cooking-units.sty.
% \texttt{Re}) are automatically rounded to integers.\footnote{You can
% -- of course -- change this behavior, see \vref{sec:options}.}
%
-% \lstinline|\cutext| and \lstinline|\Cutext| print the number and the
-% written name of the unit. Furthermore, if the package option
+%
+% \cCutext\ print the number and the written name of the unit. Since v1.10
+% it works similar\footnote{One could also say \enquote{exactly like}.} to \mycs{cunum}: it allows the conversion between units
+% and interprets the numerical part (again |_| and |/|
+% are used for (mixed) fractions and |--| for ranges).
+% Furthermore, if the package option
% \opt{use-numerals} is used, integers below a specific integer (by
-% default 13; see \opt{use-numerals-below}) are also written out with
+% default 13; see \opt{use-numerals-below}) are written out with
% \lstinline|\Cutext| capitalizing the first letter (using package \pkg{fmtcount}).
-% Conversion between
-% units is not supported. Without \opt{use-numerals}:
+%
%
% \begin{cuexamplecode}
% \cutext{1}{l} \\
@@ -607,27 +667,32 @@ and the derived file cooking-units.sty.
% and using package option \opt{use-numerals=true}
% \cusetup{use-numerals-below=13}
% \begin{cuexamplecode}
-% \cutext{1}{l} \\
+% \cutext{1--2}{l} \\
% \Cutext{1}{l} \\
% \cutext{12}{l} \\
% \Cutext{13}{l}
-%^^A \cutext{23}{kg} \\
-%^^A \Cutext{23}{kg}\\
-%^^A \cutext{1}{l}\\
-%^^A \Cutext{2}{l}\\
-%^^A \cutext{1}{C} \\
-%^^A \cutext{180}{C} \\
-%^^A \Cutext{1}{C} \\
-%^^A \Cutext{180}{C} \\
-%^^A \Cutext{1.4}{C} \\
% \end{cuexamplecode}
% \cusetup{use-numerals-below=0}
+% Furthermore,
+% since v1.10 \cCutext\ also allows their units to be changed (this behavior
+% can be altered using \opt{cutext-change-unit}):
+% \begin{cuexamplecode}
+% \cutext[l=ml]{1}{l} \\
+% \Cutext[l=ml]{1}{l} \\
+% \cutext[l=ml]{12}{l} \\
+% \Cutext[l=ml]{13}{l} \\
+% \Cutext[l=ml]{?}{l} \\
+% \Cutext[l=ml]{1/2}{l}
+% \end{cuexamplecode}
%
%
-% \lstinline|\cuam| works like a more primitive version \mycs{cunum}
-% which doesn't need a unit, but doesn't check the input like \mycs{cunum}.
-% Like in \lstinline|\cunum| \texttt{\_} and \texttt{/} are used to imply a (mixed) fraction and \texttt{-{}-} is
-% used to print ranges\footnote{Note that since v1.02 \mycs{cufrac} is obsolete.}:
+% \lstinline|\cuam| works like \mycs{cunum}, but without a unit, so
+% changing units doesn't affect it. Like \mycs{cunum} \texttt{\_} and \texttt{/}
+% are used to imply a (mixed) fraction and |--| is used to print ranges.
+%^^A works like a more primitive version \mycs{cunum}
+%^^A which doesn't need a unit, but doesn't check the input like \mycs{cunum}.
+%^^A Like in \lstinline|\cunum| \texttt{\_} and \texttt{/} are used to imply a (mixed) fraction and \texttt{-{}-} is
+%^^A used to print ranges\footnote{Note that since v1.02 \mycs{cufrac} is obsolete.}:
%
% \begin{cuexamplecode}
% \cuam{3} \\
@@ -637,6 +702,82 @@ and the derived file cooking-units.sty.
% \end{cuexamplecode}
%
%
+% \section{Label \& refs: Changing the amount of the recipe}
+% \label{sec:labeletref}
+%
+%^^A You may write or have a recipe for a specific number of persons
+%^^A (e.g. for 4), but you would like to have this recipe for another number
+%^^A (e.g. only for two). Using labels you can write your recipes and change
+%^^A the number of persons they are for. There are also two commands helping:
+%
+%^^A To change your recipe \emph{from} a specific number of persons (e.g. 4)
+%^^A \emph{to} another number of persons (e.g. 3) the following commands will
+%^^A prove helpfull:
+%
+% What if you don't want to change units, but the amounts of the recipe because
+% you cook not for 4 persons, but for 2 and don't like to do the math?
+% Simple, use the following commands:
+%
+% \begin{itemize}
+% \item \mycs{culabel} \marg{label} \marg{number of persons}
+% \item \mycs{curef} \marg{label}
+% \end{itemize}
+%
+%^^A The first one is the important one: With its help you can define a \meta{label}
+%^^A which tells this package that the recipe is originally for \meta{number of persons}
+%^^A persons. This \meta{label} is then available for the commands introduced in
+%^^A \vref{sec:commands} to be used.
+%
+% The first one is the important one: It defines a \meta{label} for a recipe
+% which is initially for \meta{number of persons}. Afterwards \meta{label}
+% can be used to tell the commands from \vref{sec:commands} that the given
+% amounts are for \meta{number of persons} people.
+% Each \meta{label} must be unique and an error is raised if a \meta{label}
+% is already defined.
+%
+% If you would like to print the number of persons this recipe is for, use
+% \mycs{curef}.
+%^^A \mycs{curef} does print the number of people the recipe (\meta{label}) is for.
+%
+% The following example uses \mycs{culabel} to specify that the recipe is
+% initially intended for 2 persons:
+% \begin{cuexamplecode}
+% \culabel{recipe}{2} @
+% recipe & for & \curef{recipe} & persons: \\
+% \cunum<recipe>{10--20}{dag} & flour, \\
+% \cunum<recipe>{1/2}{l} & water, \\
+% \cutext[ref=recipe]{10}{g} & nuts, \\
+% \cuam<recipe>{2--3} & eggs, \\
+% \cunum{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
+% changed to four persons:
+%
+% \begin{lstlisting}
+% \culabel{recipe}{2}
+% %% adding options:
+% \cusetup{set-number-of-persons=4,recalculate-amount=true}
+% \end{lstlisting}
+% \cusetup{set-number-of-persons=4,recalculate-amount=true}
+%
+% \begin{cuexamplecode}
+% recipe & for & \curef{recipe} & persons: \\
+% \cunum<recipe>{10--20}{dag} & flour, \\
+% \cunum<recipe>{1/2}{l} & water, \\
+% \cutext[ref=recipe]{10}{g} & nuts, \\
+% \cuam<recipe>{2--3} & eggs, \\
+% \cunum{180}{C} & open & fire
+% \end{cuexamplecode}
+% \cusetup{recalculate-amount=false}
+%
+% Note that fractions are automatically evaluated and that only values
+% with a \meta{label} are changed (\lstinline|\cunum{180}{C}| for example
+% stays the same which also makes sense as the heat should be the same).
+%
+%
+%
% \section{Predefined units \& some notes}
% \label{sec:pred-units}
%
@@ -747,24 +888,32 @@ and the derived file cooking-units.sty.
% \section{Defining units}
% \label{sec:def-units}
%
-% New units can be defined using \lstinline|\newcookingunit|:
+% New units can be defined using \lstinline|\declarecookingunit|,
+% \lstinline|\newcookingunit| and \lstinline|\providecookingunit|:
%
-% \begin{function}{\newcookingunit}
+% \begin{function}{\declarecookingunit,\newcookingunit,\providecookingunit}
% \begin{syntax}
+% \lstinline|\declarecookingunit|\oarg{symbol}\marg{unit-key}
% \lstinline|\newcookingunit|\oarg{symbol}\marg{new-unit-key}
+% \lstinline|\providecookingunit|\oarg{symbol}\marg{new-unit-key}
% \end{syntax}
-% This command defines the new unit \meta{new-unit-key}. If the
+% These commands define the unit \meta{unit-key}. If the
% key is not the same as the printed symbol use \oarg{symbol}.
%
+% \mycs{newcookingunit} raises an error if the unit is already defined,
+% \mycs{declarecookingunit} overwrites \meta{symbol} (if given)
+% and \mycs{providecookingunit} does nothing if the unit is already
+% defined.
+%
% Some examples (note: the definition of the printed degree Celsius is
% directly copied \& pasted from [a maybe older version of] \pkg{siunitx}):
%
% \begin{center}
% \begin{tabular}{ll}
-% \lstinline|\newcookingunit{kg}| \\
-% \lstinline|\newcookingunit{g}| \\
-% \lstinline|\newcookingunit[Msp.] {Msp}| \\
-% \lstinline|\newcookingunit[\ensuremath{{}^{\circ}}\kern-\scriptspace C] {C} |
+% \lstinline|\declarecookingunit{kg}| \\
+% \lstinline|\declarecookingunit{g}| \\
+% \lstinline|\declarecookingunit[Msp.] {Msp}| \\
+% \lstinline|\declarecookingunit[\ensuremath{{}^{\circ}}\kern-\scriptspace C] {C} |
% \end{tabular}
% \end{center}
%
@@ -783,8 +932,8 @@ and the derived file cooking-units.sty.
% \item \lstinline|\cuaddsinglekeys|
% \item \lstinline|\cuaddtokeys|
% \end{itemize}
-%
-%
+% I apologize for the inconsistency between \lstinline|\cudefinekeys| and
+% \lstinline|\cudefinesinglekey|.
%
% \begin{function}{\cudefinekeys,\cudefinesinglekey}
% \begin{syntax}
@@ -855,6 +1004,7 @@ and the derived file cooking-units.sty.
% {oz} { 35.27399 } %% 1 kg are 35.27399 oz
% {lb} { 2.204 622 6 } %% 1 kg are 2.204 622 6 lb
% }
+%
% \cudefinekeys {d}
% {
% {h} { 24 } %% 1 day are 24 hours
@@ -870,7 +1020,6 @@ and the derived file cooking-units.sty.
% T_K &= ( T_F - 459.67 ) \cdot \frac{5}{9} \\
% T_{Re} &= ( T_F - 32 ) \cdot \frac{4}{9}
% \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} and the values \texttt{C}, \texttt{K} and \texttt{Re}
@@ -1012,7 +1161,8 @@ and the derived file cooking-units.sty.
% \cunum[st=lb]{1}{st} \\
% \cunum[st=g]{1}{st} \\
% \cunum[st=kg]{1}{st} \\
-% \cunum[kg=st]{1}{kg}
+% \cunum[kg=st]{1}{kg} \\
+% \cunum[st=kg]{16}{st}
% \end{cuexamplecode}
% \end{cuexample}
%
@@ -1165,8 +1315,8 @@ and the derived file cooking-units.sty.
% \cs{usepackage}[use-numerals=\meta{true/false}]\{cooking-units\}
% \end{syntax}
% If set to \true\ loads package \pkg{fmtcount} and uses
-% \mycs{numberstringnum} for \mycs{cutext}
-% and \mycs{Numberstringnum} for \mycs{Cutext} to write-out numbers below
+% \cs{numberstringnum} for \mycs{cutext}
+% and \cs{Numberstringnum} for \mycs{Cutext} to write-out numbers below
% \opt{use-numerals-below} (13 by default), integers above are
% printed as numbers. Please note the keys \opt{one(m)}, \opt{one(f)}
% and \opt{one(n)} to change the printed \enquote{one} (as
@@ -1195,7 +1345,8 @@ and the derived file cooking-units.sty.
% Options can be set globally using \lstinline|\cusetup|.
% \end{function}
%
-%
+% \subsubsection{Unit Specific options}
+%
% \begin{function}{unit}
% \begin{syntax}
% \meta{unit-key-1} = \meta{unit-key-2}
@@ -1242,25 +1393,200 @@ and the derived file cooking-units.sty.
% 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)
%
+% \subsubsection{Command behavior}
%
-% \begin{function}{eval-fraction}
-% \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
-% through zero are not allowed.
+% \begin{function}{cutext-to-cunum}
+% \begin{syntax}
+% cutext-to-cunum = \meta{true/false}
+% \end{syntax}
+% Want to get rid of all \cCutext? Set this option to \opt{true} and all
+% \cCutext\ are changed into \mycs{cunum}.
% \end{function}
+% \begin{cuexamplecode}
+% \cutext{1}{kg} \\
+% \Cutext{2}{kg} \\
+% \cutext{1/2}{kg} \\
+% \cutext{?}{kg} \\
+% \cutext[kg=g]{1--2}{kg} \\
+% \cusetup{cutext-to-cunum = true } @
+% \cutext{1}{kg} \\
+% \Cutext{2}{kg} \\
+% \cutext{1/2}{kg} \\
+% \cutext{?}{kg} \\
+% \cutext[kg=g]{1--2}{kg}
+% \end{cuexamplecode}
%
+% \begin{function}{cuam-version,cutext-version}
+% \begin{syntax}
+% cuam-version = \meta{old/new}
+% cutext-version = \meta{old/new}
+% \end{syntax}
+% Since v1.10 this package also parses and checks the input of \cCutext\ and
+% \mycs{cuam}. If you want to restore the old behavior, set this option to \opt{old},
+% but note that then you can neither change the amounts for a given number of persons
+% nor change the unit of \cCutext. Both of them are set to \opt{new} by default.
+% \end{function}
+%
+% \begin{function}{cutext-change-unit}
+% \begin{syntax}
+% cutext-change-unit = \meta{true/false}
+% \end{syntax}
+% Set this option to \opt{true} if you do \emph{not} want the units of \cCutext\
+% to be changed.
+% \end{function}
% \begin{cuexamplecode}
-% \cusetup{eval-fraction=true} @
-% \cunum{1/3}{kg} \\
+% \cutext[kg=g]{1}{kg} \\
+% \cutext[kg=g]{1/2}{kg} \\
+% \cutext[kg=g]{1--2}{kg} \\
+% \cusetup{cutext-change-unit=false } @
+% \cutext[kg=g]{1}{kg} \\
+% \cutext[kg=g]{1/2}{kg} \\
+% \cutext[kg=g]{1--2}{kg}
+% \end{cuexamplecode}
+%
+%
+% \subsubsection{Input and signs}
+%
+% \begin{function}{set-special-sign,add-special-sign}
+% \begin{syntax}
+% set-special-sign = \meta{character(s)}
+% add-special-sign = \meta{character(s)}
+% \end{syntax}
+% Allows \meta{character(s)} to be used in the first mandatory argument of
+% \lstinline!\cunum! without raising an error (you can customize this
+% behavior, see \opt{set-unknown-message}). By default it is set to \texttt{?}.
+% \end{function}
+%
+% \begin{cuexamplecode}
+% \cunum{?}{kg} \\
+% \cunum[g=kg]{10?--20?}{kg} \\
+% \cusetup{add-special-sign={xX} } @
+% \cunum{x}{kg} \\
+% \cunum{X--?}{kg} \\
+% \cusetup{set-special-sign={} } @
+% \cunum{1}{kg} \\
+% \cunum{1--2}{kg}
+% \end{cuexamplecode}
+%
+% \begin{function}{set-unknown-message}
+% \begin{syntax}
+% set-unknown-message = \meta{error/warning/none}
+% \end{syntax}
+% Using a special sign (\texttt{?} by default) causes a warning to
+% be raised. Set this option to \opt{error} if you want an error
+% (as an extra emphasis), \opt{warning} if you want a warning
+% (default) and \opt{none} if you don't want to know anything about it.
+% \end{function}
+%
+%
+% \begin{function}{use-numerals-below}
+% \begin{syntax}
+% use-numerals-below = \meta{integer}
+% \end{syntax}
+% Only usable if the package option \opt{use-numerals} is active. Prints the name of
+% the numbers for integers used in \mycs{cutext} and \mycs{Cutext}
+% smaller than \meta{integer}. \meta{integer} is by default
+% 13. Package pkg{fmtcount} is used for this purpose.
+% \end{function}
+% \cusetup{ use-numerals-below=13 }
+% \begin{cuexamplecode}
+% \cutext{1}{kg} \\
+% \cutext{2}{kg} \\
+% \cutext{12}{kg} \\
+% \cutext{13}{kg} \\
+% \cusetup{ use-numerals-below=10 } @
+% \cutext{1}{kg} \\
+% \cutext{2}{kg} \\
+% \cutext{12}{kg} \\
+% \cutext{13}{kg} \\
+% \cusetup{ use-numerals-below=0 } @
+% \cutext{1}{kg} \\
+% \cutext{2}{kg} \\
+% \cutext{12}{kg} \\
+% \cutext{13}{kg} \\
+% \cusetup{ use-numerals-below=12001 } @
+% \cutext[kg=g]{1}{kg} \\
+% \cutext[kg=g]{2}{kg} \\
+% \cutext[kg=g]{12}{kg} \\
+% \cutext[kg=g]{13}{kg}
+% \end{cuexamplecode}
+% \cusetup{ use-numerals-below=0 }
+%
+%
+% \begin{function}{parse-number}
+% \begin{syntax}
+% parse-number = \meta{true/false}
+% \end{syntax}
+% If set to \texttt{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|_|}). It is \texttt{true} by default.
+% \end{function}
+%
+% \begin{cuexamplecode}
+% \cusetup{ parse-number=false } @
+% \cunum[kg=g]{1}{kg} \\
+% \cunum{1--2}{kg} \\
+% \cunum{1----------2}{kg} \\
+% \cunum{1.2}{kg} \\
+% \cunum[kg=g]{1,2}{kg} \\
% \cunum{1/2}{kg} \\
-% \cunum[kg=g]{1/2}{kg} \\
-% \cunum{1_1/2}{kg} \\
-% \cunum[kg=g]{1_1/2}{kg}
+% \cunum{1_2/3}{kg} \\
+% \cunum{1/2_3}{kg} \\
+% \cunum{qwertzuiop}{kg} \\
+% \cutext{1}{kg} \\
+% \cutext{100}{kg} \\
+% \cutext{gjfak}{kg} \\
+% \cuam{1----------2} \\
+% \cuam{1,2} \\
+% \cuam{1_1/2} \\
+% \cuam{kwflk} \\
+% \end{cuexamplecode}
+%
+%
+%
+% \begin{function}{range-sign}
+% \begin{syntax}
+% range-sign = \meta{string}
+% cunum-range-sign = \meta{string}
+% cutext-range-sign = \meta{string}
+% \end{syntax}
+%^^A Sets the \emph{printed} range-sign equal to \meta{string}.
+% The second sets the \emph{printed} range-sign used in \mycs{cunum}
+% (and \mycs{cuam}) to
+% \meta{string}, the third sets the printed range-sign used in
+% \mycs{cutext}/\mycs{Cutext} to \meta{string}.
+%
+%^^A If you want to change to the same range-sign for all commands
+%^^A use the first option.
+% Use \opt{range-sign} to set the printed range-signs for both
+% \mycs{cunum} (and \mycs{cuam}) and \mycs{cutext}/\mycs{Cutext} to \meta{string}.
+%
+% The default for \meta{string} is \texttt{-{}-} (for both).
+% \end{function}
+%
+% \begin{cuexamplecode}
+% \cusetup{cunum-range-sign={~to~}} @
+% \cunum{1--2}{kg} \\
+% \cuam{1--2} \\
+% \cutext{1--2}{kg} \\
+% \Cutext{1--2}{kg}
+% \end{cuexamplecode}
+% \begin{cuexamplecode}
+% \cusetup{cutext-range-sign={~to~}} @
+% \cunum{1--2}{kg} \\
+% \cuam{1--2} \\
+% \cutext{1--2}{kg} \\
+% \Cutext{1--2}{kg}
+% \end{cuexamplecode}
+% \begin{cuexamplecode}
+% \cusetup{range-sign={~to~}} @
+% \cunum{1--2}{kg} \\
+% \cuam{1--2} \\
+% \cutext{1--2}{kg} \\
+% \Cutext{1--2}{kg}
% \end{cuexamplecode}
%
+% \subsubsection{Rounding options}
%
% \begin{function}{round-precision}
% \begin{syntax}
@@ -1331,54 +1657,31 @@ and the derived file cooking-units.sty.
% \cusetup{round-half=commercial} @
% \cunum{0.005}{kg} \\
% \cunum{-0.005}{kg} \\
-% \cunum{1.245}{kg}
+% \cunum{1.245}{kg} @
% \end{cuexamplecode}
%
%
-% \begin{function}{range-sign}
-% \begin{syntax}
-% range-sign = \meta{string}
-% cunum-range-sign = \meta{string}
-% cutext-range-sign = \meta{string}
-% \end{syntax}
-%^^A Sets the \emph{printed} range-sign equal to \meta{string}.
-% The second sets the \emph{printed} range-sign used in \mycs{cunum}
-% (and \mycs{cuam}) to
-% \meta{string}, the third sets the printed range-sign used in
-% \mycs{cutext}/\mycs{Cutext} to \meta{string}.
%
-%^^A If you want to change to the same range-sign for all commands
-%^^A use the first option.
-% Use the \opt{range-sign} to set the printed range-signs for both
-% \mycs{cunum} (and \mycs{cuam}) and \mycs{cutext}/\mycs{Cutext} to \meta{string}.
+% \subsubsection{Fractions}
%
-% The default for \meta{string} is \texttt{-{}-} (for both).
+% \begin{function}{eval-fraction}
+% \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
+% through zero are not allowed.
% \end{function}
%
% \begin{cuexamplecode}
-% \cusetup{cunum-range-sign={~to~}} @
-% \cunum{1--2}{kg} \\
-% \cuam{1--2} \\
-% \cutext{1--2}{kg} \\
-% \Cutext{1--2}{kg}
-% \end{cuexamplecode}
-% \begin{cuexamplecode}
-% \cusetup{cutext-range-sign={~to~}} @
-% \cunum{1--2}{kg} \\
-% \cuam{1--2} \\
-% \cutext{1--2}{kg} \\
-% \Cutext{1--2}{kg}
-% \end{cuexamplecode}
-% \begin{cuexamplecode}
-% \cusetup{range-sign={~to~}} @
-% \cunum{1--2}{kg} \\
-% \cuam{1--2} \\
-% \cutext{1--2}{kg} \\
-% \Cutext{1--2}{kg}
+% \cusetup{eval-fraction=true} @
+% \cunum{1/3}{kg} \\
+% \cunum{1/2}{kg} \\
+% \cunum[kg=g]{1/2}{kg} \\
+% \cunum{1_1/2}{kg} \\
+% \cunum[kg=g]{1_1/2}{kg}
% \end{cuexamplecode}
%
-%
-%
% \begin{function}{fraction-command}
% \begin{syntax}
% fraction-command = \meta{\cs{command}}
@@ -1426,6 +1729,7 @@ and the derived file cooking-units.sty.
% \cunum{1_2/3}{kg}
% \end{cuexamplecode}
%
+% \subsubsection{spaces}
%
% \begin{function}{mixed-fraction-space}
% \begin{syntax}
@@ -1434,117 +1738,147 @@ and the derived file cooking-units.sty.
% Sets the length between the fraction and the number in a mixed-fraction,
% default is \texttt{0.1em} (because I said so).
% \end{function}
-%
% \begin{cuexamplecode}
-% \cuam{1_2/3}{kg} \\
+% \cuam{1_2/3} \\
% \cunum{1_2/3}{kg} \\
% \cunum{10_2/3}{kg} \\
% \cusetup{mixed-fraction-space=1em } @
-% \cuam{1_2/3}{kg} \\
+% \cuam{1_2/3} \\
% \cunum{1_2/3}{kg} \\
% \cunum{10_2/3}{kg} \\
% \cusetup{mixed-fraction-space=0em } @
-% \cuam{1_2/3}{kg} \\
+% \cuam{1_2/3} \\
% \cunum{1_2/3}{kg} \\
% \cunum{10_2/3}{kg}
% \end{cuexamplecode}
%
-%
-% \begin{function}{set-special-sign,add-special-sign}
+% \begin{function}{cutext-space}
% \begin{syntax}
-% set-special-sign = \meta{character(s)}
-% add-special-sign = \meta{character(s)}
+% cutext-space = \meta{string}
% \end{syntax}
-% Allows \meta{character(s)} to be used in the first mandatory argument of
-% \lstinline!\cunum! without raising an error (you can customize this
-% behavior, see \opt{set-unknown-message}). By default it is set to \texttt{?}.
+% \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
+% if you want to e.g. insert an unbreakable space.
% \end{function}
-%
% \begin{cuexamplecode}
-% \cunum{?}{kg} \\
-% \cunum[g=kg]{10?--20?}{kg} \\
-% \cusetup{add-special-sign={xX} } @
-% \cunum{x}{kg} \\
-% \cunum{X--?}{kg} \\
-% \cusetup{set-special-sign={} } @
-% \cunum{1}{kg} \\
-% \cunum{1--2}{kg}
+% \cutext{1}{kg}\\
+% \Cutext{10}{kg}\\
+% \cusetup { cutext-space = ~ } @
+% \cutext{1}{kg}\\
+% \Cutext{10}{kg}\\
+% \cusetup { cutext-space = {} } @
+% \cutext{1}{kg}\\
+% \Cutext{10}{kg}\\
+% \cusetup { cutext-space = {qwe} } @
+% \cutext{1}{kg}\\
+% \Cutext{10}{kg}\\
% \end{cuexamplecode}
%
%
%
+% \subsubsection{label \& refs for People}
%
-%
-% \begin{function}{parse-number}
+% \begin{function}{recalculate-amount}
% \begin{syntax}
-% parse-number = \meta{true/false}
+% recalculate-amount = \meta{true/false}
% \end{syntax}
-% If set to \texttt{false} prints the number of \lstinline!\cunum!,
-% \lstinline!\cutext! and \lstinline!\Cutext!
-% as they are (after some \dots\ well \dots\ parsing due to \enquote{\lstinline|_|}). It is \texttt{true} by default.
+% Set this option to \opt{true} if you want to change your recipes to the given
+% number of people set by \opt{set-number-of-persons}. Note that only those
+% values who have a label are changed.
% \end{function}
%
-%
+% \begin{function}{set-number-of-persons}
+% \begin{syntax}
+% 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.
+% \end{function}
% \begin{cuexamplecode}
-% \cusetup{ parse-number=false } @
-% \cunum[kg=g]{1}{kg} \\
-% \cunum{1--2}{kg} \\
-% \cunum{1----------2}{kg} \\
-% \cunum{1.2}{kg} \\
-% \cunum[kg=g]{1,2}{kg} \\
-% \cunum{1/2}{kg} \\
-% \cunum{1_2/3}{kg} \\
-% \cunum{1/2_3}{kg} \\
-% \cunum{qwertzuiop}{kg} \\
-% \cutext{1}{kg} \\
-% \cutext{100}{kg} \\
-% \cutext{gjfak}{kg}
+% \culabel{anotherrecipe}{2} @
+% \curef{anotherrecipe}~persons \\ @
+% \cusetup{ recalculate-amount = true } @
+% \curef{anotherrecipe}~persons \\
+% \cunum<anotherrecipe>{1}{kg}\\
+% \cuam<anotherrecipe>{1}\\
+% \cutext<anotherrecipe>{1}{kg}\\
+% \Cutext[ref=anotherrecipe]{10}{kg}\\ @
+% \cusetup { set-number-of-persons = 3 } @
+% \curef{anotherrecipe}~persons \\
+% \cunum<anotherrecipe>{1}{kg}\\
+% \cuam<anotherrecipe>{1}\\
+% \cutext<anotherrecipe>{1}{kg}\\
+% \Cutext[ref=anotherrecipe]{10}{kg}\\ @
+% \cusetup { set-number-of-persons = 2 } @
+% \curef{anotherrecipe}~persons \\
+% \cunum<anotherrecipe>{1}{kg}\\
+% \cuam<anotherrecipe>{1}\\
+% \cutext<anotherrecipe>{1}{kg}\\
+% \Cutext[ref=anotherrecipe]{10}{kg}\\ @
+% \cusetup { set-number-of-persons = 1 } @
+% \curef{anotherrecipe}~person \\
+% \cunum<anotherrecipe>{1}{kg}\\
+% \cuam<anotherrecipe>{1}\\
+% \cutext<anotherrecipe>{1}{kg}\\
+% \Cutext[ref=anotherrecipe]{10}{kg}\\
% \end{cuexamplecode}
+%
%
-%
-%
-%
-%
-% \begin{function}{use-numerals-below}
+% \begin{function}{label}
% \begin{syntax}
-% use-numerals-below = \meta{integer}
+% label = \meta{string}*\meta{integer}
% \end{syntax}
-% Only usable if the package option \opt{use-numerals} is active. Prints the name of
-% the numbers for integers used in \mycs{cutext} and \mycs{Cutext}
-% smaller than \meta{integer}. \meta{integer} it is by default
-% 13.
+% 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
+% label is defined globally and must be unique.
% \end{function}
-%
-% \cusetup{ use-numerals-below=13 }
% \begin{cuexamplecode}
-% \cutext{1}{kg} \\
-% \cutext{2}{kg} \\
-% \cutext{12}{kg} \\
-% \cutext{13}{kg} \\
-% \cusetup{ use-numerals-below=10 } @
-% \cutext{1}{kg} \\
-% \cutext{2}{kg} \\
-% \cutext{12}{kg} \\
-% \cutext{13}{kg} \\
-% \cusetup{ use-numerals-below=0 } @
-% \cutext{1}{kg} \\
-% \cutext{2}{kg} \\
-% \cutext{12}{kg} \\
-% \cutext{13}{kg}
+% \cusetup{label=Toast*1} @
+% \curef{Toast}~person \\
+% \cuam<Toast>{2} \\
+% \cunum<Toast>{2}{dag} \\
+% \cusetup { recalculate-amount = true } @
+% \curef{Toast}~persons \\
+% \cuam<Toast>{2} \\
+% \cunum<Toast>{2}{dag}
% \end{cuexamplecode}
-% \cusetup{ use-numerals-below=0 }
%
-% \begin{function}{set-unknown-message}
+%
+% \begin{function}{get-label}
% \begin{syntax}
-% set-unknown-message = \meta{error/warning/none}
+% get-label = \meta{label}
% \end{syntax}
-% Using a special sign (\texttt{?} by default) causes a warning to
-% be raised. Set this option to \opt{error} if you want an error
-% (as an extra emphasis), \opt{warning} if you want a warning
-% (default) and \opt{none} if you don't want to know anything about it.
+% 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.
% \end{function}
+% \begin{cuexamplecode}
+% \culabel{Schinken}{3} @
+% \cusetup{get-label=Schinken} \\
+% \curef{Schinken} \\
+% \cusetup { recalculate-amount = true } @
+% \cusetup{get-label=Schinken} \\
+% \curef{Schinken} \\
+% \end{cuexamplecode}
%
%
+% \begin{function}{ref}
+% \begin{syntax}
+% ref = \meta{label}
+% \end{syntax}
+% Instead of using the first optional arguments of the commands in \vref{sec:commands}
+% you may use this option. It requires a valid value and throws an error if \meta{label}
+% is not defined.
+% \end{function}
+% \begin{cuexamplecode}
+% \culabel{Kaese}{3} @
+% \cunum<Kaese>[m=dm]{1}{m} \\
+% \cunum[ref=Kaese,m=dm]{1}{m} \\
+% \cusetup { recalculate-amount = true } @
+% \cunum<Kaese>[m=dm]{1}{m} \\
+% \cunum[ref=Kaese,m=dm]{1}{m}
+% \end{cuexamplecode}
%
% \subsection{Weird options}
%
@@ -1815,6 +2149,16 @@ and the derived file cooking-units.sty.
%^^A &=
%^^A \end{align}
%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
% \end{documentation}
%
% \begin{implementation}
@@ -1834,6 +2178,9 @@ and the derived file cooking-units.sty.
%
%
% Na dann, auf gehts!
+%
+% PS. The whole code-section needs more attention. Not the code itself, but
+% the written text which never saw a spell-checker and has partly become obsolete.
% \begin{macrocode}
\@ifpackageloaded {xparse}
{ }
@@ -1847,11 +2194,11 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\ProvidesExplPackage
{cooking-units}
- {2016/10/19}
- {1.04}
+ {2016/11/13}
+ {1.10}
{Ein Paket fuer Kocheinheiten}
% \end{macrocode}
-% Chekcing if \pkg{expl3} is uptodate, otherwise abort the loading of the package.
+% Checking if \pkg{expl3} is uptodate, otherwise abort the loading of the package.
% \begin{macrocode}
\@ifpackagelater { expl3 } { 2016/05/18 }
{ }
@@ -1904,7 +2251,7 @@ and the derived file cooking-units.sty.
% \tl_replace_once:NVn ,
% \tl_if_in:nVTF ,
% \tl_if_in:NVT ,
-% \fp_compare:cNnT ,
+% \fp_compare:vNnT ,
% \fp_eval:c,
% }
% Some commands we will need later.
@@ -1917,6 +2264,9 @@ and the derived file cooking-units.sty.
\cs_generate_variant:Nn \fp_compare:nNnT { cNnT }
\cs_generate_variant:Nn \fp_eval:n { c }
\cs_generate_variant:Nn \prop_get:cVN { cVc }
+\cs_generate_variant:Nn \int_abs:n { c }
+\cs_generate_variant:Nn \tl_show:n { f , x }
+\cs_generate_variant:Nn \fp_compare:nNnTF { v }
% \end{macrocode}
% \end{macro}
%
@@ -1982,6 +2332,11 @@ and the derived file cooking-units.sty.
\tl_new:N \l_@@_allowed_special_signs_tl
\tl_new:N \c_@@_str_hash_one_tl
\tl_new:N \l_@@_input_range_sign_tl
+\tl_new:N \l_@@_input_for_persons_sign
+\tl_new:N \l_@@_input_times_persons_sign
+\tl_new:N \l_@@_cutext_space_tl
+\tl_new:N \l_@@_translation_tmpa_tl
+\tl_new:N \l_@@_cutext_tmp_tl
% \end{macrocode}
% \end{macro}
%
@@ -1994,12 +2349,15 @@ and the derived file cooking-units.sty.
\tl_set:Nn \l_@@_cutext_range_sign_tl { -- }
\tl_set:Nn \l_@@_value_unit_space_tl { \thinspace }
\tl_set:Nn \l_@@_input_digits_tl { 0123456789 }
+\tl_set:Nn \l_@@_input_for_persons_sign { @ }
+\tl_set:Nn \l_@@_input_times_persons_sign { * }
\tl_set:Nn \l_@@_decimal_mark_tl { . , }
\tl_set:Nn \l_@@_value_signs_tl { + - }
\tl_set:Nn \l_@@_input_range_sign_tl { -- }
\tl_set:Nn \l_@@_allowed_special_signs_tl { ? }
\tl_set_rescan:Nnn \c_@@_str_hash_one_tl
{ \char_set_catcode_letter:N \# } {#1}
+\tl_set:Nn \l_@@_cutext_space_tl { \space }
% \end{macrocode}
%
% Flat out stolen from \pkg{siunitx}
@@ -2043,6 +2401,12 @@ and the derived file cooking-units.sty.
% \end{macro}
%
%
+% \begin{macro}{ \l_@@_persons_tmp_int }
+% \begin{macrocode}
+\int_new:N \l_@@_persons_tmp_int
+% \end{macrocode}
+% \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
@@ -2067,6 +2431,13 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{ \l_@@_calc_for_number_of_persons_int }
+% \begin{macrocode}
+\int_new:N \l_@@_calc_for_number_of_persons_int
+\int_set:Nn \l_@@_calc_for_number_of_persons_int { 4 }
+% \end{macrocode}
+% \end{macro}
+%
%
%
% \begin{macro}{ \l_@@_list_of_defined_keys_clist , \g_@@_list_of_defined_units_clist }
@@ -2111,7 +2482,6 @@ and the derived file cooking-units.sty.
% \l_@@_cutext_uppercase_word_bool,
% \l_@@_error_for_unknown_value_bool,
% \l_@@_parse_range_bool,
-% ^^A \l_@@_round_special_bool
% }
% Some booleans we need later.
% \begin{macrocode}
@@ -2128,14 +2498,22 @@ and the derived file cooking-units.sty.
\bool_new:N \l_@@_cutext_uppercase_word_bool
\bool_new:N \l_@@_error_for_unknown_value_bool
\bool_new:N \l_@@_parse_range_bool
-%\bool_new:N \l_@@_round_special_bool
-%\bool_new:N \l_@@_unit_is_singlekey_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_@@_calc_because_ref_was_given_bool
+\bool_new:N \l_@@_calc_persons_tmp_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
% \end{macrocode}
% \end{macro}
%
% Setting some of them to \texttt{true}.
% \begin{macrocode}
\bool_set_true:N \l_@@_parse_input_bool
+\bool_set_true:N \l_@@_cutext_change_unit_bool
% \end{macrocode}
%
%
@@ -2180,7 +2558,7 @@ and the derived file cooking-units.sty.
%
% Let's define some keys.
% \begin{macrocode}
-\keys_define:nn { cooking - units }
+\keys_define:nn { cooking-units }
{
% \end{macrocode}
%
@@ -2287,7 +2665,7 @@ and the derived file cooking-units.sty.
%
%
% \begin{macro}{ input-range-sign }
-% Don't wanna use \verb|--| as a range sperator in \mycs{cunum}? Set
+% 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 ,
@@ -2316,6 +2694,7 @@ and the derived file cooking-units.sty.
},
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
@@ -2361,7 +2740,7 @@ and the derived file cooking-units.sty.
}
},
% \end{macrocode}
-%
+% \end{macro}
%
% \begin{macro}{ round-half }
% Choosing between \enquote{normal} rounding to even and commercial rounding.
@@ -2371,38 +2750,112 @@ and the derived file cooking-units.sty.
round-half .choices:nn =
{ default , commercial }
{
-% \bool_set_true:N \l_@@_round_special_bool
- \cs_set:Npx \@@_round_setup:n ####1
+ \int_case:nn { \l_keys_choice_int }
{
- \exp_not:N \l_@@_significant_figures_int
- \int_case:nn { \l_keys_choice_int }
- {
- { 1 } { }
- { 2 } { \exp_not:N, ####1 }
- }
+ { 1 } { \bool_set_false:N \l_@@_round_commercial_bool }
+ { 2 } { \bool_set_true:N \l_@@_round_commercial_bool }
}
},
round-half .default:n = { default },
% \end{macrocode}
+% \end{macro}
%
+% \begin{macro}{ set-number-of-persons }
+% \begin{macrocode}
+ set-number-of-persons .int_set:N = \l_@@_calc_for_number_of_persons_int ,
+ set-number-of-persons .default:n = { 4 } ,
+% \end{macrocode}
+% \end{macro}
%
% \begin{macro}{ label }
% \begin{macrocode}
- label .code:n = { \label{cooking-units-#1} } ,
+ label .code:n =
+ {
+ \@@_label_and_persons:n {#1}
+ } ,
+ label .value_required:n = { true } ,
% \end{macrocode}
+% \end{macro}
%
-% \begin{macro}{ for-persons }
+% \begin{macro}{ get-label }
% \begin{macrocode}
- for-persons .int_set:N = \l_@@_number_of_persons_int ,
- for-persons .default:n = { 4 } ,
+ get-label .code:n =
+ {
+ \@@_curef:n {#1}
+ } ,
+ label .value_required:n = { true } ,
% \end{macrocode}
+% \end{macro}
%
-% Ending the definition of keys.
+% \begin{macro}{ ref }
+% \begin{macrocode}
+ ref .code:n =
+ {
+ \@@_reference_label_and_persons:n {#1}
+ } ,
+ ref .value_required:n = { true } ,
+% \end{macrocode}
% \end{macro}
- }
+%
+% \begin{macro}{ cuam-version , cutext-version}
% \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 } ,
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{ recalculate-amount }
+% \begin{macrocode}
+ recalculate-amount .bool_set:N = \l_@@_calc_for_persons_bool ,
+ recalculate-amount .default:n = { false } ,
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{ recalculate-amount }
+% \begin{macrocode}
+ cutext-to-cunum .bool_set:N = \l_@@_cutext_to_cunum_bool ,
+ cutext-to-cunum .default:n = { false } ,
% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{ cutext-space }
+% \begin{macrocode}
+ cutext-space .tl_set:N = \l_@@_cutext_space_tl ,
+ cutext-space .default:n = { \space } ,
+% \end{macrocode}
+% \end{macro}
%
+% \begin{macro}{ cutext-change-unit }
+% \begin{macrocode}
+ cutext-change-unit .bool_set:N = \l_@@_cutext_change_unit_bool ,
+ cutext-change-unit .default:n = { true } ,
+% \end{macrocode}
+% \end{macro}
+%
+% Ending the definition of keys.
+% \begin{macrocode}
+ }
+% \end{macrocode}
+% \end{macro}
+%
%
%
% \subsection {Messages}
@@ -2449,7 +2902,7 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% Error if unit is already defined.
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { unit-already-defined }
+\msg_new:nnnn { cooking-units } { unit-already-defined }
{ The\ unit \ '#1' \ is \ already \ defined. }
{
The \ unit-key \ is \ already \ defined. \ Please \ use \ a \ different \
@@ -2460,7 +2913,7 @@ and the derived file cooking-units.sty.
%
% Missing argument in \lstinline|\cudefinesymbols| (et all).
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { missing-argument }
+\msg_new:nnnn { cooking-units } { missing-argument }
{ There \ is \ an \ missing \ argument. }
{
You \ probably \ have \ forgotten \ a \ curly-brace \ pair.
@@ -2469,13 +2922,13 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% If fractions are evaluated division by zero is not allowed.
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { Division-by-zero }
+\msg_new:nnnn { cooking-units } { Division-by-zero }
{ Division\ by \ zero \ is \ not \ allowed. }
{ See \ a \ math \ book \ of \ your \ choice \ or \ for \ example \ Wikipedia. }
% \end{macrocode}
% Showing the not allowed token in the input. Hope this helps.
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { Token-not-allowed }
+\msg_new:nnnn { cooking-units } { Token-not-allowed }
{ The \ token \ '#1' \ is \ not \ allowed. }
{
The \ command \ accepts \ only \ a \ fixed \ number \ of \ tokens.
@@ -2484,7 +2937,7 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% A second decimal sign is not allowed (No na net).
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { Second - decimal -sign - not - allowed }
+\msg_new:nnnn { cooking-units } { Second - decimal -sign - not - allowed }
{ A \ second \ decimal \ sign \ is \ not \ allowed. }
{
Perhaps \ you \ didn't \ type \ it \ correctly.
@@ -2493,7 +2946,7 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% Error message for an undefined key.
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { Key - not -defined }
+\msg_new:nnnn { cooking-units } { Key - not -defined }
{
The \ key \ '#1' \ is \ not \ defined. \ Use \ \cudefinekeys or \
\cudefinesinglekey to \ define \ keys.
@@ -2505,7 +2958,7 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% If the temperature is too low print this error message.
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { Temperature-to-low }
+\msg_new:nnnn { cooking-units } { Temperature-to-low }
{
The \ temperature \ '#1' \ is \ to \ low.\ It \ cannot \ be \
below \ the \ absolute \ zero - point \ of \ '#2'. \ Note \ that \
@@ -2519,7 +2972,7 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% If for an unit-key the value is wrong the following error message is shown.
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { key-choice-unknown }
+\msg_new:nnnn { cooking-units } { key-choice-unknown }
{
The \ key \ '#1' \ only \ accepts \ only \
'#3' \ as \ a \ set \ of \ choices \ and \ '#2' \ is \ non \ of \ these.
@@ -2536,7 +2989,7 @@ and the derived file cooking-units.sty.
%\changes {v0.99} {2016/06/12} {Renamed option: 'amount-not-known'.}
% An info message that there are unknown values.
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { amount-not-known }
+\msg_new:nnnn { cooking-units } { amount-not-known }
{
The \ amount \ of \ #1 \ is \ not \ known \ at \ line \
\msg_line_number: .
@@ -2552,7 +3005,7 @@ and the derived file cooking-units.sty.
% If a load time option not used as a package option, but later, this
% message is shown.
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { load-time-option }
+\msg_new:nnnn { cooking-units } { load-time-option }
{
The \ option \ '#1' \ is \ only \ available \ as \ a \ load-time-option. \
Please \ set \ it \ as \ a \ package \ option.
@@ -2567,7 +3020,7 @@ and the derived file cooking-units.sty.
% If a load time option not used as a package option, but later, this
% message is shown.
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { obsolete-command }
+\msg_new:nnnn { cooking-units } { obsolete-command }
{
Command \ #1 is \ obsolete. \ Please \ use \ #2 instead.
}
@@ -2580,7 +3033,7 @@ and the derived file cooking-units.sty.
% 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 }
+\msg_new:nnnn { cooking-units } { No-Value-given }
{
Please \ input \ a \ number \ to \ check \ for \
'check-temperature'.
@@ -2594,7 +3047,7 @@ and the derived file cooking-units.sty.
%
%
% \begin{macrocode}
-\msg_new:nnnn { cooking - units } { Minimum-already-defined }
+\msg_new:nnnn { cooking-units } { Minimum-already-defined }
{
A \ minimum \ for \ '#1' \ has \ already \ been \ defined.
}
@@ -2603,6 +3056,64 @@ and the derived file cooking-units.sty.
\msg_see_documentation_text:n { cooking-units }
}
% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnnn { cooking-units } { Number-of-persons-missing }
+ {
+ Please \ add \ the \ number \ of \ persons \ this \ recipe \ is \ for \ in \ '#1'. \
+ Note \ that\ the \ number \ must \ be \ given \ after \ a \ '*'.
+ }
+ {
+ Write \ 'Schweinsbraten*4' \ to \ create \ the \ label \ 'Schweinsbraten' \
+ which \ is \ initially \ for \ 4 \ persons.
+ \msg_see_documentation_text:n { cooking-units }
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnnn { cooking-units } { Number-of-persons-is-not-an-integer }
+ {
+ The \ number \ of \ persons \ the \ recipe \ is \ for \ must \ be \ an \
+ integer.
+ }
+ {
+ The \ number \ '#1' \ is \ not \ allowed.
+ \msg_see_documentation_text:n { cooking-units }
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\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 }
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnnn { cooking-units } { label-not-defined }
+ {
+ The \ label \ is \ not \ defined. \ Please \ note \ that \ a \ label
+ \ has \ to \ defined \ before \ it \ is \ referenced.
+ }
+ {
+ Define \ the \ label \ before \ using \ it.
+ \msg_see_documentation_text:n { cooking-units }
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\msg_new:nnnn { cooking-units } { redefine-unit }
+ {
+ The \ unit \ '#1' \ is \ redefined \ by \ \declarecookingunit at \ \msg_line_context: .
+ }
+ {
+ \msg_see_documentation_text:n { cooking-units }
+ }
+% \end{macrocode}
% \end{macro}
%
% \section {Helper Macros}
@@ -2630,24 +3141,31 @@ and the derived file cooking-units.sty.
%
%
%
-% \begin{macro}{\@@_if_integer_and_parse:n}
+% \begin{macro}{ \@@_if_integer:n , \@@_if_integer_and_parse:n}
% Checking if the input consists only of numbers. Furthermore tests if
% the input should be parsed at all.
%
% \begin{macrocode}
%\cs_new:Npn \@@_if_number_and_parse_aux: { }
+\prg_new_protected_conditional:Npnn \@@_if_integer:n #1 { TF }
+ {
+ \tl_map_inline:nn {#1}
+ {
+ \tl_if_in:NnF \l_@@_input_digits_tl {##1}
+ {
+ \tl_map_break:n { \use_iii:nnn }
+ }
+ }
+ \use_i:nn \prg_return_true: \prg_return_false:
+ }
+%
\prg_new_protected_conditional:Npnn \@@_if_integer_and_parse:n #1 { TF }
{
\bool_if:NTF \l_@@_parse_input_bool
{
- \tl_map_inline:nn {#1}
- {
- \tl_if_in:NnF \l_@@_input_digits_tl {##1}
- {
- \tl_map_break:n { \use_iii:nnn }
- }
- }
- \use_i:nn \prg_return_true: \prg_return_false:
+ \@@_if_integer:nTF {#1}
+ { \prg_return_true: }
+ { \prg_return_false: }
}
{ \prg_return_false: }
}
@@ -2692,15 +3210,6 @@ and the derived file cooking-units.sty.
cl= (chbareV-1)3 ,
ml= (chbareV-1)3 ,
}
- \prop_get:NVN \l_@@_change_unit_prop \l_@@_tmp_unit_tl \l_@@_option_unit_tl
- \quark_if_no_value:NT \l_@@_option_unit_tl
- {
- \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_tmp_unit_tl
- }
- \keys_set_filter:nnv
- { cooking-units }
- { change-unit }
- { l_@@_predefined_option_ \l_@@_option_unit_tl _clist }
}
% \end{macrocode}
%\end{macro}
@@ -2709,12 +3218,23 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\cs_new:Npn \@@_deftranslation:Nnn #1#2#3
{
- \deftranslation [ to=#1 ] { #2 } {#3}
+ \deftranslation [ to=#1 ] {#2} {#3}
}
\cs_generate_variant:Nn \@@_deftranslation:Nnn { Vnn , Vnv }
% \end{macrocode}
% \end{macro}
%
+% \begin{macro}{\@@_tl_set_fp_and_eval:Nn}
+% 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:Nf #1 { \fp_eval:n {#2} }
+ }
+\cs_generate_variant:Nn \@@_tl_set_fp_and_eval:Nn { Nc }
+% \end{macrocode}
+% \end{macro}
+%
% \begin{macro}{\@@_deftranslation:Nnn}
% Commands used in the option \texttt{temperature-to-check}.
% If no value is given (first command) it raises an error. If a value
@@ -2729,7 +3249,7 @@ and the derived file cooking-units.sty.
{
\@@_error_if_unit_not_defined:n {#1}
\fp_if_exist:cTF { c_@@_ #1 _min_fp }
- { \msg_error:nnn { cooking-units } { Minimum-already-defined } {#1} }
+ { \msg_warning:nnn { cooking-units } { Minimum-already-defined } {#1} }
{
\clist_put_right:Nn \l_@@_temperatures_to_check_clist {#1}
\fp_const:cn { c_@@_ #1 _min_fp } {#2}
@@ -2738,17 +3258,142 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{\@@_deftranslation:Nnn}
-% Commands used in the option \texttt{temperature-to-check}.
-% If no value is given (first command) it raises an error. If a value
-% is given the unit is added to a check-list and a new
-% constant is defined.
+% \begin{macro}{\@@_rounding_function:n}
+% \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 } }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\@@_label_and_persons:n}
+% \begin{macrocode}
+\cs_new:Npn \@@_label_and_persons:n #1
+ {
+ \tl_if_in:nnTF {#1} { @ }
+ {
+ \@@_label_and_persons_for_persons:ww #1 \q_stop
+ }{
+ \tl_if_in:nnTF {#1} { * }
+ {
+ \@@_label_and_persons_times_persons:ww #1 \q_stop
+ }{
+ \msg_error:nnn { cooking-units} { Number-of-persons-missing } {#1}
+ }
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\cs_new:Npn \@@_label_and_persons_for_persons:ww #1 @ #2 \q_stop
+ {
+ \@@_culabel:nnn {#1} {#2} { }
+ }
+% \end{macrocode}
% \begin{macrocode}
-\cs_new:Npn \@@_round_setup:n #1 { \l_@@_significant_figures_int }
+\cs_new:Npn \@@_label_and_persons_times_persons:ww #1 * #2 \q_stop
+ {
+ \@@_culabel:nnn {#1} {#2} { - }
+ }
+% \end{macrocode}
+%
+% \begin{macro}{ \@@_reference_label_and_persons:n }
+% \begin{macrocode}
+\cs_new:Npn \@@_reference_label_and_persons:n #1
+ {
+ \int_if_exist:cTF { l_@@_persons_ #1 _int }
+ {
+ \bool_set_true:N \l_@@_calc_because_ref_was_given_bool
+ \int_set:Nn \l_@@_persons_tmp_int
+ {
+ \int_abs:c { l_@@_persons_ #1 _int }
+ }
+ }
+ { \msg_error:nnn { cooking-units } { label-not-defined } {#1} }
+ }
% \end{macrocode}
% \end{macro}
%
-% \subsection {Parsing and cheking numbers}
+% \begin{macro}{ \@@_culabel:nn , \@@_curef:n }
+% \begin{macrocode}
+\cs_new:Npn \@@_culabel:nnn #1#2#3
+ {
+ \int_if_exist:cTF { l_@@_persons_ #1 _int }
+ {
+ \msg_error:nnn { cooking-units } { label-already-defined } {#1}
+ }{
+ \@@_if_integer:nTF {#2}
+ {
+ \int_new:c { l_@@_persons_ #1 _int }
+ \int_gset:cn { l_@@_persons_ #1 _int } { #3 #2 }
+ }
+ { \msg_error:nnn { cooking-units } { Number-of-persons-is-not-an-integer } {#2} }
+ }
+ }
+\cs_new:Npn \@@_curef:n #1
+ {
+ \int_if_exist:cTF { l_@@_persons_ #1 _int }
+ {
+ \bool_if:NTF \l_@@_calc_for_persons_bool
+ { \int_use:N \l_@@_calc_for_number_of_persons_int }
+ { \int_abs:c { l_@@_persons_ #1 _int } }
+ }{ \msg_error:nnn { cooking-units } { label-not-defined } {#1} }
+ }
+\NewDocumentCommand \culabel { m m } { \@@_culabel:nnn {#1} {#2} {} }
+\DeclareExpandableDocumentCommand \curef { m } { \@@_curef:n {#1} }
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
+%
+%
+% \begin{macro}{ \@@_tl_if_in_remove_and_set_bool:NnN }
+% \begin{macrocode}
+\cs_new:Npn \@@_tl_if_in_remove_and_set_bool:NnN #1#2#3
+ {
+ \tl_if_in:NnTF #1 {#2}
+ {
+ \bool_set_true:N #3
+ \tl_remove_once:Nn #1 {#2}
+ }{
+ \bool_set_false:N #3
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{ \@@_tl_if_in_remove_and_reverse_bool:NnN }
+% \begin{macrocode}
+\cs_new:Npn \@@_tl_if_in_remove_and_reverse_bool:NnN #1#2#3
+ {
+ \tl_if_in:NnT #1 {#2}
+ {
+ \bool_if:NTF #3
+ { \bool_set_false:N #3 }
+ { \bool_set_true:N #3 }
+ \tl_remove_once:Nn #1 {#2}
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
+%
+%
+%
+% \subsection {Parsing and checking numbers}
%
% This section contains macros helping an checking the input.
%
@@ -2799,7 +3444,9 @@ and the derived file cooking-units.sty.
\@@_parse_input_and_safe_in:nN {#1} \l_@@_tmpa_tl
\@@_parse_input_and_safe_in:nN {#2} \l_@@_tmpb_tl
\@@_calculate_and_print_input:N \l_@@_tmpa_tl
- \tl_use:N \l_@@_cunum_range_sign_tl
+ \bool_if:NTF \l_@@_using_cutext_bool
+ { \tl_use:N \l_@@_cutext_range_sign_tl }
+ { \tl_use:N \l_@@_cunum_range_sign_tl }
\@@_calculate_and_print_input:N \l_@@_tmpb_tl
}
% \end{macrocode}
@@ -2811,19 +3458,25 @@ and the derived file cooking-units.sty.
% 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|\@@_formatiere_fractions:nNN| indicates a
% \enquote{normal} fraction.
% \begin{macrocode}
\cs_new:Npn \@@_parse_fraction_in_input:ww #1/#2 \q_stop
{
\@@_parse_input_and_safe_in:nN {#1} \l_@@_tmpa_tl
\@@_parse_input_and_safe_in:nN {#2} \l_@@_tmpb_tl
- \bool_if:NTF \l_@@_eval_fractions_bool
+ \bool_if:nTF
+ {
+ \l_@@_calc_persons_tmp_bool ||
+ \l_@@_eval_fractions_bool
+ }
{
\@@_calculate_and_print_input:n
{ \l_@@_tmpa_tl / \l_@@_tmpb_tl }
}{
- \@@_formatiere_fractions:nnn
+ \@@_tl_if_in_remove_and_set_bool:NnN \l_@@_tmpa_tl { - } \l_tmpb_bool
+ \@@_tl_if_in_remove_and_reverse_bool:NnN \l_@@_tmpb_tl { - } \l_tmpb_bool
+ \@@_formatiere_fractions:nNN
{ }
{ \l_@@_tmpa_tl }
{ \l_@@_tmpb_tl }
@@ -2850,19 +3503,26 @@ and the derived file cooking-units.sty.
\@@_parse_input_and_safe_in:nN {#1} \l_@@_mixed_fraction_tl
\@@_parse_input_and_safe_in:nN {#2} \l_@@_tmpa_tl
\@@_parse_input_and_safe_in:nN {#3} \l_@@_tmpb_tl
- \bool_if:NTF \l_@@_eval_fractions_bool
+ \@@_tl_if_in_remove_and_set_bool:NnN \l_@@_mixed_fraction_tl { - } \l_tmpb_bool
+ \@@_tl_if_in_remove_and_reverse_bool:NnN \l_@@_tmpa_tl { - } \l_tmpb_bool
+ \@@_tl_if_in_remove_and_reverse_bool:NnN \l_@@_tmpb_tl { - } \l_tmpb_bool
+ \bool_if:nTF
{
+ \l_@@_calc_persons_tmp_bool ||
+ \l_@@_eval_fractions_bool
+ }{
\@@_calculate_and_print_input:n
{
- \l_@@_mixed_fraction_tl
- \fp_compare:nNnTF
- { \l_@@_mixed_fraction_tl } < { \c_zero_fp }
- { - }
- { + }
+ \bool_if:NTF \l_tmpb_bool
+% \l_@@_mixed_fraction_tl
+% \fp_compare:nNnTF
+% { \l_@@_mixed_fraction_tl } < { \c_zero_fp }
+ { - \l_@@_mixed_fraction_tl - }
+ { \l_@@_mixed_fraction_tl + }
\l_@@_tmpa_tl / \l_@@_tmpb_tl
}
}{
- \@@_formatiere_fractions:nnn
+ \@@_formatiere_fractions:nNN
{ \l_@@_mixed_fraction_tl }
{ \l_@@_tmpa_tl }
{ \l_@@_tmpb_tl }
@@ -2943,8 +3603,7 @@ and the derived file cooking-units.sty.
\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} }
@@ -2960,7 +3619,7 @@ and the derived file cooking-units.sty.
%
% \subsection {Formatiere \& Calculiere}
%
-% \begin{macro}{ \@@_calculate_and_print_input:n , \@@_calculate_and_print_input:n }
+% \begin{macro}{ \@@_calculate_and_print_input:n , \@@_calculate_and_print_input:N }
%
% \changes {v0.98a} {2016/06/11} {Added warning to show if an unknown value is used.}
%
@@ -2982,10 +3641,16 @@ and the derived file cooking-units.sty.
\msg_warning:nnx { cooking-units } { amount-not-known } \l_tmpa_tl
}
{
- \@@_calculate_input_and_store_in:nN {#1} \l_tmpa_tl
+ \bool_if:nTF
+ { \l_@@_using_cutext_bool && ! \l_@@_cutext_change_unit_bool }
+ { \tl_set:Nf \l_tmpa_tl {#1} }
+ { \@@_calculate_input_and_store_in:nN {#1} \l_tmpa_tl }
+ \bool_if:NT \l_@@_calc_persons_tmp_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
}
- \@@_print_nummerical_output:N \l_tmpa_tl
+ \@@_print_output:N \l_tmpa_tl
}
}
\cs_generate_variant:Nn \@@_calculate_and_print_input:n { N }
@@ -2995,7 +3660,6 @@ and the derived file cooking-units.sty.
% \begin{macro}
% {
% \@@_calculate_input_and_store_in:nN ,
-% \@@_calculate_input_and_store_in:VN
% }
% Well \dots\ this function calculates the input. First checks if the
% wanted conversion contains a \lstinline|\l_tmpa_fp| (ergo a \#1 in
@@ -3008,27 +3672,40 @@ and the derived file cooking-units.sty.
\fp_set:Nn \l_tmpa_fp {#1}
\tl_if_in:cnTF { l_@@_tmpa_ \l_@@_tmp_unit_tl _ tl } { \l_tmpa_fp }
{
- \tl_set:Nf #2
- {
- \fp_eval:c { l_@@_tmpa_ \l_@@_tmp_unit_tl _ tl }
- }
+ \@@_tl_set_fp_and_eval:Nc #2 { l_@@_tmpa_ \l_@@_tmp_unit_tl _ tl }
}{
- \tl_set:Nf #2
- {
- \fp_eval:n
- {
- \l_tmpa_fp *
- \tl_use:c { l_@@_tmpa_ \l_@@_tmp_unit_tl _ tl }
- }
- }
+ \@@_tl_set_fp_and_eval:Nn #2
+ { \l_tmpa_fp * \tl_use:c { l_@@_tmpa_ \l_@@_tmp_unit_tl _ tl } }
+% \tl_set:Nf #2
+% {
+% \fp_compare:vNnTF { l_@@_tmpa_ \l_@@_tmp_unit_tl _ tl } = { \c_one_fp }
+% {#1}
+% \fp_eval:n { \l_tmpa_fp * \tl_use:c { l_@@_tmpa_ \l_@@_tmp_unit_tl _ tl } }
+% }
}
- \@@_round_calculated_input:NV #2 #2
}
-\cs_generate_variant:Nn \@@_calculate_input_and_store_in:nN { V }
% \end{macrocode}
% \end{macro}
%
%
+% \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_@@_persons_tmp_int }
+ {
+ \@@_tl_set_fp_and_eval:Nn #1
+ {
+ \l_@@_calc_for_number_of_persons_int /
+ \l_@@_persons_tmp_int *
+ #2
+ }
+ }
+ }
+% \end{macrocode}
+%
%
% \begin{macro}{\@@_check_number_after_dot:n,\@@_check_number_after_dot_aux:w}
% Getting the number after the decimal point. If it doesn't exist
@@ -3046,8 +3723,12 @@ and the derived file cooking-units.sty.
\cs_new:Npn \@@_check_number_after_dot_aux:w #1. #2 .
{
\quark_if_recursion_tail_stop:n {#2}
- \int_compare:nNnF
- { \tl_count:n {#2} } < { \l_@@_significant_figures_plus_one_int }
+ \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:nNnTF
+ { \tl_count:n {#2} } < { \l_tmpa_int }
+ { \bool_set_false:N \l_tmpa_bool }
{ \bool_set_true:N \l_tmpa_bool }
\use_none_delimit_by_q_recursion_stop:w
}
@@ -3055,54 +3736,75 @@ and the derived file cooking-units.sty.
% \end{macro}
%
% \begin{macro}{ \@@_round_calculated_input:NN,\@@_round_calculated_input:NV }
-% After calculating the numbers are rounded (if needed). We test at first if
+% 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
% 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
{
- \bool_set_false:N \l_tmpa_bool
\@@_check_number_after_dot:n {#2}
\tl_set:Nf #1
{
- \bool_if:NTF \l_@@_round_to_int_bool
- {
- \fp_eval:n { round (#2) }
- }{
- \bool_if:NTF \l_tmpa_bool
- {
- \fp_eval:n { round( #2 , \@@_round_setup:n {#2} ) }
- }
- {#2}
- }
-% \bool_if:nTF { \l_tmpa_bool || \l_@@_round_to_int_bool }
-% {
-% \fp_eval:n
-% {
-% \bool_if:NTF \l_@@_round_to_int_bool
-% { round (#2) }
-% {
-% round( #2 , \@@_round_setup:n {#2} )
-% }
-% }
-% }
-% {#2}
+ \bool_if:NTF \l_tmpa_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}{ \@@_formatiere_fractions:nnn }
+%
+%
+%
+% \begin{macro}{ \@@_print_output:N }
+% 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_@@_tmp_unit_tl} (the unit given in the second argument of
+% \mycs{cutext} or \mycs{Cutext}) by default.
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_print_output:N #1
+ {
+ \bool_if:NTF \l_@@_using_cutext_bool
+ {
+ \tl_set_eq:NN \l_@@_cutext_tmp_tl #1
+ \@@_cutext_print_output:NV #1 \l_@@_option_unit_tl
+ }
+ { \@@_print_nummerical_output:N #1 }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{ \@@_print_nummerical_output: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_nummerical_output:N #1
+ {
+ \translatelet \l_@@_translation_tmpa_tl { decimal-mark ( cu-unitname ) }
+ \tl_replace_once:NnV #1 { . } \l_@@_translation_tmpa_tl
+ \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
+\cs_new:Npn \@@_formatiere_fractions:nNN #1#2#3
{
\bool_set_true:N \l_@@_fraction_in_input_bool
+ \bool_if:NT \l_tmpb_bool { \c_@@_minus_tl }
\tl_if_empty:nF {#1}
{
#1
@@ -3143,23 +3845,6 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{ \@@_print_nummerical_output:N }
-% Prints the nummerical ouput (if it is not a fraction).
-%
-% \lstinline|\l_@@_tmpa_tl| can be very dangerous because values are also stored
-% within \lstinline|\l_@@_tmpa_tl|, but as long as the value stored inside
-% this function is processed first all is fine.
-% \begin{macrocode}
-\cs_new_protected:Npn \@@_print_nummerical_output:N #1
- {
-%% \l_@@_tmpa_tl is sehr gefaehrlich hier.
- \translatelet \l_@@_tmpa_tl { decimal-mark ( cu-unitname ) }
- \tl_replace_once:NnV #1 { . } \l_@@_tmpa_tl
- \tl_replace_once:NnV #1 { - } \c_@@_minus_tl
- #1
- }
-% \end{macrocode}
-% \end{macro}
%
%
%
@@ -3169,13 +3854,14 @@ and the derived file cooking-units.sty.
% \begin{macro}{ \cunum }
% The main command of this package.
% \begin{macrocode}
-\NewDocumentCommand \cunum { O{} m O{} m }
+\NewDocumentCommand \cunum { d<> O{} m O{} m }
{
\group_begin:
- \@@_cunum_initialise:nnnn {#1} {#2} {#3} {#4}
+ \@@_cunum_initialise:nnnnn {#1} {#2} {#3} {#4} {#5}
\bool_if:NTF \l_@@_parse_input_bool
- { \@@_cunum:nnVV {#2} {#3} \l_@@_option_unit_tl \l_@@_tmp_unit_tl }
- { \@@_cunum_do_not_parse:nnn {#2} {#3} {#4} }
+ { \@@_parse_and_evaluate_input:n {#3} }
+ { \@@_cunum_do_not_parse:nnn {#3} {#4} {#5} }
+ \@@_cunum_print_correct_unit:nVV {#4} \l_@@_option_unit_tl \l_@@_tmp_unit_tl
\group_end:
}
% \end{macrocode}
@@ -3193,30 +3879,57 @@ and the derived file cooking-units.sty.
% set the 'normal' options given by the optional argument.
%
% \begin{macrocode}
-\cs_new_protected:Npn \@@_cunum_initialise:nnnn #1#2#3#4
+\cs_new_protected:Npn \@@_cunum_initialise:nnnnn #1#2#3#4#5
{
- \tl_set:Nn \l_@@_tmp_unit_tl {#4}
+ \@@_initialise_default:nnn {#1} {#2} {#5}
+ \@@_initialise_unit_change:nnn {#1} {#2} {#5}
+ \@@_initialise_after_unit_change:nnn {#1} {#2} {#5}
+ }
+% \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_@@_tmp_unit_tl {#3}
\@@_error_if_unit_not_defined:V \l_@@_tmp_unit_tl
- \tl_if_empty:nF {#1}
- { \keys_set_groups:nnn { cooking-units } { change-unit } {#1} }
- \bool_if:NTF \l_@@_convert_to_eV_bool
+ \bool_set_false:N \l_@@_special_sign_bool
+ \bool_set_false:N \l_@@_error_bool
+ \bool_set_false:N \l_@@_parse_range_bool
+ }
+\cs_generate_variant:Nn \@@_initialise_default:nnn { nnV}
+% \end{macrocode}
+% \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:NVN \l_@@_change_unit_prop \l_@@_tmp_unit_tl \l_@@_option_unit_tl
+ \quark_if_no_value:NT \l_@@_option_unit_tl
+ { \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_tmp_unit_tl }
+ }
+% \end{macrocode}
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_initialise_after_unit_change:nnn #1#2#3
+ {
+ \IfNoValueF {#1}
+ { \@@_reference_label_and_persons:n {#1} }
+ \clist_if_empty:cF { l_@@_predefined_option_ \l_@@_option_unit_tl _clist }
{
- \prop_get:NVN \l_@@_change_unit_prop \l_@@_tmp_unit_tl \l_@@_option_unit_tl
- \quark_if_no_value:NT \l_@@_option_unit_tl
- {
- \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_tmp_unit_tl
- }
\keys_set_filter:nnv
{ cooking-units }
{ change-unit }
{ l_@@_predefined_option_ \l_@@_option_unit_tl _clist }
- \tl_if_empty:nF {#1}
- { \keys_set_filter:nnn { cooking-units } { change-unit } {#1} }
}
- \bool_set_false:N \l_@@_special_sign_bool
- \bool_set_false:N \l_@@_error_bool
- \bool_set_false:N \l_@@_parse_range_bool
+ \tl_if_empty:nF {#2}
+ { \keys_set_filter:nnn { cooking-units } { change-unit } {#2} }
+ \bool_set:Nn \l_@@_calc_persons_tmp_bool
+ { \l_@@_calc_because_ref_was_given_bool && \l_@@_calc_for_persons_bool }
}
% \end{macrocode}
% \end{macro}
@@ -3234,18 +3947,17 @@ and the derived file cooking-units.sty.
\char_set_catcode_ignore:N \ %
} {#1}
\l_tmpa_tl
- \@@_cunum_print_correct_unit:nnn {#2} {#3} {#3}
}
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{ \@@_cunum:nnNN, \@@_cunum:nnVV }
+% \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 \@@_cunum:nnNN #1#2#3#4
+\cs_new:Npn \@@_parse_and_evaluate_input:n #1
{
\tl_set_rescan:Nnn \l_tmpa_tl
{
@@ -3262,9 +3974,7 @@ and the derived file cooking-units.sty.
}
\@@_cunum_parse_input:V \l_tmpa_tl
}
- \@@_cunum_print_correct_unit:nnn {#2} {#3} {#4}
}
-\cs_generate_variant:Nn \@@_cunum:nnNN { nnVV }
% \end{macrocode}
% \end{macro}
%
@@ -3281,12 +3991,14 @@ and the derived file cooking-units.sty.
\tl_use:N \l_@@_value_unit_space_tl
\bool_if:nTF
{
+ ! \l_@@_parse_input_bool ||
\l_@@_fraction_in_input_bool ||
- \l_@@_special_sign_bool
+ \l_@@_special_sign_bool
}
{ \translate { #3 ( cu-unit ) } }
{ \translate { #2 ( cu-unit ) } }
}
+\cs_generate_variant:Nn \@@_cunum_print_correct_unit:nnn { nVV }
% \end{macrocode}
% \end{macro}
%
@@ -3304,7 +4016,7 @@ and the derived file cooking-units.sty.
\NewDocumentCommand \cudefinekeys { m m }
{
\bool_set_false:N \l_@@_single_key_bool
- \cukeys_define_keys_and_single_keys:nn {#1} {#2}
+ \@@_cukeys_define_keys_and_single_keys:nn {#1} {#2}
}
% \end{macrocode}
% \end{macro}
@@ -3315,18 +4027,18 @@ and the derived file cooking-units.sty.
\NewDocumentCommand \cudefinesinglekey { m m }
{
\bool_set_true:N \l_@@_single_key_bool
- \cukeys_define_keys_and_single_keys:nn {#1} {#2}
+ \@@_cukeys_define_keys_and_single_keys:nn {#1} {#2}
}
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{ \cukeys_define_keys_and_single_keys:nn }
+% \begin{macro}{ \@@_cukeys_define_keys_and_single_keys:nn }
% First checks whetever the unit is defined or not, then clears some macros
% which are needed later. Further procession depends on the boolean.
% If more than one key is created, the value \lstinline|\l_tmpa_fp| is set to one.
% This is important for adding keys where \lstinline|\l_tmpa_fp| is changed accordingly.
% \begin{macrocode}
-\cs_new:Npn \cukeys_define_keys_and_single_keys:nn #1#2
+\cs_new:Npn \@@_cukeys_define_keys_and_single_keys:nn #1#2
{
\@@_error_if_unit_not_defined:n {#1}
\tl_if_blank:nF {#2}
@@ -3658,11 +4370,27 @@ and the derived file cooking-units.sty.
% \section {Creating New Units}
%
%
-%\begin{macro}{ \newcookingunit }
+%\begin{macro}{ \declarecookingunit , \newcookingunit , \providecookingunit }
% \begin{macrocode}
+\NewDocumentCommand \declarecookingunit { o m }
+ {
+ \clist_if_in:NnTF \g_@@_list_of_defined_units_clist {#2}
+ { \msg_info:nnn { cooking-units } { redefine-unit } {#2} }
+ { \@@_new_cooking_unit:nn {#1} {#2} }
+ \@@_set_cooking_unit:nn {#1} {#2}
+ }
\NewDocumentCommand \newcookingunit { o m }
{
\@@_new_cooking_unit:nn {#1} {#2}
+ \@@_set_cooking_unit:nn {#1} {#2}
+ }
+\NewDocumentCommand \providecookingunit { o m }
+ {
+ \clist_if_in:NnF \g_@@_list_of_defined_units_clist {#2}
+ {
+ \@@_new_cooking_unit:nn {#1} {#2}
+ \@@_set_cooking_unit:nn {#1} {#2}
+ }
}
% \end{macrocode}
%\end{macro}
@@ -3675,10 +4403,9 @@ and the derived file cooking-units.sty.
{
\clist_put_right:Nn \g_@@_list_of_defined_units_clist {#2}
\tl_new:c { l_@@_tmpa_ #2 _tl }
-% \tl_set:cn { l_@@_tmpa_ #2 _tl } { \c_one_fp }
\tl_set_eq:cN { l_@@_tmpa_ #2 _tl } \c_one_fp
\clist_new:c { l_@@_predefined_option_#2_clist }
- \keys_define:nn { cooking - units }
+ \keys_define:nn { cooking-units }
{
set-option-for-#2 .clist_set:c = { l_@@_predefined_option_#2_clist } ,
add-option-for-#2 .code:n =
@@ -3686,54 +4413,90 @@ and the derived file cooking-units.sty.
}
\prop_new:c { l_@@_cukeys_ #2 _prop }
\tl_new:c { l_@@_cu_unit_ #2 _tl }
- \IfNoValueTF {#1}
- {
- \tl_set:cn { l_@@_cu_unit_ #2 _tl } {#2}
- \newtranslation { #2 ( cu-unit ) } {#2}
- }{
- \tl_set:cn { l_@@_cu_unit_ #2 _tl } {#1}
- \newtranslation { #2 ( cu-unit ) } {#1}
- }
+ }
+ }
+\cs_new:Npn \@@_set_cooking_unit:nn #1#2
+ {
+ \IfNoValueTF {#1}
+ {
+ \tl_set:cn { l_@@_cu_unit_ #2 _tl } {#2}
+ \deftranslation { #2 ( cu-unit ) } {#2}
+ }{
+ \tl_set:cn { l_@@_cu_unit_ #2 _tl } {#1}
+ \deftranslation { #2 ( cu-unit ) } {#1}
}
}
% \end{macrocode}
%
%
-%
% \section { cutext \& Cutext }
%
-% \end{macro}
%
+% A quite primitive implentation of \opt{cutext-to-cunum}, but
+% sufficient for now.
% \begin{macrocode}
-\NewDocumentCommand \cutext { O{} m m }
+\NewDocumentCommand \cutext { d<> O{} m m }
{
\group_begin:
- \bool_set_false:N \l_@@_cutext_uppercase_word_bool
- \@@_cutext_default:nnn {#1} {#2} {#3}
- \@@_cutext_print_correct_unitname:nn {#2} {#3}
+ \@@_cutext_initialise:nnn {#1} {#2} {#4}
+ \bool_if:NTF \l_@@_cutext_to_cunum_bool
+ { \cunum {#3} {#4} }
+ {
+ \bool_set_false:N \l_@@_cutext_uppercase_word_bool
+ \@@_cutext:nnnn {#1} {#2} {#3} {#4}
+ }
\group_end:
}
% \end{macrocode}
%
% \begin{macrocode}
-\NewDocumentCommand \Cutext { O{} m m }
+\NewDocumentCommand \Cutext { d<> O{} m m }
{
\group_begin:
- \bool_set_true:N \l_@@_cutext_uppercase_word_bool
- \@@_cutext_default:nnn {#1} {#2} {#3}
- \@@_cutext_print_correct_unitname:nn {#2} {#3}
+ \@@_cutext_initialise:nnn {#1} {#2} {#4}
+ \bool_if:NTF \l_@@_cutext_to_cunum_bool
+ { \cunum {#3} {#4} }
+ {
+ \bool_set_true:N \l_@@_cutext_uppercase_word_bool
+ \@@_cutext:nnnn {#1} {#2} {#3} {#4}
+ }
\group_end:
}
% \end{macrocode}
%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_cutext_initialise:nnn #1#2#3
+ {
+ \bool_set_true:N \l_@@_using_cutext_bool
+ \@@_initialise_default:nnn {#1} {#2} {#3}
+ \bool_if:NTF \l_@@_cutext_change_unit_bool
+ { \@@_initialise_unit_change:nnn {#1} {#2} {#3} }
+ { \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_tmp_unit_tl }
+ \@@_initialise_after_unit_change:nnn {#1} {#2} {#3}
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new:Npn \@@_cutext:nnnn #1#2#3#4
+ {
+ \bool_if:nTF { \l_@@_cutext_old_bool || !\l_@@_parse_input_bool }
+ {
+ \@@_cutext_default:nnn {#2} {#3} {#4}
+ \@@_cutext_print_correct_unitname:nnn {#3} {#4} {#4}
+ }{
+ \@@_parse_and_evaluate_input:n {#3}
+ \@@_cutext_print_correct_unitname:VVV
+ \l_@@_cutext_tmp_tl \l_@@_option_unit_tl \l_@@_tmp_unit_tl
+ }
+ }
+% \end{macrocode}
+%
% \begin{macro} { \@@_cutext_default:nnn }
% \changes {2016/06/11} {0.98a} { New command }
% \begin{macrocode}
\cs_new:Npn \@@_cutext_default:nnn #1#2#3
{
\@@_error_if_unit_not_defined:n {#3}
- \tl_if_empty:nF {#1}
- { \keys_set:nn { cooking-units } {#1} }
\bool_if:NT \l_@@_convert_to_eV_bool
{ \@@_convert_to_eV: }
\bool_if:NTF \l_@@_parse_input_bool
@@ -3744,7 +4507,7 @@ and the derived file cooking-units.sty.
\tl_replace_once:NVn \l_tmpb_tl \l_@@_input_range_sign_tl { \q_@@_range }
\@@_cutext_parse_range:Vn \l_tmpb_tl {#3}
}{
- \@@_cutext_print_nummerical_output:Nn \l_tmpb_tl {#3}
+ \@@_cutext_print_output:Nn \l_tmpb_tl {#3}
}
}
{#2}
@@ -3762,26 +4525,16 @@ and the derived file cooking-units.sty.
{
\tl_set:Nn \l_@@_tmpa_tl {#2}
\tl_set:Nn \l_@@_tmpb_tl {#3}
- \@@_cutext_print_nummerical_output:Nn \l_@@_tmpa_tl {#1}
+ \@@_cutext_print_output:Nn \l_@@_tmpa_tl {#1}
\tl_use:N \l_@@_cutext_range_sign_tl
- \@@_cutext_print_nummerical_output:Nn \l_@@_tmpb_tl {#1}
+ \@@_cutext_print_output:Nn \l_@@_tmpb_tl {#1}
}
% \end{macrocode}
%
-% \begin{macrocode}
-\cs_new:Npn \@@_cutext_just_print_number_correctly:N #1
- {
- \translatelet \l_tmpa_tl { decimal-mark ( cu-unitname ) }
- \tl_replace_once:NnV #1 { . } \l_tmpa_tl
- \tl_replace_once:NnV #1 { - } \c_@@_minus_tl
- #1
- }
-% \end{macrocode}
-%
-% \begin{macro} {\@@_cutext_print_nummerical_output:N}
+% \begin{macro} {\@@_cutext_print_output:Nn , \@@_cutext_print_output:NV}
% \changes {2016/06/11} {0.99} {New.}
% \begin{macrocode}
-\cs_new_protected:Npn \@@_cutext_print_nummerical_output:Nn #1#2
+\cs_new_protected:Npn \@@_cutext_print_output:Nn #1#2
{
\bool_if:NTF \g_@@_load_if_opt_numeral_bool
{
@@ -3791,40 +4544,51 @@ and the derived file cooking-units.sty.
{
\fp_compare:nNnTF {#1} = { \c_one_fp }
{
- \translatelet \l_tmpa_tl { #2 (cu-unitgender) }
- \translatelet \l_tmpa_tl { one (\l_tmpa_tl) (cu-unitname) }
+ \translatelet \l_@@_translation_tmpa_tl { #2 (cu-unitgender) }
+ \translatelet \l_@@_translation_tmpa_tl
+ { one (\l_@@_translation_tmpa_tl) (cu-unitname) }
\bool_if:NTF \l_@@_cutext_uppercase_word_bool
{
- \exp_args:Nf \tl_to_uppercase:n { \tl_head:V \l_tmpa_tl }
- \tl_tail:V \l_tmpa_tl
+ \exp_args:Nf \tl_to_uppercase:n { \tl_head:V \l_@@_translation_tmpa_tl }
+ \tl_tail:V \l_@@_translation_tmpa_tl
}
- { \l_tmpa_tl }
+ { \l_@@_translation_tmpa_tl }
}{
\bool_if:NTF \l_@@_cutext_uppercase_word_bool
{ \Numberstringnum {#1} }
{ \numberstringnum {#1} }
}
- }{ \@@_cutext_just_print_number_correctly:N #1 }
- }{ \@@_cutext_just_print_number_correctly:N #1 }
+ }{ \@@_print_nummerical_output:N #1 }
+ }{ \@@_print_nummerical_output:N #1 }
}
- { \@@_cutext_just_print_number_correctly:N #1 }
+ { \@@_print_nummerical_output:N #1 }
}
+\cs_generate_variant:Nn \@@_cutext_print_output:Nn { NV }
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
-\cs_new:Npn \@@_cutext_print_correct_unitname:nn #1#2
+\cs_new:Npn \@@_cutext_print_correct_unitname:nnn #1#2#3
{
- \space
- \@@_if_integer_and_parse:nTF {#1}
+ \l_@@_cutext_space_tl
+ \bool_if:nTF
{
- \fp_compare:nNnTF {#1} = { \c_one_fp }
- { \translate { #2 (cu-unitname) } }
+ ! \l_@@_parse_input_bool ||
+ \l_@@_fraction_in_input_bool ||
+ \l_@@_special_sign_bool
+ }
+ { \translate { #3 (cu-unitname pl) } }
+ {
+ \@@_if_integer:nTF {#1}
+ {
+ \fp_compare:nNnTF {#1} = { \c_one_fp }
+ { \translate { #2 (cu-unitname) } }
+ { \translate { #2 (cu-unitname pl) } }
+ }
{ \translate { #2 (cu-unitname pl) } }
- }{
- \translate { #2 (cu-unitname pl) }
}
}
+\cs_generate_variant:Nn \@@_cutext_print_correct_unitname:nnn { VVV }
% \end{macrocode}
%
%
@@ -3894,67 +4658,115 @@ and the derived file cooking-units.sty.
%
% \section{cuam}
%
+% \begin{macrocode}
+\tl_new:N \l_@@_cuam_marker_tl
+\tl_set:Nn \l_@@_cuam_marker_tl { @@_cunum }
+\tl_new:c { l_@@_tmpa_ \l_@@_cuam_marker_tl _ tl }
+\tl_set:cn { l_@@_tmpa_ \l_@@_cuam_marker_tl _ tl } { \c_one_fp }
+\clist_new:c { l_@@_predefined_option_ \l_@@_cuam_marker_tl _clist }
+% \end{macrocode}
+%
% Replaces and extends \mycs{cufrac}.
% \begin{macro}{\cuam}
-% \begin{macrcode}
-\NewDocumentCommand \cuam { s O{} m }
+% \begin{macrocode}
+\NewDocumentCommand \cuam { d<> O{} m }
{
\group_begin:
- \tl_if_empty:nF {#2}
- { \keys_set:nn { cooking-units } {#2} }
- \IfBooleanTF {#1}
- { \@@_cuam_star:n {#3} }
- { \@@_cuam_star:n {#3} }
+ \@@_cuam_initialise:nnn {#1} {#2} {}
+ \bool_if:NTF \l_@@_parse_input_bool
+ {
+ \bool_if:NTF \l_@@_cuam_old_bool
+ { \@@_cuam_old:n {#3} }
+ { \@@_parse_and_evaluate_input:n {#3} }
+ }
+ { \@@_cunum_do_not_parse:nnn {#3} {} {} }
\group_end:
}
-% \end{macrcode}
+% \end{macrocode}
% \end{macro}
%
+%
+% \begin{macrocode}
+\cs_new_protected:Npn \@@_cuam_initialise:nnn #1#2#3
+ {
+ \tl_set_eq:NN \l_@@_tmp_unit_tl \l_@@_cuam_marker_tl
+ \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_cuam_marker_tl
+ \@@_initialise_after_unit_change:nnn {#1} {#2} {#3}
+ }
+% \end{macrocode}
+%
% \begin{macro}{\@@_cuam:n}
% \begin{macrocode}
-\cs_new:Npn \@@_cuam_star:n #1
+\cs_new:Npn \@@_cuam:n #1
+ {
+ \tl_set_rescan:Nnn \l_tmpa_tl
+ {
+ \char_set_catcode_letter:N \_ %
+ \char_set_catcode_ignore:N \ %
+ \char_set_catcode_other:N ? %
+ } {#1}
+ \@@_cuam_parse:V \l_tmpa_tl
+ }
+%
+\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_star_parse:V \l_tmpa_tl
+ \@@_cuam_old_parse:V \l_tmpa_tl
}
% \end{macrocode}
% \end{macro}
%
% \begin{macrocode}
-\cs_new_protected:Npn \@@_cuam_star_parse:n #1
+\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_star_parse_range:V \l_tmpa_tl
+ \@@_cuam_old_parse_range:V \l_tmpa_tl
}{
\tl_if_in:nnTF {#1} { / }
{
\tl_if_in:nnTF {#1} { _ }
- { \@@_cuam_star_parse_mixed_frac:www #1 \q_stop }
- { \@@_cuam_star_parse_frac:ww #1 \q_stop }
+ { \@@_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_star_parse_scale:n {#1} }
+ { \@@_cuam_old_parse_scale:n {#1} }
}
}
}
-\cs_generate_variant:Nn \@@_cuam_star_parse:n { V }
+\cs_generate_variant:Nn \@@_cuam_old_parse:n { V }
+% \end{macrocode}
+%
+% \begin{macrocode}
+\cs_new:Npn \@@_cuam_parse_range:n #1
+ {
+ \@@_cuam_parse_range_aux:ww #1 \q_nil
+ }
+\cs_generate_variant:Nn \@@_cuam_parse_range:n { V }
+\cs_new:Npn \@@_cuam_parse_range_aux:ww #1 \q_@@_range #2 \q_nil
+ {
+ \@@_parse_input_and_safe_in:nN {#1} \l_tmpa_tl
+ \@@_parse_input_and_safe_in:nN {#2} \l_tmpb_tl
+ \@@_print_nummerical_output:N \l_tmpa_tl
+ \l_@@_cunum_range_sign_tl
+ \@@_print_nummerical_output:N \l_tmpb_tl
+ }
% \end{macrocode}
%
% \begin{macrocode}
-\cs_new:Npn \@@_cuam_star_parse_range:n #1
+\cs_new:Npn \@@_cuam_old_parse_range:n #1
{
- \@@_cuam_star_parse_range_aux:ww #1 \q_nil
+ \@@_cuam_old_parse_range_aux:ww #1 \q_nil
}
-\cs_generate_variant:Nn \@@_cuam_star_parse_range:n { V }
-\cs_new:Npn \@@_cuam_star_parse_range_aux:ww #1 \q_@@_range #2 \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
}
@@ -3962,16 +4774,16 @@ and the derived file cooking-units.sty.
%
%
% \begin{macrocode}
-\cs_new:Npn \@@_cuam_star_parse_scale:n #1 {#1}
+\cs_new:Npn \@@_cuam_old_parse_scale:n #1 {#1}
% \end{macrocode}
%
% \begin{macrocode}
-\cs_new:Npn \@@_cuam_star_parse_frac:ww #1/#2 \q_stop
+\cs_new:Npn \@@_cuam_old_parse_frac:ww #1/#2 \q_stop
{ \@@_frac:nn {#1} {#2} }
% \end{macrocode}
%
% \begin{macrocode}
-\cs_new:Npn \@@_cuam_star_parse_mixed_frac:www #1_#2/#3 \q_stop
+\cs_new:Npn \@@_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop
{
#1
\hbox_to_wd:nn { \l_@@_mixed_frac_dim } { }