summaryrefslogtreecommitdiff
path: root/Master/texmf-dist
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2023-09-26 20:08:36 +0000
committerKarl Berry <karl@freefriends.org>2023-09-26 20:08:36 +0000
commit574f55abeb7ecec548e1acd1e7619d7559a7afa1 (patch)
treef289264a6e0a12ce7a9afd8fd9323e91dff7a8d8 /Master/texmf-dist
parentc1b2f7cc37f5bf1c8704ba4b37df8e0d61a97750 (diff)
non-decimal-units (26sep23)
git-svn-id: svn://tug.org/texlive/trunk@68377 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist')
-rw-r--r--Master/texmf-dist/doc/latex/non-decimal-units/README.md13
-rw-r--r--Master/texmf-dist/doc/latex/non-decimal-units/non-decimal-units.pdfbin0 -> 161903 bytes
-rw-r--r--Master/texmf-dist/doc/latex/non-decimal-units/non-decimal-units.tex584
-rw-r--r--Master/texmf-dist/doc/latex/non-decimal-units/test.pdfbin0 -> 20459 bytes
-rw-r--r--Master/texmf-dist/doc/latex/non-decimal-units/test.tex232
-rw-r--r--Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.british.tex27
-rw-r--r--Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.danish.tex122
-rw-r--r--Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.german.tex21
-rw-r--r--Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.sty598
9 files changed, 1597 insertions, 0 deletions
diff --git a/Master/texmf-dist/doc/latex/non-decimal-units/README.md b/Master/texmf-dist/doc/latex/non-decimal-units/README.md
new file mode 100644
index 00000000000..16bb099f735
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/non-decimal-units/README.md
@@ -0,0 +1,13 @@
+Non-decimal unit macros for LaTeX
+=================================
+
+Macros for displaying and manipulating historical non-decimal units.
+
+See [non-decimal-units.pdf](docs/non-decimal-units.pdf) for the documentation.
+
+Contents last updated 2023-09-26.
+
+<!-- Package available via CTAN at https://www.ctan.org/pkg/non-decimal-units -->
+
+License: CC-BY-SA 4.0
+Author: Mikkel Eide Eriksen <mikkel.eriksen@gmail.com>
diff --git a/Master/texmf-dist/doc/latex/non-decimal-units/non-decimal-units.pdf b/Master/texmf-dist/doc/latex/non-decimal-units/non-decimal-units.pdf
new file mode 100644
index 00000000000..309a4651d8d
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/non-decimal-units/non-decimal-units.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/non-decimal-units/non-decimal-units.tex b/Master/texmf-dist/doc/latex/non-decimal-units/non-decimal-units.tex
new file mode 100644
index 00000000000..06a83532fb0
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/non-decimal-units/non-decimal-units.tex
@@ -0,0 +1,584 @@
+% !TEX TS-program = LuaLaTeX-shell-escape
+\documentclass{article}
+
+\usepackage{non-decimal-units.preamble}
+
+\title{Non-Decimal Units for \LaTeX}
+\author{Mikkel Eide Eriksen\\\href{mailto:mikkel.eriksen@gmail.com}{\texttt{mikkel.eriksen@gmail.com}}}
+
+\nduset{
+ set aligned for environment=tabular,
+ aliases/danish rigsdaler,
+ restrict segment depth=2,
+}
+
+\begin{document}
+
+\maketitle
+
+\section{Preface} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+Many historical unit systems were non-decimal. For example, the Danish rigsdaler\footnote{\url{https://en.wikipedia.org/wiki/Danish_rigsdaler}} --- where 1 \nduName{danish rigsdaler}{0} consists of \nduFactor{danish rigsdaler}{0} \nduName{danish rigsdaler}{1}, each again consisting of \nduFactor{danish rigsdaler}{1} \nduName{danish rigsdaler}{2} for a total of 96 \nduName{danish rigsdaler}{2} or per \nduName{danish rigsdaler}{0} --- was used from 1625 to 1875, when currency was decimalised to the current system of 1 krone = 100 øre.
+
+% https://en.wikipedia.org/wiki/Non-decimal_currency
+
+Units for such measures as length, area, weight, and so on were also often non-decimal, and in fact remain so in the few places of the world that have not made the change to the metric system.
+
+The non-decimal numbers were chosen due to their larger number of division factors, which simplified mental arithmetic --- eg. when sharing an amount of money or dividing goods.
+
+This package enables creation and configuration of such units to facilitate their presentation in textual and tabular contexts, as well as simple arithmetic.
+
+In order to do this, values are divided into \emph{segments}, which are separated by decimal points: for example, the historical Danish monetary value \nduValue{danish rigsdaler}{1.2.3} is entered as \texttt{1.2.3}, which the code then formats appropriately.
+
+Issues can be reported at \url{https://github.com/mikkelee/latex-units/issues} but keep in mind I am not very experienced with \LaTeX ;)
+
+\clearpage
+\section{Configuration} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+The package is configured in the following manner:
+
+\begin{docCommand}
+ {usepackage}
+ {\oarg{options}\brackets{non-decimal-units}}
+
+Where \meta{options} may contain one or more of the following unit systems. See \cpageref{units:included} for details.
+
+\begin{description}
+\item[british] Currencies
+\item[danish] Currencies and areas
+\item[german] Currencies
+\end{description}
+
+Alternately, one may configure new units via \refCom{nduNewUnit}.
+
+\end{docCommand}
+
+\begin{docCommand}
+ {nduset}
+ {\marg{options}}
+
+ Can be used to set options globally (in the preamble) or locally (in a group). See further documentation for possible keys/values.
+
+\end{docCommand}
+
+\clearpage
+\section{Usage} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\subsection{Formatting Values} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+The central macro is \docAuxCommand*{nduValue}. It formats values for display and is configurable in a number of ways.
+
+\begin{docCommand}
+ {nduValue}
+ {\marg{unit name}\oarg{options}\marg{value}}
+
+Formats \meta{value} according to the setup configured for the \meta{unit name}, as well as any provided \meta{options}. The number of decimal points and the values between them determine how many and which segments are displayed.
+
+Empty segments are skipped, unless the \refKey{replace nil with} key is set.
+
+\begin{dispExample*}{
+ title=Example usage: \docAuxCommand*{nduValue} macro
+}
+\nduValue{danish rigsdaler}{1.2.3}\\
+\nduValue{danish rigsdaler}{1..}\\
+\nduValue{danish rigsdaler}{.2.}\\
+\nduValue{danish rigsdaler}{..3}\\
+\end{dispExample*}
+\end{docCommand}
+
+\clearpage
+\subsubsection{Options}
+
+\begin{docKeys}[
+ doc name = show,
+ ]{
+ {
+ doc parameter = {=values},
+ },
+ {
+ doc parameter = {=values and symbols},
+ doc description = initially \texttt{values and symbols},
+ },
+ {
+ doc parameter = {=symbols},
+ },
+ }
+
+Changes which information is included in the expansion.
+
+Because only those segments with a value will be included, \docAuxKey*{show}=\docValue*{symbols} can be used to list the segment units (though if only one or two is needed, it may be preferable to use \refCom{nduSymbol}).
+
+\begin{dispExample}
+\nduValue{danish hartkorn}
+ [show=symbols]
+ {0.0.0.0.0}
+
+\nduValue{danish hartkorn}
+ [show=symbols]
+ {0.0...}
+\end{dispExample}
+\end{docKeys}
+
+See also \cref{units:new} for further discussion on possible options.
+
+\clearpage
+\begin{docKeys}
+ []
+ {
+ {
+ doc name = replace nil with,
+ doc parameter = {=\meta{...}},
+ doc description = {no default, initially empty},
+ },
+ {
+ doc name = treat zero as nil,
+ doc description = {initially not set},
+ },
+ }
+
+The key \docAuxKey*{replace nil with} replaces nil (empty) segments with a custom string.
+
+The key \docAuxKey*{treat zero as nil} replaces 0 with nothing, which in turn means that setting both will replace both zero and nil with the custom string.
+
+These keys also apply in non-tabular contexts, but are probably most useful here.
+
+\begin{dispExample*}{
+ title=Example usage: \docAuxKey*{replace nil with} key
+}
+\begingroup
+\nduset{
+ treat zero as nil,
+ replace nil with=---,
+}
+\begin{tabular}{r r}
+ \toprule
+ & \nduHeader{danish rigsdaler} \\
+ \midrule
+ a & \nduValue{danish rigsdaler}{1.2.3} \\
+ b & \nduValue{danish rigsdaler}{100.0.0} \\
+ c & \nduValue{danish rigsdaler}{.1.} \\
+ \bottomrule
+\end{tabular}
+\endgroup
+\end{dispExample*}
+\end{docKeys}
+
+
+\clearpage
+\subsection{Tabular Data} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+In order to align values in a tabular context, the \docAuxKey*{aligned} key causes \docAuxCommand{nduValue} to wrap each segment in a cell of equal width, using \docAuxCommand*{makebox}.
+
+Additionally, the \docAuxCommand*{nduHeader} macro provides a convenient header showing the unit symbols.
+
+All segments will be included in the headers and cells, whether they contain a value or not. If no value is provided for the segment, and no nil replacement is specified with the \refKey{replace nil with} key, the cell will be empty.
+
+\begin{docCommand}
+ {nduHeader}
+ {\marg{unit name}\oarg{options}}
+ Formats the unit symbols in boxes suitable for a header. See \cpageref{units:new} for configuration of symbols.
+\end{docCommand}
+
+\clearpage
+\subsubsection{Options}
+
+\begin{docKeys}
+ []
+ {
+ {
+ doc name = aligned,
+ doc description = {initially not set},
+ },
+ {
+ doc name = set aligned for environment,
+ doc description = {initially not set},
+ },
+ }
+
+ Setting \docAuxKey*{aligned} will format the presently displayed header in aligned boxes, desirable in tabular contexts.
+
+ In this document, the \docAuxKey*{set aligned for environment} key has been set for \texttt{tabular}, which means that all values in the tables are automatically aligned. It can be set multiple times, once for each required environment.
+
+\begin{dispExample*}{
+ title=Example usage: \docAuxCommand*{nduHeader} and \docAuxCommand*{nduValue} macros with \docAuxKey*{aligned} key.
+}
+\begingroup
+\begin{tabular}{r r}
+ \toprule
+ & \nduHeader{danish rigsdaler} \\
+ \midrule
+ a & \nduValue{danish rigsdaler}{1.2.3} \\
+ b & \nduValue{danish rigsdaler}{100..} \\
+ c & \nduValue{danish rigsdaler}{.1.} \\
+ \bottomrule
+\end{tabular}
+\endgroup
+\end{dispExample*}
+
+\end{docKeys}
+
+\begin{docKey}
+ {cell width}
+ {=\meta{length}}
+ {initially \texttt{5em}}
+
+Changes the width of each segment.
+
+\begin{dispExample*}{
+ title=Example usage: \docAuxKey*{cell width} key
+}
+\begingroup
+\nduset{
+ cell width=3em,
+}
+\begin{tabular}{r r}
+ \toprule
+ & \nduHeader{danish rigsdaler} \\
+ \midrule
+ a & \nduValue{danish rigsdaler}{1.2.3} \\
+ b & \nduValue{danish rigsdaler}{100..} \\
+ c & \nduValue{danish rigsdaler}{.1.} \\
+ \bottomrule
+\end{tabular}
+\endgroup
+\end{dispExample*}
+\end{docKey}
+
+\clearpage
+\subsection{Arithmetical Operations} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+Basic arithmetic functions can be used to build a result for display. Internally, this is done by converting the value to a representation, which is the total number of the smallest usable unit, eg. \nduValue{danish rigsdaler}{1.2.3} is 131 \nduName{danish rigsdaler}{2}.
+
+Results can be gathered in two ways, either manually via the \docAuxCommand*{nduMath} macro, or automatically via the \docAuxKey*{add to variable} and \docAuxKey*{subtract from variable} keys, the latter being especially suitable in tabular contexts.
+
+\begin{docCommands}[]{
+ {
+ doc name = nduMath,
+ doc parameter = \marg{unit name}\oarg{options}\marg{variable}\marg{operator}\marg{value}
+ },
+ {
+ doc name = nduResult,
+ doc parameter = \marg{unit name}\oarg{options}\marg{variable}
+ }
+}
+
+The first arguments of \docAuxCommand*{nduMath} are identical to those of the \refCom{nduValue} macro. In addition, it has \meta{operator} (one of \texttt{+ - * /}) and \meta{variable} arguments. The first time a variable is used, it is assumed that the value is 0. The given value is then converted to its internal representation and stored in the variable. The command does not expand to any output.
+
+Note that mixing units in the same variable is not currently supported, and will likely give incorrect results.
+
+The \docAuxCommand*{nduResult} macro takes a stored \meta{variable} and formats it for display in the same way as \refCom{nduValue}.
+
+Both may be further configured via the \meta{options} in the same way as the other macros.
+
+\begin{dispExample*}{
+ title=Example usage: \docAuxCommand*{nduMath} and \docAuxCommand*{nduResult} macros
+}
+\nduMath{danish rigsdaler}{example 1}{+}{0.0.10}
+\nduMath{danish rigsdaler}{example 1}{+}{..8}
+\nduMath{danish rigsdaler}{example 1}{+}{0.2}
+\nduMath{danish rigsdaler}{example 1}{+}{0.5.1}
+\nduResult{danish rigsdaler}{example 1} % = 1.2.3
+\end{dispExample*}
+
+\begin{dispExample*}{
+ title=Example usage: \docAuxCommand*{nduResult} macro
+}
+\nduHeader{danish rigsdaler}\\
+\nduResult{danish rigsdaler}[aligned]{example 1}
+\end{dispExample*}
+\end{docCommands}
+
+\clearpage
+\subsubsection{Options}
+
+\begin{docKeys}
+ [
+ doc parameter = {=\meta{...}},
+ ]
+ {
+ {
+ doc name = add to variable,
+ },
+ {
+ doc name = subtract from variable,
+ },
+ }
+
+Setting either of these keys will cause all uses of \docAuxCommand*{nduValue} in the current group to be added to or subtracted from the variable with the given name.
+
+\begin{dispExample*}{
+ title=Example usage: \docAuxKey*{add to variable} key
+}
+\begingroup
+\nduset{
+ cell width=3em,
+ replace nil with=---,
+ add to variable=example 2
+}
+\begin{tabular}{r r}
+ \toprule
+ & \nduHeader{danish rigsdaler} \\
+ \midrule
+ a & \nduValue{danish rigsdaler}{1.2.3} \\
+ b & \nduValue{danish rigsdaler}{100.1.} \\
+ \bottomrule
+ total & \nduResult{danish rigsdaler}{example 2} \\ % = 101.3.3
+\end{tabular}
+\endgroup
+\end{dispExample*}
+
+Results are global and remain accessible outside the group:
+\begin{dispExample}
+\nduResult{danish rigsdaler}{example 2}
+\end{dispExample}
+
+Adding an additional 15 \nduName{danish rigsdaler}{2} to the existing result gives:
+\begin{dispExample}
+\nduMath{danish rigsdaler}{example 2}{+}{0.0.15}
+\nduResult{danish rigsdaler}{example 2} % = 101.4.2
+\end{dispExample}
+\end{docKeys}
+
+\subsection{Accessing Information About Units} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\begin{docCommand}
+ {nduName}
+ {\marg{unit name}\marg{segment}}
+ Expands to the name of the the given segment of the unit.
+
+ Set by \refKey{segment:name}.
+\end{docCommand}
+
+\begin{docCommand}
+ {nduSymbol}
+ {\marg{unit name}\marg{segment}}
+ Expands to the symbol of the the given segment of the unit.
+
+ Set by \refKey{segment:symbol}.
+\end{docCommand}
+
+\begin{docCommand}
+ {nduFactor}
+ {\marg{unit name}\marg{segment}}
+ Expands to the conversion factor of the the given segment of the unit, ie. how many of the underlying segment the given segment consists of.
+
+\begin{dispExample}
+That is, 1 \nduName{danish rigsdaler}{0} consists of
+\nduFactor{danish rigsdaler}{1} \nduName{danish rigsdaler}{1}.
+\end{dispExample}
+\end{docCommand}
+
+\clearpage
+\section{Creating New Units} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\label{units:new}
+If the included units are not suitable, more can be created. Pull requests are also welcome at \url{https://github.com/mikkelee/latex-units}.
+
+\begin{docCommand}
+ {nduNewUnit}
+ {\marg{unit name}\marg{key/value pairs}}
+
+Units can have up to 7 segments, numbered \meta{0-6}. The left-most segment, that is, the \emph{top} or \emph{root} segment, is numbered \texttt{0}.
+
+The numeral part of the below key paths \docAuxKey*{segment 0/} can be any integer up to \texttt{6}, ie. \docAuxKey*{segment 6/}. The internal number of segments is determined by how many name keys are created.
+
+See below for available settings.
+
+\end{docCommand}
+
+\begin{docCommand}
+ {nduNewMacro}
+ {\marg{unit name}\oarg{key/value pairs}\marg{control sequence}}
+
+ It is possible to create shortcut macros for commonly used \meta{unit name}s with optional overriding options.
+
+ These macros take the same arguments as the full \refCom{nduValue} macro, except without the first argument (ie. the name of the unit).
+
+\begin{dispExample}
+\nduNewMacro{rigsdaler.mark.skilling}
+ [unit groups/rigsdaler.mark.skilling/segment 0/symbol={R\textsuperscript{dl}}]
+ {myRdl}
+\myRdl{1.2.3}
+\end{dispExample}
+
+\end{docCommand}
+
+%\begin{docCommand}
+% {nduCommonSymbols}
+% {\marg{key/value pairs}}
+%
+% It is possible to configure commonly used symbols using the form \texttt{\meta{name}=\meta{symbol}}. These will be used as fallbacks if no specific symbol is configured for a segment via \refKey{segment:symbol}.
+%
+%\end{docCommand}
+%
+%\begin{docCommand}
+% {nduCommonFactors}
+% {\marg{key/value pairs}}
+%
+% Not currently implemented.
+%
+%\end{docCommand}
+
+\clearpage
+\subsubsection{Options}
+
+\begin{docKey}
+ {segment separator}
+ {=\meta{...}}
+ {initially \texttt{\~{}}}
+
+ When displaying a value, this string will be inserted between each segment.
+
+\begin{dispExample}
+\nduValue{danish hartkorn}[
+ show=values,
+ segment separator=.
+ ]
+ {1.2.3.4}
+
+\nduValue{danish rigsdaler}
+ [segment separator={---}]
+ {1.2.3}
+\end{dispExample}
+
+\end{docKey}
+
+\begin{docKey}
+ {restrict segment depth}
+ {=\meta{integer}}
+ {initially no restriction}
+
+ When calculating or displaying a value, only the segments up to and including \meta{integer} will be considered.
+
+ In this document, the depth has been globally set to \texttt{2} for \docAuxKey*{danish rigsdaler}, but the older historical sub-unit \nduName{danish rigsdaler}{3} can be included by locally setting the depth to \texttt{3} (or indeed not restricting it globally).
+
+\begin{dispExample}
+\nduValue{danish rigsdaler}
+ [restrict segment depth=3]
+ {1.2.3.4}
+\end{dispExample}
+\end{docKey}
+
+\begin{docKey}
+ []
+ [doc label=segment:name]
+ {segment \meta{n}/name}
+ {=\meta{name}}
+ {no default, initially undefined}
+
+ Gives the proper name of the segment's unit. Used internally to determine how many segments the unit contains.
+
+ Can be accessed with by \refCom{nduName}.
+\end{docKey}
+
+\begin{docKey}
+ []
+ [doc label=segment:symbol]
+ {segment \meta{n}/symbol}
+ {=\meta{symbol}}
+ {no default, initially undefined}
+
+ Configures a symbol displaying the unit. This is used in \docAuxCommand{nduHeader} and is also available via \docAuxCommand{nduSym} when defining the \refKey{segment:display} (see below).
+
+ If none is configured, an attempt to look up a common symbol by its name is made. These can be configured with \refCom{nduCommonSymbols}.
+\end{docKey}
+
+\begin{docKeys}
+ [
+ doc parameter = {=\meta{...}},
+ ]
+ {
+ {
+ doc name = {segment \meta{n}/prefix},
+ doc label = segment:prefix,
+ doc description = {initially set to \texttt{\{\}}},
+ },
+ {
+ doc name = {segment \meta{n}/suffix},
+ doc label = segment:suffix,
+ doc description = {initially set to \texttt{\{~\docAuxCommand*{nduSym}\}}},
+ },
+ }
+
+ When displaying a value, segments will be wrapped between the \meta{prefix} and \meta{suffix}.
+
+ The macro \docAuxCommand{nduSym} is available here to show the symbol configured for the segment.
+\end{docKeys}
+
+\begin{docKey}
+ []
+ [doc label=segment:display]
+ {segment \meta{n}/display}
+ {=\marg{prefix}\marg{suffix}}
+ {}
+
+ Sets both \refKey{segment:prefix} and \refKey{segment:suffix} at the same time.
+\end{docKey}
+
+\begin{docKey}
+ []
+ [doc label=segment:factor]
+ {segment \meta{n}/factor}
+ {=\meta{integer}}
+ {no default, initially undefined}
+
+ The conversion factor of a segment is how many of the underlying segment the given segment consists of.
+
+ This is used in the math macros, in order to calculate the correct segment values.
+
+ Can be accessed via \refCom{nduFactor}.
+\end{docKey}
+
+These keys can of course also be set temporarily in \refCom{nduValue}
+
+\begin{dispExample}
+\nduValue{danish rigsdaler}
+ [segment 1/symbol=Mk.]
+ {.9.}
+
+\nduValue{danish rigsdaler}
+ [segment 0/display={}{~Rigsdaler og}]
+ {1.2.3}
+
+\nduValue{danish rigsdaler}[
+ segment separator={---},
+ segment 0/display={(}{)},
+ segment 1/display={[}{]},
+ segment 2/display={\{}{\}},
+ ]
+ {1.2.3}
+\end{dispExample}
+
+\begin{docKey}
+ {create macro named}
+ {=\meta{control sequence}}
+ {no default, initially empty}
+
+ Units may provide a default shortcut macro, for example the \docValue*{danish rigsdaler} unit configures \docAuxCommand*{rdl}.
+
+ This is done via \refCom{nduNewMacro} which describes the arguments of the resulting macros.
+
+\begin{dispExample*}{
+ sidebyside,
+ righthand width=1.75cm,
+}
+\rdl{2.3.}
+\end{dispExample*}
+\end{docKey}
+
+\clearpage
+\section{Included Units} %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\label{units:included}
+On the following pages are the units included with the package.
+
+\unitlisting{british}
+
+\clearpage
+\unitlisting{danish}
+
+\unitlisting{german}
+
+\printindex %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\end{document} \ No newline at end of file
diff --git a/Master/texmf-dist/doc/latex/non-decimal-units/test.pdf b/Master/texmf-dist/doc/latex/non-decimal-units/test.pdf
new file mode 100644
index 00000000000..6cb11b3f93b
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/non-decimal-units/test.pdf
Binary files differ
diff --git a/Master/texmf-dist/doc/latex/non-decimal-units/test.tex b/Master/texmf-dist/doc/latex/non-decimal-units/test.tex
new file mode 100644
index 00000000000..69b5d73a9b1
--- /dev/null
+++ b/Master/texmf-dist/doc/latex/non-decimal-units/test.tex
@@ -0,0 +1,232 @@
+% !TEX TS-program = LuaLaTeX-shell-escape
+\documentclass{article}
+\usepackage{trace}
+
+\usepackage{non-decimal-units.preamble}
+
+%\nduset{logging}
+
+\makeatletter
+
+\begin{document}
+
+
+\nduNewMacro{rigsdaler.mark.skilling}
+ [unit groups/rigsdaler.mark.skilling,segment 0/symbol={R\textsuperscript{dl}}]
+ {myRdl}
+\myRdl{1.2.3}
+
+\end{document}
+
+\nduValue{sletdaler.mark}{1.2}%
+
+
+%\traceon
+\nduValue{sletdaler.mark}[restrict segment depth=2]{1.2}%
+%\traceoff
+
+%\end{document}
+
+
+\nduValue{danish rigsbankdaler}{.120}
+
+
+normalize 120 skilling = \nduValue{danish rigsdaler}[
+ normalize,
+ treat zero as nil,
+]{..120} = 1.1.8
+
+
+\nduValue{danish rigsbankdaler}{.100}
+
+\nduValue{sletdaler.mark}{1.2}%
+
+\rbd{1.2} = 1.2
+
+\rbd{.100} = 1.4
+
+\rdl{..120} = 1.1.8
+
+
+
+%\end{document}
+
+\nduAliasOrGroup{danish rigsbankdaler} == \nduAliasOrGroup{rigsbankdaler.skilling}
+
+\nduValue{danish rigsbankdaler}{50.10} == \nduValue{rigsbankdaler.skilling}{50.10}
+
+\begingroup
+\nduset{
+ aliases/danish sletdaler,
+ restrict segment depth=2,
+}
+
+\nduset{
+ unit groups/sletdaler.mark.skilling.penning/restrict segment depth=2,
+}
+\endgroup
+
+\nduValue{danish rigsdaler}[
+ restrict segment depth=2,
+ segment separator=!,
+]{1..3} = 1!3
+
+\nduValue{sletdaler.mark.skilling}[
+ restrict segment depth=2,
+ segment separator=!,
+]{1..2} = 1!2
+
+
+factor: \pgfkeysvalueof{/ndu/base units/rigsdaler/factors/ort}
+
+factor: \pgfkeysvalueof{/ndu/base units/rigsdaler/factors/mark}
+
+factor: \pgfkeysvalueof{/ndu/base units/tønde/factors/skæppe}
+
+
+%\nduFactor{danish rigsdaler}{0}
+
+\nduFactor{danish rigsdaler}{1} \nduSymbol{danish rigsdaler}{1} per \nduSymbol{danish rigsdaler}{0}
+
+\nduFactor{danish rigsdaler}{2} \nduSymbol{danish rigsdaler}{2} per \nduSymbol{danish rigsdaler}{1}
+
+\nduFactor{danish rigsdaler}{3} \nduSymbol{danish rigsdaler}{3} per \nduSymbol{danish rigsdaler}{2}
+
+%\nduFactor{danish rigsdaler}{4} \nduSymbol{danish rigsdaler}{4} per \nduSymbol{danish rigsdaler}{3}
+
+%\end{document}
+
+
+\section{Aligned math test}
+
+ testing with 1.2.3.4 = 1*6*16*12 + 2*16*12 + 3*12 + 4 = 1576
+
+ \csdef{ndu@repr@TEST}{0}
+ init as 0: \csuse{ndu@repr@TEST}
+
+ \nduConvertToRepr@helper{danish rigsdaler}{TEST}{0}{1}
+ no conv, add rdl: 0 + 1 = 1 --- is \csuse{ndu@repr@TEST}
+
+ \nduConvertToRepr@helper{danish rigsdaler}{TEST}{1}{2}
+ conv to mk, add mk: 1*6 + 2 = 8 --- is \csuse{ndu@repr@TEST}
+
+ \nduConvertToRepr@helper{danish rigsdaler}{TEST}{2}{3}
+ conv to sk, add sk: 8*16 + 3 = 131 --- is \csuse{ndu@repr@TEST}
+
+ \nduConvertToRepr@helper{danish rigsdaler}{TEST}{3}{4}
+ conv to pg, add pg: 131*12 + 4 = 1576 --- is \csuse{ndu@repr@TEST}
+
+ \nduConvertToRepr@helper{danish rigsdaler}{TEST}{4}{0}
+ no conv, no add: --- is \csuse{ndu@repr@TEST}
+
+\nduResult{danish rigsdaler}{TEST}
+
+
+\nduValue{danish rigsdaler}[replace nil with=---]{1..3} = 1.---.3.---
+
+\nduValue{danish rigsdaler}{1..3} = 1..3
+
+\nduValue{danish rigsdaler}{1.2.3} = 1.2.3
+
+\nduConvertToRepr{danish rigsdaler}{baz}{1.2.3.4} 1.2.3.4 =
+baz: \nduResult{danish rigsdaler}{baz}
+
+\nduConvertToRepr{danish rigsdaler}{foo}{1.2.3} 1.2.3 =
+foo: \nduResult{danish rigsdaler}{foo}
+
+foo with local zero as nil: \nduResult{danish rigsdaler}[treat zero as nil]{foo}
+
+Setting depth to 2
+
+\traceon
+\nduset{
+% unit groups/rigsdaler.mark.skilling.penning/restrict segment depth=2,
+ aliases/danish rigsdaler,
+ restrict segment depth=2,
+}
+\traceoff
+
+\nduConvertToRepr{danish rigsdaler}{zap}{1.2.3.4} 1.2.3.4 =
+zap: \nduResult{danish rigsdaler}{zap}
+
+\nduConvertToRepr{danish rigsdaler}{bar}{1.2.3} 1.2.3 =
+bar: \nduResult{danish rigsdaler}{bar}
+
+
+\section{Zero test}
+
+should be 1.0.1: \nduValue{danish rigsdaler}{1.0.1}
+
+should be 1..1: \nduValue{danish rigsdaler}[treat zero as nil]{1.0.1}
+
+
+\section{Math test}
+
+\nduMath{danish rigsdaler}{math}{+}{..8}
+\nduResult{danish rigsdaler}{math}
+
+\nduMath{danish rigsdaler}{math}{+}{..8}
+\nduResult{danish rigsdaler}{math}
+
+\nduMath{danish rigsdaler}{math}{+}{..9}
+\nduResult{danish rigsdaler}{math}
+
+\nduMath{danish rigsdaler}{math}{-}{..8}
+\nduResult{danish rigsdaler}{math} = 0.1.1
+
+\nduMath{danish rigsdaler}{math}{+}{..8}
+\nduResult{danish rigsdaler}{math} = 0.1.9
+
+\nduMath{danish rigsdaler}{math}{*}{2}
+\nduResult{danish rigsdaler}{math} = 0.3.2
+
+\section{Aligned math test}
+
+\begingroup
+\nduset{
+ aligned,
+ cell width=3em,
+ replace nil with=---,
+ treat zero as nil,
+ add to variable=example 2
+}
+\begin{tabular}{r r}
+ \toprule
+ & \nduHeader{danish rigsdaler} \\
+ \midrule
+ a & \nduValue{danish rigsdaler}{1.2.3} \\
+ b & \nduValue{danish rigsdaler}{100.1.} \\
+ c & \nduValue{danish rigsdaler}{0..15} \\
+ \bottomrule
+ total & \nduResult{danish rigsdaler}{example 2} \\
+\end{tabular} = 101.4.2
+\endgroup
+
+\end{document}
+
+Does not work because 1 ort = 1.5 mark
+
+\section{All coins test}
+
+\nduMath{danish rigsdaler all coins}{all coins}{+}{..10}
+\nduResult{danish rigsdaler all coins}{all coins}
+
+\nduMath{danish rigsdaler all coins}{all coins}{+}{...100}
+\nduResult{danish rigsdaler all coins}{all coins}
+
+\nduMath{danish rigsdaler all coins}{all coins}{+}{.5}
+\nduResult{danish rigsdaler all coins}{all coins}
+
+\nduMath{danish rigsdaler all coins}{all coins}{+}{....10}
+\nduResult{danish rigsdaler all coins}{all coins} = XXXX
+
+\end{document}
+
+segment depth: \pgfkeysvalueof{/ndu/aliases/danish rigsdaler/segment depth}
+
+restrict segment depth: \pgfkeysvalueof{/ndu/aliases/danish rigsdaler/restrict segment depth}
+
+segment depth: \pgfkeysvalueof{/ndu/unit groups/sletdaler.mark.skilling/segment depth}
+
+restrict segment depth: \pgfkeysvalueof{/ndu/unit groups/sletdaler.mark.skilling/restrict segment depth}
+
diff --git a/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.british.tex b/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.british.tex
new file mode 100644
index 00000000000..28c849f641d
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.british.tex
@@ -0,0 +1,27 @@
+%%% CURRENCY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+% https://en.wikipedia.org/wiki/£sd
+
+\nduBaseUnits{%
+ pound sterling={%
+ symbol=£,
+ display={\nduSym}{},
+ },
+ shilling={%
+ symbol=s,
+ factor=20 per pound sterling,
+ display={}{\nduSym},
+ },
+ penny={%
+ symbol=d,
+ factor=12 per shilling,
+ display={}{\nduSym},
+ },
+}
+
+\nduAliases{%
+ british pound sterling lsd={%
+ units=pound sterling.shilling.penny,
+ segment separator={. },
+ },
+}
diff --git a/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.danish.tex b/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.danish.tex
new file mode 100644
index 00000000000..0ac75c3587c
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.danish.tex
@@ -0,0 +1,122 @@
+%%% CURRENCY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\nduBaseUnits{%
+ rigsbankdaler={%
+ symbol=Rbd.,
+ },
+ rigsdaler={%
+ symbol=Rdl.,
+ },
+ sletdaler={%
+ symbol=Sldl.,
+ },
+ speciedaler={%
+ symbol=Spdl.,
+ },
+ ort={symbol=Ort,factor=4 per rigsdaler},
+ mark={%
+ symbol=Mk.,
+ factor=6 per rigsdaler,
+ factor=4 per sletdaler,
+ },
+ skilling={%
+ symbol=Sk.,
+ factor=16 per mark,
+ factor=24 per ort,
+ factor=84 per speciedaler,
+ factor=96 per rigsbankdaler,
+ },
+ hvid={%
+ symbol=Hvid,
+ factor=3 per skilling,
+ },
+ penning={%
+ symbol=Pg.,
+ factor=4 per hvid,
+ factor=12 per skilling,
+ },
+}
+
+\nduAliases{%
+ danish rigsbankdaler={%
+ units=rigsbankdaler.skilling,
+ macro={rbd}{%
+ normalize,
+ treat zero as nil
+ },
+ },
+ danish rigsdaler={%
+ units=rigsdaler.mark.skilling.penning,
+ macro={rdl}{%
+ normalize,
+ treat zero as nil
+ },
+ },
+ danish sletdaler={%
+ units=sletdaler.mark.skilling.penning,
+ macro={sldl}{%
+ normalize,
+ treat zero as nil
+ },
+ },
+}
+
+
+%%%% AREA %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\nduBaseUnits{%
+ tønde={%
+ symbol=Td.,
+ },
+ skæppe={%
+ symbol=Skp.,
+ factor=8 per tønde,
+ },
+ fjerdingkar={%
+ symbol=Fjk.,
+ factor=4 per skæppe,
+ },
+ album={%
+ symbol=Alb.,
+ factor=3 per fjerdingkar,
+ },
+ penning/factor=4 per album, % penning symbols defined under currency
+}
+
+\nduAliases{%
+ danish hartkorn={%
+ units=tønde.skæppe.fjerdingkar.album.penning,
+ macro={hartkorn}{%
+ normalize,
+ treat zero as nil
+ },
+ },
+}
+
+
+%%%% WEIGHT %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\nduBaseUnits{%
+ skippund={%
+ symbol=Spd.,
+ },
+ lispund={%
+ symbol=Lpd.,
+ factor=20 per skippund,
+ },
+ skaalpund={%
+ symbol=Pd.,
+ factor=16 per lispund,
+ },
+}
+
+\nduAliases{%
+ danish pund={%
+ units=skippund.lispund.skaalpund,
+ macro={pund}{%
+ normalize,
+ treat zero as nil
+ },
+ },
+}
+
diff --git a/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.german.tex b/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.german.tex
new file mode 100644
index 00000000000..912ee0d4280
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.german.tex
@@ -0,0 +1,21 @@
+%%% CURRENCY %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\nduBaseUnits{%
+ reichsthaler={%
+ symbol=Rthl., % \mufi{reichtalold}
+ },
+ groschen={%
+ symbol=Gr., % \mufi{grosch}
+ factor=30 per reichsthaler,
+ },
+ pfennig={%
+ symbol=Pf., % \mufi{20B0}
+ factor=12 per groschen,
+ },
+}
+
+\nduAliases{%
+ german reichsthaler={%
+ units=reichsthaler.groschen.pfennig,
+ },
+}
diff --git a/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.sty b/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.sty
new file mode 100644
index 00000000000..92459759cc0
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/non-decimal-units/non-decimal-units.sty
@@ -0,0 +1,598 @@
+\ProvidesPackage{non-decimal-units}[2023/09/26 Macros for displaying and manipulating historical non-decimal units]
+
+% License: CC-BY-SA 4.0
+% Author: Mikkel Eide Eriksen <mikkel.eriksen@gmail.com>
+
+\RequirePackage{pgfkeys}
+\RequirePackage{pgfopts}
+\RequirePackage{bigintcalc}
+
+\RequirePackage{etoolbox}
+\RequirePackage{ifthen}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\pgfkeys{/handlers/.store in cs/.code=\pgfkeysalso{%
+ \pgfkeyscurrentpath/.code=\csdef{#1}{##1}}%
+}
+
+\def\nduset{\pgfqkeys{/ndu}}
+
+\newif\ifndushowvalues
+\newif\ifndushowaffixes
+\newif\ifndutreatzeroasnil
+\newif\ifndualigned
+\ndushowvaluestrue
+\ndushowaffixestrue
+\newif\ifndunormalize
+
+\newcounter{autorepr}
+
+\gdef\ndu@nextdelim{}%
+\gdef\ndu@delim{}%
+
+\nduset{%
+ base units/.is family,
+ base units/.unknown/.code={%
+ \expandafter\nduBuildBaseUnitKeys\expandafter{\pgfkeyscurrentname}{#1}%
+ },
+ unit groups/.is family,
+ unit groups/.unknown/.code={%
+ \expandafter\nduBuildUnitGroupKeys\expandafter{\pgfkeyscurrentname}%
+ },
+ aliases/.is family,
+ aliases/.unknown/.code={%
+ \expandafter\nduBuildAliasKeys\expandafter{\pgfkeyscurrentname}{#1}%
+ },
+ show/.is choice,
+ show/values/.code={\ndushowvaluestrue\ndushowaffixesfalse},
+ show/values and symbols/.code={\ndushowvaluestrue\ndushowaffixestrue},
+ show/symbols/.code={\ndushowvaluesfalse\ndushowaffixestrue},
+ show=values and symbols,
+ cell width/.initial=5em,
+ add to variable/.code={%
+ \csdef{ndu@current@variable}{#1}%
+ \csdef{ndu@current@operator}{+}%
+ },
+ subtract from variable/.code={%
+ \csdef{ndu@current@variable}{#1}%
+ \csdef{ndu@current@operator}{-}%
+ },
+ replace nil with/.store in cs=ndu@nil@replacement,
+ treat zero as nil/.is if=ndutreatzeroasnil,
+ treat zero as nil=false,
+ normalize/.is if=ndunormalize,
+ normalize=false,
+ segment separator/.initial={~},
+ aligned/.is if=ndualigned,
+ aligned=false,
+ set aligned for environment/.code={%
+ \AtBeginEnvironment{#1}{\nduset{aligned}}%
+ },
+}
+
+\newcommand\nduBuildBaseUnitKeys[2]{%
+ \nduset{%
+ base units/#1/.is family,base units/#1,
+ symbol/.initial={#1},
+ factor/.style args={##1 per ##2}{%
+ /ndu/base units/##2/factors/#1/.initial=##1,
+ },
+ prefix/.initial={},
+ suffix/.initial={~\nduSym},
+ display/.style 2 args={%
+ prefix={##1},
+ suffix={##2},
+ },
+ #2,
+ }%
+}
+
+\newcommand\nduBaseUnits[1]{%
+ \nduset{%
+ base units,#1,
+ }%
+}
+
+\newcommand\nduBuildUnitGroupKeys[1]{% called by .unknown handler
+ \nduset{%
+ unit groups/#1/.search also={/ndu},
+ unit groups/#1/.is family,unit groups/#1,
+ segment separator/.link=/ndu/segment separator,
+ segment depth/.initial=-1,
+ update segment depth/.code={%
+ \ifnum##1>\pgfkeysvalueof{/ndu/unit groups/#1/segment depth}%
+ \nduset{%
+ unit groups/#1/segment depth=##1,
+ }%
+ \fi%
+ },
+ restrict segment depth/.link=/ndu/unit groups/#1/segment depth,
+ }%
+ \nduBuildSegments{#1}{#1}%
+}
+
+\newcommand\nduUnitGroups[1]{%
+ \nduset{%
+ unit groups,#1,
+ }%
+}
+
+\newcommand\nduBuildAliasKeys[2]{% called by .unknown handler
+ \nduset{%
+ aliases/#1/.is family,aliases/#1,
+ units/.code={%
+ % create unit group and set search path
+ \pgfkeys{%
+ /ndu/unit groups/##1,
+ /ndu/aliases/#1/.search also={/ndu/unit groups/##1},
+ /ndu/aliases/#1/unit group/.initial=##1,
+ }%
+ },
+ macro/.code 2 args={%
+ \nduNewMacro{#1}[##2]{##1}%
+ },
+ #2,
+ }%
+}
+
+\newcommand\nduAliases[1]{%
+ \nduset{%
+ aliases,#1,
+ }%
+}
+
+\NewDocumentCommand\nduBuildSegments{ m > { \SplitArgument { 6 } { . } } m }{%
+ \nduBuildSegments@internal{#1}#2%
+}
+
+\newcommand\nduBuildSegments@internal[8]{%
+ \nduNewUnit@segment{#1}{0}{#2}{#1}%
+ \nduNewUnit@segment{#1}{1}{#3}{#2}%
+ \nduNewUnit@segment{#1}{2}{#4}{#3}%
+ \nduNewUnit@segment{#1}{3}{#5}{#4}%
+ \nduNewUnit@segment{#1}{4}{#6}{#5}%
+ \nduNewUnit@segment{#1}{5}{#7}{#6}%
+ \nduNewUnit@segment{#1}{6}{#8}{#7}%
+}
+
+\newcommand\nduNewUnit@segment[4]{%
+ \IfValueT{#3}{%
+ \nduset{
+ unit groups/#1/segment #2/.is family,unit groups/#1/segment #2,
+ name/.initial=#3,
+ symbol/.link=/ndu/base units/#3/symbol,
+ prefix/.link=/ndu/base units/#3/prefix,
+ suffix/.link=/ndu/base units/#3/suffix,
+ display/.style 2 args={%
+ segment #2/prefix={##1}, % why is the segment needed here ???
+ segment #2/suffix={##2},
+ },
+ factor/.link=/ndu/base units/#4/factors/#3,
+ }%
+ \nduset{%
+ unit groups/#1/update segment depth=#2,
+ }%
+ }%
+}
+
+\NewDocumentCommand\nduNewMacro{ m O{} m }{%
+ \expandafter\NewDocumentCommand\csname#3\endcsname { O{} m } {%
+ \begingroup%
+ \nduset{unit groups/#1,#2}%
+ \nduValue{#1}[##1]{##2}%
+ \endgroup%
+ }%
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newcommand\nduName[2]{%
+ \pgfkeysifdefined{/ndu/unit groups/\nduAliasOrGroup{#1}/segment #2/name}{%
+ \pgfkeysvalueof{/ndu/unit groups/\nduAliasOrGroup{#1}/segment #2/name}%
+ }{%
+ \PackageError{non-decimal-units}{No name defined for "\nduAliasOrGroup{#1}" segment #2}{}%
+ \nduNameMissing%
+ }%
+}
+
+\newcommand\nduSymbol[2]{%
+ \pgfkeysifdefined{/ndu/unit groups/\nduAliasOrGroup{#1}/segment #2/symbol}{%
+ \pgfkeysvalueof{/ndu/unit groups/\nduAliasOrGroup{#1}/segment #2/symbol}%
+ }{%
+ \PackageError{non-decimal-units}{No symbol defined for "\nduAliasOrGroup{#1}" segment #2 (\nduName{#1}{#2})}{}%
+ \nduSymbolMissing%
+ }%
+}
+
+\newcommand\nduPrefix[2]{%
+ \pgfkeysifdefined{/ndu/unit groups/\nduAliasOrGroup{#1}/segment #2/prefix}{%
+ \gdef\nduSym{\nduSymbol{\nduAliasOrGroup{#1}}{#2}}%
+ \pgfkeysvalueof{/ndu/unit groups/\nduAliasOrGroup{#1}/segment #2/prefix}%
+ }{%
+ \PackageError{non-decimal-units}{No prefix defined for "\nduAliasOrGroup{#1}" segment #2 (\nduName{#1}{#2})}{}%
+ \nduPrefixMissing%
+ }%
+}
+
+\newcommand\nduSuffix[2]{%
+ \pgfkeysifdefined{/ndu/unit groups/\nduAliasOrGroup{#1}/segment #2/suffix}{%
+ \gdef\nduSym{\nduSymbol{\nduAliasOrGroup{#1}}{#2}}%
+ \pgfkeysvalueof{/ndu/unit groups/\nduAliasOrGroup{#1}/segment #2/suffix}%
+ }{%
+ \PackageError{non-decimal-units}{No suffix defined for "\nduAliasOrGroup{#1}" segment #2 (\nduName{#1}{#2})}{}%
+ \nduSuffixMissing%
+ }%
+}
+
+\newcommand\nduFactor[2]{%
+ \pgfkeysifdefined{/ndu/unit groups/\nduAliasOrGroup{#1}/segment #2/factor}{%
+ \pgfkeysvalueof{/ndu/unit groups/\nduAliasOrGroup{#1}/segment #2/factor}%
+ }{%
+ % Having a PackageError here breaks bigintcalc.
+ \nduFactorMissing@#1@#2%
+ }%
+}
+
+\newcommand\ifnduFactorDefined[4]{%
+ \pgfkeysifdefined{/ndu/base units/\nduName{#1}{\the\numexpr#2-1\relax}/factors/\nduName{#1}{#2}}{%
+ #3%
+ }{%
+ #4%
+ }%
+}
+
+\newcommand\nduNamedFactor[2]{%
+ \pgfkeysifdefined{/ndu/base units/\nduAliasOrGroup{#1}/factors/#2}{%
+ \pgfkeysvalueof{/ndu/base units/\nduAliasOrGroup{#1}/factors/#2}%
+ }{%
+ % Having a PackageError here breaks bigintcalc.
+ \nduFactorMissing@#1@#2%
+ }%
+}
+
+\newcommand\nduSegmentDepth[1]{%
+ \pgfkeysifdefined{/ndu/unit groups/\nduAliasOrGroup{#1}/restrict segment depth}{%
+ \pgfkeysvalueof{/ndu/unit groups/\nduAliasOrGroup{#1}/restrict segment depth}%
+ }{%
+ \pgfkeysvalueof{/ndu/unit groups/\nduAliasOrGroup{#1}/segment depth}%
+ }%
+}
+
+\newcommand\nduAliasOrGroup[1]{%
+ \pgfkeysifdefined{/ndu/aliases/#1/unit group}{%
+ \pgfkeysvalueof{/ndu/aliases/#1/unit group}%
+ }{%
+ #1%
+ }%
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newcommand\ndu@if@depth@at@least[3]{%
+ \ifnum#2>\nduSegmentDepth{#1}%
+ \relax%
+ \else%
+ #3%
+ \fi%
+}
+
+\newcommand\ndu@nil@helper[4]{%
+ \IfValueTF{#1}{%
+ \ifblank{#1}{%
+ \ifcsvoid{ndu@nil@replacement}{}{#2\ndu@nil@replacement{}#4}%
+ }{%
+ \ifndutreatzeroasnil%
+ \expandafter\ifnum#1=0
+ \ifcsvoid{ndu@nil@replacement}{}{#2\csuse{ndu@nil@replacement}#4}%
+ \else%
+ #2#3#4%
+ \fi%
+ \else%
+ #2#3#4%
+ \fi%
+ }%
+ }{%
+ \ifcsvoid{ndu@nil@replacement}{}{#2\csuse{ndu@nil@replacement}#4}%
+ }%
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\NewDocumentCommand\nduValue{ m O{} m }{%
+ \nduValue@unitgroup{\nduAliasOrGroup{#1}}[#2]{#3}%
+}
+
+\NewDocumentCommand\nduValue@unitgroup{ m O{} m }{%
+ % #1 = unit group
+ % #2 = options
+ % #3 = values joined by .
+ \nduset{unit groups/#1}%
+ \begingroup%
+ \nduset{unit groups/#1,#2}%
+ \ifndualigned%
+ \nduAlignedValue@entry{#1}{#3}%
+ \else%
+ \nduFormatValue@entry{#1}{#3}%
+ \fi%
+ \endgroup%
+ \ifcsvoid{ndu@current@variable}{}{%
+ \nduMath{#1}{\ndu@current@variable}{\ndu@current@operator}{#3}%
+ }%
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newcommand\nduFormatSegment[3]{%
+ % #1 = unit group
+ % #2 = segment
+ % #3 = value
+ %\csshow{nduSym}%
+ \ndu@nil@helper{#3}{%
+ \ndu@delim%
+ \ifndushowaffixes\nduPrefix{#1}{#2}\fi%
+ \edef\ndu@delim{\ndu@nextdelim}%
+ }{%
+ \ifndushowvalues#3\fi%
+ }{%
+ \ifndushowaffixes\nduSuffix{#1}{#2}\fi%
+ }%
+}
+
+\newcommand\nduFormatValue@helper[3]{%
+ \ndu@if@depth@at@least{#1}{#2}{%
+ \nduFormatSegment{#1}{#2}{#3}%
+ }%
+}
+
+\newcommand\nduFormatValue@internal[8]{%
+ % #1 = unit group
+ % #2-8 = values
+ \edef\ndu@nextdelim{\pgfkeysvalueof{/ndu/unit groups/#1/segment separator}}%
+ \edef\ndu@delim{}%
+ \nduFormatValue@helper{#1}{0}{#2}%
+ \nduFormatValue@helper{#1}{1}{#3}%
+ \nduFormatValue@helper{#1}{2}{#4}%
+ \nduFormatValue@helper{#1}{3}{#5}%
+ \nduFormatValue@helper{#1}{4}{#6}%
+ \nduFormatValue@helper{#1}{5}{#7}%
+ \nduFormatValue@helper{#1}{6}{#8}%
+}
+
+\NewDocumentCommand\nduFormatValue@entry{ m > { \SplitArgument { 6 } { . } } m }{%
+ % #1 = unit group
+ % #2 = values joined by .
+ \ifndunormalize%
+ \stepcounter{autorepr}%
+ \nduConvertToRepr@internal{#1}{autorepr\arabic{autorepr}}#2%
+ \nduResult{#1}{autorepr\arabic{autorepr}}%
+ \else%
+ \nduFormatValue@internal{#1}#2%
+ \fi%
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newcommand*{\ndu@minwidthbox}[2]{%
+ \makebox[{\ifdim#1<\width\width\else#1\fi}][r]{%
+ #2%
+ }%
+}
+
+\newcommand\nduAlignedHeader@helper[2]{%
+ \ndu@if@depth@at@least{#1}{#2}{\ndu@minwidthbox{\pgfkeysvalueof{/ndu/cell width}}{%
+ \nduSymbol{#1}{#2}%
+ }}%
+}
+
+\newcommand\nduAlignedValue@helper[3]{%
+ \ndu@if@depth@at@least{#1}{#2}{\ndu@minwidthbox{\pgfkeysvalueof{/ndu/cell width}}{\nduFormatSegment{#1}{#2}{#3}}}%
+}
+
+\newcommand\nduAlignedValue@internal[8]{%
+ % #1 = unit group
+ % #2-8 = values
+ \nduAlignedValue@helper{#1}{0}{#2}%
+ \nduAlignedValue@helper{#1}{1}{#3}%
+ \nduAlignedValue@helper{#1}{2}{#4}%
+ \nduAlignedValue@helper{#1}{3}{#5}%
+ \nduAlignedValue@helper{#1}{4}{#6}%
+ \nduAlignedValue@helper{#1}{5}{#7}%
+ \nduAlignedValue@helper{#1}{6}{#8}%
+}
+
+\NewDocumentCommand\nduHeader{ m O{} }{%
+ \nduHeader@unitgroup{\nduAliasOrGroup{#1}}[#2]%
+}
+
+\NewDocumentCommand\nduHeader@unitgroup{ m O{} }{%
+ \nduset{unit groups/#1}%
+ \begingroup%
+ \nduset{unit groups/#1,#2}%
+ \nduAlignedHeader@helper{#1}{0}%
+ \nduAlignedHeader@helper{#1}{1}%
+ \nduAlignedHeader@helper{#1}{2}%
+ \nduAlignedHeader@helper{#1}{3}%
+ \nduAlignedHeader@helper{#1}{4}%
+ \nduAlignedHeader@helper{#1}{5}%
+ \nduAlignedHeader@helper{#1}{6}%
+ \endgroup%
+}
+
+\NewDocumentCommand\nduAlignedValue@entry{ m > { \SplitArgument { 6 } { . } } m }{%
+ % #1 = unit group
+ % #2 = values joined by .
+ \begingroup%
+ \nduset{show=values}%
+ \ifndunormalize%
+ \stepcounter{autorepr}%
+ \nduConvertToRepr@internal{#1}{autorepr\arabic{autorepr}}#2%
+ \nduResult{#1}[aligned]{autorepr\arabic{autorepr}}%
+ \else%
+ \nduAlignedValue@internal{#1}#2%
+ \fi%
+ \endgroup%
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\newcommand\ndu@val@or@zero[1]{%
+ \IfValueTF{#1}{%
+ \ifblank{#1}{%
+ 0%
+ }{%
+ #1%
+ }%
+ }{%
+ 0%
+ }%
+}
+
+\newcommand\nduConvertToRepr@helper[4]{%
+ % convert from overlying unit and add value
+ % #1 = unit group
+ % #2 = repr name
+ % #3 = segment
+ % #4 = value
+ \ndu@if@depth@at@least{#1}{#3}{%
+ \ifnum#3=0%
+ % no conversion at top level
+ \else%
+ \ifnduFactorDefined{#1}{#3}{%
+ %\show#3%
+ \csxdef{ndu@repr@#2}{\bigintcalcMul{\csuse{ndu@repr@#2}}{\nduFactor{#1}{#3}}}%
+ }{%
+ % there is no factor to the overlying unit
+ % instead attempt to skip ahead to the underlying unit?
+ \PackageError{non-decimal-units}{Cannot convert to representation because there is no conversion factor from \nduName{#1}{\the\numexpr#3-1\relax} to \nduName{#1}{#3}}{}%
+ }%
+ \fi%
+ \csxdef{ndu@repr@#2}{\bigintcalcAdd{\csuse{ndu@repr@#2}}{\ndu@val@or@zero{#4}}}%
+ \csxdef{ndu@repr@#2@unit}{\nduName{#1}{#3}}%
+ }%
+}
+
+\newcommand\nduConvertToRepr@internal[9]{%
+ % #1 = unit group
+ % #2 = repr name
+ % #3-9 = values
+ \csdef{ndu@repr@#2}{0}%
+ \nduConvertToRepr@helper{#1}{#2}{0}{#3}%
+ \nduConvertToRepr@helper{#1}{#2}{1}{#4}%
+ \nduConvertToRepr@helper{#1}{#2}{2}{#5}%
+ \nduConvertToRepr@helper{#1}{#2}{3}{#6}%
+ \nduConvertToRepr@helper{#1}{#2}{4}{#7}%
+ \nduConvertToRepr@helper{#1}{#2}{5}{#8}%
+ \nduConvertToRepr@helper{#1}{#2}{6}{#9}%
+}
+
+\NewDocumentCommand\nduConvertToRepr{ m O{} m > { \SplitArgument { 6 } { . } } m }{%
+ \nduset{unit groups/#1,#2}%
+ \nduConvertToRepr@internal{#1}{#3}#4%
+}
+
+\newcommand\nduFormatRepr@helper[3]{%
+ % V = mod(R, F)
+ % R = div(R - V, F)
+ % #1 = unit group
+ % #2 = repr name
+ % #3 = segment (F)
+ \ndu@if@depth@at@least{#1}{#3}{%
+ \ifnum#3=0%
+ \csxdef{ndu@repr@#2@result@#3}{\csuse{ndu@repr@#2}}%
+ \else%
+ \ifnduFactorDefined{#1}{#3}{%
+ \csxdef{ndu@repr@#2@result@#3}{\bigintcalcMod{\csuse{ndu@repr@#2}}{\nduFactor{#1}{#3}}}%
+ \csxdef{ndu@repr@#2}{\bigintcalcDiv{\bigintcalcSub{\csuse{ndu@repr@#2}}{\csuse{ndu@repr@#2@result@#3}}}{\nduFactor{#1}{#3}}}%
+ }{%
+ % there is no factor to the underlying unit
+ % instead attempt to skip ahead to the overlying unit?
+ \PackageError{non-decimal-units}{Cannot convert from representation because there is no conversion factor from \nduName{#1}{\the\numexpr#3-1\relax} to \nduName{#1}{#3}}{}%
+ }%
+ \fi%
+ }%
+}
+
+\NewDocumentCommand\nduResult{ m O{} m }{%
+ \nduResult@unitgroup{\nduAliasOrGroup{#1}}[#2]{#3}%
+}
+
+\NewDocumentCommand\nduResult@unitgroup{ m O{} m }{%
+ % #1 = unit group
+ % #2 = options
+ % #3 = repr name
+ \nduset{unit groups/#1}%
+ \csdef{ndu@repr@tmp #3}{\csuse{ndu@repr@#3}}%
+ \nduFormatRepr@helper{#1}{tmp #3}{6}%
+ \nduFormatRepr@helper{#1}{tmp #3}{5}%
+ \nduFormatRepr@helper{#1}{tmp #3}{4}%
+ \nduFormatRepr@helper{#1}{tmp #3}{3}%
+ \nduFormatRepr@helper{#1}{tmp #3}{2}%
+ \nduFormatRepr@helper{#1}{tmp #3}{1}%
+ \nduFormatRepr@helper{#1}{tmp #3}{0}%
+ \edef\ndu@nextdelim{\pgfkeysvalueof{/ndu/unit groups/#1/segment separator}}%
+ \edef\ndu@delim{}%
+ \begingroup%
+ \nduset{unit groups/#1,#2}%
+ \ifndualigned%
+ \nduset{show=values}%
+ \nduAlignedValue@helper{#1}{0}{\csuse{ndu@repr@tmp #3@result@0}}%
+ \nduAlignedValue@helper{#1}{1}{\csuse{ndu@repr@tmp #3@result@1}}%
+ \nduAlignedValue@helper{#1}{2}{\csuse{ndu@repr@tmp #3@result@2}}%
+ \nduAlignedValue@helper{#1}{3}{\csuse{ndu@repr@tmp #3@result@3}}%
+ \nduAlignedValue@helper{#1}{4}{\csuse{ndu@repr@tmp #3@result@4}}%
+ \nduAlignedValue@helper{#1}{5}{\csuse{ndu@repr@tmp #3@result@4}}%
+ \nduAlignedValue@helper{#1}{6}{\csuse{ndu@repr@tmp #3@result@4}}%
+ \else%
+ \nduFormatValue@helper{#1}{0}{\csuse{ndu@repr@tmp #3@result@0}}%
+ \nduFormatValue@helper{#1}{1}{\csuse{ndu@repr@tmp #3@result@1}}%
+ \nduFormatValue@helper{#1}{2}{\csuse{ndu@repr@tmp #3@result@2}}%
+ \nduFormatValue@helper{#1}{3}{\csuse{ndu@repr@tmp #3@result@3}}%
+ \nduFormatValue@helper{#1}{4}{\csuse{ndu@repr@tmp #3@result@4}}%
+ \nduFormatValue@helper{#1}{5}{\csuse{ndu@repr@tmp #3@result@4}}%
+ \nduFormatValue@helper{#1}{6}{\csuse{ndu@repr@tmp #3@result@4}}%
+ \fi%
+ \endgroup%
+}
+
+\newcommand\nduMath[4]{%
+ \nduMath@unitgroup{\nduAliasOrGroup{#1}}{#2}{#3}{#4}%
+}
+
+\newcommand\nduMath@unitgroup[4]{%
+ % #1 = unit group
+ % #2 = repr name
+ % #3 = operator
+ % #4 = value
+ \nduset{unit groups/#1}%
+ \ifcsvoid{ndu@repr@#2}{\csxdef{ndu@repr@#2}{0}}{}%
+ \ifthenelse{\equal{#3}{+}}{%
+ \nduConvertToRepr{#1}{tmp #2}{#4}%
+ \csxdef{ndu@repr@#2}{\bigintcalcAdd{\csuse{ndu@repr@#2}}{\csuse{ndu@repr@tmp #2}}}%
+ }{%
+ \ifthenelse{\equal{#3}{-}}{%
+ \nduConvertToRepr{#1}{tmp #2}{#4}%
+ \csxdef{ndu@repr@#2}{\bigintcalcSub{\csuse{ndu@repr@#2}}{\csuse{ndu@repr@tmp #2}}}%
+ }{%
+ \ifthenelse{\equal{#3}{*}}{%
+ \csxdef{ndu@repr@#2}{\bigintcalcMul{\csuse{ndu@repr@#2}}{#4}}%
+ }{%
+ \ifthenelse{\equal{#3}{/}}{%
+ \csxdef{ndu@repr@#2}{\bigintcalcDiv{\csuse{ndu@repr@#2}}{#4}}%
+ }{%
+ \PackageError{non-decimal-units}{Unrecognized math operator: #3}{Only + - * / are allowed.}%
+ }%
+ }%
+ }%
+ }%
+}
+
+%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
+
+\nduset{
+ options/.cd,
+ british/.code={\input{non-decimal-units.british}},
+ danish/.code={\input{non-decimal-units.danish}},
+}
+
+\ProcessPgfPackageOptions{/ndu/options}