Debian Codegraph @

texmf-dist/doc/latex/pdftoolbox/Documentation/pdfdata-docs.tex

raw
1 The pdfData section of the \pdftoolbox{} toolbox is meant for creating instances of and manipulating datatypes.
2
3 \subsection{Arrays}
4
5 In the {\tt pdfData/arrays} file, \pdftoolbox{} defines various macros for creating and manipulating arrays.
6 There are two types of arrays, which are different in the macros used for them and the way they are stored internally.
7 \blist
8 \item (Normal) arrays: these arrays are stored in the traditional way: an array $[1;2;3]$ is stored in a macro whose meaning is equivalent to \inlinecode|\X{1}\X{2}\X{3}|.
9 Manipulation of the array is done by defining \macro\X, and then executing the array macro.
10 \item Macro arrays: these arrays are stored in a collection of macros: each element is stored in its own indexed macro.
11 So an array $[1;2;3]$ will be stored in three macros, whose values are $1$, $2$, $3$ respectively.
12 \elist
13
14 \bnote
15
16 All arrays are zero-indexed.
17
18 \eppbox
19
20 \subsubsection{Normal Arrays}
21
22 \macroexp{\createarray {<name>}}
23 creates an (normal) array whose name is {\it name}.
24 \emacroexp
25
26 \macroexp{\ensurearray {<name>}}
27 ensures that an array by the name of {\it name} exists.
28 \emacroexp
29
30 \macroexp{\localizearray {<name>}}
31 localizes (see \gotoanchor{localization}{localization}) the array named by {\it name}.
32 \emacroexp
33
34 \macroexp{\appendarray {<name>}{<value>}}
35 appends {\it value} to the end of the array array named by {\it name}.
36 {\it value} is inserted according to \gotomacro\currdef.
37 \emacroexp
38
39 \macroexp{\prependarray {<name>}{<value>}}
40 prepends {\it value} to the end of the array array named by {\it name}.
41 {\it value} is inserted according to \gotomacro\currdef.
42 \emacroexp
43
44 \macroexp{\appendarraymany {<name>}{{<value1>}{<value2>}...{<valueN>}}}
45 appends {\it value1} through {\it valueN} to the end of the array array named by {\it name}.
46 Each {\it value} is inserted according to \gotomacro\currdef.
47 \emacroexp
48
49 \macroexp{\arraylen {<name>}}
50 expands to the length of the array specified by {\it name}.
51 \emacroexp
52
53 \macroexp{\getarraylen {<name>}<macro>}
54 inserts the length of the array specified by {\it name} into the macro {\it macro}.
55 \emacroexp
56
57 \macroexp{\arraymap {<name>}<macro>}
58 if the array specified by {\it name} is equivalent to $\tt [x0;\dots;xN]$ then doing \inlinecode|\arraymap{name}\X| will execute \inlinecode|\X{x1}{0}...\X{xN}{N}|.
59 \emacroexp
60
61 \macroexp{\indexarray {<name>}{<i>}<macro>}
62 Puts the $i$th element in the array specified by {\it name} into the macro {\it macro}.
63 \emacroexp
64
65 \macroexp{\removearray {<name>}{<i>}<macro>}
66 Removes the $i$th element in the array specified by {\it name} and places it into the macro {\it macro}.
67 \emacroexp
68
69 \macroexp{\removeitemarray {<name>}{<value>}}
70 Removes all instances of {\it value} from the array specifed by {\it name} (comparison is done using \macro\ifx{} on macros containing {\it value} and the current index).
71 \emacroexp
72
73 \macroexp{\printarray {<name>}}
74 Prints the array specified by {\it name}.
75 \emacroexp
76
77 \macroexp{\copyarray {<src>}{<dest>}}
78 Copies the array {\it src} into {\it dest}.
79 \emacroexp
80
81 \macroexp{\concatenatearrays {<arr1>}{<arr2>}{<dest>}}
82 Concatenates the arrays {\it arr1} and {\it arr2} and places the result into a new array {\it dest}.
83 \emacroexp
84
85 \macroexp{\initarray {<name>}{<x1>,...,<xN>}}
86 Creates a new array by the name of {\it name} equivalent to $\tt[x1;\dots;xN]$.
87 \emacroexp
88
89 \macroexp{\findarray {<name>}{<value>}}
90 Checks if the value {\it value} exists in the array {\it name} (checking is done via \macro\ifx).
91 If the value exists, the value \macro\True{} is placed into \macro\@return@value, otherwise it is equal to \macro\False.
92 \emacroexp
93
94 \macroexp{\uniqueappendarray {<name>}{<value>}}
95 Appends {\it value} to the array {\it name} only if it does not already exist in {\it name} (\macro\@return@value{} is set accordingly).
96 \emacroexp
97
98 \macroexp{\convertarray {<src>}{<dest>}}
99 Converts a normal array {\it src} to a macro array {\it dest}.
100 \emacroexp
101
102 \macroexp{\mergesort {<src>}{<dest>}}
103 Sorts the array {\it src} and places the result in {\it dest}.
104 \emacroexp
105
106 \subsubsection{Macro Arrays}
107
108 \macroexp{\createmarray {<name>}}
109 Creates a macro array by the name of {\it name}.
110 \emacroexp
111
112 \macroexp{\localizemarray {<name>}}
113 Localizes (see \gotoanchor{localization}{localization}) the macro array specified by {\it name}.
114 \emacroexp
115
116 \macroexp{\appendmarray {<name>}{<value>}}
117 Appends {\it value} to the macro array specified by {\it name}.
118 \emacroexp
119
120 \macroexp{\printmarray {<name>}}
121 Prints the macro array specifed by {\it name}.
122 \emacroexp
123
124 \macroexp{\convertmarray {<src>}{<dest>}}
125 Converts the macro array {\it src} into a normal array {\it dest}.
126 \emacroexp
127
128 \macroexp{\copymarray {<src>}{<dest>}}
129 Copies the macro array {\it src} into {\it dest}.
130 \emacroexp
131
132 \macroexp{\initmarray {<name>}{<x1>,...,<xN>}}
133 Creates a macro array {\it name} whose value is equivalent to $\tt[x1,\dots,xN]$.
134 \emacroexp
135
136 \macroexp{\findmarray {<name>}{<value>}<macro>}
137 Searches for {\it value} in the macro array {\it name}.
138 If found, sets \macro\@return@value{} to \macro\True{} and {\it macro} to the index where {\it value} was found.
139 Otherwise \macro\@return@value{} is set to \macro\False.
140 \emacroexp
141
142 \subsection{Stacks}
143
144 In the {\tt pdfData/stacks.tex} file, \pdftoolbox{} offers macros for creating and manipulating stack data structures.
145 There are two types of stacks, which differ in how they store their data.
146 They are generally used for different purposes:
147
148 \blist
149 \item Normal stacks: these are normal stacks which store just the values given.
150 \item Macro stacks: these stacks are meant to store only macros: they store both the definition and name of the macro.
151 \elist
152
153 \subsubsection{Normal Stacks}
154
155 \macroexp{\createstack {<name>}}
156 Creates a normal stack by the name of {\it name}.
157 \emacroexp
158
159 \macroexp{\stackpush {<name>}{<value>}}
160 Pushes the value {\it value} onto the stack specified by {\it name}.
161 \emacroexp
162
163 \macroexp{\stackdecrement {<name>}}
164 Pops from the top of the stack specified by {\it name} (deleting the value).
165 \emacroexp
166
167 \macroexp{\stackpop {<name>}<macro>}
168 Pops from the top of the stack specified by {\it name} into {\it macro}.
169 \emacroexp
170
171 \macroexp{\stacktop {<name>}<macro>}
172 Places the top of the stack specified by {\it name} into the macro {\it macro} without popping.
173 \emacroexp
174
175 \subsubsection{Macro Stacks} \anchor{macro stacks}
176
177 Macro stacks store macros, as opposed to values.
178 When pushing a macro \macro\X{} onto the stack, not only is the meaning of \macro\X{} stored, but so is its name.
179
180 \macroexp{\createmacrostack {<name>}}
181 Creates a macro stack by the name of {\it name}.
182 \emacroexp
183
184 \macroexp{\macrostackpush {<name>}<macro>}
185 Pushes the macro {\it macro} onto the macro stack specified by {\it name}.
186 \emacroexp
187
188 \macroexp{\macrostackdecrement {<name>}}
189 Pops from the top of the macro stack specified by {\it name} (deleting the value).
190 \emacroexp
191
192 \macroexp{\macrostackset {<name>}}
193 If the top of the macro stack specified by {\it name} has name \macro\X{} and value {\tt value}, sets \macro\X{} to {\tt value}.
194 \emacroexp
195
196 \macroexp{\macrostackpop {<name>}}
197 Pops from the top of the macro stack specified by {\it name} (same as \macro\macrostackset, but also pops the value off of the stack).
198 \emacroexp
199
200 \macroexp{\macrostackpeek {<name>}<macro1><macro2>}
201 If the top of the macro stack specified by {\it name} is $(\macro\X,{\tt value})$, then \macro\X{} is placed into {\it macro1}, and {\tt value} into {\it macro2}.
202 \emacroexp
203
204 \subsection{Localization} \anchor{localization}
205
206 Using \gotoanchor{macro stacks}{macro stacks}, \pdftoolbox{} allows for {\it localization}.
207 This gives the user the ability to create block scopes (as opposed to just plain-ol` \TeX{} groups).
208 The usage is simple and as follows:
209 \benum
210 \item The user enters a scope using \macro\beginscope.
211 \item The user {\it localizes} a macro \macro\X{} by doing \inlinecode|\localize\X|.
212 \item The user exits the scope using \macro\endscope.
213 Once the scope is exited, the previous definition of localized macros is restored.
214 \eenum
215 So for example,
216
217 \blisting
218 \def\X{0}
219 \beginscope
220 \localize\X
221 \def\X{1}
222 \X
223 \beginscope
224 \def\X{2}
225 \X
226 \endscope
227 \X
228 \endscope
229 \X
230 \elisting
231
232 Will output 1 2 2 0.
233 As opposed to
234
235 \blisting
236 \def\X{0}
237 \bgroup
238 \def\X{1}
239 \X
240 \bgroup
241 \def\X{2}
242 \X
243 \egroup
244 \X
245 \egroup
246 \X
247 \elisting
248
249 Which will output 1 2 1 0.
250
251 \subsection{Counters}
252
253 In the {\tt pdfData/counters.tex}, \pdftoolbox{} implements counters.
254 Counters are simple wrappers over plain-\TeX{} counters.
255 They hold integer values, are mutable, and can be made dependent on one another so that when one is altered another is set to zero.
256
257 \macroexp{\createcounter {<name>}[<c1>,...,<cN>]}
258 Creates a counter by the name {\it name} dependent on counters {\it c1,\dots,cN}.
259 \emacroexp
260
261 \macroexp{\adddependentcounter {<secondary>}{<primary>}}
262 Makes the {\it secondary} counter dependent on the {\it primary} one; whenever {\it primary} is (non-independently; see e.g. \gotomacro\seticounter) altered, {\it secondary} is set to zero.
263 \emacroexp
264
265 \macroexp{\zerodependents {<primary>}}
266 Sets to zero all counters dependent on {\it primary}.
267 \emacroexp
268
269 \macroexp{\setcounter {<counter>}{<amount>}}
270 Sets {\it counter} to {\it amount} (zeroing all counters dependent on {\it counter}).
271 \emacroexp
272
273 \macroexp{\advancecounter {<counter>}{<amount>}}
274 Advances {\it counter} by {\it amount} (zeroing all counters dependent on {\it counter}).
275 \emacroexp
276
277 \macroexp{\seticounter {<counter>}{<amount>}}
278 Sets {\it counter} to {\it amount} ({\it without} zeroing all counters dependent on {\it counter}).
279 \emacroexp
280
281 \macroexp{\advanceicounter {<counter>}{<amount>}}
282 Advances {\it counter} by {\it amount} ({\it without} zeroing all counters dependent on {\it counter}).
283 \emacroexp
284
285 \macroexp{\counter {<name>}}
286 Returns the \TeX{} counter corresponding to the \pdftoolbox{} counter {\it name}.
287 Useful for example when printing the value of a counter: simply do \inlinecode|\the\counter{name}|.
288 \emacroexp
289
290 \subsection{Dictionaries}
291
292 In the {\tt pdfData/dictionaries.tex} file, \pdftoolbox{} implements dictionaries (also colloquially known as ``hashmaps'' or ``maps'').
293 These are simple maps between keys and values.
294
295 \macroexp{\createdict {<name>}}
296 Creates a dictionary by the name {\it name}.
297 \emacroexp
298
299 \macroexp{\adddict {<name>}{<key>}{<value>}}
300 Adds the $({\it key}:{\it value})$ key-value pair to the dictionary specified by {\it name}.
301 \emacroexp
302
303 \macroexp{\indexdict {<name>}{<key>}}
304 Expands to the value of {\it key} in the dictionary {\it name}.
305 \emacroexp
306
307 \macroexp{\keyindict {<name>}{<key>}}
308 Sets \macro\@return@value{} according to if {\it key} is found in the dictionary {\it name}.
309 \emacroexp
310
311 \subsection{Mappings}
312
313 In {\tt pdfData/key-value.tex}, \pdftoolbox{} implements the ability to pass key-value parameters to macros.
314
315 \macroexp{\mapkeys {<options>}{<input>}}
316 Maps the key-value pairs given in {\it input} according to {\it options}.
317 {\it options} is itself a set of key-value pairs, where the value of each key is an array which may contain:
318 \blist
319 \item {\tt name} (required): the name of the macro to give the value of the key;
320 \item {\tt required}: added if the key is required;
321 \item {\tt definition}: what definition macro to use for defining the value (e.g. \macro\def, \macro\edef);
322 \item {\tt mapping}: how to map the input to the value: the input is defined relative to {\tt definition} into a macro wrapped with {\tt mapping};
323 \item {\tt default}: the default value of the key.
324 \elist
325 Or the value may be empty (no array), which means it is {\it valueless} and acts as a boolean flag.
326 \emacroexp
327
328 So for example, you may have a macro defined like so:
329
330 \blisting
331 \def\puthi#1{Hello (#1)}
332
333 \def\getinput#1{%
334 \mapkeys{
335 first={
336 name=fst,
337 required,
338 definition=\edef,
339 mapping=\puthi%
340 },
341 second={
342 name=snd,
343 default=A. Feiglin%
344 }%
345 }{#1}%
346 }
347
348 \getinput{first=pdftoolbox}
349 (\fst) (\snd)
350 \elisting
351
352 This will output {\tt (Hello (pdftoolbox)) (A. Feiglin)}.
353
354 \macroexp{\keyexists {<key>}<macro>\lastkeys}
355 This is an internal command, added to this documentation only due to its usefulness.
356 Given a key name {\it key}, this macro checks if it exists in the map corresponding to the last call to \macro\mapkeys{} (the macro itself is more versatile, but we restrict it to this case).
357 If the key does not exist, then {\it macro} is set to \macro\_nul.
358 This is useful with valueless keys.
359 \emacroexp
360
361 \bwarning
362 \macro\mapkeys{} is a bit finnicky when it comes to spaces and commas, but the rule is simple: place a comment at the end of each list.
363 That means that within each key's array, you must place a comment at the end (otherwise an extraneous space is added to the value), and after the last key's array you must place a comment.
364 \eppbox
365