texlive[62942] Master/texmf-dist: dataref (25mar22)

commits+karl at tug.org commits+karl at tug.org
Wed Apr 6 00:11:25 CEST 2022


Revision: 62942
          http://tug.org/svn/texlive?view=revision&revision=62942
Author:   karl
Date:     2022-04-06 00:11:24 +0200 (Wed, 06 Apr 2022)
Log Message:
-----------
dataref (25mar22)

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.pdf
    trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.tex
    trunk/Master/texmf-dist/tex/latex/dataref/dataref.sty

Modified: trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.pdf
===================================================================
(Binary files differ)

Modified: trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.tex	2022-04-05 22:11:06 UTC (rev 62941)
+++ trunk/Master/texmf-dist/doc/latex/dataref/dataref-doc.tex	2022-04-05 22:11:24 UTC (rev 62942)
@@ -15,7 +15,7 @@
 % This work consists of the files dataref.tex and dataref.sty
 
 \documentclass{ltxdoc}
-\usepackage[usagereport]{dataref}[2017/01/06]
+\usepackage[usagereport]{dataref}[2019/02/01]
 
 \EnableCrossrefs
 \CodelineIndex
@@ -83,6 +83,7 @@
    Right brace   \}     Tilde         \~}
 
 
+ \changes{v0.7}{2019/02/15}{Fix math backends, \cmd{\drefinput}}
  \changes{v0.6}{2016/11/15}{Units, Unit Scaling, general overhaul}
  \changes{v0.4}{2015/04/21}{Remove Spurious Whitespaces}
  \changes{v0.1}{2013/12/06}{Initial version}
@@ -296,12 +297,13 @@
 
 \Macro{\drefinput[\meta{prefix}]\{\meta{filename}\}}
 
-Uses \cmd{\input} to read the file. During the processing of this file
-\option{prefix} is set to the given value. This is useful to include
-several files that resulted from different experiments but include
-equal datapoint keys.
+Reads in the given \TeX/dataref file with the given key prefix. Therefore, all included \cmd{\drefset} commands are define their keys with the given prefix.
+This is useful to include several files that resulted from different experiments but include equal datapoint keys.
 
+This command uses \cmd{\subimport} from the \texttt{import} package to read the file.
+Hence, if there is an \cmd{\drefinput} in an included file, it search its filename relative to its own directory.\footnote{In former versions, \cmd{\drefinput} relied directly on \cmd{\input} and, therefore, the filename was interpreted relative to the root file.}.
 
+
 \subsection{Referencing Datapoints}
 
 

Modified: trunk/Master/texmf-dist/tex/latex/dataref/dataref.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/dataref/dataref.sty	2022-04-05 22:11:06 UTC (rev 62941)
+++ trunk/Master/texmf-dist/tex/latex/dataref/dataref.sty	2022-04-05 22:11:24 UTC (rev 62942)
@@ -1,4 +1,4 @@
-%%  Copyright 2013-2017 Christian Dietrich
+%%  Copyright 2013-2022 Christian Dietrich
 %%
 %% This work may be distributed and/or modified under the
 %% conditions of the LaTeX Project Public License, either version 1.3
@@ -15,7 +15,7 @@
 %% This work consists of the files dataref.dtx and dataref.ins
 %% and the derived file dataref.sty.
 \NeedsTeXFormat{LaTeX2e}[1999/12/01]
-\ProvidesPackage{dataref}[2017/01/06 v0.6 dataref]
+\ProvidesPackage{dataref}[2022/03/25 v0.7 dataref]
 
 \ifx\drefloaded\undefined
   \let\drefloaded=\relax
@@ -33,7 +33,10 @@
 \RequirePackage{iftex}
 \RequirePackage{kvoptions}
 \RequirePackage{etoolbox}
+\RequirePackage{import}
 
