summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/cooking-units
diff options
context:
space:
mode:
authorNorbert Preining <norbert@preining.info>2020-01-15 03:00:56 +0000
committerNorbert Preining <norbert@preining.info>2020-01-15 03:00:56 +0000
commit3bd863734612dc2fe9c5c7c1405358ffb1228afb (patch)
tree9f7d421c227b998debe92dac90f4cf8634a8f94f /macros/latex/contrib/cooking-units
parentb3225c4301e7724de481f410444fef5463799b9d (diff)
CTAN sync 202001150300
Diffstat (limited to 'macros/latex/contrib/cooking-units')
-rw-r--r--macros/latex/contrib/cooking-units/README.md2
-rw-r--r--macros/latex/contrib/cooking-units/cooking-units.dtx2428
-rw-r--r--macros/latex/contrib/cooking-units/cooking-units.ins8
-rw-r--r--macros/latex/contrib/cooking-units/cooking-units.pdfbin658095 -> 700306 bytes
4 files changed, 1635 insertions, 803 deletions
diff --git a/macros/latex/contrib/cooking-units/README.md b/macros/latex/contrib/cooking-units/README.md
index 9ae432ec6b..f5ab89dd31 100644
--- a/macros/latex/contrib/cooking-units/README.md
+++ b/macros/latex/contrib/cooking-units/README.md
@@ -55,7 +55,7 @@ License
-------
This material is subject to the LaTeX Project Public License 1.3c or later. See
- https://ctan.org/license/lppl1.3c
+ https://www.latex-project.org/lppl/
for the details of that license.
diff --git a/macros/latex/contrib/cooking-units/cooking-units.dtx b/macros/latex/contrib/cooking-units/cooking-units.dtx
index 74cd835484..0e01884a27 100644
--- a/macros/latex/contrib/cooking-units/cooking-units.dtx
+++ b/macros/latex/contrib/cooking-units/cooking-units.dtx
@@ -1,7 +1,7 @@
% \iffalse meta-comment
% !TEX encoding = UTF-8 Unicode
% !TEX program = pdfLaTeX
-%
+%^^A PdfLaTeX-dev
%
%<*internal>
\iffalse
@@ -65,7 +65,7 @@ License
-------
This material is subject to the LaTeX Project Public License 1.3c or later. See
- https://ctan.org/license/lppl1.3c
+ https://www.latex-project.org/lppl/
for the details of that license.
@@ -82,14 +82,14 @@ for the details of that license.
%\keepsilent
\askforoverwritefalse
\preamble
-Copyright (C) 2016--2018 by Ben Vitecek (current Maintainer)
+Copyright (C) 2016--2020 by Ben Vitecek (current Maintainer)
This file may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3c of this license or (at your option) any later
version. The latest version of this license is in:
- https://ctan.org/license/lppl1.3c
+ https://www.latex-project.org/lppl/
and version 1.3c or later is part of all distributions of
LaTeX version 2008-05-04 or later.
@@ -136,7 +136,7 @@ and the derived file cooking-units.sty.
]{l3doc}
\usepackage[utf8]{inputenc}
\usepackage[main=english]{babel}
-\usepackage[use-numerals=true]{cooking-units}
+\usepackage[use-fmtcount-numerals=true]{cooking-units}
\usepackage{tikzsymbols}
\usepackage{listings}
\usepackage{environ}
@@ -146,6 +146,7 @@ and the derived file cooking-units.sty.
\usepackage{siunitx}
\usepackage{totalcount}
\usepackage{microtype}
+\usepackage{enumitem}
\newcounter{CookingUnitsCounter}
@@ -168,15 +169,21 @@ and the derived file cooking-units.sty.
\DeclareSIUnit{\stone}{st}
\DeclareSIUnit{\st}{\stone}
\DeclareSIUnit{\stick}{st}
+\DeclareSIUnit{\inch}{in}
\cusetup{print-numerals=false}
%\EnableCrossrefs
+\newcommand\US{$^{\mathrm{U.S.}}$}
+
-%\newcommand\TODO[1]{\footnote{\textcolor{red}{#1}}}
\ExplSyntaxOn
+\NewDocumentCommand \cookingunitsToDo { m }
+ {
+% \marginpar { \textcolor{red}{#1} }
+ }
\clist_new:N \l_cookingunits_list_of_defined_befehlen_clist
@@ -200,13 +207,21 @@ and the derived file cooking-units.sty.
culabel,
curef,
cudefinephrase,
+ declarecookingderivatives ,
+ cufrac ,
+ cusetoptionfor, cuaddoptionfor, cuclearoptionfor,
+ cudeclareunitgroup, cuaddtounitgroup, cuclearunitgroup
}
\NewDocumentCommand \mycs { m }
{
\clist_if_in:NnTF \l_cookingunits_list_of_defined_befehlen_clist {#1}
- { \cs{\textcolor{blue}{#1}} }
- { \ERROR }
+ {
+ \cs_if_exist:cTF {#1}
+ { \cs{\textcolor{blue}{#1}} }
+ { \mycsERRORII }
+ }
+ { \mycsERROR }
}
\newcommand\opt{\texttt}
\newcommand\myunit{\texttt}
@@ -235,7 +250,7 @@ and the derived file cooking-units.sty.
\NewDocumentCommand \PrintGroup { m }
{
\mygroup {#1} &
- \seq_use:cn { l__cookingunits_group_ #1 _seq } { ,~ }
+ \texttt{\seq_use:cn { l__cookingunits_group_ #1 _seq } { \textrm{,~} }}
}
\NewDocumentCommand \DeactivateForbiddenUnitError { }
@@ -247,7 +262,8 @@ and the derived file cooking-units.sty.
%% Allyourwhitespacearebelongtous (too long)
%% 42
%% Miep!
-\NewDocumentCommand \dothewhitespace { O{ Ducks } }
+%% Ducks
+\NewDocumentCommand \dothewhitespace { O{ cup~of~tea } }
{
\textcolor{white} {#1} \\
}
@@ -331,6 +347,7 @@ and the derived file cooking-units.sty.
\ProvideDocumentEnvironment{cuexamplecode}{}{}{}{}
+
\NewDocumentEnvironment { cuexample } { }
{
\paragraph{Example:}
@@ -346,6 +363,13 @@ and the derived file cooking-units.sty.
\paragraph{Note:}
}{ }
+\NewEnviron { cuenumnote }
+ {
+ \begin{enumerate}[label={Note \space \arabic*:}]
+ \BODY
+ \end{enumerate}
+ }
+
\NewDocumentEnvironment { cuinterest } { m }
{
@@ -569,9 +593,15 @@ and the derived file cooking-units.sty.
culabel,
curef,
cudefinephrase,
+ declarecookingderivatives
}
}
+\newcommand\eneunit[3]{\sfrac{#1\,#2${}^2$}{#3${}^2$}}
+%% Can overflow and takes too long, hard code it
+%\declarecookingderivatives{kg,m,s}{#1*#2-#3}{ (#1)*(#2)^2/(#3)^2 } {\eneunit{#1}{#2}{#3}}
+\newcookingunit[\eneunit{kg}{m}{s}]{kg*m-s}
+\newcookingunit[\eneunit{oz}{in}{min}]{oz*in-min}
\newcookingunit {st}
\newcookingunit [\ensuremath{ {} ^ { \circ } }\kern-\scriptspace R{\text{\o}}] {Ro}
\newcookingunit {ft}
@@ -585,6 +615,9 @@ and the derived file cooking-units.sty.
{
{Ro} { #1*21/40 + 7.5 }
}
+
+
+
\cusetup
{
commands-add-hook = {\stepcounter{CookingUnitsCounter}} ,
@@ -592,7 +625,7 @@ and the derived file cooking-units.sty.
cutext-add-hook = {\stepcounter{cutextCounter}} ,
Cutext-add-hook = {\stepcounter{CutextCounter}} ,
cuam-add-hook = {\stepcounter{cuamCounter}} ,
- set-option-for-Ro = { round-to-int = true } ,
+ set-option-for-Ro = { round-precision= 0 } ,
% add-unit-to-group = { weight = {st} , temperature = {Ro} }
}
@@ -768,73 +801,37 @@ and the derived file cooking-units.sty.
% \begin{documentation}
% \begin{abstract}
% 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
+% between them and change your recipes to a given
% number of persons.
+%
+% For not implemented units or differences between Imperial and U.S.\ unit
+% you may have a look at \cref{sec:other-units}.
+%
% 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.}
+% cookery books (and not e.g. scientific texts; use e.g.\ \pkg{siunitx} for those).
%
% Please read through the section \enquote{Important Changes}
% \end{abstract}
%
% \tableofcontents
%
-% \begin{comment}
-% \begin{myde}
-% \cusetup{print-numerals=true,use-phrases=true}
-% \cunum[convert-to-eV=true]{1}{m} \\
-% \cunum[convert-to-eV=true]{1}{m} \\
-% \cuam{6} Eier \\
-% \cuam{12} Eier \\
-% \cuam{18} Eier \\
-% \cuam{132--168} Eier \\
-% \cuam{12--60} Eier \\
-% \cuam{12--24} Eier \\
-% \cuam{12--24.2} Eier \\
-% \cuam{24--12} Eier \\
-% \cuam{18--6} Eier \\
-% \cuam[recalculate-amount=true, set-number-of-persons=10, label=Hallo*4, ref=Hallo]{24} Eier \\
-% \cuam[recalculate-amount=true, set-number-of-persons=10, ref=Hallo, use-phrases=false]{24} Eier (phrase-false)\\
-% \cuam[recalculate-amount=true, set-number-of-persons=10, ref=Hallo, parse-number=false]{12--24} Eier (no parse)\\
-% \cuam{23} Eier \\
-% \cuam{60} Eier \\
-% \cuam{62} Eier \\
-% \cuam{12--60} Eier \\
-% \cuam{288} Eier \\
-% \end{myde}
-%
-% \begingroup
-% \cusetup{print-numerals=true}
-% \cutext[convert-to-eV=true]{1}{m} \\
-% \cunum[convert-to-eV=true]{1}{m} \\
-% \cuam{6} Eier \\
-% \cuam{12} Eier \\
-% \cuam{18} Eier \\
-% \cuam[recalculate-amount=true, set-number-of-persons=10, ref=Hallo]{24} Eier \\
-% \cuam[recalculate-amount=true, set-number-of-persons=10, ref=Hallo, use-phrases=false]{24} Eier \\
-% \cuam{23} Eier \\
-% \cuam{60} Eier \\
-% \cuam{62} Eier \\
-% \endgroup
-% \end{comment}
-%
% \section{Introduction}
%
%
-% While writing on a cookery book I used -- for reasons whatsoever --
+% While writing on a cookery book I used -- for some reasons whatsoever --
% three different units for weight: kilogram (kg), gram (g) and
% decagram (dag, or older: dkg). Later my mother told me that she
% doesn't like it if a cookery book uses more than two different units
% (for weight in this case). Happily I hardly used Decagram and
% therefore didn't have many problems changing the units. But, well
% \dots\ I am using \LaTeX\ and changing those units by hand seemed
-% not very \LaTeX\-like, so I started writing some code to convert
+% not very \LaTeX-like, so I started writing some code to convert
% units. I expanded the code, rewrote it in \LaTeX3 (which is much
% more pleasant than \LaTeXe) and here it is.
%
%
-% \subsection{Important Changes}
-%
+% \begin{comment}
+% \subsection{Overview}
% \begin{description}
% \item[Language] I am now using the \pkg{translations} package
% and I hope it makes things easier. As such, declaring the used language
@@ -851,22 +848,24 @@ and the derived file cooking-units.sty.
% tries to \enquote{fix} this idea (at least make it work). If any problems occur
% (for this specific case or in general) please feel free to contact me.
% \end{description}
+% \end{comment}
+%
%
%
% \subsection{Supported languages}
-%
+% \cookingunitsToDo{Passt.}
% \begin{itemize}
% \item German
% \item English
% \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?
+% Want to contribute a new language or make a correction to an existing one?
% See \cref{sec:bug-feed} for more details. Wanna just check the
% existing translations? See \cref{sec:Translations}.
%
% \section {The Commands}
% \label{sec:commands}
-%
+% \cookingunitsToDo{Passt.}
%
% This package offers the following commands for unit printing (and
% converting):
@@ -924,11 +923,14 @@ and the derived file cooking-units.sty.
% 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 written out with
-% \lstinline|\Cutext| capitalizing the first letter (using package
-% \pkg{fmtcount}).
+% (mixed) fractions and |--| for ranges). Furthermore, \cCutext\ allow
+% the usages of numerals (see \cref{sec:load-time-options} for more information).
+%^^A if the package
+%^^A option \opt{use-fmtcount-numerals} (see \cref{sec:load-time-options})
+%^^A is used, integers below a specific integer
+%^^A (by default 13; see \opt{use-numerals-below}) are written out with
+%^^A \lstinline|\Cutext| capitalizing the first letter (using package
+%^^A \pkg{fmtcount}).
%
%
% \begin{cuexamplecode}
@@ -938,7 +940,7 @@ and the derived file cooking-units.sty.
% \cutext{12}{l} \\
% \Cutext{13}{l}
% \end{cuexamplecode}
-% and using package option \opt{use-numerals=true}
+% and using (e.g.) package option \opt{use-fmtcount-numerals=true}
% \cusetup{print-numerals=true}
% \begin{cuexamplecode}
% \cutext{1}{l} \\
@@ -949,6 +951,9 @@ and the derived file cooking-units.sty.
% \Cutext{13}{l}
% \end{cuexamplecode}
% \cusetup{print-numerals=false}
+% You can customize the numeral functions used with \opt{numeral-function} and
+% \opt{Numeral-function}.
+%
% Furthermore,
% since v1.10 \cCutext\ also allow their units to be changed (this behavior
% can be altered using \opt{cutext-change-unit}):
@@ -976,7 +981,7 @@ and the derived file cooking-units.sty.
% \end{cuexamplecode}
%
% Furthermore it allows the concept of \enquote{phrases} (replacing a positive integer
-% by a word, such as \enquote{12} becoming \enquote{dozen}\footnote{At least I think})
+% by a word; such as \enquote{12} becoming \enquote{dozen}\footnote{At least I think})
% which can be activated by the option \opt{use-phrases}
% (as I don't know any english phrases, I switched the language to german for the following examples)
% \begin{myde}
@@ -996,7 +1001,7 @@ and the derived file cooking-units.sty.
%
% \section{Label \& refs: Changing the amount of the recipe}
% \label{sec:labeletref}
-%
+% \cookingunitsToDo{Also not much to change}
%
% 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?
@@ -1056,22 +1061,22 @@ and the derived file cooking-units.sty.
%
%
%
-%
+% \begin{comment}
% \section{Some Interesting options}
-%
+% \cookingunitsToDo{This section is horrible, change or delete as a whole, but later}
% This package has some options which might be of interest and to highlight them, this section exists. All options can be
% found in \cref{sec:options}.
%
%
%\subsection{Numerals}
-% \begin{cuinterest}{use-numerals, use-numerals-below, print-numerals}
+% \begin{cuinterest}{use-fmtcount-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
+% \opt{use-fmtcount-numerals} to print integers used by \cCutext{} below
% \opt{use-numerals-below} (13 by default) by \pkg{fmtcount}.
% You can still decide if numerals should be printed or not with \opt{print-numerals}.
%
% \begin{cunote}
-% \opt{use-numerals} is a package option as it needs to load
+% \opt{use-fmtcount-numerals} is a package option as it needs to load
% \pkg{fmtcount} which is not loaded by default.
% \end{cunote}
%
@@ -1100,7 +1105,7 @@ and the derived file cooking-units.sty.
% \cuam{60}
% \end{cuexamplecode}
% \end{myde}
-% This of course also works with the \emph{package}-option \opt{use-numerals}:
+% This of course also works with the \emph{package}-option \opt{use-fmtcount-numerals}:
% \begin{myde}
% \cusetup{print-numerals=true}
% \begin{cuexamplecode}
@@ -1116,30 +1121,38 @@ and the derived file cooking-units.sty.
%
%
% \begin{cunote}
-% Currently only the lower-case variant for \opt{use-numerals} is
+% Currently only the lower-case variant for \opt{use-fmtcount-numerals} is
% supported. Furthermore this feature is only available for \mycs{cuam}.
% \end{cunote}
%
% \end{cuinterest}
%
+% \end{comment}
+%
+%
+%
+%
+%
+%
%
%\subsection{Rounding temperatures}
%
-% By default temperatures are rounded to integers (using \opt{round-to-int = true}).
+% By default temperatures are rounded to integers (using \opt{round-precision=0}).
% 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{182}{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} \\
+% \cusetoptionfor{C,F,K,Re}{ round-precision = -1 } @
+%^^A \cusetup{set-option-for-C = { round-precision = -1 } } @
+%^^A \cusetup{set-option-for-F = { round-precision = -1 } } @
+%^^A \cusetup{set-option-for-Re = { round-precision = -1 } } @
+%^^A \cusetup{set-option-for-K = { round-precision = -1 } } @
+% \cunum{182}{C} \\
% \cunum[C=F]{180}{C} \\
% \cunum[C=Re]{180}{C} \\
% \cunum[C=K]{180}{C} \\
@@ -1147,7 +1160,7 @@ and the derived file cooking-units.sty.
%
% \section{Predefined units \& some notes}
% \label{sec:pred-units}
-%
+% \cookingunitsToDo{Passt.}
% \begin{comment}
% In \cref{tab:def-units} and \cref{tab:some-more-units} (and \cref{tab:strange-units})
% you can find
@@ -1248,23 +1261,28 @@ and the derived file cooking-units.sty.
%
% \section{Defining units}
% \label{sec:def-units}
-%
+% \cookingunitsToDo{Passt.}
% New units can be defined using
% \begin{itemize}
-% \item \mycs{declarecookingunit}
-% \item \mycs{newcookingunit}
-% \item \mycs{providecookingunit}
+% \item \mycs{declarecookingunit}\oarg{symbol}\marg{unit-key}
+% \item \mycs{newcookingunit}\oarg{symbol}\marg{new-unit-key}
+% \item \mycs{providecookingunit}\oarg{symbol}\marg{new-unit-key}
% \end{itemize}
%
% \begin{function}{\declarecookingunit,\newcookingunit,\providecookingunit}
% \begin{syntax}
% \mycs{declarecookingunit}\oarg{symbol}\marg{unit-key}
% \mycs{newcookingunit}\oarg{symbol}\marg{new-unit-key}
-% \mycs{providecookingunit}\oarg{symbol}\marg{new-unit-key}
+% \mycs{providecookingunit}\oarg{symbol}\marg{unit-key}
% \end{syntax}
% These commands define the unit \meta{unit-key}. If the
% key is not the same as the printed symbol use \oarg{symbol}.
-% Note that \meta{unit-key} should neither contain |/| nor |,|.
+% Note that \meta{unit-key} can neither contain |/| nor |,|.
+%
+% Please note due to the current implementation catcodes may cause
+% trouble. For example using |:| inside \meta{unit-key} may cause
+% the key to \enquote{not be defined} in the document. If that happens
+% try removing or changing the \meta{unit-key}.
%
% \mycs{newcookingunit} raises an error if the unit is already defined,
% \mycs{declarecookingunit} creates or (if given) overwrites \meta{symbol}
@@ -1274,7 +1292,6 @@ and the derived file cooking-units.sty.
% All units have male gender |m| by default.
%
% Some examples:
-%
% \begin{lstlisting}
% \declarecookingunit{kg}
% \declarecookingunit{g}
@@ -1282,18 +1299,61 @@ and the derived file cooking-units.sty.
% \declarecookingunit[\ensuremath{{}^{\circ}}\kern-\scriptspace C] {C}
% \end{lstlisting}
%
+% \end{function}
% \begin{cunote}
% The definition of the printed degree Celsius is
-% directly copied and pasted from (a maybe older version of) \pkg{siunitx}
+% copied and pasted from (a maybe older version of) \pkg{siunitx}.
% \end{cunote}
%
%
+%
+% \begin{function}{\declarecookingderivatives}
+% \begin{syntax}
+% \mycs{declarecookingderivatives} \marg{unit-list} \marg{unit-key}
+% \ \ \marg{mathematical-relation} \marg{unit-symbol}
+% \end{syntax}
+%
+% \emph{This function is experimental}. Defines new units which are a combination
+% of the units given in \meta{unit-list} \emph{and} their linked-units.
+% \meta{unit-key}, \meta{mathematical-relation} and \meta{unit-symbol}
+% accept |#1| to |#n| as arguments with $n$ being the number of units
+% given in \meta{unit-list}. $n$ \emph{cannot} be greater than $8$ (and it will
+% probably compile for quite a while). Also note that this command doesn't work/isn't
+% tested for single keys.
+%
+% Also note that it is quite possible that an \enquote{overflow-error} will
+% occur if there are too many units.
+%
% \end{function}
%
+% \begin{cunote}
+% Due to catcodes (and my inability to deal with them properly)
+% there can be problems when using |:|
+% (and probably other signs) inside \meta{unit-key}.
+% \end{cunote}
+%
+% \begin{cuexample}
+% Your homework is to change the unit of energy \si{\kg\m\squared\per\s\squared}
+% into \si{\ounce\inch\squared\per\minute\squared}. To check if you are correct
+% you use \mycs{declarecookingderivatives}:
+% \begin{lstlisting}
+% \declarecookingderivatives{kg,m,s}{#1*#2-#3}
+% { (#1)*(#2)^2/(#3)^2 } {\sfrac{#1\,#2${}^2$}{#3${}^2$}}
+% \end{lstlisting}
+%
+% Using |\cunum[kg*m-s=oz*in-min]{1}{kg*m-s}| shows that
+% \cunum{1}{kg*m-s} is equal to \cunum{196829101.34}{oz*in-min}.
+% (Note: This is \emph{really} experimental and it can easily happen that
+% an \enquote{overflow-error} occurs) (like for me which is why I hard-coded the
+% results after testing).
+%
+% \end{cuexample}
+%
+%
%
% \section{Defining options to change units}
% \label{sec:defining-opt}
-%
+% \cookingunitsToDo{Passt.}
% Options (to change units) can be newly defined or added to already existing keys (units)
% using
% \begin{itemize}
@@ -1304,29 +1364,29 @@ 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 differently).
%
% \begin{function}{\cudefinekeys,\cudefinesinglekey}
% \begin{syntax}
% \mycs{cudefinekeys}\marg{unit-key-1}
% \ \ \{
-% \ \ \ \ \marg{unit-key-2} \marg{1 unit-key-1 are \dots\ unit-key-2}
-% \ \ \ \ \marg{unit-key-3} \marg{1 unit-key-1 are \dots\ unit-key-3}
-% \ \ \ \ \marg{unit-key-4} \marg{1 unit-key-1 are \dots\ unit-key-4}
+% \ \ \ \ \marg{unit-key-2} \marg{$1$ unit-key-1 are \dots\ unit-key-2}
+% \ \ \ \ \marg{unit-key-3} \marg{$1$ unit-key-1 are \dots\ unit-key-3}
+% \ \ \ \ \marg{unit-key-4} \marg{$1$ unit-key-1 are \dots\ unit-key-4}
% \ \ \ \ \dots
% \ \ \}
%
% \mycs{cudefinesinglekey}\marg{unit-key-1}
% \ \ \{
-% \ \ \ \ \marg{unit-key-2} \marg{1 unit-key-2 are \dots\ unit-key-1}
-% \ \ \ \ \marg{unit-key-3} \marg{1 unit-key-3 are \dots\ unit-key-1}
+% \ \ \ \ \marg{unit-key-2} \marg{$1$ unit-key-2 are \dots\ unit-key-1}
+% \ \ \ \ \marg{unit-key-3} \marg{$1$ unit-key-3 are \dots\ unit-key-1}
% \ \ \ \ \dots
% \ \ \}
% \end{syntax}
%
% If you define new units (see \cref{sec:def-units}) and cannot add
% them to already existing keys you can use
-% \lstinline|\cudefinekeys| bzw. \lstinline|\cudefinesinglekey| to
+% \lstinline|\cudefinekeys| or \lstinline|\cudefinesinglekey| respectively to
% define new keys.
%
% \lstinline|\cudefinekeys| takes \marg{unit-key-1} as a
@@ -1365,8 +1425,6 @@ and the derived file cooking-units.sty.
% \myunit{min} and \myunit{s}
% \item \dots
% \end{itemize}
-%
-%
% \begin{align*}
% \SI{1}{\kg}&= \SI{1}{\kg} &
% \SI{1}{\kg}&= \SI{100}{\deka\g} &
@@ -1374,7 +1432,6 @@ and the derived file cooking-units.sty.
% \SI{1}{\kg}&= \SI{35.27399}{\ounce} &
% \SI{1}{\kg}&= \SI{2.204 622 6}{\pound}
% \end{align*}
-%
% \begin{lstlisting}
% \cudefinekeys {kg}
% {
@@ -1425,16 +1482,16 @@ and the derived file cooking-units.sty.
% \begin{syntax}
% \mycs{cuaddkeys}\marg{unit-key-1}
% \ \ \{
-% \ \ \ \ \marg{unit-key-2} \marg{1 unit-key-1 are \dots\ unit-key-2}
-% \ \ \ \ \marg{unit-key-3} \marg{1 unit-key-1 are \dots\ unit-key-3}
-% \ \ \ \ \marg{unit-key-4} \marg{1 unit-key-1 are \dots\ unit-key-4}
+% \ \ \ \ \marg{unit-key-2} \marg{$1$ unit-key-1 are \dots\ unit-key-2}
+% \ \ \ \ \marg{unit-key-3} \marg{$1$ unit-key-1 are \dots\ unit-key-3}
+% \ \ \ \ \marg{unit-key-4} \marg{$1$ unit-key-1 are \dots\ unit-key-4}
% \ \ \ \ \dots
% \ \ \}
%
% \mycs{cuaddsinglekeys}\marg{unit-key-1}
% \ \ \{
-% \ \ \ \ \marg{unit-key-2} \marg{1 unit-key-2 are \dots\ unit-key-1}
-% \ \ \ \ \marg{unit-key-3} \marg{1 unit-key-3 are \dots\ unit-key-1}
+% \ \ \ \ \marg{unit-key-2} \marg{$1$ unit-key-2 are \dots\ unit-key-1}
+% \ \ \ \ \marg{unit-key-3} \marg{$1$ unit-key-3 are \dots\ unit-key-1}
% \ \ \ \ \dots
% \ \ \}
% \end{syntax}
@@ -1447,11 +1504,11 @@ and the derived file cooking-units.sty.
% \meta{unit-key-2}, \meta{unit-key-3}, etc. to its
% values. Furthermore it adds those new values to other keys linked
% to \meta{unit-key-1} and defines the new keys \meta{unit-key-2},
-% etc. with the same values as \meta{unit-key-1}.
+% etc.\ with the same values as \meta{unit-key-1}.
%
%
% If the conversion is more complicated use
-% \lstinline|\cuaddsinglekeys|. It adds \meta{unit-key-2}, etc. as
+% \lstinline|\cuaddsinglekeys|. It adds \meta{unit-key-2}, etc.\ as
% values to \meta{unit-key-1}. The numerical input can be placed
% using \myunit{\#1} (see \lstinline|\cudefinesinglekey|). This
% command neither defines new keys nor does it add values to other
@@ -1504,7 +1561,7 @@ and the derived file cooking-units.sty.
% }
% \cusetup %% round to integer automatically
% {
-% set-option-for-Ro = { round-to-int = true }
+% set-option-for-Ro = { round-precision = 0 }
% }
% \end{lstlisting}
% \begin{cuexamplecode}
@@ -1525,7 +1582,7 @@ and the derived file cooking-units.sty.
%
% \begin{function}{\cuaddtokeys}
% \begin{syntax}
-% \mycs{cuaddtokeys} \marg{unit-key-1} \marg{unit-key-2} \marg{1 unit-key-2 are \dots\ unit-key-1}
+% \mycs{cuaddtokeys} \marg{unit-key-1} \marg{unit-key-2} \marg{$1$ unit-key-2 are \dots\ unit-key-1}
% \end{syntax}
% Works similar to \mycs{cuaddkeys} regarding the definition of keys.
% \end{function}
@@ -1579,15 +1636,16 @@ and the derived file cooking-units.sty.
%
% \section{Language support}
% \label{sec:language}
+% \cookingunitsToDo{Passt.}
%
% Unit names and symbols depend on the language. To change the
-% name depending on the language you can use \lstinline|\cudefinename|
-% and to only change symbols use \lstinline|\cudefinesymbol|.
+% name and symbol for given language you can use \lstinline|\cudefinename|;
+% to only change symbols use \lstinline|\cudefinesymbol|.
%
% \begin{function}{decimal-mark,cutext-range-sign, one(m),one(f),one(n)}
% Those are special keys (as they cannot be used as units). Not only
% are printed units language depending, but as is the decimal mark
-% (\enquote{.} or \enquote{,}) and the text which substitutes the range-sign.
+% (|.| or |,|) and the text which substitutes the range-sign.
% To set the decimal mark use
% \opt{decimal-mark} (see examples below), to set the range-sign for \cCutext\
% use \opt{cutext-range-sign}.
@@ -1596,14 +1654,14 @@ and the derived file cooking-units.sty.
% \opt{cutext-range-sign}. If the \emph{option} is set, then the language symbol
% will be ignored.
%
-% Furthermore if you are using the package-option \opt{use-numerals}
+% Furthermore if you are using numerals
% you may also use the keys \opt{one(m)}, \opt{one(f)} and
-% \opt{one(n)}. If you use this option, integers below a certain
+% \opt{one(n)}. Integers below a certain
% value (see option \opt{use-numerals-below}) are written-out. The
% only problem is the written-out \enquote{1} mostly depends on the
-% gender of the following word (e.g. \enquote{ein Baum} (m),
+% gender of the word following (e.g. \enquote{ein Baum} (m),
% \enquote{eine Pflanze} (f) and \enquote{ein Auto} (n)). To set the
-% written-out 1 to be correct with the gender of the used unit, use
+% written-out \enquote{1} to be correct with the gender of the used unit, use
% these keys (see also examples below)
% \end{function}
%
@@ -1624,10 +1682,10 @@ and the derived file cooking-units.sty.
% \pkg{translations} documentation.
%
% If the plural form of the name differs from the singular form use
-% \oarg{plural} to specify the plural form, if no \oarg{plural} is
-% given the plural will be set equal to its singular. The singular form
+% \oarg{plural} to specify the plural form, else it will be equal to its singular
+% form. The singular form
% is only used if the number in \lstinline|\cutext| and
-% \lstinline|\Cutext| is equal to 1.
+% \lstinline|\Cutext| is equal to $1$.
%
% \meta{gender} can be \texttt{m} (maskulin), \texttt{f} (feminin) or
% \texttt{n} (neutrum). If not given \texttt{m} is used as default.
@@ -1676,9 +1734,9 @@ and the derived file cooking-units.sty.
% \end{syntax}
%
% This command defines the symbols of the units printed in
-% \lstinline|\cunum| for the specific \meta{language}. It works
+% \lstinline|\cunum| for the specific \meta{Language}. It works
% similar as \lstinline|\cudefinename|, but only the symbols (and no
-% names) can be set. For details regarding \meta{language} see
+% names) can be set. For details regarding \meta{Language} see
% the \pkg{translations} documentation.
%
% \end{function}
@@ -1775,12 +1833,10 @@ and the derived file cooking-units.sty.
% the phrase with the highest number is used (if used at all).
%
% Furthermore, it chooses star (|*|) phrases over non-star phrases.
-%
% \begin{cunote}
% Numbers with the optional star |*| are stored as negative numbers.
% \end{cunote}
% \end{function}
-%
% \begin{cuexample}
% The following example creates some phrases for the language
% \enquote{German}:
@@ -1824,40 +1880,82 @@ and the derived file cooking-units.sty.
% \section{Options}
% \label{sec:options}
%
+% \cookingunitsToDo{Done. Passr.}
+%
% Options in \pkg{cooking-units} can mostly be set globally using
% \lstinline|\cusetup| or locally using the optional argument of the
% respective command (but \emph{not} as a package option). The only
% exception is the option given in \cref{sec:load-time-options} which
% needs to be used as a package option.
%
+% \begin{function}{\cusetup}
+% \begin{syntax}
+% \mycs{cusetup}\marg{options}
+% \end{syntax}
+% Options can be set using \mycs{cusetup}\Arg{options}.
+% \end{function}
+%
+%
+% \begin{function}{\cusetoptionfor,\cuaddoptionfor,\cuclearoptionfor}
+%
+% \begin{syntax}
+% \mycs{cusetoptionfor}\marg{unit-list}\marg{options}
+% \mycs{cuaddoptionfor}\marg{unit-list}\marg{options}
+% \mycs{cuclearoptionfor}\marg{unit-list}
+% \end{syntax}
+% \pkg{cooking-units} allows you to attach options to units.
+% Those
+% options are activated if (and only if) the specific unit is used \emph{or}
+% if another unit is converted
+% into it. Those options allow you to e.g.\ round temperatures to
+% integers automatically. Furthermore, those added options are
+% overwritten by local options.
+%
+% \mycs{cusetoptionfor} \emph{sets} \meta{options} to each unit in \meta{unit-list}
+% overwriting the old ones.
+%
+% \mycs{cuaddoptionfor} \emph{add}s \meta{options} to each unit in \meta{unit-list}.
+%
+% \mycs{cuclearoptionfor} clears all options given to each unit in \meta{unit-list}.
+% \end{function}
+% \begin{cuexample}
+% Temperatures \myunit{C}, \myunit{F}, \myunit{K} and \myunit{Re} are
+% by default rounded to integers.
+% \begin{cuexamplecode}
+% \cunum{75.23}{C} \\
+% \cunum{75.23}{F} \\
+% \cunum{75.23}{K} \\
+% \cunum{75.23}{Re} \\
+% \cusetoptionfor{C,F,K,Re}{round-precision=-1} @
+% \cunum{75.23}{C} \\
+% \cunum{75.23}{F} \\
+% \cunum{75.23}{K} \\
+% \cunum{75.23}{Re} \\
+% \cuclearoptionfor{C,F,K,Re} @
+% \cunum{75.23}{C} \\
+% \cunum{75.23}{F} \\
+% \cunum{75.23}{K} \\
+% \cunum{75.23}{Re}
+% \end{cuexamplecode}
+% \end{cuexample}
+%
% \subsection{Load time options}
% \label{sec:load-time-options}
-%
-% \begin{function}{use-numerals}
+% \begin{function}{use-fmtcount-numerals}
% \begin{syntax}
-% \cs{usepackage}[use-numerals=\meta{true/false}]\{cooking-units\}
+% \cs{usepackage}[use-fmtcount-numerals=\meta{true/false}]\{cooking-units\}
% \end{syntax}
% If set to \true\ loads package \pkg{fmtcount} and uses
% \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
+% \opt{use-numerals-below} ($13$ by default), integers above are
% printed as numbers.
% You can decide to not print any numerals by setting \opt{print-numerals}
% to \false.
%
-% \begin{cunote}
-% \opt{use-numerals} is a package option as it needs to load
-% \pkg{fmtcount} which is not loaded by default.
-% \end{cunote}
-%
-% \begin{cunote}
-% Please note the keys \opt{one(m)}, \opt{one(f)}
-% and \opt{one(n)} to change the printed \enquote{one} (as
-% \enquote{one} is in many languages dependent on the gender of the
-% following word. E.g in German: Masculine: ein Baum,
-% Feminin: eine Pflanze, Neutrum: ein Auto).
-% \end{cunote}
-%
+% Note: You don't need to use this function to use numerals. Using
+% \opt{print-numerals} and setting \opt{numeral-function} and \opt{Numeral-function}
+% also works.
% \end{function}
%
% \cusetup{print-numerals=true}
@@ -1867,21 +1965,37 @@ and the derived file cooking-units.sty.
% \cutext{2}{kg} \\
% \Cutext{2}{kg} \\
% \cutext{12}{kg} \\
+% \Cutext{12}{kg} \\
% \cutext{13}{kg} \\
% \cutext{13}{kg} \\
% \Cutext{14}{kg}
% \end{cuexamplecode}
% \cusetup{print-numerals=false}
%
+% \begin{cunote}
+% \opt{use-fmtcount-numerals} is a package option as it needs to load
+% \pkg{fmtcount} which is not loaded by default.
+% \end{cunote}
+%
+% \begin{cunote}
+% Please note the keys \opt{one(m)}, \opt{one(f)}
+% and \opt{one(n)} to change the printed \enquote{one} (as
+% \enquote{one} is in many languages dependent on the gender of the
+% following word. E.g in German: Masculine: ein Baum,
+% Feminin: eine Pflanze, Neutrum: ein Auto).
+% \end{cunote}
+%
+% \begin{cunote}
+% You can always change the functions used to print numerals with
+% \opt{numeral-function} and \opt{Numeral-function}.
+% \end{cunote}
+%
% \subsection{Normal options}
%
% Options in this subsection can only be set as local options or using
% \lstinline|\cusetup|, but \emph{not} as load time options.
%
-% \begin{function}{\cusetup}
-% Options can be set using \mycs{cusetup}\Arg{options}.
-% \end{function}
-%
+%
% \subsubsection{Unit Specific options}
% \label{sec:opt:unit-spec}
%
@@ -1924,7 +2038,47 @@ and the derived file cooking-units.sty.
% \cunum{1}{stick} \\
% \end{cuexamplecode}
%
+% You can define new groups using \mycs{cudeclareunitgroup}:
+% \begin{function} {\cudeclareunitgroup}
+% \begin{syntax}
+% \mycs{cudeclareunitgroup} \marg{group-name} \marg{unit-list}
+% \end{syntax}
+% Defines the group \meta{group-name} containing the list \meta{unit-list}.
+% This allows the usage of |\meta{group-name}=\meta{unit-key}| to
+% change all units in the group \meta{group-name} to \meta{unit-key}
+% (which has to be part of \meta{unit-list}).
+% \end{function}
%
+% \begin{cuexample}
+% Define the group \enquote{weight}:
+% \begin{lstlisting}
+% \cudeclareunitgroup {weight} { kg , dag, g, oz, lb, stick }
+% \end{lstlisting}
+% Now \lstinline|\cusetup{weight=dag}| can be used to change all units
+% contained in |weight| to |dag|.
+% \end{cuexample}
+%
+%
+% \begin{function}{\cuaddtounitgroup}
+% \begin{syntax}
+% \mycs{cuaddtounitgroup}\marg{group}\marg{unit-list}
+% \end{syntax}
+% Adds \meta{unit-list} to an already existing \meta{group} (both need to exist).
+% \end{function}
+% \begin{cuexample}
+% Adding \myunit{st} to the group \mygroup{weight}
+% \begin{cuexamplecode}
+% \cuaddtounitgroup {weight} {st} @
+% \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}{add-unit-to-group}
@@ -1937,8 +2091,10 @@ and the derived file cooking-units.sty.
% \ \}
% \end{syntax}
% Adds each \meta{unit-key} in \meta{unit-keys-list} to \meta{group}.
+% The key-val equivalent of \mycs{cuaddtounitgroup}.
% \end{function}
% \begin{cuexample}
+% The same as above:
% This example adds the unit \myunit{st} to the group \mygroup{weight}
% and \myunit{Ro} to \mygroup{temperature}.
% \begin{lstlisting}
@@ -1962,6 +2118,7 @@ and the derived file cooking-units.sty.
% \end{cuexamplecode}
% \end{cuexample}
%
+%
%
% \begin{function}{set-option-for-<unit-key>,add-option-for-<unit-key>}
% \begin{syntax}
@@ -1973,16 +2130,20 @@ and the derived file cooking-units.sty.
% \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
-% \meta{unit-key}. Those options are automatically activated if (and
-% only if) the specific \meta{unit-key} is used (or changed into this
-% unit). Setting options overwrites old options. Adding options, well
-% \dots\ adds the options to the old ones.
+% The less flexible key-value version of \mycs{cusetoptionfor} and
+% \mycs{cuaddoptionfor}.
+%
+%
+%^^A You may want to attach some options to a special
+%^^A \meta{unit-key}. Those options are automatically activated if (and
+%^^A only if) the specific \meta{unit-key} is used (or changed into this
+%^^A unit). Setting options overwrites old options. Adding options, well
+%^^A \dots\ adds the options to the old ones.
%
-% 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)
+%^^A You can \enquote{delete} the options by setting
+%^^A an empty value for a specific \meta{unit-key} (or use
+%^^A \opt{erase-all-options} (or \opt{erase-all-options-for} )
+%^^A (see below) to erase all options for all \meta{unit-key}s)
%
% \end{function}
%
@@ -1992,23 +2153,17 @@ and the derived file cooking-units.sty.
% \begin{lstlisting}
% \cusetup
% {
-% set-option-for-F = { round-to-int = true } ,
-% set-option-for-C = { round-to-int = true } ,
-% set-option-for-K = { round-to-int = true } ,
-% set-option-for-Re = { round-to-int = true }
+% set-option-for-F = { round-precision = 0 } ,
+% set-option-for-C = { round-precision = 0 } ,
+% set-option-for-K = { round-precision = 0 } ,
+% set-option-for-Re = { round-precision = 0 }
% }
% \end{lstlisting}
+% although note that it would be easier to simply write
+% \begin{lstlisting}
+% \cusetoptionfor {F,C,K,Re} { round-precision = 0 }
+% \end{lstlisting}
%
-%^^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}
%
%
@@ -2031,6 +2186,8 @@ and the derived file cooking-units.sty.
% the same way their \opt{set-option-for-\meta{unit-key}} and
% \opt{add-option-for-\meta{unit-key}} counterparts.
%
+% The less flexible versions of the commands \mycs{cusetoptionfor} and
+% \mycs{cuaddoptionfor}.
% \end{function}
%
% \begin{cuexample}
@@ -2040,10 +2197,10 @@ and the derived file cooking-units.sty.
% {
% set-option-for =
% {
-% F = { round-to-int = true } ,
-% C = { round-to-int = true } ,
-% K = { round-to-int = true } ,
-% Re = { round-to-int = true }
+% F = { round-precision = 0 } ,
+% C = { round-precision = 0 } ,
+% K = { round-precision = 0 } ,
+% Re = { round-precision = 0 }
% }
% }
% \end{lstlisting}
@@ -2061,7 +2218,7 @@ and the derived file cooking-units.sty.
%^^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.
+% the specified \meta{unit-key}s (key-value version of \mycs{cuclearoptionfor}).
%
% \end{function}
%
@@ -2072,6 +2229,10 @@ and the derived file cooking-units.sty.
% \begin{lstlisting}
% \cusetup{ erase-all-options-for = {C, F, K, Re} }
% \end{lstlisting}
+% It's the same as
+% \begin{lstlisting}
+% \cuclearoptionfor {C, F, K, Re}
+% \end{lstlisting}
% \end{cuexample}
%
%
@@ -2104,7 +2265,7 @@ and the derived file cooking-units.sty.
% \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\
+% Set this option to \opt{false} if you do \emph{not} want the units of \cCutext\
% to be changed. Set to \true\ by default
% \end{function}
% \begin{cuexamplecode}
@@ -2187,11 +2348,11 @@ and the derived file cooking-units.sty.
% \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
+% \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.
+% It is set to \texttt{n} (no expansion) by default.
%
% \end{function}
%
@@ -2244,12 +2405,23 @@ and the derived file cooking-units.sty.
% \begin{syntax}
% print-numerals = \meta{true/false}
% \end{syntax}
-% If the package option \opt{use-numerals} is set to \true\ you can
-% deactivate the printing of numerals by setting \opt{print-numerals} to
-% \false\ and activate them by setting it to \true.
%
-% Note that this option is automatically set to \opt{true} if \opt{use-numerals} is used.
+% Prints numerals for integers smaller then \opt{use-numerals-below} if
+% set to \true. If set to \false\ no numerals are printed.
+%
+% If you use the package option \opt{use-fmtcount-numerals} this option
+% is automatically set to \true.
+%
+% If you want to use another package, just set this option to \true\ and
+% use \opt{numeral-function} and \opt{Numeral-function}.
+%
+%^^A If the package option \opt{use-fmtcount-numerals} is set to \true\ you can
+%^^A deactivate the printing of numerals by setting \opt{print-numerals} to
+%^^A \false\ and activate them by setting it to \true.
+%
% \end{function}
+% \begin{cuexample}
+% (Using the package option \opt{use-fmtcount-numerals}:
% \cusetup{ print-numerals=true }
% \begin{cuexamplecode}
% \cutext{1}{kg} \\
@@ -2263,16 +2435,15 @@ and the derived file cooking-units.sty.
% \cutext{13}{kg} \\
% \end{cuexamplecode}
% \cusetup{ print-numerals=false }
+% \end{cuexample}
%
% \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.
+% If \opt{print-numerals} is \true, prints the numerals in
+% \mycs{cutext} and \mycs{Cutext} for integers smaller than
+% \meta{integer}. \meta{integer} is by default 13.
% You can deactivate the printing of numerals by \opt{print-numerals=false}.
% \end{function}
% \cusetup{ print-numerals=true }
@@ -2299,6 +2470,28 @@ and the derived file cooking-units.sty.
% \end{cuexamplecode}
% \cusetup{ print-numerals=false }
%
+% \begin{function}{numeral-function, Numeral-function }
+% \begin{syntax}
+% numeral-function = \meta{function}
+% Numeral-function = \meta{function}
+% \end{syntax}
+% Sets the functions used for printing numerals.
+% \opt{numeral-function} is used for lowercase, \opt{Numeral-function}
+% for capitalized cases.
+% \end{function}
+% \begin{cuexample}
+% Using the commands from \pkg{fmtcount} you can set the
+% numeral function equal to
+% \begin{lstlisting}
+% \cusetup{
+% numeral-function = \numberstringnum ,
+% Numeral-function = \Numberstringnum
+% }
+% \end{lstlisting}
+% (this happens if you use the package option \opt{use-fmtcount-numerals})
+% \end{cuexample}
+%
+%
%
% \begin{function}{parse-number}
% \begin{syntax}
@@ -2339,10 +2532,10 @@ and the derived file cooking-units.sty.
% 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
+% \opt{cunum-range-sign} sets the \emph{printed} range sign used in \mycs{cunum}
+% (and \mycs{cuam}) to \meta{string}, \opt{cutext-range-sign} sets the printed
% range sign used in \cCutext{} to \meta{string}.
-% Using the first option sets the
+% Using \opt{range-sign} sets the
% range signs for both \mycs{cunum} (and \mycs{cuam}) and
% \mycs{cutext}/\mycs{Cutext} to \meta{string}.
%
@@ -2440,9 +2633,7 @@ and the derived file cooking-units.sty.
% \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-F={round-precision=-1}} @
+% \cusetoptionfor{C,F}{round-precision=-1} @
% \cunum{-271,2}{C} \\
% \cunum[K=C]{0.0012}{K} \\
% \cunum{185}{C} \\
@@ -2454,17 +2645,18 @@ and the derived file cooking-units.sty.
% \begin{syntax}
% round-to-int = \meta{true/false}
% \end{syntax}
-% Rounds the amount to an integer if set \true.
+% \emph{This option is deprecated.} Rounds the amount to an integer if set \true.
+% Use \opt{round-precision=0} instead.
% \end{function}
%
%
-% \begin{cuexamplecode}
-% \cusetup{round-to-int=true} @
-% \cunum{1.23456789}{kg} \\
-% \cunum{12.58}{kg} \\
-% \cunum[g=kg]{194--294}{g} \\
-% \cunum[kg=g]{1.23456789}{kg}
-% \end{cuexamplecode}
+%^^A \begin{cuexamplecode}
+%^^A \cusetup{round-to-int=true} @
+%^^A \cunum{1.23456789}{kg} \\
+%^^A \cunum{12.58}{kg} \\
+%^^A \cunum[g=kg]{194--294}{g} \\
+%^^A \cunum[kg=g]{1.23456789}{kg}
+%^^A \end{cuexamplecode}
%
% \begin{function}{round-half}
% \begin{syntax}
@@ -2506,7 +2698,7 @@ and the derived file cooking-units.sty.
% eval-fraction = \meta{true/false}
% \end{syntax}
% This option takes \true\ or \false\ as values.
-% If set to \true\ fractions are evaluated. Please note that divisions
+% If set to \true\ all fractions are evaluated. Please note that divisions
% through zero are not allowed.
% \end{function}
%
@@ -2521,12 +2713,36 @@ and the derived file cooking-units.sty.
% \cunum[kg=g]{1_?/2}{kg} \\
% \end{cuexamplecode}
%
+%
+%
+% \begin{function}{convert-fraction}
+% \begin{syntax}
+% convert-fraction = \meta{true/false}
+% \end{syntax}
+% By default units of fractions are not converted into another unit.
+% Setting this option to \true\
+% allows fractions to be evaluated when a change of units is requested
+% (and \emph{only} if a change of unit is requested).
+% \end{function}
+%
+% \begin{cuexamplecode}
+% \cusetup{convert-fraction=true} @
+% \cunum{1/3}{kg} \\
+% \cunum[kg=g]{1/3}{kg} \\
+% \cunum{1_1/2}{kg} \\
+% \cunum[kg=g]{1_1/2}{kg} \\
+% \cunum[kg=g]{1_?/2}{kg} \\
+% \end{cuexamplecode}
+%
+%
+%
+%
% \begin{function}{fraction-command}
% \begin{syntax}
-% fraction-command = \meta{\cs{command}}
+% fraction-command = \cs{command}
% \end{syntax}
-% Sets the command used for printing fractions equal to \meta{\cs{command}}.
-% \meta{\cs{command}} has to take two arguments. By default
+% Sets the command used for printing fractions equal to \cs{command}.
+% \cs{command} has to take two arguments. By default
% it is equal to |\sfrac| from \pkg{xfrac}.
%
% Please note that the amount is \emph{not} printed inside a math
@@ -2651,7 +2867,6 @@ and the derived file cooking-units.sty.
% \end{function}
%
% \begin{cuexamplecode}
-% \selectlanguage{ngerman} @
% \cunum{1}{kg}\\
% \cunum{1/2}{kg}\\
% \cunum{1--2}{kg}\\
@@ -2799,7 +3014,7 @@ and the derived file cooking-units.sty.
%^^A by the label \& ref system. Of course, you can also remove units or clear the whole list.
%
% There are units which do not depend on the number of folks you are cooking for, units measuring
-% the temperature are for example some of them. Changing those units with the label \& ref
+% the temperature are an example. Changing those units with the label \& ref
% system would be accidental and in the best case throw an error. With the following options
% you can add units to the \enquote{forbidden unit list}, remove them and clear the whole list
% entirely.
@@ -3004,7 +3219,7 @@ and the derived file cooking-units.sty.
%
%
%
-% \clearpage
+%\clearpage
%
% \section{Bens Einheitensammelsurium (Bens unit Almanac)}
%
@@ -3152,7 +3367,6 @@ and the derived file cooking-units.sty.
%
%
%
-% \clearpage
% \appendix
%
% \section{Translations}
@@ -3168,7 +3382,7 @@ and the derived file cooking-units.sty.
%
% \small
%
-% \newpage
+%\clearpage
% \subsection{English}
% \begin{tabular}{ l l l l l }
% \toprule
@@ -3176,7 +3390,7 @@ and the derived file cooking-units.sty.
% \end{tabular}
%
%
-% \newpage
+%\clearpage
% \subsection{american}
%
% \begin{tabular}{ l l l l l }
@@ -3184,7 +3398,7 @@ and the derived file cooking-units.sty.
% \CreateTableForLanguages{ american }
% \end{tabular}
%
-% \newpage
+%\clearpage
% \subsection{German}
% \begin{tabular}{ l l l l l }
% \toprule
@@ -3212,7 +3426,7 @@ and the derived file cooking-units.sty.
%
% Note that Gro{\ss}gros has other (probably more common) synonyms.
%
-% \newpage
+%\clearpage
% \subsection{French}
% \begin{tabular}{ l l l l l }
% \toprule
@@ -3225,7 +3439,122 @@ and the derived file cooking-units.sty.
% \item cuill\`{e}re \`{a} caf\'{e} rase
% \end{itemize}
%
-% \clearpage
+%\clearpage
+%
+%
+%
+%
+%
+%
+%
+%
+% \section{US, Imperial and Other units}
+% \label{sec:other-units}
+%
+% As source \cite{WM1985} has been used for imperial units, while \cite{Nist2006}
+% and \cite{Nist2008} were used for U.S.\ units. I hope someone will find this
+% bringing together useful.
+%
+%\begin{center}
+%\begin{tabular}{ l @{ } l }
+%\toprule
+% 1 yard &= \SI{0.9144}{\m} (exact) \\
+% 1 yard &= 3 foot \\
+% 1 yard &= 36 Inch \\ \midrule
+% 1 Inch &= \SI{0.0254}{\m} (also exact) \\
+% \bottomrule
+%\end{tabular}
+%\end{center}
+%
+%\begin{center}
+%\begin{tabular}{r@{ }l r@{ }l}
+%\toprule
+% \multicolumn{4}{c}{ 1 liter = \SI{1}{\cubic\deci\meter} } \\ \midrule
+% 1 gallon &= \SI{4.54609}{liter} (exact) & 1 U.S.\ gallon &= 231\,Inch$^3$ $=$
+% $231\times \num{0,016387064}$ liter \\
+% 1 gallon &= 4 Quart & 1 U.S.\ gallon &= 4 Quart\US\\
+% 1 gallon &= 8 Pint & 1 U.S.\ gallon &= 8 Pint\US\\
+% 1 gallon &= 32 Gill & 1 U.S.\ gallon &= 32 Gill\US\\
+% 1 gallon &= 160\,fl.\,oz & 1 U.S.\ gallon &= 128\,fl.\,oz\US \\\midrule
+% 1 \,fl.\,oz&= \num{0.0284130625} liter & 1\,fl.\,oz\US & = \num{0.0295735295625} liter
+% \\ \bottomrule
+%\end{tabular}\\ \footnotesize\raggedright
+%\begin{cuenumnote}
+% \item I think the American fl.\,oz\US\ is more common. Maybe. Most bottles
+% have something like 10\,fl.\,oz, which they say is equal to \SI{30}{\ml}. This would
+% work really well with fl.\,oz\US.
+% \item Sometimes \enquote{fl.\,oz} is written without the dot. I am also not sure what
+% kind of spacing has to be between \enquote{fl.} and \enquote{oz} (currently
+% using \cs{thinspace}).
+% \item This maybe sounds stupid, but could we introduce something like
+% \enquote{flouz}, \enquote{floiz} and \enquote{floez}? \enquote{flouz} would be
+% \enquote{fl.\,oz\US}, \enquote{floiz} would be \enquote{Imperial fl.\,oz} and
+% \enquote{floez} would simply be equal to \SI{30}{\ml}?
+%\end{cuenumnote}
+%\end{center}
+%
+%
+% For \enquote{stick} see \cite{StickSource}.
+%\begin{center}
+%\begin{tabular} { l @{ } l }
+% \toprule
+% 1\,lb &= \SI{0.453 592 37}{\kg} (exact) \\
+% 1\,lb &= 16\,oz \\
+% 1\,lb &= \sfrac{1}{14}\,st \\
+% 1\,lb &= \sfrac{175}{12}\,ounce~troy \\
+% 1\,lb &= 4 stick \\
+% \bottomrule
+%\end{tabular}
+%\end{center}
+%
+%
+%
+%\begin{center}
+%\begin{tabular} { r @{ } l @{ }l r @{ } l }
+% \toprule
+% 1 cup &$\approx$ \num{0.25} litre &= \SI{250}{\ml} &1 cup\US &= 8\, fl.\,oz\US \\
+% 1 tablespoon &$\approx$ \num{0.015} litre&= \SI{15}{\ml} & 1 tablespoon\US &= \sfrac{1}{2}\, fl.\,oz\US \\
+% 1 teaspoon &$\approx$ \num{0.005} litre &= \SI{5}{\ml} & 1 teaspoon\US&= \sfrac{1}{6}\, fl.\,oz\US \\
+% \bottomrule
+%\end{tabular} \footnotesize \\ \raggedright
+%\begin{cuenumnote}
+% \item I tested the approximation for tablespoon with water
+% ($\SI{1}{\mg} \approx \SI{1}{\mg}$) and the approximation looks good enough.
+% It of course depends on how full you fill your spoon.
+%\end{cuenumnote}
+%\end{center}
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
%
% \begin{comment}
%^^A \section{Notes and other stuff}
@@ -3370,8 +3699,8 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\ProvidesExplPackage
{cooking-units}
- {2018/09/24}
- {1.45}
+ {2020/01/13}
+ {1.46}
{Ein Paket fuer Kocheinheiten}
% \end{macrocode}
%
@@ -3410,14 +3739,28 @@ and the derived file cooking-units.sty.
}
% \end{macrocode}
%
-% Define the only load-time option for this package. If it is set,
-% load package \pkg{fmtcount}.
+% \begin{macrocode}
+\msg_new:nnnn { cooking-units } { Option-deprecated }
+ {
+ The \ option \ '#1' \ is \ deprecated \ and \ should \ be \
+ replaced \ by \ '#2'.
+ }{
+ Please \ replace \ the \ option.
+ \msg_see_documentation_text:n { cooking-units }
+ }
+% \end{macrocode}
% \begin{macrocode}
\bool_new:N \g_@@_opt_numeral_bool
\keys_define:nn { cooking-units }
{
- use-numerals .bool_gset:N = \g_@@_opt_numeral_bool ,
+ use-numerals .code:n =
+ {
+ \msg_warning:nnnn { cooking-units } { Option-deprecated } { use-numerals } { use-fmtcount-numerals }
+ \keys_set:nn { cooking-units } { use-fmtcount-numerals = #1 }
+ } ,
use-numerals .default:n = { false },
+ use-fmtcount-numerals .bool_gset:N = \g_@@_opt_numeral_bool ,
+ use-fmtcount-numerals .default:n = { false },
}
% \end{macrocode}
% Now process the package options \dots
@@ -3432,7 +3775,12 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\keys_define:nn { cooking-units }
{
- use-numerals .code:n = { \msg_error:nnn { cooking-units } { load-time-option } { fmtcount } } ,
+ use-numerals .code:n =
+ {
+ \msg_warning:nnnn { cooking-units } { Option-deprecated } { use-numerals } { use-fmtcount-numerals }
+ \msg_error:nnn { cooking-units } { load-time-option } { fmtcount }
+ } ,
+ use-fmtcount-numerals .code:n = { \msg_error:nnn { cooking-units } { load-time-option } { fmtcount } } ,
}
% \end{macrocode}
%
@@ -3443,14 +3791,15 @@ and the derived file cooking-units.sty.
% \begin{macro}
% {
% \tl_replace_all:NVn,
-% \tl_replace_once:NnV , \tl_replace_once:NVn ,
+% \tl_replace_once:NVn ,
% \tl_if_in:nVTF ,
% \tl_if_in:NVTF ,
% \tl_if_in:NVT ,
% \fp_compare:vNnT ,
-% \fp_eval:c ,
% \prop_get:cVc ,
-% \int_abs:c ,
+% \tl_set_rescan:NnV,
+% \msg_error:nnnV, \msg_error:nnV, \msg_warning:nnV,
+% \prop_put:cnx
% }
% Some variations of commands we will need later.
% \begin{macrocode}
@@ -3465,20 +3814,14 @@ and the derived file cooking-units.sty.
\cs_generate_variant:Nn \msg_error:nnnn { nnnV }
\cs_generate_variant:Nn \msg_error:nnn { nnV }
\cs_generate_variant:Nn \msg_warning:nnn { nnV }
+\cs_generate_variant:Nn \prop_put:Nnn { cnx }
% \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}
%
% \begin{macro}{\@@_frac:nn}
-% This command is used to print the fractions and can be changed
+% This command is used to print fractions and can be changed
% accordingly.
% \begin{macrocode}
\cs_new_eq:NN \@@_frac:nn \sfrac
@@ -3486,6 +3829,7 @@ and the derived file cooking-units.sty.
% \end{macro}
%
% \begin{macro}{\@@_set_amount:Nn,\@@_set_unit:Nn}
+% Allows for potential parsing of amount and or unit.
% \begin{macrocode}
\cs_new_eq:NN \@@_set_amount:Nn \tl_set:Nn
\cs_new_eq:NN \@@_set_unit:Nn \tl_set:Nn
@@ -3494,11 +3838,12 @@ and the derived file cooking-units.sty.
%
%
% \begin{macro}{\@@_print_numeral:n , \@@_print_Numeral:n}
-% This command is used to print the fractions and can be changed
-% accordingly.
+% Commands to print numerals. Either use default or set yourself.
% \begin{macrocode}
-\cs_new:Npn \@@_print_numeral:n #1 { }
-\cs_new:Npn \@@_print_Numeral:n #1 { }
+\cs_new:Npn \@@_print_numeral:n #1
+ { \msg_error:nnn {cooking-units} { define-numeral-function } }
+\cs_new:Npn \@@_print_Numeral:n #1
+ { \msg_error:nnn {cooking-units} { define-Numeral-function } }
\bool_if:NT \g_@@_opt_numeral_bool
{
\cs_set_eq:NN \@@_print_numeral:n \numberstringnum
@@ -3520,40 +3865,60 @@ and the derived file cooking-units.sty.
% \end{macro}
%
%
+%
+% \begin{macro} { \g_@@_master_changer_prop }
+% Similar to |\l_@@_change_unit_prop|, but doesn't store the requested
+% unit change, but the values needed for conversion. Either a numerical
+% value is stored or a formula (using |#1| to insert the original value).
+%
+% Put and get values via \cs{\@@_prop_gput_master:nnn}
+% and \cs{@@_prop_get_master:nnNTF}.
+% \begin{macrocode}
+\prop_new:N \g_@@_master_changer_prop
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
% \begin{macro}
% {
-% \l_@@_number_tmpa_tl,
-% \l_@@_number_tmpb_tl,
-% \l_@@_tmpa_tl,
-% \l_@@_tmpb_tl,
-% \l_@@_mixed_fraction_tl,
-% \l_@@_given_unit_tl,
-% \l_@@_option_unit_tl,
-% \l_@@_language_tl,
-% \l_@@_cunum_range_sign_tl,
-% \l_@@_cutext_range_sign_tl,
-% \l_@@_value_unit_space_tl,
-% \l_@@_input_digits_tl ,
-% \l_@@_input_decimal_mark_tl,
-% \l_@@_input_value_signs_tl,
-% \l_@@_input_allowed_special_signs_tl ,
-% \c_@@_input_str_hash_one_tl ,
-% \l_@@_input_range_sign_tl,
-% \l_@@_cutext_space_tl,
-% \l_@@_cuphrase_space_tl,
-% \l_@@_translation_tmpa_tl,
-% \l_@@_cutext_last_value_tl,
-% \l_@@_phrase_phrase_tl ,
+% \l_@@_number_tmpa_tl,
+% \l_@@_number_tmpb_tl,
+% \l_@@_mixed_fraction_tl,
+% \l_@@_original_amount_tl,
+% \l_@@_original_unit_tl,
+% \l_@@_option_unit_tl,
+% \l_@@_language_tl,
+% \l_@@_cunum_range_sign_tl,
+% \l_@@_cutext_range_sign_tl,
+% \l_@@_value_unit_space_tl,
+% \l_@@_input_digits_tl ,
+% \l_@@_input_decimal_mark_tl,
+% \l_@@_input_value_signs_tl,
+% \l_@@_input_allowed_special_signs_tl ,
+% \g_@@_input_str_hash_one_tl ,
+% \l_@@_input_range_sign_tl,
+% \l_@@_cutext_space_tl,
+% \l_@@_cuphrase_space_tl,
+% \l_@@_translation_tmpa_tl,
+% \l_@@_cutext_last_value_tl,
+% \l_@@_phantom_tl,
+% \l_@@_phrase_phrase_tl,
+% \l_@@_unit_letter_not_allowed_tl,
+% \l_@@_input_fraction_sign_tl,
+% \l_@@_input_mixed_fraction_sign_tl,
+% \l_@@_list_of_units_tl,
+% \l_@@_list_of_values_tl,
+% \l_@@_cunum_hook_tl , \l_@@_cutext_hook_tl ,
+% \l_@@_Cutext_hook_tl , \l_@@_cuam_hook_tl
% }
% Quite a lot of tl's.
% \begin{macrocode}
\tl_new:N \l_@@_number_tmpa_tl
\tl_new:N \l_@@_number_tmpb_tl
-\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_@@_original_amount_tl
+\tl_new:N \l_@@_original_unit_tl
\tl_new:N \l_@@_option_unit_tl
\tl_new:N \l_@@_language_tl
\tl_new:N \l_@@_cunum_range_sign_tl
@@ -3563,7 +3928,7 @@ and the derived file cooking-units.sty.
\tl_new:N \l_@@_input_decimal_mark_tl
\tl_new:N \l_@@_input_value_signs_tl
\tl_new:N \l_@@_input_allowed_special_signs_tl
-\tl_new:N \c_@@_input_str_hash_one_tl
+\tl_new:N \g_@@_input_str_hash_one_tl
\tl_new:N \l_@@_input_range_sign_tl
\tl_new:N \l_@@_cutext_space_tl
\tl_new:N \l_@@_cuphrase_space_tl
@@ -3574,6 +3939,8 @@ and the derived file cooking-units.sty.
\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
+\tl_new:N \l_@@_list_of_units_tl
+\tl_new:N \l_@@_list_of_values_tl
% \end{macrocode}
% \begin{macrocode}
\tl_new:N \l_@@_cunum_hook_tl
@@ -3585,8 +3952,8 @@ and the derived file cooking-units.sty.
%
%
% Setting some token lists to their default value.
-% \lstinline|str_hash_one_tl| is used for defining single keys.
-% (You will see, I didn't have a better idea)
+% \cs{c_@@_input_str_hash_one_tl} is used for defining single keys.
+% (As 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_range_sign_tl { -- }
@@ -3595,19 +3962,19 @@ and the derived file cooking-units.sty.
\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 { ? }
-\tl_set_rescan:Nnn \c_@@_input_str_hash_one_tl
+\tl_gset_rescan:Nnn \g_@@_input_str_hash_one_tl
{ \char_set_catcode_letter:N \# } {#1}
% \end{macrocode}
% \begin{macrocode}
\tl_set:Nn \l_@@_cunum_range_sign_tl { -- }
-\tl_set:Nn \l_@@_cutext_range_sign_tl {}
+\tl_set:Nn \l_@@_cutext_range_sign_tl { }
\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_letter_not_allowed_tl { , / }
% \end{macrocode}
%
-% Flat out stolen from \pkg{siunitx}
+% Flat out stolen from \pkg{siunitx}.
% \begin{macrocode}
\AtBeginDocument {
\cs_if_free:cT { T@TS1 }
@@ -3649,7 +4016,7 @@ and the derived file cooking-units.sty.
%
%
% \begin{macro}{ \l_@@_round_precision_int }
-% Stores the round-precision inside.
+% Stores the round-precision inside. Can also take negative values.
% \begin{macrocode}
\int_new:N \l_@@_round_precision_int
\int_set:Nn \l_@@_round_precision_int { 2 }
@@ -3657,7 +4024,7 @@ and the derived file cooking-units.sty.
% \end{macro}
%
% \begin{macro}{ \l_@@_print_numerals_below_int }
-% Used if option 'use-numerals' is active. Uses numerals for
+% Used if option \opt{use-numerals} is active. Uses numerals for
% integers smaller than this number. I learned this number
% at school.
% \begin{macrocode}
@@ -3670,7 +4037,7 @@ and the derived file cooking-units.sty.
% \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.
+% the value is retrieved and stored inside this temporal integer variable.
% \begin{macrocode}
\int_new:N \l_@@_local_number_of_persons_int
% \end{macrocode}
@@ -3679,17 +4046,21 @@ and the derived file cooking-units.sty.
% \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.
+% the recipe to be. This information is stored here.
% \begin{macrocode}
\int_new:N \l_@@_wanted_number_of_persons_int
\int_set:Nn \l_@@_wanted_number_of_persons_int { 4 }
% \end{macrocode}
% \end{macro}
%
+%
+% \begin{macro}{ \l_@@_phrase_number_tl }
+% Stores the current \enquote{phrase number}. For \enquote{Dutzend} this would
+% be \enquote{12}, etc.
% \begin{macrocode}
\int_new:N \l_@@_phrase_number_tl
% \end{macrocode}
-%
+% \end{macro}
%
% \begin{macro}{ \l_@@_list_of_defined_keys_clist , \g_@@_list_of_defined_units_clist }
% Sequence of defined units and keys. Units are defined
@@ -3715,12 +4086,35 @@ and the derived file cooking-units.sty.
% \begin{macro} { \l_@@_phrase_numbers_seq }
% Inside this list the numbers for which a phrase is defined
% is stored in. As this is language specific, the list is stored
-% inside a language-sensitive command and retrived when needed.
+% inside a language-sensitive command and retrieved when needed.
% \begin{macrocode}
\seq_new:N \l_@@_phrase_numbers_seq
% \end{macrocode}
% \end{macro}
%
+%
+% \begin{macro}{\l_@@_number_of_iterations_seq, \l_@@_derivative_unit_list_seq ,
+% \l_@@_derivative_symbol_list_seq , \l_@@_derivative_value_list_seq
+% }
+% Variables used in \mycs{declarecookingderivatives}.
+% \begin{macrocode}
+\seq_new:N \l_@@_number_of_iterations_seq
+\seq_new:N \l_@@_derivative_unit_list_seq
+\seq_new:N \l_@@_derivative_symbol_list_seq
+\seq_new:N \l_@@_derivative_value_list_seq
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macro}{\l_@@_max_depth_int, \l_@@_curr_depth_int}
+% Also some variables used in \mycs{declarecookingderivatives}.
+% \begin{macrocode}
+\int_new:N \l_@@_max_depth_int
+\int_new:N \l_@@_curr_depth_int
+% \end{macrocode}
+% \end{macro}
+%
+%
+%
% \begin{macro} { \l_@@_temperatures_to_check_seq }
% \changes {1.02h} {New.}
% Stores units which should be tested if \opt{check-temperature} equals true.
@@ -3746,38 +4140,49 @@ and the derived file cooking-units.sty.
% \end{macro}
%
%
+%
% \begin{macro}
% {
% \l_@@_minus_bool,
-% \l_@@_round_number_bool,
-% \l_@@_error_bool,
-% \l_@@_eval_fractions_bool,
-% \l_@@_draft_bool,
-% \l_@@_round_to_int_bool,
-% \l_@@_special_sign_bool,
-% \l_@@_single_key_bool,
-% \l_@@_check_temperature_bool,
-% \l_@@_convert_to_eV_bool,
-% \l_@@_cutext_uppercase_word_bool,
-% \l_@@_error_for_unknown_value_bool,
-% \l_@@_using_cutext_bool,
-% \l_@@_cuam_old_bool,
-% \l_@@_change_number_of_persons_bool,
-% \l_@@_calc_because_ref_was_given_bool,
-% \l_@@_lokal_persons_bool,
-% \l_@@_cutext_to_cunum_bool,
-% \l_@@_cutext_old_bool,
-% \l_@@_cutext_keep_unit_bool,
-% \l_@@_round_commercial_bool,
-% \l_@@_use_phrases_bool,
-% \l_@@_lokal_phrase_bool
+% \l_@@_round_number_bool,
+% \l_@@_error_bool,
+% \l_@@_unit_error_bool,
+% \l_@@_eval_fractions_bool,
+% \l_@@_convert_fractions_bool,
+% \l_@@_draft_bool,
+% \l_@@_round_to_int_bool,
+% \l_@@_special_sign_bool,
+% \l_@@_single_key_bool,
+% \l_@@_check_temperature_bool,
+% \l_@@_convert_to_eV_bool,
+% \l_@@_cutext_uppercase_word_bool,
+% \l_@@_using_cutext_bool,
+% \l_@@_cuam_old_bool,
+% \l_@@_change_number_of_persons_bool,
+% \l_@@_calc_because_ref_was_given_bool,
+% \l_@@_lokal_persons_bool,
+% \l_@@_cutext_to_cunum_bool,
+% \l_@@_cutext_old_bool,
+% \l_@@_cutext_keep_unit_bool,
+% \l_@@_round_commercial_bool,
+% \l_@@_use_phrases_bool,
+% \l_@@_lokal_phrase_bool,
+% \l_@@_print_numeral_bool,
+% \l_@@_lokal_numeral_bool,
+% \l_@@_round_precision_negative_bool,
+% \l_@@_fourty_two_bool,
+% \l_@@_phrase_negative_bool ,
+% \l_@@_range_in_input_bool, \l_@@_lokal_fraction_bool ,
+% \l_@@_print_fraction_bool, \l_@@_check_decimal_bool ,
% }
% Some booleans we need later.
% \begin{macrocode}
\bool_new:N \l_@@_minus_bool
\bool_new:N \l_@@_round_number_bool
\bool_new:N \l_@@_error_bool
+\bool_new:N \l_@@_unit_error_bool
\bool_new:N \l_@@_eval_fractions_bool
+\bool_new:N \l_@@_convert_fractions_bool
\bool_new:N \l_@@_draft_bool
\bool_new:N \l_@@_round_to_int_bool
\bool_new:N \l_@@_special_sign_bool
@@ -3785,7 +4190,6 @@ and the derived file cooking-units.sty.
\bool_new:N \l_@@_check_temperature_bool
\bool_new:N \l_@@_convert_to_eV_bool
\bool_new:N \l_@@_cutext_uppercase_word_bool
-\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_@@_change_number_of_persons_bool
@@ -3799,7 +4203,7 @@ and the derived file cooking-units.sty.
\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_@@_round_precision_negative_bool
\bool_new:N \l_@@_fourty_two_bool
\bool_new:N \l_@@_phrase_negative_bool
% \end{macrocode}
@@ -3810,7 +4214,6 @@ and the derived file cooking-units.sty.
\bool_new:N \l_@@_range_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_@@_check_decimal_bool
% \end{macrocode}
% \end{macro}
@@ -3832,28 +4235,26 @@ and the derived file cooking-units.sty.
%\end{macro}
%
% \begin{macro}{ \q_@@_no_translation }
+% Checking value if a translation is avaiable.
% \begin{macrocode}
\quark_new:N \q_@@_no_translation
% \end{macrocode}
%\end{macro}
%
-% \begin{macro}{ \q_@@_decimal , \q_@@_fraction , \q_@@_mixed_fraction }
-% \begin{macrocode}
-\quark_new:N \q_@@_decimal
-\quark_new:N \q_@@_fraction
-\quark_new:N \q_@@_mixed_fraction
-% \end{macrocode}
-%\end{macro}
%
% \begin{macro}{
+% \l_@@_tmpa_tl , \l_@@_tmpb_tl , \l_@@_tmp_unit_tl ,
% \l_@@_tmpa_fp ,
% \l_@@_tmpa_clist ,
-% \l_@@_tmpa_prop ,
-% \l_@@_tmpb_prop ,
+% \l_@@_tmpa_prop , \l_@@_tmpb_prop ,
% \l_@@_tmpa_seq ,
+% \l_@@_tmpa_int , \l_@@_tmpb_int ,
% }
% Some temporal stores which are used throughout the code.
% \begin{macrocode}
+\tl_new:N \l_@@_tmpa_tl
+\tl_new:N \l_@@_tmpb_tl
+\tl_new:N \l_@@_tmp_unit_tl
\fp_new:N \l_@@_tmpa_fp
\clist_new:N \l_@@_tmpa_clist
\prop_new:N \l_@@_tmpa_prop
@@ -3881,8 +4282,8 @@ and the derived file cooking-units.sty.
add-unit-to-group .code:n =
{
\keyval_parse:NNn
- \@@_unit_group_add_unit_error:n
- \@@_unit_group_add_unit:nn
+ \@@_add_to_unit_group_error:n
+ \@@_add_to_unit_group:nn
{#1}
} ,
add-unit-to-group .default:n = {} ,
@@ -3916,28 +4317,28 @@ and the derived file cooking-units.sty.
% \end{macro}
%
% \begin{macro}{ erase-all-options }
-% Erasing all preset options.
+% Erasing all preset options. Again not the best approach \dots\ maybe I need a lower
+% level \enquote{clear} option.
% \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 }
- }
+ \exp_args:Nx \cuclearoptionfor { \seq_use:Nn \g_@@_list_of_defined_units_seq { , } }
},
erase-all-options .value_forbidden:n = { true } ,
% \end{macrocode}
% \end{macro}
%
%\begin{macro}{ erase-all-options-for }
-% Erasing options.
+% Erasing options. As this simply clears the unit options the argument |#1|
+% is simply a clist, as such no keyval parsing is needed.
% \begin{macrocode}
erase-all-options-for .code:n =
{
- \keyval_parse:NNn
- \@@_erase_options_for:n
- \@@_erase_options_for_error:nn
- {#1}
+ \cuclearoptionfor {#1}
+% \keyval_parse:NNn
+% \@@_erase_options_for:n
+% \@@_erase_options_for_error:nn
+% {#1}
},
erase-all-options-for .value_required:n = { true } ,
% \end{macrocode}
@@ -4027,7 +4428,7 @@ and the derived file cooking-units.sty.
%
%
%\begin{macro}{ set-special-sign }
-% Doing the same as above but also overrides the old signs.
+% Setting allowd special signs. Note that |<| is not allowed.
% \begin{macrocode}
set-special-sign .code:n =
{
@@ -4152,8 +4553,9 @@ and the derived file cooking-units.sty.
{
\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 }
+ { \bool_set_true:N }
+ { \bool_set_false:N }
+ \l_@@_round_precision_negative_bool
} ,
round-precision .default:n = { 2 } ,
% \end{macrocode}
@@ -4163,6 +4565,18 @@ and the derived file cooking-units.sty.
% Rounding the results to an integer.
% \begin{macrocode}
round-to-int .bool_set:N = \l_@@_round_to_int_bool ,
+ round-to-int .choices:nn =
+ { true , false }
+ {
+ \msg_error:nnnn { cooking-units } { Option-deprecated } { round-to-int } { round-precision = 0 }
+ \int_compare:nNnTF { \l_keys_choice_int } = { 1 }
+ {
+ \int_set:Nn \l_@@_round_precision_int { 0 }
+ }{
+
+ }
+ \use:c { bool_set_ \l_keys_choice_tl :N } \l_@@_round_to_int_bool
+ } ,
round-to-int .default:n = { false } ,
% \end{macrocode}
%\end{macro}
@@ -4192,6 +4606,15 @@ and the derived file cooking-units.sty.
% \end{macrocode}
%\end{macro}
%
+%\begin{macro}{ convert-fraction }
+% If set to true the fractions are evaluated \emph{if} the unit is transformed!
+% \begin{macrocode}
+ convert-fraction .bool_set:N = \l_@@_convert_fractions_bool ,
+ convert-fraction .default:n = { true } ,
+% \end{macrocode}
+%\end{macro}
+%
+%
%\begin{macro}{ fraction-command }
% Setting the fraction command
% \begin{macrocode}
@@ -4270,7 +4693,7 @@ and the derived file cooking-units.sty.
% \end{macro}
%
% \begin{macro}{ label }
-% Defines a label \dots\ is \mycs{culabel} as a key.
+% Defines a label. Is \mycs{culabel} in key form.
% \begin{macrocode}
label .code:n = \@@_label_and_persons:n {#1} ,
label .value_required:n = { true } ,
@@ -4338,10 +4761,15 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
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
+ \seq_map_inline:Nn \l_@@_tmpa_seq
+ {
+ \@@_error_if_unit_not_defined:nF {##1}
+ {
+ \seq_if_in:NnF \g_@@_natural_units_seq {##1}
+ { \seq_gput_right:Nn \g_@@_natural_units_seq {##1} }
+ }
+ }
} ,
add-natural-unit .value_required:n = { true } ,
% \end{macrocode}
@@ -4393,7 +4821,12 @@ and the derived file cooking-units.sty.
%
%
%
-% \begin{macro}{hooks}
+% \begin{macro}{
+% commands-add-hook ,
+% cunum-add-hook ,
+% cutext-add-hook , Cutext-add-hook ,
+% cuam-add-hook ,
+% }
% \begin{macrocode}
commands-add-hook .meta:n =
{
@@ -4425,34 +4858,19 @@ and the derived file cooking-units.sty.
%
%
%
-% \begin{macro}{curef-add-forbidden-unit, curef-remove-forbidden-unit, curef-clear-forbidden-units}
+% \begin{macro}{
+% curef-add-forbidden-unit,
+% curef-remove-forbidden-unit,
+% curef-clear-forbidden-units
+% }
% \begin{macrocode}
- curef-add-forbidden-unit .code:n =
- {
- \seq_set_from_clist:Nn \l_@@_tmpa_seq {#1}
- \seq_map_inline:Nn \l_@@_tmpa_seq
- {
- \seq_if_in:NnF \l_@@_curef_do_not_change_seq {##1}
- { \seq_put_right:Nn \l_@@_curef_do_not_change_seq {##1} }
- }
- } ,
+ curef-add-forbidden-unit .code:n = { \@@_add_forbidden_unit:n {#1} } ,
curef-add-forbidden-unit .default:n = { } ,
- curef-remove-forbidden-unit .code:n =
- {
- \seq_set_from_clist:Nn \l_@@_tmpa_seq {#1}
- \seq_map_inline:Nn \l_@@_tmpa_seq
- {
- \seq_if_in:NnTF \l_@@_curef_do_not_change_seq {##1}
- { \seq_remove_all:Nn \l_@@_curef_do_not_change_seq {##1} }
- {
- \msg_warning:nnn { cooking-units } { curef-not-inside-list } {##1}
- { \seq_use:Nnnn \l_@@_curef_do_not_change_seq { ',~ ' } { ',~ ' } { ' ~ and ~ ' } }
- }
- }
- } ,
+ curef-remove-forbidden-unit .code:n = { \@@_remove_forbidden_unit:n {#1} } ,
curef-remove-forbidden-unit .default:n = { } ,
+%
curef-clear-forbidden-units .choice: ,
- curef-clear-forbidden-units/true .code:n = { \seq_clear:N \l_@@_curef_do_not_change_seq } ,
+ curef-clear-forbidden-units/true .code:n = { \@@_clear_forbidden_unit: } ,
curef-clear-forbidden-units/false .code:n = { } ,
curef-clear-forbidden-units .value_required:n = true,
% \end{macrocode}
@@ -4466,7 +4884,6 @@ and the derived file cooking-units.sty.
%
%
%
-%
% Ending the definition of keys.
% \begin{macrocode}
}
@@ -4520,7 +4937,7 @@ and the derived file cooking-units.sty.
\msg_new:nnnn { cooking-units } { unknown-unit }
{
The \ unit \ '#1' \ is \ not \ defined. \ Use \
- \newcookingunit ~ (or \ one \ of \ the \ others) \ to \
+ \newcookingunit (or \ one \ of \ the \ others) \ to \
define \ new \ units.
}{
Define \ units \ before \ using \ or \ check \ if \ the \
@@ -4606,8 +5023,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.
@@ -4623,8 +5040,7 @@ and the derived file cooking-units.sty.
The \ temperature \ '#1' \ is \ too \ low.\ It \ cannot \ be \
below \ the \ absolute \ zero - point \ of \ '#2'. \ Note \ that \
the \ temperatures \
- '\seq_use:Nnnn \l_@@_temperatures_to_check_seq
- { ', ~ ' } { ', ~ ' } { ' ~ and ~ ' }' \
+ '\@@_seq_use_msg:N \l_@@_temperatures_to_check_seq' \
are \ rounded \ to \ integers \ by \ default.
\\\\
You \ can \ disable \ the \ option \ 'check-temperature' \ to \
@@ -4640,8 +5056,8 @@ and the derived file cooking-units.sty.
'#3' \ as \ a \ set \ of \ choices \ and \ '#2' \ is \ non \ of \ these.
}{
The \ key \ accepts \ only \ a \ fixed \ set \ of \ choices. \
- You \ can \ add \ new \ choices \ via \ \cuaddkeys, ~ \cuaddsinglekeys ~
- and \ \cuaddtokeys.
+ You \ can \ add \ new \ choices \ via \ \token_to_str:N \cuaddkeys, ~
+ \token_to_str:N \cuaddsinglekeys ~ and \ \token_to_str:N \cuaddtokeys.
\msg_see_documentation_text:n {cooking-units}
}
% \end{macrocode}
@@ -4666,8 +5082,7 @@ and the derived file cooking-units.sty.
{
The \ amount \ '#1' \ is \ not \ known \ at \ line \
\msg_line_number: .
- }
- {
+ }{
You \ used\ a\ special\ sign\ indicating\ that\ the\ true\ amount\ of\ the\
specific\ ingredient\ is\ (was) \ not\ known\ to\ you. This\ message\
reminds\ you\ about\ that\ fact.
@@ -4693,8 +5108,7 @@ and the derived file cooking-units.sty.
{
The \ option \ '#1' \ is \ only \ available \ as \ a \ load-time-option. \
Please \ set \ it \ as \ a \ package \ option.
- }
- {
+ }{
You \ cannot \ set \ this \ option \ using \ \cusetup ~
but \ only \ as \ a \ package \ option.
\msg_see_documentation_text:n { cooking-units }
@@ -4716,8 +5130,7 @@ and the derived file cooking-units.sty.
\msg_new:nnnn { cooking-units } { No-Value-given }
{
Please \ input \ a \ value \ for \ the \ key-value \ list \ in \ '#1'
- }
- {
+ }{
Each \ element \ of \ the \ list \ needs \ a \ value.
\msg_see_documentation_text:n { cooking-units }
}
@@ -4727,8 +5140,7 @@ and the derived file cooking-units.sty.
\msg_new:nnnn { cooking-units } { Value-not-allowed }
{
The \ key-list \ in \ '#1' \ does \ not \ take \ a \ value.
- }
- {
+ }{
This \ key-list \ does \ not \ take \ a \ value. \ The \
given \ value \ will \ be \ ignored.
\msg_see_documentation_text:n { cooking-units }
@@ -4753,8 +5165,7 @@ and the derived file cooking-units.sty.
{
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 }
@@ -4767,8 +5178,7 @@ and the derived file cooking-units.sty.
{
The \ number \ of \ persons \ the \ recipe \ is \ for \ must \ be \ an \
integer. \ '#1' \ is \ not \ allowed.
- }
- {
+ }{
The \ number \ '#1' \ is \ not \ allowed.
\msg_see_documentation_text:n { cooking-units }
}
@@ -4826,11 +5236,10 @@ and the derived file cooking-units.sty.
\msg_new:nnnn { cooking-units } { cutext-no-translation-available }
{
For \ the \ unit \ '#1' \ there \ exists \ no \ translation \ to \ be \ used \
- for \ \cutext ~ and \ \Cutext. \
+ for \ \cutext ~ and \ \token_to_str:N \Cutext. \
You \ can \ define \ new \ translations \ for \ a \ given \ language \ using \
\cudefinename.
- }
- {
+ }{
\cunum ~ is \ used \ instead.
\msg_see_documentation_text:n { cooking-units }
}
@@ -4841,9 +5250,8 @@ and the derived file cooking-units.sty.
\msg_new:nnnn { cooking-units } { Translation-not-available }
{
The \ translation \ for \ #1 \ does \ not \ exist.
- Please \ define \ it \ using \ \cudefinename.
- }
- {
+ Please \ define \ it \ using \ \token_to_str:N\cudefinename.
+ }{
And \ you \ may \ send \ me \ the \ translation \ as \ it \ is \
not \ available \ yet.
\msg_see_documentation_text:n { cooking-units }
@@ -4856,8 +5264,7 @@ and the derived file cooking-units.sty.
{
Currently \ (and \ probably \ forever) \ the \ sign \ '<' \
is \ not \ allowed \ to \ be \ used \ as \ a \ special \ sign.
- }
- {
+ }{
I \ apologize \ for \ the \ inconvenience.
\msg_see_documentation_text:n { cooking-units }
}
@@ -4891,7 +5298,8 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\msg_new:nnnn { cooking-units } { curef-forbidden-unit }
{
- The \ amount \ of \ '#1' \ cannot \ be \ changed \ using \ cooking-units` \ label \ \& \ ref \ feature.
+ The \ amount \ of \ '#1' \ cannot \ be \ changed \ using \ cooking-units`
+ \ label \ and \ ref \ feature.
}{
You \ can \ remove \ the \ unit \ using \ 'curef-remove-forbidden-unit'.
\msg_see_documentation_text:n { cooking-units }
@@ -4899,6 +5307,31 @@ and the derived file cooking-units.sty.
% \end{macrocode}
%
% \begin{macrocode}
+\msg_new:nnnn { cooking-units } { define-numeral-function }
+ {
+ You \ are \ using \ numerals \ (lowercase) \ without \ the \ load-time \ option \
+ 'use-fmtcount-numerals' \ as \ such \ you \ need \ to \ define \
+ which \ function \ is \ to \ be \ used \ for \ numerals. \ You \ can
+ \ do \ that \ via \ 'numeral-function' \ and \ 'Numeral-function'
+ }{
+ Please \ specify\ which \ function \ should \ be \ used \ to \ print \
+ numerals (lowercase \ and \ uppercase).
+ \msg_see_documentation_text:n { cooking-units }
+ }
+\msg_new:nnnn { cooking-units } { define-Numeral-function }
+ {
+ You \ are \ using \ numerals \ (capitalized) \ without \ the \ load-time \ option \
+ 'use-fmtcount-numerals' \ as \ such \ you \ need \ to \ define \
+ which \ function \ is \ to \ be \ used \ for \ numerals. \ You \ can
+ \ do \ that \ via \ 'numeral-function' \ and \ 'Numeral-function'
+ }{
+ Please \ specify\ which \ function \ should \ be \ used \ to \ print \
+ numerals (lowercase \ and \ uppercase).
+ \msg_see_documentation_text:n { cooking-units }
+ }
+% \end{macrocode}
+%
+% \begin{macrocode}
\msg_new:nnnn { cooking-units } { 42-is-...-wrong? }
{
You \ requested \ to \ set \ 42 \ to \ 'false'. \ This \ doesn't \ make
@@ -4911,14 +5344,34 @@ and the derived file cooking-units.sty.
Phew ... \ this \ might \ have \ ended \ disastrous.
\msg_see_documentation_text:n { cooking-units }
}
+% \end{macrocode}
+%
+%
+% \begin{macrocode}
+\msg_new:nnnn { cooking-units } { empty-amount }
+ {
+ The \ amount \ given \ is \ empty \ ( spaces \ are \ removed ).
+ }{
+ The \ amount \ given \ is \ empty.
+ \msg_see_documentation_text:n { cooking-units }
+ }
+%
+\msg_new:nnnn { cooking-units } { unknown-option }
+ {
+ The \ option \ '#1' \ is \ not \ defined.
+ }{
+ Perhaps \ you \ misspelled \ the \ option.
+ \msg_see_documentation_text:n { cooking-units }
+ }
% \end{macrocode}
%
+%
% \begin{macrocode}
\msg_new:nnnn { cooking-units } { internal-error }
{
This \ error \ shouldn't \ show. \ This \ means \ I
\ (the \ package \ author) \ screwed
- \ up.
+ \ up. \ The \ error \ code \ is \ '#1'.
}{
Please \ send \ me \ a \ bug \ report.
\msg_see_documentation_text:n { cooking-units }
@@ -4933,21 +5386,32 @@ and the derived file cooking-units.sty.
%\begin{macro}
% {
% \@@_error_if_unit_not_defined:n,
-% \@@_error_if_unit_not_defined:V,
+% \@@_error_if_unit_not_defined:nTF,
+% \@@_error_if_unit_not_defined:VTF,
% }
% A little helper macro. Checks if the unit is defined, if not raise an error.
% \begin{macrocode}
-\cs_new:Npn \@@_error_if_unit_not_defined:n #1
+\prg_new_protected_conditional:Npnn \@@_error_if_unit_not_defined:n #1 { TF, T, F }
{
- \seq_if_in:NnF \g_@@_list_of_defined_units_seq {#1}
- { \msg_error:nnn { cooking-units } { unknown-unit } {#1} }
+ \seq_if_in:NnTF \g_@@_list_of_defined_units_seq {#1}
+ { \prg_return_false: }
+ {
+ \msg_error:nnn { cooking-units } { unknown-unit } {#1}
+ \prg_return_true:
+ }
}
-\cs_generate_variant:Nn \@@_error_if_unit_not_defined:n { V }
+\cs_new:Npn \@@_error_if_unit_not_defined:n #1
+ { \@@_error_if_unit_not_defined:nTF {#1} { } { } }
+\cs_generate_variant:Nn \@@_error_if_unit_not_defined:nTF { V }
% \end{macrocode}
%\end{macro}
%
%
-%
+% \begin{macrocode}
+\cs_new:Npn \@@_seq_use_msg:N #1
+ { \seq_use:Nnnn #1 { ' , ~ ' } { ' , ~ ' } { ' ~ and ~ ' } }
+\cs_generate_variant:Nn \@@_seq_use_msg:N { c }
+% \end{macrocode}
%
%
%
@@ -4991,7 +5455,7 @@ and the derived file cooking-units.sty.
%
%
% \begin{macro}[TF]{ \@@_fp_if_equal_one:n}
-% \begin{macro}[TF]{ \@@_int_if_equal_one:n}f
+% \begin{macro}[TF]{ \@@_int_if_equal_one:n}
% \begin{macrocode}
\prg_new_conditional:Npnn \@@_fp_if_equal_one:n #1 { TF }
{
@@ -5024,6 +5488,20 @@ and the derived file cooking-units.sty.
%
% \begin{macro}{ \@@_check_if_correct_gender_input:n }
% \begin{macrocode}
+\prg_new_conditional:Npnn \@@_if_gender_error:n #1 { TF }
+ {
+ \str_case:nnTF {#1}
+ {
+ { m } { }
+ { f } { }
+ { n } { }
+ }
+ { \prg_return_false: }
+ {
+ \msg_error:nnn { cooking-units } { unknown-gender } {#1}
+ \prg_return_true:
+ }
+ }
\cs_new:Npn \@@_check_if_correct_gender_input:n #1
{
\str_case:nnF {#1}
@@ -5036,77 +5514,79 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{\@@_define_unit_group:nn}
+% \begin{macro}{\@@_define_clear_unit_group:nn,\@@_add_to_unit_group_error:n,\@@_add_to_unit_group:nn}
% \begin{macrocode}
-\cs_new:Npn \@@_define_unit_group:nn #1#2
+\cs_new:Npn \@@_define_clear_unit_group:nn #1#2
{
- \seq_new:c { l_@@_group_ #1 _seq }
- \seq_set_from_clist:cn { l_@@_group_ #1 _seq } {#2}
+ \seq_clear_new:c { l_@@_group_ #1 _seq }
\keys_define:nn { cooking-units }
{
#1 .code:n = { \@@_unit_group_convert_units:nn {#1} {##1} } ,
#1 .groups:n = { change-unit } ,
}
}
+%
+\cs_new:Npn \@@_add_to_unit_group_error:n #1
+ { \msg_error:nnn { cooking-units } { No-Value-given } { add-unit-to-group } }
+%
+\cs_new:Npn \@@_add_to_unit_group:nn #1#2
+ {
+ \@@_error_if_group_not_defined:nF {#1}
+ {
+ \clist_map_inline:nn {#2}
+ {
+ \@@_error_if_unit_not_defined:nF {##1}
+ {
+ \seq_if_in:cnF { l_@@_group_ #1 _seq } {##1}
+ { \seq_put_right:cn { l_@@_group_ #1 _seq } {##1} }
+ }
+ }
+ }
+ }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_error_if_group_not_defined:n}
% \begin{macrocode}
-\cs_new:Npn \@@_error_if_group_not_defined:n #1
+\prg_new_conditional:Npnn \@@_error_if_group_not_defined:n #1 { F }
{
- \seq_if_exist:cF { l_@@_group_ #1 _seq }
- { \msg_error:nn { cooking-units} { group-key-unknown } }
+ \seq_if_exist:cTF { l_@@_group_ #1 _seq }
+ { \prg_return_false: }
+ {
+ \msg_error:nn { cooking-units} { group-key-unknown }
+ \prg_return_true:
+ }
}
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_unit_group_convert_units:nn}
+% Didn't feel like intending the groups, as such use |\use_none:nnnnn(nnn)|.
+% (Always wanted to use those |\use_none:|)
% \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}
- \seq_if_in:cnTF { l_@@_group_ #1 _seq } {#2}
+ \@@_error_if_group_not_defined:nF {#1}
{
- \seq_map_inline:cn { l_@@_group_ #1 _seq }
- { \@@_keys_set:nnn { cooking-units } {##1} {#2} }
- }{
- \msg_error:nnxxx
- { cooking-units }
- { group-choice-not-allowed }
- {#1}
- {#2}
- { \seq_use:cnnn { l_@@_group_ #1 _seq } { ',~ ' } { ',~ ' } { ' ~ and ~ ' } }
+ \@@_error_if_unit_not_defined:nF {#2}
+ {
+ \seq_if_in:cnTF { l_@@_group_ #1 _seq } {#2}
+ {
+ \seq_map_inline:cn { l_@@_group_ #1 _seq }
+ { \@@_keys_set:nnn { cooking-units } {##1} {#2} }
+ }{
+ \msg_error:nnxxx
+ { cooking-units }
+ { group-choice-not-allowed }
+ {#1} {#2}
+ { \@@_seq_use_msg:c { l_@@_group_ #1 _seq } }
+ }
+ }
}
}
-\@@_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}
- \seq_if_in:cnF { l_@@_group_ #1 _seq } {##1}
- { \seq_put_right:cn { l_@@_group_ #1 _seq } {##1} }
- }
- }
-% \end{macrocode}
-% \end{macro}
%
% \begin{macro}{\@@_convert_to_eV:}
% Still work in progress. Will probably forever be. Changes all
@@ -5116,7 +5596,7 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\seq_new:N \g_@@_natural_units_seq
\prop_new:N \g_@@_convert_to_eV_remember_prop
-\seq_set_from_clist:Nn \g_@@_natural_units_seq
+\seq_gset_from_clist:Nn \g_@@_natural_units_seq
{
eV ,
eVc-2 ,
@@ -5125,32 +5605,31 @@ and the derived file cooking-units.sty.
(chbareV-1)3 ,
}
\cs_new:Npn \@@_keys_set:nnn #1#2#3
- {
- \keys_set:nn {#1} { #2 = #3 }
- }
+ { \keys_set:nn {#1} { #2 = #3 } }
\cs_generate_variant:Nn \@@_keys_set:nnn { nVV , nVn }
\cs_new:Npn \@@_convert_to_eV:
{
- \prop_if_exist:cT { l_@@_cukeys_ \l_@@_given_unit_tl _prop }
+ \tl_set_eq:Nc \l_@@_tmp_unit_tl { l_@@_base_key_unit_ \l_@@_original_unit_tl _tl }
+ \tl_if_empty:NF \l_@@_tmp_unit_tl
{
\prop_get:NVNTF \g_@@_convert_to_eV_remember_prop
- \l_@@_given_unit_tl \l_@@_tmpa_tl
+ \l_@@_original_unit_tl \l_@@_tmpa_tl
+ { \@@_keys_set:nVV { cooking-units } \l_@@_original_unit_tl \l_@@_tmpa_tl }
{
- \@@_keys_set:nVV { cooking-units } \l_@@_given_unit_tl \l_@@_tmpa_tl
- }{
- \prop_get:cnNT { l_@@_cukeys_ \l_@@_given_unit_tl _prop } { Liste } \l_@@_tmpa_seq
+ \prop_get:cnNTF { l_@@_cukeys_ \l_@@_tmp_unit_tl _prop } { Liste } \l_@@_tmpa_seq
{
\seq_map_inline:Nn \g_@@_natural_units_seq
{
\seq_if_in:NnT \l_@@_tmpa_seq {##1}
{
\prop_gput:NVn \g_@@_convert_to_eV_remember_prop
- \l_@@_given_unit_tl {##1}
- \@@_keys_set:nVn { cooking-units } \l_@@_given_unit_tl {##1}
+ \l_@@_original_unit_tl {##1}
+ \@@_keys_set:nVn { cooking-units } \l_@@_original_unit_tl {##1}
\seq_map_break:
}
}
- }
+ }
+ { \msg_error:nnn { cooking-units } { internal-error } { convert-to-eV } }
}
}
}
@@ -5172,8 +5651,9 @@ and the derived file cooking-units.sty.
%
% \begin{macro}{ }
% I am using this construction often enough, so \dots\ yeah.
+% Note that if the evaluation is |true|, the path taken is the |false| one.
% \begin{macrocode}
-\prg_new_conditional:Npnn \@@_change_unit: { TF }
+\prg_new_conditional:Npnn \@@_change_unit: { TF , T }
{
\bool_lazy_any:nTF
{
@@ -5201,32 +5681,22 @@ and the derived file cooking-units.sty.
}
\cs_new:Npn \@@_temperatures_to_check_define:nn #1#2
{
- \@@_error_if_unit_not_defined:n {#1}
- \fp_if_exist:cTF { c_@@_ #1 _min_fp }
- { \msg_warning:nnn { cooking-units } { Minimum-already-defined } {#1} }
+ \@@_error_if_unit_not_defined:nF {#1}
{
- \seq_put_right:Nn \l_@@_temperatures_to_check_seq {#1}
- \fp_const:cn { c_@@_ #1 _min_fp } {#2}
+ \fp_if_exist:cTF { l_@@_ #1 _min_fp }
+ {
+% \msg_warning:nnn { cooking-units } { Minimum-already-defined } {#1}
+ \fp_set:cn { l_@@_ #1 _min_fp } {#2}
+ }{
+ \seq_put_right:Nn \l_@@_temperatures_to_check_seq {#1}
+ \fp_new:c { l_@@_ #1 _min_fp }
+ \fp_set:cn { l_@@_ #1 _min_fp } {#2}
+ }
}
}
% \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
@@ -5235,10 +5705,7 @@ and the derived file cooking-units.sty.
\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}
- }
+ { \cusetoptionfor {#1} {#2} }
% \end{macrocode}
% \end{macro}
%
@@ -5250,10 +5717,7 @@ and the derived file cooking-units.sty.
\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}
- }
+ { \cuaddoptionfor {#1} {#2} }
% \end{macrocode}
% \end{macro}
%
@@ -5263,9 +5727,7 @@ and the derived file cooking-units.sty.
\cs_new:Npn \@@_rounding_function:n #1
{
#1
- \bool_if:NTF \l_@@_round_to_int_bool
- { , 0 }
- { , \l_@@_round_precision_int }
+ , \l_@@_round_precision_int
\bool_if:NT \l_@@_round_commercial_bool
{ , #1 }
}
@@ -5351,32 +5813,27 @@ and the derived file cooking-units.sty.
%
%
%
-% \begin{macro}{ \@@_tl_if_in_remove_and_set_bool:NnN }
+% \begin{macro}{ \@@_bool_reverse:N, \@@_check_minus_remove_and_reverse:NN }
% Can probably optimize this as the sign is always at the first place
-% (this is done after cheking the input, so the asumption is safe), but yeah \dots
+% (this is done after cheking the input, so the assumption is safe), but yeah \dots
% \begin{macrocode}
-\cs_new:Npn \@@_tl_if_in_remove_and_set_bool:NnN #1#2#3
+\cs_new:Npn \@@_bool_reverse:N #1
{
- \tl_if_in:NnTF #1 {#2}
- {
- \bool_set_true:N #3
- \tl_remove_once:Nn #1 {#2}
- }
- { \bool_set_false:N #3 }
+ \bool_if:NTF #1
+ { \bool_set_false:N }
+ { \bool_set_true:N }
+ #1
}
-% \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
+\cs_new:Npn \@@_check_minus_remove_and_reverse:NN #1#2
{
- \tl_if_in:NnT #1 {#2}
+ \quark_if_nil:NF #2
{
- \bool_if:NTF #3
- { \bool_set_false:N #3 }
- { \bool_set_true:N #3 }
- \tl_remove_once:Nn #1 {#2}
+ \tl_if_in:NnT #2 { - }
+ {
+ \tl_remove_once:Nn #2 { - }
+ \@@_bool_reverse:N #1
+ }
+ \@@_check_minus_remove_and_reverse:NN #1
}
}
% \end{macrocode}
@@ -5395,8 +5852,8 @@ and the derived file cooking-units.sty.
\tl_const:Nn \c_@@_postfix_phrase_tl { ( cu-unitphrase ) }
% \end{macrocode}
%
-% \begin{macro}{ \@@_deftranslation:nn }
-% \begin{macro}{ \@@_deftranslation:xxn , \@@_deftranslation:Vnv}
+% \begin{macro}{\@@_deftranslation_base:nnn, \@@_deftranslation_base:xVn }
+% \begin{macro}{\@@_deftranslation_to:nnnn , \@@_deftranslation_to:VxVv,\@@_deftranslation_to:VxVV,\@@_deftranslation_to:VxVn}
% \begin{macrocode}
\cs_new:Npn \@@_deftranslation_base:nnn #1#2#3
{
@@ -5406,8 +5863,8 @@ and the derived file cooking-units.sty.
{
\declaretranslation {#1} { #2 #3 } {#4}
}
-\cs_generate_variant:Nn \@@_deftranslation_base:nnn { xx , xxV }
-\cs_generate_variant:Nn \@@_deftranslation_to:nnnn { Vxxv, VxxV , Vxxn, Vxxx,Vxxo,Vxxf }
+\cs_generate_variant:Nn \@@_deftranslation_base:nnn { xV }
+\cs_generate_variant:Nn \@@_deftranslation_to:nnnn { VxVv, VxVV , VxVn }
% \end{macrocode}
% \end{macro}
% \end{macro}
@@ -5547,13 +6004,18 @@ and the derived file cooking-units.sty.
% \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
+ \@@_set_unit:Nn \l_@@_original_unit_tl {#1}
\bool_set_false:N \l_@@_error_bool
+ \@@_error_if_unit_not_defined:VTF \l_@@_original_unit_tl
+ {
+ \bool_set_true:N \l_@@_unit_error_bool
+ \cs_set_eq:NN \@@_print_correct_unit: \@@_print_default_unit:
+ }
+ { \bool_set_false:N \l_@@_unit_error_bool }
+ \bool_set_false:N \l_@@_special_sign_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
+ \bool_set_false:N \l_@@_minus_bool
}
% \end{macrocode}
% Some units have options added to them. To get those options it is first
@@ -5569,8 +6031,8 @@ and the derived file cooking-units.sty.
{ \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 }
+ \prop_get:NVNF \l_@@_change_unit_prop \l_@@_original_unit_tl \l_@@_option_unit_tl
+ { \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_original_unit_tl }
}
% \end{macrocode}
% \begin{macrocode}
@@ -5578,12 +6040,12 @@ and the derived file cooking-units.sty.
{
\IfNoValueF {#1}
{ \@@_reference_label_and_persons:n {#1} }
- \clist_if_empty:cF { l_@@_predefined_option_ \l_@@_option_unit_tl _clist }
+ \clist_if_empty:cF { l_@@_unit_option_ \l_@@_option_unit_tl _clist }
{
\keys_set_filter:nnv
{ cooking-units }
{ change-unit }
- { l_@@_predefined_option_ \l_@@_option_unit_tl _clist }
+ { l_@@_unit_option_ \l_@@_option_unit_tl _clist }
}
\tl_if_empty:nF {#2}
{ \keys_set_filter:nnn { cooking-units } { change-unit } {#2} }
@@ -5591,10 +6053,7 @@ and the derived file cooking-units.sty.
{ \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 }
+ \bool_set_eq:NN \l_@@_lokal_numeral_bool \l_@@_print_numeral_bool
}
% \end{macrocode}
% \end{macro}
@@ -5604,7 +6063,7 @@ and the derived file cooking-units.sty.
% \@@_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
+% is set to \cs{l_@@_original_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 { }
@@ -5670,20 +6129,28 @@ and the derived file cooking-units.sty.
% \end{macro}
%
%
-% \begin{macro}{ \@@_print_fractions:nnn }
+% \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.
+% The minus sign is always put in front of the fraction.
+%
+% The first argument regards the mixed fraction part. It is either empty
+% or not empty. If empty, do nothing. Else insert and add space.
+%
+% The 2nd and 3rd argument are the nominator and denominator, they are
+% used in the fraction command directly.
+%
+% All three arguments are currently tl varables, but only the first is a dedicated
+% \enquote{can only take one token}.
%
% Since v.1.10(alpha) it also prints the minus sign (hopefully correct).
% \begin{macrocode}
-\cs_new:Npn \@@_print_fractions:nnn #1#2#3
+\cs_new:Npn \@@_print_fractions:Nnn #1#2#3
{
\bool_if:NT \l_@@_minus_bool { \c_@@_minus_tl }
- \tl_if_empty:nF {#1}
+ \tl_if_empty:NF #1
{
#1
- \@@_dim_horizontal:N \l_@@_mixed_frac_dim
+ \skip_horizontal:N \l_@@_mixed_frac_dim
}
\@@_frac:nn {#2} {#3}
}
@@ -5723,22 +6190,47 @@ and the derived file cooking-units.sty.
\cs_new:Npn \@@_create_error:n #1
{
\bool_set_true:N \l_@@_error_bool
- \msg_error:nnV { cooking-units } {#1} \l_@@_given_amount_tl
+ \msg_error:nnV { cooking-units } {#1} \l_@@_original_amount_tl
}
\cs_new:Npn \@@_create_error_and_stop:n #1
{
\bool_set_true:N \l_@@_error_bool
- \msg_error:nnV { cooking-units } {#1} \l_@@_given_amount_tl
+ \msg_error:nnV { cooking-units } {#1} \l_@@_original_amount_tl
\use_none_delimit_by_q_nil:w
}
\cs_new:Npn \@@_create_error:nn #1#2
{
\bool_set_true:N \l_@@_error_bool
- \msg_error:nnnV { cooking-units } {#1} {#2} \l_@@_given_amount_tl
+ \msg_error:nnnV { cooking-units } {#1} {#2} \l_@@_original_amount_tl
}
% \end{macrocode}
% \end{macro}
%
+% The following command is needed after the parsing. It further processes
+% the parsed input and prints. The actual parsing and printing process (|\@@_process_tmp|)
+% depends on the command (|\cunum|, etc.) used.
+% \begin{macrocode}
+\cs_new:Npn \@@_process_tmp: { }
+\cs_new:Npn \@@_process_and_print_input:
+ {
+ \bool_lazy_or:nnTF
+ { \l_@@_error_bool }
+ { \l_@@_unit_error_bool }
+ { \l_@@_original_amount_tl }
+ { \@@_process_tmp: }
+ }
+% \end{macrocode}
+% If there is an error or there is a special case (like \opt{42=true}) these commands
+% are used.
+% \begin{macrocode}
+\cs_new:Npn \@@_process_default: { \l_@@_original_amount_tl }
+\cs_new:Npn \@@_print_default_unit:
+ {
+ \tl_if_empty:NF \l_@@_phantom_tl { \phantom { \l_@@_phantom_tl } }
+ \,\l_@@_original_unit_tl
+ }
+% \end{macrocode}
+%
% \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).
@@ -5747,26 +6239,27 @@ and the derived file cooking-units.sty.
% \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_@@_given_amount_tl
+ \@@_set_amount:Nn \l_@@_original_amount_tl {#1}
+ \tl_set_rescan:NnV \l_@@_original_amount_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_@@_given_amount_tl }
+ } \l_@@_original_amount_tl
+ \bool_lazy_any:nTF
{
- \bool_if:NTF \l_@@_fourty_two_bool
- { 42 }
- { \l_@@_given_amount_tl }
+ { \l_@@_fourty_two_bool }
+ { \l_@@_draft_bool }
+ { \tl_if_empty_p:N \l_@@_original_amount_tl }
}{
- \tl_set_eq:NN \l_@@_tmpa_tl \l_@@_given_amount_tl
+ \cs_set_eq:NN \@@_process_tmp: \@@_process_default:
+ \tl_if_empty:NT \l_@@_original_amount_tl
+ { \msg_error:nnV { cooking-units } { empty-amount } \l_@@_original_amount_tl }
+ \bool_if:NT \l_@@_fourty_two_bool
+ { \tl_set:Nn \l_@@_original_amount_tl { 42 } }
+ }{
+ \tl_set_eq:NN \l_@@_tmpa_tl \l_@@_original_amount_tl
\@@_split_input:N \l_@@_tmpa_tl
- \@@_process_and_print_input:
}
}
% \end{macrocode}
@@ -5789,27 +6282,10 @@ and the derived file cooking-units.sty.
\bool_if:NT \l_@@_range_in_input_bool
{ \@@_create_error_and_stop:n { fraction-not-allowed-with-range } }
}
- \tl_if_in:NnT #1 { _ }
- {
- \bool_set_true:N \l_@@_lokal_mixed_fraction_bool
- \bool_if:NF \l_@@_lokal_fraction_bool
- { \@@_create_error_and_stop:n { missing-slash } }
- }
\@@_split:N #1
\use_none_delimit_by_q_nil:w \q_nil
}
% \end{macrocode}
-% If an error was raised during parsing, just print the input. Else, go to the next set
-% of commands.
-% \begin{macrocode}
-\cs_new:Npn \@@_process_tmp: { }
-\cs_new:Npn \@@_process_and_print_input:
- {
- \bool_if:NTF \l_@@_error_bool
- { \l_@@_given_amount_tl }
- { \@@_process_tmp: }
- }
-% \end{macrocode}
% \end{macro}
%
% \begin{macro}{ \@@_split_input:}
@@ -5850,19 +6326,34 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\cs_new:Npn \@@_split_fraction:n #1
{
- \bool_if:NTF \l_@@_lokal_mixed_fraction_bool
- {
- \cs_set_eq:NN \@@_process_tmp: \@@_process_mixed_fraction_in_input:
- \@@_split_fraction_mixed:ww
- }{
- \cs_set_eq:NN \@@_process_tmp: \@@_process_fraction_in_input:
- \@@_split_fraction_frac:ww
- }
- #1 \q_stop / \q_recursion_tail \q_stop
- \q_recursion_stop
+ \cs_set_eq:NN \@@_process_tmp: \@@_process_generel_fraction_in_input:
+ \@@_split_fraction_mixed:ww
+ #1 \q_stop / \q_recursion_tail _ \q_nil \q_stop
+ \q_recursion_stop
+% \end{macrocode}
+% At this point we have all information we need to determine whatever or not
+% the fractions should be evaluated or if the units should be changed.
+% \begin{macrocode}
\bool_lazy_or:nnT
{ \l_@@_lokal_persons_bool }{ \l_@@_eval_fractions_bool }
{ \bool_set_false:N \l_@@_lokal_fraction_bool }
+ \bool_if:NT \l_@@_convert_fractions_bool
+ {
+ \tl_if_eq:NNF \l_@@_original_unit_tl \l_@@_option_unit_tl
+ { \bool_set_false:N \l_@@_lokal_fraction_bool }
+ }
+ }
+%
+\cs_new:Npn \@@_split_fraction_mixed:ww #1 _ #2 \q_stop
+ {
+ \quark_if_nil:nTF {#2}
+ {
+ \tl_clear:N \l_@@_mixed_fraction_tl
+ \@@_split_fraction_frac:ww #1 \q_stop
+ }{
+ \@@_parse_input_and_safe_in:nN {#1} \l_@@_mixed_fraction_tl
+ \@@_split_fraction_frac:ww #2 \q_stop
+ }
}
\cs_new:Npn \@@_split_fraction_frac:ww #1 / #2 \q_stop
{
@@ -5872,11 +6363,6 @@ and the derived file cooking-units.sty.
\@@_parse_input_and_safe_in:nN {#2} \l_@@_number_tmpb_tl
\use_none_delimit_by_q_recursion_stop:w
}
-\cs_new:Npn \@@_split_fraction_mixed:ww #1 _ #2 \q_stop
- {
- \@@_parse_input_and_safe_in:nN {#1} \l_@@_mixed_fraction_tl
- \@@_split_fraction_frac:ww #2 \q_stop
- }
% \end{macrocode}
% \begin{macrocode}
\cs_generate_variant:Nn \@@_split_number:n { V }
@@ -5897,7 +6383,7 @@ and the derived file cooking-units.sty.
\cs_set_eq:NN \@@_parse:N \@@_start_loop:N
\tl_map_function:nN {#1} \@@_parse:N
\bool_if:NTF \l_@@_error_bool
- { \use_none_delimit_by_q_nil:w }
+ { }
{ \tl_set_eq:NN #2 \l_@@_tmpa_tl }
}
% \end{macrocode}
@@ -5967,7 +6453,11 @@ and the derived file cooking-units.sty.
{ \@@_create_error:n { Second-fraction-sign-not-allowed } }
{
\tl_if_in:NnTF \l_@@_input_mixed_fraction_sign_tl {#1}
- { \@@_create_error:n { Second-mixed-fraction-sign-not-allowed } }
+ {
+ \bool_if:NTF \l_@@_lokal_fraction_bool
+ { \@@_create_error:n { Second-mixed-fraction-sign-not-allowed } }
+ { \@@_create_error:n { missing-slash } }
+ }
{ \@@_create_error:nn { Token-not-allowed } {#1} }
}
}
@@ -6023,82 +6513,68 @@ and the derived file cooking-units.sty.
% \end{macrocode}
% \end{macro}
%
-% \begin{macro}{ \@@_process_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|\@@_print_fractions:nnn| indicates a
-% \enquote{normal} fraction.
-% \begin{macrocode}
-\cs_new:Npn \@@_process_fraction_in_input:
- {
- \bool_lazy_or:nnTF
- { \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
- \@@_print_fractions:nnn
- { }
- { \l_@@_number_tmpa_tl }
- { \l_@@_number_tmpb_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
- }
- }
-% \end{macrocode}
-% \end{macro}
+% \begin{macro}{ \@@_process_generel_fraction_in_input: }
+% This function prints both mixed and normal fractions. Those was done
+% by two functions beforehand, but they shared mostly the same code, so I
+% managed to fuse them.
%
-% \begin{macro}{ \@@_process_mixed_fraction_in_input: }
-% The same procedure as last function? The same procedure as every
-% function!
-%
-% If it should be evaluated it is important to check if the mixed-fraction
-% part is positive or negative. That's why the minuses are removed \emph{before}
-% checking if there is a fraction (in opposite to the command before).
+% The first part removes the minus sign. It cycles through the variables
+% (|\l_@@_mixed_fraction_tl| can be emtpy) and removes the minus signs.
+% It furthermore saves how many minuses are used by reversing a bool.
+% If a minus sign is found, the bool is reversed to true (from false). Another
+% minus: minus and minus is plus, reverse bool again (to false this time), etc.
+%
+% Afterwards: Is a fraciton printed, or is the input evaluated. Printing is
+% straight forward.
%
+% Due to how mixed fractions are evaluated, one can just evaluate the
+% absolute values of the inputs and add a minus sign on the left side afterwards
+% (if necessary).
% \begin{align}
% \cuam{1_2/3} &= 1 + 2/3 \\
-% \cuam{-1_2/3} &= -1 - 2/3
+% \cuam{-1_2/3} &= -1 - 2/3 = - ( 1 + 2/3 )
% \end{align}
-%
+%
+% If |\l_@@_mixed_fraction_tl| is empty the calculation just evaluates to
+% |+\l_@@_number_tmpa_tl / \l_@@_number_tmpb_tl|, which is also valid.
+%
% \begin{macrocode}
-\cs_new:Npn \@@_process_mixed_fraction_in_input:
+\cs_new:Npn \@@_process_generel_fraction_in_input:
{
- \@@_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
+ \@@_check_minus_remove_and_reverse:NN
+ \l_@@_mixed_fraction_tl
+ \l_@@_number_tmpa_tl
+ \l_@@_number_tmpb_tl
+ \q_nil
\bool_lazy_or:nnTF
{ \l_@@_lokal_fraction_bool }
{ \l_@@_special_sign_bool }
{
- \@@_print_fractions:nnn
- { \l_@@_mixed_fraction_tl }
+ \bool_if:NT \l_@@_special_sign_bool
+ {
+ \msg_warning:nnV { cooking-units } { amount-not-known } \l_@@_original_amount_tl
+ }
+ \@@_print_fractions:Nnn
+ \l_@@_mixed_fraction_tl
{ \l_@@_number_tmpa_tl }
- { \l_@@_number_tmpb_tl }
+ { \l_@@_number_tmpb_tl }
}{
\fp_compare:nNnT { \l_@@_number_tmpb_tl } = { 0 }
- { \msg_error:nnV { cooking-units } { Division-by-zero } \l_@@_given_amount_tl }
+ { \msg_error:nnV { cooking-units } { Division-by-zero } \l_@@_original_amount_tl }
\@@_tl_eval:Nn \l_@@_number_tmpa_tl
{
- \bool_if:NTF \l_@@_minus_bool
- { - \l_@@_mixed_fraction_tl - }
- { \l_@@_mixed_fraction_tl + }
+ \l_@@_mixed_fraction_tl +
\l_@@_number_tmpa_tl / \l_@@_number_tmpb_tl
}
+ \bool_if:NT \l_@@_minus_bool
+ { \tl_put_left:Nn \l_@@_number_tmpa_tl { - } }
\@@_process_and_print_number_in_input:N \l_@@_number_tmpa_tl
}
}
% \end{macrocode}
% \end{macro}
%
-%
+%
%
%
%
@@ -6145,12 +6621,12 @@ 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_@@_unit_change_ \l_@@_given_unit_tl _tl } { \l_@@_tmpa_fp }
+ \tl_if_in:cnTF { l_@@_unit_change_ \l_@@_original_unit_tl _tl } { \l_@@_tmpa_fp }
{
- \@@_tl_eval:Nv #2 { l_@@_unit_change_ \l_@@_given_unit_tl _tl }
+ \@@_tl_eval:Nv #2 { l_@@_unit_change_ \l_@@_original_unit_tl _tl }
}{
\@@_tl_eval:Nn #2
- { \l_@@_tmpa_fp * \tl_use:c { l_@@_unit_change_ \l_@@_given_unit_tl _tl } }
+ { \l_@@_tmpa_fp * \tl_use:c { l_@@_unit_change_ \l_@@_original_unit_tl _tl } }
}
}
% \end{macrocode}
@@ -6170,10 +6646,7 @@ and the derived file cooking-units.sty.
=
{ \l_@@_local_number_of_persons_int }
{
-% \@@_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_@@_given_unit_tl
+ \tl_set_eq:NN \l_@@_tmpb_tl \l_@@_original_unit_tl
\seq_if_in:NVTF \l_@@_curef_do_not_change_seq \l_@@_tmpb_tl
{ \msg_error:nnV { cooking-units } { curef-forbidden-unit } \l_@@_tmpb_tl }
{ \@@_calc_references_aux:NN #1 #2 }
@@ -6215,18 +6688,12 @@ and the derived file cooking-units.sty.
{
\quark_if_recursion_tail_stop_do:nn {#2}
{
- \bool_lazy_or:nnF
- { \l_@@_round_precision_positive_bool }
- { \l_@@_round_to_int_bool }
+ \bool_if:NT \l_@@_round_precision_negative_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 }
- }
+ { \l_@@_round_precision_int }
{ \bool_set_true:N \l_@@_round_number_bool }
\use_none_delimit_by_q_recursion_stop:w
}
@@ -6246,12 +6713,6 @@ and the derived file cooking-units.sty.
\bool_if:NTF \l_@@_round_number_bool
{ \@@_tl_eval:Nn #1 { round ( \@@_rounding_function:n {#2} ) } }
{ \tl_set:Nn #1 {#2} }
-% \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}
@@ -6277,13 +6738,13 @@ and the derived file cooking-units.sty.
\seq_if_in:NVT \l_@@_temperatures_to_check_seq \l_@@_option_unit_tl
{
\fp_compare:vNnT
- { c_@@_ \l_@@_option_unit_tl _min_fp } > {#1}
+ { l_@@_ \l_@@_option_unit_tl _min_fp } > {#1}
{
\msg_error:nnxx { cooking-units }
{ Temperature-too-low }
{ #1 \space \l_@@_option_unit_tl }
{
- \fp_use:c { c_@@_ \l_@@_option_unit_tl _min_fp }
+ \fp_use:c { l_@@_ \l_@@_option_unit_tl _min_fp }
\space \l_@@_option_unit_tl
}
}
@@ -6360,6 +6821,7 @@ and the derived file cooking-units.sty.
\@@_cunum_initialise:nnnnn {#1} {#2} {#3} {#4} {#5}
\l_@@_cunum_hook_tl
\@@_parse_input:n {#3}
+ \@@_process_and_print_input:
\@@_print_correct_unit:
}
% \end{macrocode}
@@ -6404,7 +6866,7 @@ and the derived file cooking-units.sty.
\tl_use:N \l_@@_value_unit_space_tl
\@@_change_unit:TF
{ \@@_translate:VV \l_@@_option_unit_tl \c_@@_postfix_unit_tl }
- { \@@_translate:VV \l_@@_given_unit_tl \c_@@_postfix_unit_tl }
+ { \@@_translate:VV \l_@@_original_unit_tl \c_@@_postfix_unit_tl }
}
% \end{macrocode}
% \end{macro}
@@ -6459,14 +6921,14 @@ and the derived file cooking-units.sty.
\@@_initialise_default:n {#3}
\@@_initialise_unit_change:n {#2}
\bool_if:NT \l_@@_cutext_keep_unit_bool
- { \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_given_unit_tl }
+ { \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_original_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}
%
-% #1: label, #2: Options, #3: Values, #4: unit
+%^^A #1: label, #2: Options, #3: Values, #4: unit
% \begin{macrocode}
\cs_new:Npn \@@_cutext:nnnn #1#2#3#4
{
@@ -6476,7 +6938,10 @@ and the derived file cooking-units.sty.
{ \l_@@_cutext_hook_tl }
\bool_if:NTF \l_@@_cutext_old_bool
{ \@@_old_cutext:nnn {#2} {#3} {#4} }
- { \@@_parse_input:n {#3} }
+ {
+ \@@_parse_input:n {#3}
+ \@@_process_and_print_input:
+ }
\@@_print_correct_unit:
}
% \end{macrocode}
@@ -6514,7 +6979,7 @@ and the derived file cooking-units.sty.
{
\@@_change_unit:TF
{ \@@_cutext_print_input:NV #1 \l_@@_option_unit_tl }
- { \@@_cutext_print_input:NV #1 \l_@@_given_unit_tl }
+ { \@@_cutext_print_input:NV #1 \l_@@_original_unit_tl }
}
% \end{macrocode}
% \end{macro}
@@ -6529,7 +6994,7 @@ and the derived file cooking-units.sty.
{ \@@_translate:VV \l_@@_option_unit_tl \c_@@_postfix_unitname_tl }
{ \@@_translate:VV \l_@@_option_unit_tl \c_@@_postfix_unitname_pl_tl }
}
- { \@@_translate:VV \l_@@_given_unit_tl \c_@@_postfix_unitname_pl_tl }
+ { \@@_translate:VV \l_@@_original_unit_tl \c_@@_postfix_unitname_pl_tl }
}
% \end{macrocode}
%
@@ -6538,7 +7003,7 @@ and the derived file cooking-units.sty.
{
\@@_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_@@_original_unit_tl }
\@@_unitname_get:NxF \l_@@_tmpa_tl \l_@@_tmpb_tl
{
\msg_warning:nnx
@@ -6584,7 +7049,7 @@ and the derived file cooking-units.sty.
{ \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 }
}
}
{ \bool_set_false:N \l_@@_lokal_numeral_bool }
@@ -6605,7 +7070,7 @@ and the derived file cooking-units.sty.
\tl_const:Nn \c_@@_cuam_marker_tl { @@_cunum }
\tl_new:c { l_@@_unit_change_ \c_@@_cuam_marker_tl _tl }
\tl_set:cn { l_@@_unit_change_ \c_@@_cuam_marker_tl _tl } { 1.0 }
-\clist_new:c { l_@@_predefined_option_ \c_@@_cuam_marker_tl _clist }
+\clist_new:c { l_@@_unit_option_ \c_@@_cuam_marker_tl _clist }
% \end{macrocode}
%
% Replaces and extends \mycs{cufrac}.
@@ -6633,6 +7098,7 @@ and the derived file cooking-units.sty.
{ \@@_cuam_old:n {#3} }
{
\@@_parse_input:n {#3}
+ \@@_process_and_print_input:
\@@_print_correct_unit:
}
}
@@ -6642,7 +7108,7 @@ and the derived file cooking-units.sty.
\cs_new_protected:Npn \@@_cuam_initialise:nn #1#2
{
\@@_set_process_and_print_for_cuam:
- \tl_set_eq:NN \l_@@_given_unit_tl \c_@@_cuam_marker_tl
+ \tl_set_eq:NN \l_@@_original_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}
@@ -6860,17 +7326,22 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\cs_new:Npn \@@_cukeys_define_keys_and_single_keys:nn #1#2
{
- \@@_error_if_unit_not_defined:n {#1}
+ \@@_error_if_unit_not_defined:nTF {#1}
+ { \bool_set_true:N } { \bool_set_false:N }
+ \l_@@_unit_error_bool
\tl_if_blank:nF {#2}
{
+ \prop_gclear:N \g_@@_master_changer_prop
+ \prop_gclear:N \g_@@_convert_to_eV_remember_prop
\seq_clear:N \l_@@_tmpa_seq
\prop_clear:N \l_@@_tmpa_prop
+ \prop_clear_new:c { l_@@_cukeys_ #1 _prop }
\bool_if:NTF \l_@@_single_key_bool
{
\@@_cukeys_parse_and_create_single_key:nn {#1} {#2}
}{
\fp_set:Nn \l_@@_tmpa_fp { 1.0 }
- \tl_set:Nn \l_@@_given_unit_tl {#1}
+ \tl_set:Nn \l_@@_original_unit_tl {#1}
\@@_cukeys_parse_and_create_keys:nn {#1}
{
{#1} { 1.0 } #2
@@ -6890,10 +7361,14 @@ and the derived file cooking-units.sty.
{
\@@_cukeys_parse_input:nn #2
\q_recursion_tail \q_recursion_tail \q_recursion_stop
- \@@_cukeys_create_key_prop:n {#1}
- \clist_set_from_seq:NN \l_@@_tmpa_clist \l_@@_tmpa_seq
- \@@_cukeys_define_keys:V \l_@@_tmpa_clist
+ \bool_if:NF \l_@@_unit_error_bool
+ {
+ \@@_cukeys_create_key_prop:n {#1}
+ \clist_set_from_seq:NN \l_@@_tmpa_clist \l_@@_tmpa_seq
+ \@@_cukeys_define_keys:V \l_@@_tmpa_clist
+ }
}
+\cs_generate_variant:Nn \@@_cukeys_parse_and_create_keys:nn { Vn }
% \end{macrocode}
% \end{macro}
%
@@ -6908,11 +7383,15 @@ and the derived file cooking-units.sty.
\quark_if_recursion_tail_stop:n {#1}
\quark_if_recursion_tail_stop_do:nn {#2}
{ \msg_error:nn { cooking-units } { missing-argument } }
- \@@_error_if_unit_not_defined:n {#1}
- \seq_put_right:Nn \l_@@_tmpa_seq {#1}
- \prop_put:Nnx \l_@@_tmpa_prop {#1} { \fp_eval:n { (#2) / \l_@@_tmpa_fp } }
+ \@@_error_if_unit_not_defined:nF {#1}
+ {
+ \seq_if_in:NnF \l_@@_tmpa_seq {#1}
+ { \seq_put_right:Nn \l_@@_tmpa_seq {#1} }
+ \prop_put:Nnx \l_@@_tmpa_prop {#1} { \fp_eval:n { (#2) * \l_@@_tmpa_fp } }
+ }
\@@_cukeys_parse_input:nn
}
+
% \end{macrocode}
% \end{macro}
%
@@ -6973,27 +7452,13 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\cs_new:Npn \@@_cukeys_create_key_prop:n #1
{
- \prop_clear:N \l_@@_tmpb_prop
- \prop_put:NnV \l_@@_tmpb_prop { Liste } \l_@@_tmpa_seq
- \prop_put:NnV \l_@@_tmpb_prop { prop } \l_@@_tmpa_prop
- \prop_put:NnV \l_@@_tmpb_prop { Erstes Ding } \l_@@_given_unit_tl
+ \prop_set_eq:cN { l_@@_cukeys_ #1 _prop } \l_@@_tmpa_prop
+ \prop_put:cnV { l_@@_cukeys_ #1 _prop } { Liste } \l_@@_tmpa_seq
\seq_map_inline:Nn \l_@@_tmpa_seq
{
- \prop_set_eq:cN { l_@@_cukeys_ ##1 _prop } \l_@@_tmpb_prop
+ \tl_set_eq:cN { l_@@_base_key_unit_ ##1 _tl } \l_@@_original_unit_tl
\tl_set:cn { l_@@_unit_change_ ##1 _tl } { 1.0 }
- \seq_map_inline:Nn \l_@@_tmpa_seq
- {
- \prop_put:cnx { l_@@_cukeys_ ##1 _prop }
- {####1}
- {
- \fp_eval:n
- {
- ( \prop_item:Nn \l_@@_tmpa_prop {####1} ) /
- ( \prop_item:Nn \l_@@_tmpa_prop {##1} )
- }
- }
- }
- }
+ }
}
% \end{macrocode}
% \end{macro}
@@ -7006,43 +7471,78 @@ and the derived file cooking-units.sty.
{
\seq_map_inline:Nn \l_@@_tmpa_seq
{
- \seq_if_in:NnF \l_@@_list_of_defined_keys_seq {##1}
- { \seq_put_right:Nn \l_@@_list_of_defined_keys_seq {##1} }
- \keys_define:nn { cooking-units }
- {
- ##1 .choices:Vn =
- \l_@@_tmpa_clist
- {
- \@@_cukeys_define_keys_and_single_key_aux:n {##1}
- } ,
- ##1 / unknown .code:n=
- {
- \seq_set_split:Nnn \l_tmpa_seq { , } {#1}
- \msg_error:nnxxx
- { cooking-units }
- { key-choice-unknown }
- {##1}
- {####1}
- { \seq_use:Nnnn \l_tmpa_seq { ',~ ' } { ',~ ' } { ' ~ and ~ ' } }
- } ,
- ##1 .default:n = {##1} ,
- ##1 .groups:n = { change-unit }
- }
+ \@@_cukeys_keys_define:nn {##1} {#1}
}
}
+\cs_new:Npn \@@_cukeys_keys_define: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} }
+ \keys_define:nn { cooking-units }
+ {
+ #1 .choices:nn =
+ {#2}
+ {
+ \@@_cukeys_define_keys_and_single_key_aux:n {#1}
+ } ,
+ #1 / unknown .code:n=
+ {
+ \seq_set_split:Nnn \l_tmpa_seq { , } {#2}
+ \msg_error:nnxxx
+ { cooking-units }
+ { key-choice-unknown }
+ {#1}
+ {##1}
+ { \@@_seq_use_msg:N \l_tmpa_seq }
+ } ,
+ #1 .default:n = {#1} ,
+ #1 .groups:n = { change-unit }
+ }
+ }
\cs_generate_variant:Nn \@@_cukeys_define_keys:n { V }
% \end{macrocode}
% \end{macro}
%
% \begin{macro}{\@@_cukeys_define_keys_and_single_key_aux:n}
-%
+%^^A <<
% \begin{macrocode}
+\prg_new_conditional:Npnn \@@_prop_get_master:nnN #1#2#3 { F }
+ {
+ \prop_get:NnNTF \g_@@_master_changer_prop { #1 ~->~ #2 } #3
+ { \prg_return_true: }
+ { \prg_return_false: }
+ }
+\cs_generate_variant:Nn \@@_prop_get_master:nnNF { nVc }
+%
+\cs_new:Npn \@@_prop_gput_master:nnn #1#2#3
+ {
+ \prop_gput:Nnn \g_@@_master_changer_prop { #1 ~->~ #2 } {#3}
+ }
+\cs_generate_variant:Nn \@@_prop_gput_master:nnn { nVV, nVv }
+%
\cs_new:Npn \@@_cukeys_define_keys_and_single_key_aux:n #1
{
- \prop_get:cVc
- { l_@@_cukeys_#1_prop }
- \l_keys_choice_tl
- { l_@@_unit_change_ #1_tl }
+ \@@_prop_get_master:nVcF {#1} \l_keys_choice_tl { l_@@_unit_change_ #1_tl }
+ {
+ \prop_if_exist:cTF { l_@@_cukeys_ #1 _prop }
+ {
+ \prop_get:cVc
+ { l_@@_cukeys_ #1 _prop }
+ \l_keys_choice_tl
+ { l_@@_unit_change_ #1_tl }
+ \@@_prop_gput_master:nVv {#1} \l_keys_choice_tl { l_@@_unit_change_ #1_tl }
+ }{
+ \tl_set_eq:Nc \l_@@_tmpa_tl { l_@@_base_key_unit_ #1 _tl }
+ \prop_set_eq:Nc \l_@@_tmpa_prop { l_@@_cukeys_ \l_@@_tmpa_tl _prop }
+ \@@_tl_eval:Nn \l_@@_tmpb_tl
+ {
+ (\exp_args:NNV\prop_item:Nn \l_@@_tmpa_prop \l_keys_choice_tl) /
+ (\prop_item:Nn \l_@@_tmpa_prop {#1})
+ }
+ \@@_prop_gput_master:nVV {#1} \l_keys_choice_tl \l_@@_tmpb_tl
+ \tl_set:cV { l_@@_unit_change_ #1 _tl } \l_@@_tmpb_tl
+ }
+ }
\prop_put:NnV \l_@@_change_unit_prop {#1} \l_keys_choice_tl
}
% \end{macrocode}
@@ -7058,9 +7558,12 @@ and the derived file cooking-units.sty.
\char_set_catcode_ignore:N\ %
} { {#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
- \@@_cukeys_define_singlekey:nV {#1} \l_@@_tmpa_clist
+ \bool_if:NF \l_@@_unit_error_bool
+ {
+ \@@_cusinglekeys_create_key_prop:n {#1}
+ \clist_set_from_seq:NN \l_@@_tmpa_clist \l_@@_tmpa_seq
+ \@@_cukeys_define_singlekey:nV {#1} \l_@@_tmpa_clist
+ }
}
% \end{macrocode}
%
@@ -7077,11 +7580,14 @@ and the derived file cooking-units.sty.
\quark_if_recursion_tail_stop:n {#1}
\quark_if_recursion_tail_stop_do:nn {#2}
{ \msg_error:nn { cooking-units } { missing-argument } }
- \@@_error_if_unit_not_defined:n {#1}
- \seq_put_right:Nn \l_@@_tmpa_seq {#1}
- \tl_set:Nn \l_@@_tmpa_tl {#2}
- \tl_replace_all:NVn \l_@@_tmpa_tl \c_@@_input_str_hash_one_tl { \l_@@_tmpa_fp }
- \prop_put:NnV \l_@@_tmpa_prop {#1} \l_@@_tmpa_tl
+ \@@_error_if_unit_not_defined:nF {#1}
+ {
+ \seq_if_in:NnF \l_@@_tmpa_seq {#1}
+ { \seq_put_right:Nn \l_@@_tmpa_seq {#1} }
+ \tl_set:Nn \l_@@_tmpa_tl {#2}
+ \tl_replace_all:NVn \l_@@_tmpa_tl \g_@@_input_str_hash_one_tl { \l_@@_tmpa_fp }
+ \prop_put:NnV \l_@@_tmpa_prop {#1} \l_@@_tmpa_tl
+ }
\@@_cusinglekeys_parse_input_aux:nn
}
% \end{macrocode}
@@ -7090,38 +7596,16 @@ and the derived file cooking-units.sty.
\cs_new:Npn \@@_cusinglekeys_create_key_prop:n #1
{
\tl_set:cn { l_@@_unit_change_ #1 _tl } { 1.0 }
+ \tl_set:cn { l_@@_base_key_unit_ #1 _tl } {#1}
\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
- \prop_put:cnV { l_@@_cukeys_ #1 _prop } { prop } \l_@@_tmpa_prop
}
% \end{macrocode}
%
% \begin{macrocode}
\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} }
- \keys_define:nn { cooking-units }
- {
- #1 .choices:Vn =
- \l_@@_tmpa_clist
- {
- \@@_cukeys_define_keys_and_single_key_aux:n {#1}
- } ,
- #1 / unknown .code:n=
- {
- \seq_set_split:Nnn \l_tmpa_seq { , } {#2}
- \msg_error:nnxxx
- { cooking-units }
- { key-choice-unknown }
- {#1}
- {##1}
- { \seq_use:Nnnn \l_tmpa_seq { ',' } { ',' } { ' ~ and ~ ' } }
- } ,
- #1 .default:n = {#1} ,
- #1 .groups:n = { change-unit } ,
- }
+ \@@_cukeys_keys_define:nn {#1} {#2}
}
\cs_generate_variant:Nn \@@_cukeys_define_singlekey:nn { nV }
% \end{macrocode}
@@ -7129,8 +7613,6 @@ and the derived file cooking-units.sty.
%
% \section {Adding Keys}
%
-% Question to me: Why do we need \cs{l_tmpa(b)_tl}?
-% Maybe due to \cs{cuaddtokeys}?
% \begin{macrocode}
\NewDocumentCommand \cuaddkeys { m m }
{
@@ -7161,28 +7643,39 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\cs_new:Npn \@@_cukeys_add_keys_or_single_keys:nn #1#2
{
- \@@_error_if_unit_not_defined:n {#1}
- \seq_if_in:NnF \l_@@_list_of_defined_keys_seq {#1}
- { \msg_error:nnn { cooking-units } { Key-not-defined } {#1} }
- \tl_if_blank:nF {#2}
+ \@@_error_if_unit_not_defined:nF {#1}
{
- \@@_cukeys_add_keys_and_single_key_aux:n {#1}
- \bool_if:NTF \l_@@_single_key_bool
- { \@@_cukeys_parse_and_create_single_key:nn {#1} {#2} }
- { \@@_cukeys_parse_and_create_keys:nn {#1} {#2} }
+ \seq_if_in:NnF \l_@@_list_of_defined_keys_seq {#1}
+ { \msg_error:nnn { cooking-units } { Key-not-defined } {#1} }
+ \tl_if_blank:nF {#2}
+ {
+ \prop_gclear:N \g_@@_master_changer_prop
+ \@@_cukeys_add_keys_and_single_key_aux:n {#1}
+ \bool_if:NTF \l_@@_single_key_bool
+ { \@@_cukeys_parse_and_create_single_key:nn {#1} {#2} }
+ { \@@_cukeys_parse_and_create_keys:Vn \l_@@_original_unit_tl {#2} }
+ }
}
}
\cs_generate_variant:Nn \@@_cukeys_add_keys_or_single_keys:nn { nV }
% \end{macrocode}
%
-%
+%^^A ((((
+% Now this does the following: 1) get the \enquote{original unit} (the unit used
+% in the first argument of |\cudefinekeys|) 2) Get the list of units already in the
+% list (It is important that the units are alway in the same order and one cannot
+% rely on the order of the property-lists 3) Get the property list of the
+% \enquote{original unit}. In the old code I simply stored the whole property list inside
+% another property list, but this shouldn't be done this way. So \dots\ simply
+% copy the original one. 4) As there is a unit added the unit it is added to
+% might not be the \enquote{original unit}. As such we need the conversion factor.
% \begin{macrocode}
\cs_new:Npn \@@_cukeys_add_keys_and_single_key_aux:n #1
{
- \prop_get:cnN { l_@@_cukeys_ #1 _prop } { Liste } \l_@@_tmpa_seq
- \prop_get:cnN { l_@@_cukeys_ #1 _prop } { prop } \l_@@_tmpa_prop
- \prop_get:cnN { l_@@_cukeys_ #1 _prop } { Erstes Ding } \l_@@_given_unit_tl
- \prop_get:cVN { l_@@_cukeys_ #1 _prop } \l_@@_given_unit_tl \l_@@_tmpa_fp
+ \tl_set_eq:Nc \l_@@_original_unit_tl { l_@@_base_key_unit_ #1 _tl }
+ \prop_set_eq:Nc \l_@@_tmpa_prop { l_@@_cukeys_ \l_@@_original_unit_tl _prop }
+ \prop_get:NnN\l_@@_tmpa_prop { Liste } \l_@@_tmpa_seq
+ \prop_get:NnN \l_@@_tmpa_prop {#1} \l_@@_tmpa_fp
}
% \end{macrocode}
%
@@ -7226,17 +7719,16 @@ and the derived file cooking-units.sty.
\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}
+ \seq_gput_right:Nn \g_@@_list_of_defined_units_seq {#2}
\tl_new:c { l_@@_unit_change_ #2 _tl }
\tl_set:cn { l_@@_unit_change_ #2 _tl } { 1.0 }
- \clist_new:c { l_@@_predefined_option_#2_clist }
+ \clist_new:c { l_@@_unit_option_ #2 _clist }
\keys_define:nn { cooking-units }
{
- set-option-for-#2 .clist_set:c = { l_@@_predefined_option_#2_clist } ,
- add-option-for-#2 .code:n =
- { \clist_put_right:cn { l_@@_predefined_option_#2_clist } {##1} },
+ set-option-for-#2 .code:n = { \cusetoptionfor {#2} {##1} } ,
+ add-option-for-#2 .code:n = { \cuaddoptionfor {#2} {##1} },
}
- \prop_new:c { l_@@_cukeys_ #2 _prop }
+ \tl_new:c { l_@@_base_key_unit_ #2 _tl }
\tl_new:c { l_@@_default_unit_ #2 _tl }
}
}
@@ -7245,19 +7737,186 @@ and the derived file cooking-units.sty.
\IfNoValueTF {#1}
{
\tl_set:cn { l_@@_default_unit_ #2 _tl } {#2}
- \@@_deftranslation_base:xxn {#2} \c_@@_postfix_unit_tl {#2}
+ \@@_deftranslation_base:xVn {#2} \c_@@_postfix_unit_tl {#2}
}{
\tl_set:cn { l_@@_default_unit_ #2 _tl } {#1}
- \@@_deftranslation_base:xxn {#2} \c_@@_postfix_unit_tl {#1}
+ \@@_deftranslation_base:xVn {#2} \c_@@_postfix_unit_tl {#1}
}
- \@@_deftranslation_base:xxn {#2} \c_@@_postfix_unitname_tl { \q_@@_no_translation }
- \@@_deftranslation_base:xxn {#2} \c_@@_postfix_unitname_pl_tl { \q_@@_no_translation }
- \@@_deftranslation_base:xxn {#2} \c_@@_postfix_gender_tl { m }
+ \@@_deftranslation_base:xVn {#2} \c_@@_postfix_unitname_tl { \q_@@_no_translation }
+ \@@_deftranslation_base:xVn {#2} \c_@@_postfix_unitname_pl_tl { \q_@@_no_translation }
+ \@@_deftranslation_base:xVn {#2} \c_@@_postfix_gender_tl { m }
}
% \end{macrocode}
%
%
%
+% \begin{macro}{\declarecookingderivatives}
+% Now this is an experimental command. The idea is simple: Combine units
+% (like meter and second giving meter per second or in any way possible).
+% The first argument contains a list of the units that should be connected, one of every type is enough.
+% Second is the unit-key, containing |#1|, \dots\ |#(number of units in first argument)|.
+% Third is the calculation. The formula for the new unit should be written in here.
+% And last, but not least: The last argument contains the unit-symbol.
+%
+% Now this command simply defines a bunch of units, declaring them makes things easier.
+% \begin{macrocode}
+\NewDocumentCommand \declarecookingderivatives { m m m m }
+ {
+ \@@_declare_cooking_derivative:nnnn {#1} {#2} {#3} {#4}
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% The idea is the following. The relation between the units are given as
+% |(#1)/(#2)| (e.g.). The idea is the following:
+% \begin{enumerate}
+% \item The derivative contains two units.
+% \item The mathematical relationship is given by |(#1)/(#2)|
+% \item Define |\@@_tmp:w| to be |(#1)/(#2)|.
+% \item Parse through all values and store them in a list (e.g. |\l_tmpa_t|) as | {value-1}{value-2} |
+% \item Use |\exp_after:wN \@@_tmp:w \l_tmpa_t | to expand to |\@@_tmp:w {value-1} {value-2} |
+% \item Let |\@@_tmp:w| do its job.
+% \end{enumerate}
+%
+% \begin{macro}{\@@_tl_set_list:Nnn, \@@_tl_set_list:NnV, \@@_tl_set_list:NVV, \@@_tl_set_list_aux:Nnnnnnnnn }
+% The following argument creates the list. I am a bit lazy here and don't quite know how
+% to do it \enquote{correctly}. And I know, there are too many |\q_nil|.
+% \begin{macrocode}
+\cs_new:Npn \@@_tl_set_list:Nnn #1#2#3
+ {
+ \@@_tl_set_list_aux:Nnnnnnnnn #1 {#2} #3
+ \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil \q_nil
+ \q_recursion_stop
+ }
+\cs_generate_variant:Nn \@@_tl_set_list:Nnn { NnV, NVV }
+\cs_new:Npn \@@_tl_set_list_aux:Nnnnnnnnn #1#2#3#4#5#6#7#8#9
+ {
+ \tl_set:Nf #1
+ {
+ \int_case:nn { \l_@@_curr_depth_int }
+ {
+ { 1 } { }
+ { 2 } { {#3} }
+ { 3 } { {#3}{#4} }
+ { 4 } { {#3}{#4}{#5} }
+ { 5 } { {#3}{#4}{#5}{#6} }
+ { 6 } { {#3}{#4}{#5}{#6}{#7} }
+ { 7 } { {#3}{#4}{#5}{#6}{#7}{#8} }
+ { 8 } { {#3}{#4}{#5}{#6}{#7}{#8}{#9} }
+ }
+ {#2}
+ }
+ \use_none_delimit_by_q_recursion_stop:w
+ }
+% \end{macrocode}
+% \end{macro}
+% \begin{macro} { \@@_declare_cooking_derivative:nnnn }
+% This command has the following parts:
+% \begin{enumerate}
+% \item Get list of units in |#1|, count their number and store in |\l_@@_max_depth_int|
+% \item Use |\cs_generate_from_arg_count:NNnn| to create the commands
+% \item Define lists |l_@@_tmp_ 1 ... \l_@@_max_depth_int |, same for prop. I know
+% that there is a better way to do it, but this \emph{is} experimental. In the end, it
+% safes a bit of brain-power for me.
+% \item The main part: Map trough all units in the |l_@@_cukeys_ <unit> _prop| lists.
+% \item Create key-porperty and define keys.
+% \end{enumerate}
+% \begin{macrocode}
+\cs_new:Npn \@@_declare_cooking_derivative:nnnn #1#2#3#4
+ {
+ \prop_gclear:N \g_@@_master_changer_prop
+ \seq_set_from_clist:Nn \l_@@_tmpa_seq {#1}
+ \seq_clear:N \l_@@_number_of_iterations_seq
+ \seq_clear:N \l_@@_derivative_unit_list_seq
+ \seq_clear:N \l_@@_derivative_symbol_list_seq
+ \seq_clear:N \l_@@_derivative_value_list_seq
+ \int_set:Nn \l_@@_max_depth_int { \seq_count:N \l_@@_tmpa_seq }
+ \int_set:Nn \l_@@_curr_depth_int { 1 }
+% \end{macrocode}
+% \begin{macrocode}
+ \cs_generate_from_arg_count:NNnn \@@_tmp_unit_and_symbol_list:w \cs_set:Npn
+ { \l_@@_max_depth_int }
+ {
+ \seq_put_right:Nn \l_@@_derivative_unit_list_seq {#2}
+ \seq_put_right:Nn \l_@@_derivative_symbol_list_seq {#4}
+ }
+ \cs_generate_from_arg_count:NNnn \@@_tmp_value_list:w \cs_set:Npn
+ { \l_@@_max_depth_int }
+ { \seq_put_right:Nx \l_@@_derivative_value_list_seq { \fp_eval:n {#3} } }
+% \end{macrocode}
+% \begin{macrocode}
+ \int_step_inline:nn { \l_@@_max_depth_int }
+ {
+ \tl_set_eq:Nc \l_@@_original_unit_tl
+ { l_@@_base_key_unit_ \seq_item:Nn \l_@@_tmpa_seq {##1} _tl }
+ \prop_set_eq:Nc \l_@@_tmpa_prop { l_@@_cukeys_ \l_@@_original_unit_tl _prop }
+ \prop_get:NnN \l_@@_tmpa_prop { Liste } \l_@@_tmpb_seq
+ \int_set:Nn \l_@@_tmpa_int { \seq_count:N \l_@@_tmpb_seq }
+% \end{macrocode}
+% \begin{macrocode}
+ \seq_put_right:NV \l_@@_number_of_iterations_seq \l_@@_tmpa_int
+ \seq_clear_new:c { l_@@_tmp_ ##1 _seq }
+ \prop_clear_new:c { l_@@_tmp_ ##1 _prop }
+ \seq_set_eq:cN { l_@@_tmp_ ##1 _seq } \l_@@_tmpb_seq
+ \prop_set_eq:cN { l_@@_tmp_ ##1 _prop } \l_@@_tmpa_prop
+ }
+% \end{macrocode}
+% \begin{macrocode}
+ \seq_map_function:cN
+ { l_@@_tmp_ \int_use:N \l_@@_curr_depth_int _seq }
+ \@@_seq_step_function:n
+% \end{macrocode}
+% \begin{macrocode}
+ \seq_get_left:NN \l_@@_derivative_unit_list_seq \l_@@_original_unit_tl
+ \prop_clear_new:c { l_@@_cukeys_ \l_@@_original_unit_tl _prop }
+% \end{macrocode}
+% \begin{macrocode}
+ \int_zero:N \l_@@_tmpa_int
+ \clist_set_from_seq:NN \l_@@_tmpa_clist \l_@@_derivative_unit_list_seq
+ \seq_map_inline:Nn \l_@@_derivative_unit_list_seq
+ {
+ \int_incr:N \l_@@_tmpa_int
+ \tl_set:Nx \l_@@_tmpa_tl { \seq_item:Nn \l_@@_derivative_symbol_list_seq { \l_@@_tmpa_int } }
+ \exp_after:wN \declarecookingunit \exp_after:wN [ \l_@@_tmpa_tl ] {##1}
+ \prop_put:cnx
+ { l_@@_cukeys_ \l_@@_original_unit_tl _prop }
+ {##1}
+ { \seq_item:Nn \l_@@_derivative_value_list_seq { \l_@@_tmpa_int } }
+ \tl_clear_new:c { l_@@_base_key_unit_ ##1 _tl }
+ \tl_set_eq:cN { l_@@_base_key_unit_ ##1 _tl } \l_@@_original_unit_tl
+ \exp_args:NnV \@@_cukeys_keys_define:nn {##1} \l_@@_tmpa_clist
+ }
+ }
+% \end{macrocode}
+% \end{macro}
+%
+% \begin{macrocode}
+\cs_new:Npn \@@_seq_step_function:n #1
+ {
+ \@@_tl_set_list:NnV \l_@@_list_of_units_tl {#1} \l_@@_list_of_units_tl
+ \prop_get:cnN { l_@@_tmp_ \int_use:N \l_@@_curr_depth_int _prop } {#1} \l_@@_tmpa_tl
+ \@@_tl_set_list:NVV \l_@@_list_of_values_tl \l_@@_tmpa_tl \l_@@_list_of_values_tl
+ \int_compare:nNnTF { \l_@@_curr_depth_int } = { \l_@@_max_depth_int }
+ {
+ \exp_after:wN \@@_tmp_unit_and_symbol_list:w \l_@@_list_of_units_tl
+ \exp_after:wN \@@_tmp_value_list:w \l_@@_list_of_values_tl
+ }{
+ \int_incr:N \l_@@_curr_depth_int
+ \seq_map_function:cN
+ { l_@@_tmp_ \int_use:N \l_@@_curr_depth_int _seq }
+ \@@_seq_step_function:n
+ \int_decr:N \l_@@_curr_depth_int
+ }
+ }
+% \end{macrocode}
+%
+%
+%
+%
+%
+%
+%
+%
% \section {Names}
%
% Stolen from \pkg{l3keys.dtx}
@@ -7358,15 +8017,16 @@ and the derived file cooking-units.sty.
\quark_if_recursion_tail_stop:n {#1}
\quark_if_recursion_tail_stop_do:nn {#2}
{ \msg_error:nn { cooking-units } { missing-argument } }
- \@@_error_if_unit_not_defined:n {#1}
+ \@@_error_if_unit_not_defined:nT {#1}
+ { \use_none_delimit_by_q_recursion_stop:w }
\quark_if_no_value:nTF {#2}
{
- \@@_deftranslation_to:Vxxv
+ \@@_deftranslation_to:VxVv
\l_@@_language_tl {#1}
\c_@@_postfix_unit_tl
{ l_@@_default_unit_ #1 _tl }
}{
- \@@_deftranslation_to:Vxxn
+ \@@_deftranslation_to:VxVn
\l_@@_language_tl {#1}
\c_@@_postfix_unit_tl {#2}
}
@@ -7382,8 +8042,11 @@ and the derived file cooking-units.sty.
\quark_if_recursion_tail_stop_do:nn {#2}
{ \msg_error:nn { cooking-units } { missing-argument } }
\seq_if_in:NnF \g_@@_allowed_special_keys_seq {#1}
- { \@@_error_if_unit_not_defined:n {#1} }
- \@@_deftranslation_to:Vxxn
+ {
+ \@@_error_if_unit_not_defined:nT {#1}
+ { \use_none_delimit_by_q_recursion_stop:w }
+ }
+ \@@_deftranslation_to:VxVn
\l_@@_language_tl {#1}
\c_@@_postfix_unitname_tl {#2}
\peek_meaning_ignore_spaces:NTF [
@@ -7397,7 +8060,7 @@ and the derived file cooking-units.sty.
{
\seq_if_in:NnF \g_@@_allowed_special_keys_seq {#1}
{
- \@@_deftranslation_to:Vxxn \l_@@_language_tl {#1}
+ \@@_deftranslation_to:VxVn \l_@@_language_tl {#1}
\c_@@_postfix_unitname_pl_tl {#2}
}
\peek_meaning_ignore_spaces:NTF <
@@ -7409,10 +8072,20 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\cs_new:Npn \@@_cuname_parse_gender:nw #1 <#2>
{
- \@@_check_if_correct_gender_input:n {#2}
- \@@_deftranslation_to:Vxxn
- \l_@@_language_tl {#1}
- \c_@@_postfix_gender_tl {#2}
+% \@@_check_if_correct_gender_input:n {#2}
+% \@@_deftranslation_to:VxVn
+% \l_@@_language_tl {#1}
+% \c_@@_postfix_gender_tl {#2}
+ \@@_if_gender_error:nTF {#2}
+ {
+ \@@_deftranslation_to:VxVn
+ \l_@@_language_tl {#1}
+ \c_@@_postfix_gender_tl { m }
+ }{
+ \@@_deftranslation_to:VxVn
+ \l_@@_language_tl {#1}
+ \c_@@_postfix_gender_tl {#2}
+ }
\@@_cuname_parse_input:n
}
% \end{macrocode}
@@ -7439,13 +8112,15 @@ and the derived file cooking-units.sty.
{ \msg_error:nn { cooking-units } { missing-argument } }
\seq_if_in:NnTF \g_@@_allowed_special_keys_seq {#1}
{
- \@@_deftranslation_to:Vxxn \l_@@_language_tl {#1}
+ \@@_deftranslation_to:VxVn \l_@@_language_tl {#1}
\c_@@_postfix_unitname_tl {#2}
}{
- \@@_error_if_unit_not_defined:n {#1}
- \@@_deftranslation_to:Vxxn
- \l_@@_language_tl {#1}
- \c_@@_postfix_unit_tl {#2}
+ \@@_error_if_unit_not_defined:nF {#1}
+ {
+ \@@_deftranslation_to:VxVn
+ \l_@@_language_tl {#1}
+ \c_@@_postfix_unit_tl {#2}
+ }
}
\@@_cuprint_define_printed_unit:nn
}
@@ -7520,11 +8195,11 @@ and the derived file cooking-units.sty.
}
% \end{macrocode}
% \begin{macrocode}
- \@@_deftranslation_to:VxxV
+ \@@_deftranslation_to:VxVV
\l_@@_language_tl { phrase-prop }
\c_@@_postfix_phrase_tl
\l_@@_phrase_prop
- \@@_deftranslation_to:VxxV
+ \@@_deftranslation_to:VxVV
\l_@@_language_tl { phrase-clist }
\c_@@_postfix_phrase_tl \l_@@_phrase_numbers_seq
}
@@ -7582,10 +8257,16 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\cs_new:Npn \@@_chuphrase_parse_gender:nw #1 <#2>
{
- \@@_check_if_correct_gender_input:n {#2}
- \@@_deftranslation_to:Vxxn
- \l_@@_language_tl { #1-phrase-gender }
- \c_@@_postfix_gender_tl {#2}
+ \@@_if_gender_error:nTF {#2}
+ {
+ \@@_deftranslation_to:VxVn
+ \l_@@_language_tl { #1-phrase-gender }
+ \c_@@_postfix_gender_tl { m }
+ }{
+ \@@_deftranslation_to:VxVn
+ \l_@@_language_tl { #1-phrase-gender }
+ \c_@@_postfix_gender_tl {#2}
+ }
\@@_cuphrase_parse:n
}
% \end{macrocode}
@@ -7599,7 +8280,7 @@ and the derived file cooking-units.sty.
% \begin{macrocode}
\cs_new:Npn \@@_old_cutext:nnn #1#2#3
{
- \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_given_unit_tl
+ \tl_set_eq:NN \l_@@_option_unit_tl \l_@@_original_unit_tl
\@@_old_cutext_default:nnn {#1} {#2} {#3}
}
% \end{macrocode}
@@ -7752,7 +8433,7 @@ and the derived file cooking-units.sty.
\cs_new:Npn \@@_cuam_old_parse_mixed_frac:www #1_#2/#3 \q_stop
{
#1
- \@@_dim_horizontal:N \l_@@_mixed_frac_dim
+ \skip_horizontal:N \l_@@_mixed_frac_dim
\@@_frac:nn {#2} {#3}
}
% \end{macrocode}
@@ -7800,12 +8481,146 @@ and the derived file cooking-units.sty.
\cs_new:Npn \@@_cufrac_parse_mixed_frac:www #1_#2/#3 \q_stop
{
#1
- \@@_dim_horizontal:N \l_@@_mixed_frac_dim
+ \skip_horizontal:N \l_@@_mixed_frac_dim
\@@_frac:nn {#2} {#3}
}
% \end{macrocode}
%
%
+%
+%
+% \begin{macrocode}
+\cs_new:Npn \@@_add_forbidden_unit:n #1
+ {
+ \seq_set_from_clist:Nn \l_@@_tmpa_seq {#1}
+ \seq_map_inline:Nn \l_@@_tmpa_seq
+ {
+ \@@_error_if_unit_not_defined:nF {##1}
+ {
+ \seq_if_in:NnF \l_@@_curef_do_not_change_seq {##1}
+ { \seq_put_right:Nn \l_@@_curef_do_not_change_seq {##1} }
+ }
+ }
+ }
+\cs_new:Npn \@@_remove_forbidden_unit:n #1
+ {
+ \seq_set_from_clist:Nn \l_@@_tmpa_seq {#1}
+ \seq_map_inline:Nn \l_@@_tmpa_seq
+ {
+ \@@_error_if_unit_not_defined:nF {##1}
+ {
+ \seq_if_in:NnTF \l_@@_curef_do_not_change_seq {##1}
+ { \seq_remove_all:Nn \l_@@_curef_do_not_change_seq {##1} }
+ {
+ \msg_warning:nnnn { cooking-units } { curef-not-inside-list } {##1}
+ { \@@_seq_use_msg:N \l_@@_curef_do_not_change_seq }
+ }
+ }
+ }
+ }
+\cs_new:Npn \@@_clear_forbidden_unit:
+ { \seq_clear:N \l_@@_curef_do_not_change_seq }
+% \end{macrocode}
+%
+%
+%
+%
+%
+%
+% \begin{macrocode}
+\NewDocumentCommand \cudeclareunitgroup { m m }
+ {
+ \@@_define_clear_unit_group:nn {#1} {#2}
+ \@@_add_to_unit_group:nn {#1} {#2}
+ }
+\NewDocumentCommand \cuaddtounitgroup { m m }
+ {
+ \@@_add_to_unit_group:nn {#1} {#2}
+ }
+\NewDocumentCommand \cuclearunitgroup { m }
+ {
+ \@@_error_if_group_not_defined:nF {#1}
+ { \@@_define_clear_unit_group:nn {#1} { } }
+ }
+% \end{macrocode}
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+%
+% Works better now.
+% \begin{macrocode}
+\NewDocumentCommand \cusetoptionfor { m m }
+ {
+ \@@_map_trough_valid_unit_options:nnn {#1} {#2}
+ { \clist_set:cn { l_@@_unit_option_ ##1 _clist } {##2} }
+ }
+\NewDocumentCommand \cuaddoptionfor { m m }
+ {
+ \@@_map_trough_valid_unit_options:nnn {#1} {#2}
+ { \clist_put_right:cn { l_@@_unit_option_ ##1 _clist } {##2} }
+ }
+\NewDocumentCommand \cuclearoptionfor { m }
+ {
+ \@@_map_trough_valid_unit_options:nnn {#1} { }
+ { \clist_clear:c { l_@@_unit_option_ ##1 _clist } }
+ }
+% \end{macrocode}
+% The reason I map trough the units twice is simply: I think it makes more
+% sense if an \enquote{unknown unit} error is shown before an
+% \enquote{unknown option} error (at least for me).
+% It is kinda stupid, but this is not really a heavily used function, so \dots\ yeah.
+%
+% Note: I cannot check if |\l_@@_tmpa_clist| is empty because one could
+% use |\cusetoptionfor{F,C,Re,K}{}| to clear the options of the given units.
+% \begin{macrocode}
+\cs_new:Npn \@@_tmp:w { }
+\cs_new:Npn \@@_map_trough_valid_unit_options:nnn #1#2 #3
+ {
+ \seq_clear:N \l_@@_tmpa_seq
+ \clist_clear:N \l_@@_tmpa_clist
+ \cs_set:Npn \@@_tmp:w ##1##2 {#3}
+ \clist_map_inline:nn {#1}
+ {
+ \@@_error_if_unit_not_defined:nF {##1}
+ { \seq_put_right:Nn \l_@@_tmpa_seq {##1} }
+ }
+ \tl_if_empty:nF {#2}
+ { \@@_unit_options_check_validity:n {#2} }
+ \seq_map_inline:Nn \l_@@_tmpa_seq
+ { \exp_args:NnV \@@_tmp:w {##1} \l_@@_tmpa_clist }
+ }
+\cs_new:Npn \@@_unit_options_check_validity:n #1
+ {
+ \keyval_parse:NNn
+ \@@_unit_options_check_validity_aux_i:n
+ \@@_unit_options_check_validity_aux_ii:nn
+ {#1}
+ }
+\cs_new:Npn \@@_unit_options_check_validity_aux_i:n #1
+ {
+ \keys_if_exist:nnTF { cooking-units } {#1}
+ { \clist_put_right:Nn \l_@@_tmpa_clist {#1} }
+ { \msg_error:nnn { cooking-units } { unknown-option } {#1} }
+ }
+\cs_new:Npn \@@_unit_options_check_validity_aux_ii:nn #1#2
+ {
+ \keys_if_exist:nnTF { cooking-units } {#1}
+ { \clist_put_right:Nn \l_@@_tmpa_clist { #1={#2} } }
+ { \msg_error:nnn { cooking-units } { unknown-option } {#1} }
+ }
+% \end{macrocode}
+%
+%
+%
+%
+%
%
%
% \subsection {cusetup}
@@ -7821,6 +8636,9 @@ and the derived file cooking-units.sty.
%
% \subsection{Definitions et all}
%
+% Plase note that at his point we are still inside the Expl3 \enquote{Environment}
+% and that spaces are ignored!
+%
% \begin{macrocode}
\newcookingunit { kg }
\newcookingunit { dag }
@@ -8091,9 +8909,9 @@ and the derived file cooking-units.sty.
{
{ dag }{ 100 }
{ g } { 1000 }
- { oz } { 35.27399 }
- { lb } { 2.2046226 } %% 2.204 622 6
- { stick } { 8.81849 }
+ { lb } { 1/0.45359237 }
+ { oz } { 16/0.45359237 }
+ { stick } { 4/0.45359237 }
{ eVc-2 } { 560958865.0e+27 } %% 560958865.0 +- 3.5 e+27
}
% \end{macrocode}
@@ -8113,7 +8931,7 @@ and the derived file cooking-units.sty.
{ dm } { 10 }
{ cm } { 100 }
{ mm } { 1000 }
- { in } { 39.370079 }
+ { in } { 36/0.9144 }
{ chbareV-1 } { 5067730.759 } %% 5067730.759 +- 0.070
}
%\cuaddtokeys { m } { chbareV-1 } { 1.97326972e-7 }
@@ -8186,12 +9004,15 @@ and the derived file cooking-units.sty.
% \subsection{Finish}
%
% \begin{macrocode}
+\cudeclareunitgroup { weight } { kg , dag, g, oz, lb, stick }
+\cudeclareunitgroup { length } { m , dm , cm , mm , in }
+\cudeclareunitgroup { volume } { l , dl , cl , ml }
+\cudeclareunitgroup { temperature } { C , F , K , Re }
+\cudeclareunitgroup { energy } { cal, kcal , J , kJ , eV }
+\cudeclareunitgroup { time } { d , h , min , s }
+\cusetoptionfor { F , C , K , Re } { round-precision = 0 }
\cusetup
{
- set-option-for-F = { round-to-int = true } ,
- set-option-for-C = { round-to-int = true } ,
- set-option-for-K = { round-to-int = true } ,
- set-option-for-Re = { round-to-int = true } ,
curef-add-forbidden-unit = { F , C , K , Re } ,
add-temperature-to-check =
{
@@ -8223,13 +9044,24 @@ and the derived file cooking-units.sty.
%
% \begin{thebibliography}{}
% \bibitem{Gattopardo}
-% Guiseppe Tomasi di Lampedusa, \enquote{Der Gattopardo},
+% Guiseppe Tomasi di Lampedusa, \emph{Der Gattopardo},
% Piper, Volume~8 (2018), ISBN~978-3-492-24586-9
%
% \bibitem{Sh:3}
-% Sir Arthur Conan Doyle, \enquote{Sherlock Holmes The Complete Novels and Stories Volume~II},
+% Sir Arthur Conan Doyle, \emph{Sherlock Holmes The Complete Novels and Stories Volume~II},
% Bantam Books
-%
+%
+% \bibitem{Nist2008} \emph{Guide for the Use of the International System of Units (SI)},
+% NIST Special Publication 811, 2008 Edition, Ambler Thompson and Barry N. Taylor
+%
+% \bibitem{Nist2006} \emph{The International System of Units (SI) – Conversion Factors
+% for General Use}, NIST Special Publication 1038, May 2006,
+% Kenneth Butcher, Linda Crown and Elizabeth J. Gentry
+%
+% \bibitem{WM1985} \emph{Weights and Measures Act 1985},
+% \url{https://www.legislation.gov.uk/ukpga/1985/72}
+%
+% \bibitem{StickSource} \url{https://cooking.stackexchange.com/questions/784/translating-cooking-terms-between-us-uk-au-ca-nz}
%
% \end{thebibliography}
%
diff --git a/macros/latex/contrib/cooking-units/cooking-units.ins b/macros/latex/contrib/cooking-units/cooking-units.ins
index d023c107e9..e20b719ad6 100644
--- a/macros/latex/contrib/cooking-units/cooking-units.ins
+++ b/macros/latex/contrib/cooking-units/cooking-units.ins
@@ -5,14 +5,14 @@
%% The original source files were:
%%
%% cooking-units.dtx (with options: `install')
-%% Copyright (C) 2016--2018 by Ben Vitecek (current Maintainer)
+%% Copyright (C) 2016--2020 by Ben Vitecek (current Maintainer)
%%
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.3c of this license or (at your option) any later
%% version. The latest version of this license is in:
%%
-%% https://ctan.org/license/lppl1.3c
+%% https://www.latex-project.org/lppl/
%%
%% and version 1.3c or later is part of all distributions of
%% LaTeX version 2008-05-04 or later.
@@ -25,14 +25,14 @@
\input l3docstrip.tex
\askforoverwritefalse
\preamble
-Copyright (C) 2016--2018 by Ben Vitecek (current Maintainer)
+Copyright (C) 2016--2020 by Ben Vitecek (current Maintainer)
This file may be distributed and/or modified under the
conditions of the LaTeX Project Public License, either
version 1.3c of this license or (at your option) any later
version. The latest version of this license is in:
-https://ctan.org/license/lppl1.3c
+ https://www.latex-project.org/lppl/
and version 1.3c or later is part of all distributions of
LaTeX version 2008-05-04 or later.
diff --git a/macros/latex/contrib/cooking-units/cooking-units.pdf b/macros/latex/contrib/cooking-units/cooking-units.pdf
index 948ebcfe7f..ef512cc946 100644
--- a/macros/latex/contrib/cooking-units/cooking-units.pdf
+++ b/macros/latex/contrib/cooking-units/cooking-units.pdf
Binary files differ