summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/readarray/readarray.sty
diff options
context:
space:
mode:
Diffstat (limited to 'macros/latex/contrib/readarray/readarray.sty')
-rw-r--r--macros/latex/contrib/readarray/readarray.sty115
1 files changed, 63 insertions, 52 deletions
diff --git a/macros/latex/contrib/readarray/readarray.sty b/macros/latex/contrib/readarray/readarray.sty
index fb6c2ba90d..912d43c48b 100644
--- a/macros/latex/contrib/readarray/readarray.sty
+++ b/macros/latex/contrib/readarray/readarray.sty
@@ -1,5 +1,5 @@
-\def\readarrayPackageVersion{3.0}
-\def\readarrayPackageDate{2021/08/08}
+\def\readarrayPackageVersion{3.1}
+\def\readarrayPackageDate{2021/09/17}
\ProvidesPackage{readarray}
[\readarrayPackageDate\ \readarrayPackageVersion\ %
Routines for inputting 2D and 3D array data and recalling it on an
@@ -17,25 +17,6 @@ element-by-element basis.]
%
% The Current Maintainer of this work is Steven B. Segletes.
%
-% Revisions:
-% v1.01 -Documentation revision
-% v1.1 -Added \csname record\roman{@row}\endcsname to \readdef
-% v1.2 -Corrected the [truncated] LPPL license info
-% -Added \arrayij and \arrayijk, which can be put into \edef
-% -Used \romannumeral in preference to \roman{}, when possible,
-% to avoid unnecessary use of counters.
-% v1.3 -Moved \newread outside of \readdef, so as not to exhaust the
-% 16 allotted file streams (Thanks to Ken Kubota for the tip).
-% v2.0 -Converted parsing to listofitems package. This allows for
-% ANY parsing character or combination of characters (via logical OR).
-% -Replaced all \protected@edef's with appropriately expanded \def's.
-% -Use listofitems package in preference to \getargsC.
-% -Deprecated \Arrayijk, \arrayijk, \Arrayij, & \arrayij. Direct
-% access now preferred, e.g., \xyz[2,3,1].
-% -Deprecated most other commands in favor of a more natural syntax.
-% v3.0 (2021-08-05)
-% -Added features: \setvalue, \initarray, \mergearray, \typesetarray
-% -Allowed for \readarrayendlinechar to be set other than 9
\RequirePackage{forloop}
\RequirePackage{listofitems}[2016-10-22]
%
@@ -50,6 +31,8 @@ element-by-element basis.]
\newtoks\@arrayident@toks
\newread\rdar@file
\newcount\readarrayendlinechar
+\newif\ifignoreblankreadarrayrecords
+\ignoreblankreadarrayrecordsfalse
\edef\readarraybackslash{\expandafter\@firstoftwo\string\\}
%
\newcommand\readdef[2]{\@readdef{#1}{#2}{ArrayRecord}}
@@ -123,39 +106,51 @@ element-by-element basis.]
\def\@readdef#1#2#3{%
\clear@array{#3}%
\edef\former@recordcount{\csname #3CELLS\endcsname}%
+ \def\nrows{0}%
\def\first@row{T}%
- \def\first@plane{T}%
+ \def\first@plane{F}%
\catcode\endlinechar=\readarrayendlinechar\relax %
\def#2{}%
\setcounter{@record}{0}%
\openin\rdar@file=#1%
+ \ifignoreblankreadarrayrecords
+ \def\rdar@iftest{\rdar@record\empty}\else\def\rdar@iftest{01}\fi
\loop\unless\ifeof\rdar@file%
- \read\rdar@file to\rdar@fileline % Reads file line into \rdar@fileline%
- \addtocounter{@record}{1}%
- \expandafter\g@addto@macro\expandafter#2\expandafter{\rdar@fileline}%
- \ifx\rdar@fileline\empty\else\expandafter\g@addto@macro%
- \expandafter#2\expandafter{\read@array@sepchar}\fi%
- \if T\first@row\read@array{#2}\setcounter{@col}{\numexpr(\Arg@listlen-1)}%
- \edef\ncols{\arabic{@col}}\def\first@row{F}\setcounter{@row}{1}%
- \else%
- \if T\first@plane%
- \ifx\rdar@fileline\empty
- \edef\nrows{\arabic{@row}}\def\first@plane{F}%
+ \read\rdar@file to\rdar@record % Reads record into \rdar@record%
+ \expandafter\ifx\rdar@iftest\else
+ \stepcounter{@record}%
+ \expandafter\g@addto@macro\expandafter#2\expandafter{\rdar@record}%
+ \ifx\rdar@record\empty\else\expandafter
+ \g@addto@macro\expandafter#2\expandafter{\read@array@sepchar}%
+ \if T\first@row
+ \read@array{#2}%
+ \setcounter{@col}{\numexpr(\Arg@listlen-1)}%
+ \edef\ncols{\arabic{@col}}%
+ \def\first@row{F}%
+ \setcounter{@row}{0}%
+ \def\first@plane{T}%
+ \fi
+ \fi
+ \if T\first@plane
+ \ifx\rdar@record\empty
+ \edef\nrows{\arabic{@row}}%
+ \def\first@plane{F}%
\else
- \addtocounter{@row}{1}%
+ \stepcounter{@row}%
\fi
- \fi%
- \fi%
- \def\record@name{\csname #3[\the@record]\endcsname}%
- \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter%
- \expandafter\def\expandafter\record@name\expandafter{\rdar@fileline}%
- \repeat%
+ \fi
+ \def\record@name{\csname #3[\the@record]\endcsname}%
+ \expandafter\expandafter\expandafter\expandafter\expandafter\expandafter
+ \expandafter\def\expandafter\record@name\expandafter{\rdar@record}%
+ \fi
+ \repeat
+ \ifnum\nrows=0 \edef\nrows{\arabic{@row}}\fi
\edef\nrecords{\arabic{@record}}%
\expandafter\edef\csname #3PLANES\endcsname{0}%
\expandafter\edef\csname #3ROWS\endcsname{\nrecords}%
\expandafter\edef\csname #3COLS\endcsname{0}%
\expandafter\edef\csname #3CELLS\endcsname{\nrecords}%
- \closein\rdar@file%
+ \closein\rdar@file
\catcode\endlinechar=5 %
\define@rootmacro{#3}%
}
@@ -252,7 +247,7 @@ element-by-element basis.]
}
%
\def\clear@array#1{%
- \ifcsname #1\endcsname%
+ \ifcsname #1ROWS\endcsname%
\forloop{@row}{1}{\value{@row}<\numexpr\csname #1ROWS\endcsname+1}{%
\ifnum\csname #1COLS\endcsname=0\relax%
\expandafter\let\csname #1[\the@row]\endcsname\undefined%
@@ -494,16 +489,32 @@ element-by-element basis.]
\endinput
-
-
-
-
-
-
-
-
-
-
+% Revisions:
+% v1.0 -Initial release.
+% v1.01 -Documentation revision.
+% v1.1 -Added \csname record\roman{@row}\endcsname to \readdef.
+% v1.2 -Corrected the [truncated] LPPL license info.
+% -Added \arrayij and \arrayijk, which can be put into \edef.
+% -Used \romannumeral in preference to \roman{}, when possible,
+% to avoid unnecessary use of counters.
+% v1.3 -Moved \newread outside of \readdef, so as not to exhaust the
+% 16 allotted file streams (Thanks to Ken Kubota for the tip).
+% v2.0 -Converted parsing to listofitems package. This allows for
+% ANY parsing character or combination of characters (via logical OR).
+% -Replaced all \protected@edef's with appropriately expanded \def's.
+% -Use listofitems package in preference to \getargsC.
+% -Deprecated \Arrayijk, \arrayijk, \Arrayij, & \arrayij. Direct
+% access now preferred, e.g., \xyz[2,3,1].
+% -Deprecated most other commands in favor of a more natural syntax.
+% v3.0 (2021-08-05)
+% -Added features: \setvalue, \initarray, \mergearray, \typesetarray.
+% -Allowed for \readarrayendlinechar to be set other than 9.
+% v3.1 (2021-09-17)
+% -Bug fix to not break if first line of file subject to \readdef
+% is blank/comment line.
+% -Introduce \ifignoreblankreadarrayrecords
+% -Bug fix in \clear@array, if selected array name is defined,
+% but not defined as an array.