+
+
 \SetupKeyvalOptions{
   family=dref,
   prefix=dref@
@@ -49,11 +52,14 @@
 
 % Load & Store Layer
 
+% \dref at xdef is only used in \dref at set
+\let\dref at xdef=\xdef % \dref at xdef is overridden in case of listadd
+
 \def\dref at set#1#2#3{%
   \edef\dref at set@path{#3}%
   \edef\dref at set@value{#2}%
   \expandafter\pgfkeys at temptoks\expandafter{\dref at set@value}%
-  \expandafter\xdef%
+  \expandafter\dref at xdef%
       \csname pgfk@\dref at datapath\dref at set@path\endcsname%
   {\the\pgfkeys at temptoks}%
   % Setting the Unit is a little bit more tricky
@@ -85,6 +91,16 @@
   }%
 }
 
+% List Looping. We define this upfront, as we have to build a pgfk@
+% name here. The @loop at do macro is a helper to invoke list/do with the
+% list element. dref at loop uses the etoolbox for looping feature.
+\def\dref at loop@do#1{\drefkeys{list/do={#1}}}
+\def\dref at loop#1{%
+  \forlistcsloop{\dref at loop@do}{%
+      pgfk@\dref at datapath #1%
+  }%
+}
+
 \def\drefifdefined#1{%
   \pgfkeysifdefined{\dref at datapath\drefprefix #1}%{then}{else}
 }
@@ -107,7 +123,7 @@
   .search also={/pgf/number format},
   % The @init action is used to initialize all other actions
   @[/.code={\begingroup%
-    \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}% No more dimensions too large
+    % /pgf/fpu: \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}% No more dimensions too large
     \def\drefunit{}% At first we are unitless
     \aftergroup\edef%
     \aftergroup\drefresult%
@@ -186,7 +202,13 @@
         \aftergroup\drefresult%
         \aftergroup}}
   },
