summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/getitems/getitems.sty
blob: ecec8062098cd74aaca259cf36d8a57ee708927d (plain)
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
%%
%% This is file `getitems.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% getitems.dtx  (with options: `package')
%% 
%% This is a generated file.
%% 
%% Copyright (C) 2016 by Anders Hendrickson <anders.hendrickson@snc.edu>
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
\ProvidesPackage{getitems}
    [2016/01/11 v1.0 gather items from a list]
\RequirePackage{environ}
\RequirePackage{trimspaces}
\let\xa=\expandafter
\def\gathereditem#1{\csname getitems@item@#1\endcsname}
\newcounter{numgathereditems}
\long\def\gatheritems#1{%
  \setcounter{getitems@begindepth}{0}%
  \setcounter{numgathereditems}{0}%
  \xa\long\xa\gdef\csname getitems@item@0\endcsname{}%
  \gatheritems@int\getitems@relax#1\item\getitems@terminalitem\getitems@endgatheritems
  \xa\let\xa\gatheredheader\xa=\csname getitems@item@0\endcsname
}
\def\@getitems@terminalitem{\getitems@terminalitem}%
\def\@dummy@relax{\getitems@relax}%
\long\def\gatheritems@int#1\item#2\getitems@endgatheritems{%
  \getitems@trackbegindepth{#1}%
  \ifnum\c@getitems@begindepth=0\relax
    \def\getitems@test@i{#1}%
    \ifx\getitems@test@i\@dummy@relax
      \relax
    \else
      \xa\xa\xa\g@addto@macro
         \xa\xa\csname getitems@item@\the\c@numgathereditems\endcsname
            \xa{\getitems@stripfirsttokenfrom#1\getitems@endstrip}%
    \fi
    \def\getitems@test@ii{#2}%
    \ifx\getitems@test@ii\@getitems@terminalitem
      \let\getitems@next=\relax
    \else
      \stepcounter{numgathereditems}%
      \xa\gdef\csname getitems@item@\the\c@numgathereditems\endcsname{}%
      \def\getitems@next{\gatheritems@int\getitems@relax#2\getitems@endgatheritems}%
    \fi
  \else
    \xa\xa\xa\g@addto@macro
       \xa\xa\csname getitems@item@\the\c@numgathereditems\endcsname
          \xa{\getitems@stripfirsttokenfrom#1\getitems@endstrip}%
    \xa\g@addto@macro\csname getitems@item@\the\c@numgathereditems\endcsname{\item}%
    \def\getitems@next{\gatheritems@int\getitems@relax#2\getitems@endgatheritems}%
  \fi
  \getitems@next
}
\long\def\getitems@stripfirsttokenfrom#1#2\getitems@endstrip{#2}
\newcounter{getitems@begindepth}
\long\def\getitems@trackbegindepth#1{%
  \getitems@trackbegindepth@int#1\getitems@terminalbegindepth\getitems@endtrackbegindepth
}
\def\@getitems@begin{\begin}%
\def\@getitems@end{\end}%
\def\@getitems@terminalbegindepth{\getitems@terminalbegindepth}%
\long\def\getitems@trackbegindepth@int#1#2\getitems@endtrackbegindepth{%
  \def\getitems@test@i{#1}%
  \ifx\getitems@test@i\@getitems@begin
    \advance\c@getitems@begindepth by 1\relax
  \else
    \ifx\getitems@test@i\@getitems@end
      \advance\c@getitems@begindepth by -1\relax
    \fi
  \fi
  \def\getitems@test@ii{#2}%
  \trim@spaces@in\getitems@test@ii
  \ifx\getitems@test@ii\@getitems@terminalbegindepth
    \let\getitems@trackbegindepth@next=\relax
  \else
    \def\getitems@trackbegindepth@next{%
      \getitems@trackbegindepth@int#2\getitems@endtrackbegindepth}%
  \fi
  \getitems@trackbegindepth@next
}
\newif\ifgatherbeginningofloop
\newcounter{currentitemnumber}
\def\loopthroughitemswithcommand#1{%
  \setcounter{currentitemnumber}{1}%
  \gatherbeginningoflooptrue
  \loopthroughitemswithcommand@int{#1}%
}

\def\loopthroughitemswithcommand@int#1{%
  \ifnum\c@currentitemnumber>\c@numgathereditems\relax
    \let\getitems@loop@next=\relax%
  \else
    \xa\xa\xa#1\xa\xa\xa{\csname getitems@item@\the\c@currentitemnumber\endcsname}%
    \def\getitems@loop@next{\loopthroughitemswithcommand@int{#1}}%
    \stepcounter{currentitemnumber}%
  \fi
  \gatherbeginningofloopfalse
  \getitems@loop@next
}
\endinput
%%
%% End of file `getitems.sty'.