summaryrefslogtreecommitdiff
path: root/macros/generic/texdimens/texdimens.tex
diff options
context:
space:
mode:
Diffstat (limited to 'macros/generic/texdimens/texdimens.tex')
-rw-r--r--macros/generic/texdimens/texdimens.tex49
1 files changed, 47 insertions, 2 deletions
diff --git a/macros/generic/texdimens/texdimens.tex b/macros/generic/texdimens/texdimens.tex
index 8103bef1cd..d8bf99e0bc 100644
--- a/macros/generic/texdimens/texdimens.tex
+++ b/macros/generic/texdimens/texdimens.tex
@@ -1,6 +1,6 @@
% This is file texdimens.tex, part of texdimens package, which
% is distributed under the LPPL 1.3c. Copyright (c) 2021 Jean-François Burnol
-% 2021/07/21 v0.9
+% 2021/11/02 v0.99
% All macros from 0.9delta release have changed names: \texdimen prefix
% has replaced \texdimin.
\edef\texdimensendinput{\endlinechar\the\endlinechar\catcode`\noexpand _=\the\catcode`\_\relax\noexpand\endinput}%
@@ -10,6 +10,12 @@
% Mathematics ("down" and "up" macros)
% ===========
%
+% In the entire discussion here, "uu" stands for some core unit,
+% or some unit corresponding to a dimension > 1pt. For the case
+% of a unit corresponding to a dimension < 1pt, i.e. to
+% \texdimenwithunit macro added at 0.99, refer to the
+% comments of issue #2 on the tracker site.
+%
% Is T sp attainable from unit "uu"?.
% If not, what is largest dimension < Tsp which is attainable?
% Here we suppose T>0.
@@ -325,7 +331,7 @@
% there is ample room for 7227k+1 using \numexpr.
%
% But this step, as well as initial step to get kmax will require to separate
-% hangdling of negative input from positive one.
+% handling of negative input from positive one.
%
% Alternative
% -----------
@@ -368,4 +374,43 @@
\def\texdimenbothsp_neg#1#2-#3;{#1-\numexpr(((2*#3-3612)/7227)*7227+1)/2-1\relax\relax}%
%
\let\texdimenbothcminsp\texdimenbothincmsp
+% (\texdimenwithunit, added at 0.99)
+% Mathematics
+% ===========
+%
+% <comments to be added> (see discussion #2)
+%
+% Implementation
+% ==============
+%
+% <comments to be added> (see discussion #2)
+% #2 is unit, assumed positive. We will need to branch whether
+% #2 is <1pt or >1pt.
+% pre-multiplication of #1 by 2 here
+\def\texdimenwithunit#1#2{\expandafter\texdimenwithunit_
+ \the\numexpr\dimexpr#2\expandafter;\the\numexpr2*\dimexpr#1;}%
+\def\texdimenwithunit_#1;#2{\ifnum#1>65535
+ \expandafter\texdimenwithunit_A\else\expandafter\texdimenwithunit_B\fi
+ #2#1;%
+}%
+% unit>=1pt, handle this as for bp
+\def\texdimenwithunit_A#1#2;#3;{\expandafter\texdimenstrippt
+ \the\dimexpr\numexpr(#1#3+\if-#1-\fi1)*32768/#2sp\relax
+}%
+% unit<1pt
+% if dim1<0, simply negate result for dim1>0 as it can not be 0.0
+\def\texdimenwithunit_B#1{\if-#1\expandafter\texdimenwithunit_Bneg\fi\texdimenwithunit_Ba#1}%
+\def\texdimenwithunit_Ba#1#2;#3;{\expandafter\texdimenwithunit_Bb\the\numexpr#1#3+1;#2;}%
+\def\texdimenwithunit_Bb#1;#2;{\expandafter\texdimenwithunit_Bc\the\numexpr(#1-#2)/(2*#2);#1;#2;}%
+% not adding f-expandability slight overhead here
+% oh well, let's do \the\numexpr..+0.ddddd which does the trick and allows
+% recycling strippt here with no need of another utility
+% (thinking about it it means we could do this for unit >1pt as this method
+% works even for \the\dimexpr producing 1pt or more... (as TeX outputs 1.0pt, not 1pt
+% so the dot remains to stop the \numexpr scan)
+\def\texdimenwithunit_Bc#1;#2;#3;{\the\numexpr#1+\expandafter\texdimenstrippt
+ \the\dimexpr\numexpr(#2-#1*2*#3)*32768/#3sp\relax}%
+% definitly not caring about f-expandability here
+\def\texdimenwithunit_Bneg\texdimenwithunit_Ba-#1;#2;%
+ {-\expandafter\texdimenwithunit_Bb\the\numexpr#2+1;#1;}%
\texdimensendinput