1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
|
% ARRAY STRUCTURE - arrayjobx.sty - Version 1.04 - 05/03/10
%
% By Zhuhan Jiang (01/05/95), extracted from formlett.sty
% (see CTAN/macros/generic/formlett.sty from line 344 to line 483)
%
% This program can be redistributed and/or modified under the terms
% of the LaTeX Project Public License distributed from CTAN archives
% in directory macros/latex/base/lppl.txt
%
% * 01/05/95 - Version 1.00
% + Original version
% * 12/21/99 - Version 1.01
% + Spurious blanks removed in \read@array and \get@max@count
% (reported by Antonio Leitao <aml@gia.ist.utl.pt>
% and Denis Girou <Denis.Girou@idris.fr>)
% * 04/05/00 - Version 1.02
% + Add the \ifexpandarrayelement macro to allow to evaluate
% or not the content to put as an element of the array
% (from Denis Girou <Denis.Girou@idris.fr>)
% + Put this package under the terms of the LaTeX Project
% Public License
% * 05/03/00 - Version 1.03
% + Add a \ProvidesPackage macro when LaTeX is used
% (according to the example given by Bernd Raichle
% <raichle@Informatik.Uni-Stuttgart.DE>)
% * 05/03/10 - Version 1.04
% + Change the name of the macro \array to \arrayx
% to avoid conflict with macros in the amsmath package.
% Change suggested by Michael Sharpe (msharpe at ucsd.edu)
%
%
% \newarray\ARRAYNAME
% \delarray\ARRAYNAME
%
% \ARRAYNAME(A1,..,An)={T}
% \readarray{ARRAYNAME}{ B1 & B2 & ... & Bm }
% \dataheight
%
% \data(A1,...,An)=\data( A1 + (A2-1)*\dataheight +
% ... + (An-1)*\dataheight^{n-1} )
% if \normalindextrue
% =\data( An + (An-1 -1)*\dataheight +
% ... + (A1-1)*\dataheight^{n-1} )
% if \normalindexfalse
%
% \checkARRAYNAME(A1,..,An)
% \ifemptydata valid when \checkARRAYNAME is just executed
% \cachedata: keeps the data of \ARRAYNAME(m)
% when \checkARRAYNAME(m) is executed
%
% OTHERS:
% save to array: \arrayx{n}(m)={T}
% get from array: \arrayx{n}(m)
% clear element: \clrarray{n}(m)
% test element: \testarray{n}(m)
% macro save to \temp@macro
%
%
% e.g.
%
% \newarray\Table
% \readarray{Table}{one&two& \unknownmacro && &six}
% \Table(7)={seven}
% \dataheight=0 % or 1 or < 0
% \Table(7) = \Table(2,6,1) % 7=1+(2-1)+(6-1)+(1-1)
% \normalindexfalse
% \dataheight=3
% \Table(7) = \Table(1,7) = \Table(3,1)
% \normalindextrue
% \Table(7) = \Table(7,1) = \Table(1,3)
%
% \checkTable(4) \ifemptydata (4)=empty \fi
% \checkTable(5) \ifemptydata\else (5)=nonempty \fi
% \ifx\cachedata\space ={\tt <space>}\fi
% \checkTable(1000) \ifemptydata (1000)=empty \fi
%
% \delarray\Table
%
%
\begingroup\expandafter\expandafter\expandafter\endgroup
\expandafter\ifx\csname ProvidesPackage\endcsname\relax%
\else
\ProvidesPackage{arrayjobx}[2010/05/03 v1.04 Array management]
\fi
%
\xdef\EntryArrayJob{\the\catcode`\@}\catcode`\@=11\relax
\newif\ifemptydata \newcount\dataheight
\newif\ifnormalindex \normalindexfalse
%
\newcount\array@width \newcount\index@count \newcount\index@total
\newif\ifone@VEC \newif\if@rev@index
\newtoks\temp@toks \newcount\temp@count
\newcount\temp@@count \newcount\temp@@@count
%
\newif\ifexpandarrayelement
%
\long\def\assign@VEC#1(#2)=#3{\temp@count=#2 \relax
\get@max@count{total@#1}\temp@count
\ifexpandarrayelement
\expandafter\xdef\csname#1#2\string~\endcsname{#3}%
\else
\expandafter\gdef\csname#1#2\string~\endcsname{#3}%
\fi}
\def\get@VEC#1(#2){\csname#1#2\string~\endcsname}
\def\clrarray#1(#2){%
\global\expandafter\let\csname#1#2\string~\endcsname=\undefined@}
%
\def\testarray#1(#2){%
\expandafter\let\expandafter\temp@macro\csname#1#2\string~\endcsname
\ifx\temp@macro\relax \def\temp@macro{}\fi}%
%
\def\arrayx#1(#2){\def\check@VEC{%
\ifx=\next@VEC \def\full@VEC####1{\assign@VEC#1(#2)####1}%
\else \def\full@VEC{\get@VEC#1(#2)}\fi \full@VEC}%check@VEC
\futurelet\next@VEC\check@VEC}
%
\def\get@index(#1)#2\safty@mark{\one@VEC#2,\safty@mark
\def\next@@VEC{#1}\ifx\next@@VEC\empty\def\next@@VEC{\array@width}\fi
\if@rev@index
{\temp@count=1 \advance\index@count1 \relax
\ifnum\index@count<\index@total
\loop \multiply\temp@count \next@@VEC
\advance\index@count-1 \relax
\ifnum\index@count>0 \repeat
\fi \global\temp@@count\temp@count }%
\else \multiply\temp@@count \next@@VEC \fi
\ifnum\temp@@count=0 \temp@@count=1 \relax \fi
\advance\temp@count-1 \ifnum\temp@count<0 \temp@count=0 \fi
\multiply\temp@count \temp@@count
\advance\temp@@@count by \temp@count \advance\index@count1
\ifone@VEC
\def\next@@VEC{\index@total=\index@count \advance\temp@@@count1 }%
\else \one@VEC#2\safty@mark \edef\next@@VEC{\noexpand\get@index(#1)%
\the\temp@toks\noexpand\safty@mark}%
\fi \next@@VEC}%
%
\def\one@VEC#1,#2\safty@mark{\def\temp@macro{#2}\temp@toks={#2}%
\ifx\temp@macro\empty \one@VECtrue \else \one@VECfalse \fi
\temp@count=#1 \relax }%
%
\def\get@all@index(#1)#2\safty@mark{%
\temp@@@count=0 \temp@@count=0 \index@count=0 \@rev@indexfalse
\get@index(#1)#2\safty@mark
\ifnormalindex\else
\temp@@@count=0 \temp@@count=0 \index@count=0 \@rev@indextrue
\get@index(#1)#2\safty@mark \fi }%
%
\def\read@array[#1]#2#3{\temp@count=1
\def\one@item##1#1##2\safty@mark{\def\temp@macro{##2}\temp@toks={##2}%
\ifx\temp@macro\empty\else
\def\temp@macro{\one@item##2\safty@mark}\fi
{\temp@toks={##1}\def\temp@@macro{\arrayx{#2}(\the\temp@count)=}%
\expandafter\temp@@macro\expandafter{\the\temp@toks}}%
\expandafter\edef\csname total@#2\endcsname{\the\temp@count}%
\advance\temp@count1\temp@macro}%
\one@item#3#1\safty@mark}%
%
\def\strip@esc#1{\temp@count=\escapechar \escapechar=-1 %
\temp@toks=\expandafter{\string#1}\escapechar\temp@count}
\def\get@max@count#1#2{\edef\temp@macro{\csname #1\endcsname}%
\ifnum\temp@macro<#2\expandafter\xdef\csname #1\endcsname{\the#2}\fi}%
%
\def\newarray#1{\strip@esc{#1}%
\expandafter\gdef\csname total@\the\temp@toks\endcsname{0}%
\expandafter\edef\csname\the\temp@toks\endcsname(##1)%
{\noexpand\get@all@index(\noexpand\dataheight)##1\noexpand\safty@mark
% \noexpand\get@max@count{total@\the\temp@toks}\noexpand\temp@@@count
\noexpand\arrayx{\the\temp@toks}(\noexpand\the\noexpand\temp@@@count)}%
\expandafter\edef\csname check\the\temp@toks\endcsname(##1)%
{\noexpand\get@all@index(\noexpand\dataheight)##1\noexpand\safty@mark
\noexpand\testarray{\the\temp@toks}(\noexpand\the
\noexpand\temp@@@count)\noexpand\let\noexpand\cachedata
\noexpand\temp@macro\noexpand\ifx\noexpand\temp@macro\noexpand\empty
\noexpand\emptydatatrue\noexpand\else\noexpand\emptydatafalse
\noexpand\fi}}%
%
\def\delarray#1{\strip@esc{#1}% delete array globally
\temp@count=0 \temp@@count=\csname total@\the\temp@toks\endcsname
\loop \expandafter\global\expandafter\let
\csname\the\temp@toks\string~\endcsname\undefined@
\advance\temp@count1 %
\ifnum\temp@count<\temp@@count \repeat % global loop for less memory
\global\expandafter\let\csname total@\the\temp@toks\endcsname\undefined@
\global\expandafter\let\csname \the\temp@toks\endcsname\undefined@
\global\expandafter\let\csname check\the\temp@toks\endcsname\undefined@ }%
%
\def\readarray#1#2{\read@array[&]{#1}{#2}}%
%
\catcode`\@=\EntryArrayJob\relax
\endinput
%
% END OF MACROS
|