From c441617a2cd82c0b0907d0106dbf047987ffd97d Mon Sep 17 00:00:00 2001 From: Norbert Preining Date: Sat, 26 Mar 2022 03:00:32 +0000 Subject: CTAN sync 202203260300 --- macros/latex/contrib/dataref/doc/dataref-doc.pdf | Bin 238060 -> 260049 bytes macros/latex/contrib/dataref/doc/dataref-doc.tex | 12 ++- macros/latex/contrib/dataref/tex/dataref.sty | 116 +++++++++++++++++++---- 3 files changed, 107 insertions(+), 21 deletions(-) (limited to 'macros/latex/contrib/dataref') diff --git a/macros/latex/contrib/dataref/doc/dataref-doc.pdf b/macros/latex/contrib/dataref/doc/dataref-doc.pdf index ec64e4c97a..6e1da0af9a 100644 Binary files a/macros/latex/contrib/dataref/doc/dataref-doc.pdf and b/macros/latex/contrib/dataref/doc/dataref-doc.pdf differ diff --git a/macros/latex/contrib/dataref/doc/dataref-doc.tex b/macros/latex/contrib/dataref/doc/dataref-doc.tex index d50200f57a..8041e40e3a 100644 --- a/macros/latex/contrib/dataref/doc/dataref-doc.tex +++ b/macros/latex/contrib/dataref/doc/dataref-doc.tex @@ -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 @@ include all dead mice before.} 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,10 +297,11 @@ It is a value-typed PGF key, so operations like \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} diff --git a/macros/latex/contrib/dataref/tex/dataref.sty b/macros/latex/contrib/dataref/tex/dataref.sty index bb6f013032..2eb4931c17 100644 --- a/macros/latex/contrib/dataref/tex/dataref.sty +++ b/macros/latex/contrib/dataref/tex/dataref.sty @@ -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,6 +33,9 @@ \RequirePackage{iftex} \RequirePackage{kvoptions} \RequirePackage{etoolbox} +\RequirePackage{import} + + \SetupKeyvalOptions{ family=dref, @@ -49,11 +52,14 @@ % Load & Store Layer +% \dref@xdef is only used in \dref@set +\let\dref@xdef=\xdef % \dref@xdef is overridden in case of listadd + \def\dref@set#1#2#3{% \edef\dref@set@path{#3}% \edef\dref@set@value{#2}% \expandafter\pgfkeys@temptoks\expandafter{\dref@set@value}% - \expandafter\xdef% + \expandafter\dref@xdef% \csname pgfk@\dref@datapath\dref@set@path\endcsname% {\the\pgfkeys@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@do macro is a helper to invoke list/do with the +% list element. dref@loop uses the etoolbox for looping feature. +\def\dref@loop@do#1{\drefkeys{list/do={#1}}} +\def\dref@loop#1{% + \forlistcsloop{\dref@loop@do}{% + pgfk@\dref@datapath #1% + }% +} + \def\drefifdefined#1{% \pgfkeysifdefined{\dref@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@xdef=\listxadd}, + % Apply loop/do for every item + list/loop/.code={% + \dref@loop{\drefprefix #1} + }, + % Various Keys debug/.is if=dref@debug, ignoremissing/.is if=dref@ignoremissing, defaultvalue/.store in=\dref@defaultvalue, @@ -300,11 +322,27 @@ \drefkeys{@[, @init, value={#3}, #1, save={#2}, @set, @]}% } +\def\dref@splitpath@helper#1/#2\@nnil{% + \ifx&% Basename found + \def\dref@basename{#1}\let\@next\relax% + \else% Another Dirname + \edef\dref@dirname{\dref@dirname #1/}% + \def\@next{\dref@splitpath@helper#2\@nnil}% + \fi% + \@next% +} +\def\dref@splitpath#1{% + % Splits path into \dref@dirname and \dref@basename + \def\dref@dirname{}% + \dref@splitpath@helper #1/\@nnil% +} + \newcommand{\drefinput}[2][]{% - \begingroup - \drefkeys{prefix/.append={#1}} - \input{data/#2} - \endgroup + \begingroup% + \drefkeys{prefix/.append={#1}}% + \dref@splitpath{#2}% + \subimport{\dref@dirname}{\dref@basename}% + \endgroup% } @@ -460,6 +498,51 @@ \def\dref@parser@end#1#2\@nnil{} \csdef{dref@parser@@}{\dref@parser@end} +\newif\ifdrefbadmath +\newif\ifdref@xfp +\IfFileExists{xfp.sty}{\dref@xfptrue}{\dref@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@xfp + \RequirePackage{xfp} + \drefbadmathfalse% + \ExplSyntaxOn% we want to do tests % Usepackage xfp + \cs_set_eq:NN \dref@fpeval \fp_eval:n% + \ExplSyntaxOff% + \def\drefmathparse#1{% + \edef\pgfmathresult{\dref@fpeval{#1}}% + }% +%% Fallback to PGFMath +\else + \drefbadmathtrue% + \def\drefmathparse#1{% + \pgfkeys{/pgf/fpu,/pgf/fpu/output format=fixed}% + \pgfmathparse{#1}% + }% + \dref@warning{****************************************************}% + \dref@warning{Dataref will use bad math library (/pgf/fpu). Be aware% + of floating point rounding errors}% + \dref@warning{****************************************************}% + \fi +\fi + + \drefkeys{ @init/.append style={% @calc/.code={},% @@ -467,19 +550,20 @@ @calc pgf/.style={ @calc/.append code={% \dref@parser{#1}{\dref@calc@@ready}% - \pgfmathparse{\dref@calc@@ready}% + \drefmathparse{\dref@calc@@ready}% \dref@debug{#1 -> \dref@calc@@ready = \pgfmathresult}% \edef\drefresult{\pgfmathresult}% - } + } } } + \protected\def\drefcalc{\@ifstar\drefcalc@starred\drefcalc@unstarred} \newcommand{\drefcalc@unstarred}[2][]{% Unstarred \drefkeys{@[,@init, print=default, @calc pgf={#2}, #1, @calc, @print, @set,% @annotate={\textbackslash drefcalc[#1]\{#2\}},@]}% } -\newcommand{\drefcalc@starred}[2][]{ % Starred +\newcommand{\drefcalc@starred}[2][]{% Starred \drefkeys{@[,@init, @calc pgf={#2}, #1, @calc, @set,% @annotate={\textbackslash \drefcalc*[#1]\{#2\}},@]% }% @@ -722,7 +806,7 @@ \else% \dref@error{Assertion failed: #1}% \fi% - \else + \else% \dref@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@unit@key{/dref/units/\expandafter\detokenize\expandafter{\drefunit} to \detokenize{####1}}% \pgfkeys{\dref@unit@key/.get=\dref@unit@factor}% - \pgfmathparse{\@@score{\drefunit@bestvalue} < \@@score{\drefresult \dref@unit@factor}}% + \drefmathparse{\@@score{\drefunit@bestvalue} < \@@score{\drefresult \dref@unit@factor}}% %\typeout{\drefunit \pgfmathresult \detokenize{####1}}% \ifdim\pgfmathresult pt=1.0 pt% - \pgfmathparse{(\drefresult) \dref@unit@factor}% + \drefmathparse{(\drefresult) \dref@unit@factor}% \edef\drefunit@bestvalue{\pgfmathresult}% \def\drefunit@best{####1}% %\typeout{\expandafter\detokenize\expandafter{\drefunit} to -- cgit v1.2.3