% !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}