-  %
+  % List Keys
+  list/append/.code={\let\dref at xdef=\listxadd},
+  % Apply loop/do for every item
+  list/loop/.code={%
+    \dref at loop{\drefprefix #1}
+  },
+  % Various Keys
   debug/.is if=dref at debug,
   ignoremissing/.is if=dref at ignoremissing,
   defaultvalue/.store in=\dref at defaultvalue,
@@ -300,11 +322,27 @@
   \drefkeys{@[, @init, value={#3}, #1, save={#2}, @set, @]}%
 }
 
+\def\dref at splitpath@helper#1/#2\@nnil{%
+  \ifx&#2&% Basename found
+     \def\dref at basename{#1}\let\@next\relax%
+  \else% Another Dirname
+     \edef\dref at dirname{\dref at dirname #1/}%
+     \def\@next{\dref at splitpath@helper#2\@nnil}%
+  \fi%
+  \@next%
+}
+\def\dref at splitpath#1{%
+   % Splits path into \dref at dirname and \dref at basename
+   \def\dref at dirname{}%
+   \dref at splitpath@helper #1/\@nnil%
+}
+
 \newcommand{\drefinput}[2][]{%
-  \begingroup
-  \drefkeys{prefix/.append={#1}}
-  \input{data/#2}
-  \endgroup
+  \begingroup%
+  \drefkeys{prefix/.append={#1}}%
+  \dref at splitpath{#2}%
+  \subimport{\dref at dirname}{\dref at basename}%
+  \endgroup%
 }
 
 
@@ -460,6 +498,51 @@
 \def\dref at parser@end#1#2\@nnil{}
 \csdef{dref at parser@@}{\dref at parser@end}
 
+\newif\ifdrefbadmath
+\newif\ifdref at xfp
+\IfFileExists{xfp.sty}{\dref at xfptrue}{\dref at xfpfalse}
+
+% For LuaLaTeX: use the lua math engine
+\ifLuaTeX
+  \drefbadmathfalse%
+  \def\drefmathparse#1{%
+    \edef\pgfmathresult{\directlua{%
+      abs=math.abs ;
+      result = (#1);
+      if result == false then
+         tex.print(0);
+      elseif result == true then
+         tex.print(1);
+      else
+         tex.print(string.format(string.char(37).."s", result))
+      end
+    }}}%
+% We use the FP Library of expl3. This seems to work better for
+% floating numbers and for integers
+\else \ifdref at xfp
+  \RequirePackage{xfp}
+  \drefbadmathfalse%
+  \ExplSyntaxOn% we want to do tests % Usepackage xfp
+  \cs_set_eq:NN \dref at fpeval \fp_eval:n%
+  \ExplSyntaxOff%
+  \def\drefmathparse#1{%
+    \edef\pgfmathresult{\dref at fpeval{#1}}%
+  }%
+%% Fallback to PGFMath
+\else
+  \drefbadmathtrue%
+  \def\drefmathparse#1{%
+    \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}%
+    \pgfmathparse{#1}%
+  }%
+  \dref at warning{****************************************************}%
+  \dref at warning{Dataref will use bad math library (/pgf/fpu). Be aware%
+  of floating point rounding errors}%
+  \dref at warning{****************************************************}%
+  \fi
+\fi
+
+
 \drefkeys{
   @init/.append style={%
     @calc/.code={},%
@@ -467,19 +550,20 @@
   @calc pgf/.style={
     @calc/.append code={%
       \dref at parser{#1}{\dref at calc@@ready}%
-      \pgfmathparse{\dref at calc@@ready}%
+      \drefmathparse{\dref at calc@@ready}%
       \dref at debug{#1 -> \dref at calc@@ready = \pgfmathresult}%
       \edef\drefresult{\pgfmathresult}%
-     }
+    }
   }
 }
 
+
 \protected\def\drefcalc{\@ifstar\drefcalc at starred\drefcalc at unstarred}
 \newcommand{\drefcalc at unstarred}[2][]{% Unstarred
   \drefkeys{@[, at init, print=default, @calc pgf={#2}, #1, @calc, @print, @set,%
     @annotate={\textbackslash drefcalc[#1]\{#2\}},@]}%
 }
-\newcommand{\drefcalc at starred}[2][]{ % Starred
+\newcommand{\drefcalc at starred}[2][]{% Starred
   \drefkeys{@[, at init, @calc pgf={#2}, #1, @calc, @set,%
     @annotate={\textbackslash \drefcalc*[#1]\{#2\}},@]%
   }%
@@ -722,7 +806,7 @@
       \else%
         \dref at error{Assertion failed: #1}%
         \fi%
-     \else
+     \else%
        \dref at warning{Assertion holds: #1}%
      \fi%
   \endgroup%
@@ -738,7 +822,7 @@
     @calc pgf={100 * (\drefresult)},
   },
   percent of/.style={
-    factor of=#1, percent,
+    factor of={#1}, percent,
     @calc/.append code={\def\drefunit{}},
   },
   scale by/.style={
@@ -904,10 +988,10 @@
       \def\do####1{%
         \edef\dref at unit@key{/dref/units/\expandafter\detokenize\expandafter{\drefunit} to \detokenize{####1}}%
         \pgfkeys{\dref at unit@key/.get=\dref at unit@factor}%
-        \pgfmathparse{\@@score{\drefunit at bestvalue} < \@@score{\drefresult \dref at unit@factor}}%
+        \drefmathparse{\@@score{\drefunit at bestvalue} < \@@score{\drefresult \dref at unit@factor}}%
         %\typeout{\drefunit \pgfmathresult \detokenize{####1}}%
         \ifdim\pgfmathresult pt=1.0 pt%
-          \pgfmathparse{(\drefresult) \dref at unit@factor}%
+          \drefmathparse{(\drefresult) \dref at unit@factor}%
           \edef\drefunit at bestvalue{\pgfmathresult}%
           \def\drefunit at best{####1}%
            %\typeout{\expandafter\detokenize\expandafter{\drefunit} to



More information about the tex-live-commits mailing list.