Debian Codegraph @

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

raw
1 Due to the nature of its use, most of the macros defined in the pdfData section have already been explained.
2 The only part of pdfData which requires explanation regarding its internals is mappings, which offers richer features than already explained.
3
4 \subsection{Mappings}
5
6 Mappings are stored in two places: a {\it key list}, which is simply a macro consisting of pairs of the form \inlinecode|{key}{value}|, and macros \inlinecode|\key@k| (the second {\tt k} is variable in the name) whose definition
7 is {\tt v}.
8
9 Essentially, the major macro in this part is \macro\_mapkeys_with_setter\anchormacro\_mapkeys_with_setter.
10 Its usage is
11
12 \getmacrousage{\_mapkeys_with_setter <mapkey macro><key macro>{<map>}}
13 where {\it mapkey macro} is the macro which manages the creation of a key-value pair (explained below), {\it key macro} is a macro to store
14 the list of keys, and {\it map} is a map of key-value pairs.
15
16 What happens is \macro\_mapkeys_with_setter{} will iterate over {\it map} and for every key-value pair $({\tt k,v})$ if the setter {\it mapkey macro} is \macro\M{} and {\it key macro} is \macro\K{}, it calls
17 \inlinecode|\M \K{k}{v}|.
18 This should (if \macro\M{} is defined properly) update \macro\K{} to include the pair $({\tt k,v})$.
19 Furthermore, it should store the value {\tt v} in the macro \inlinecode|\key@k| (the second {\tt k} is variable in the name).
20
21 The macro \macro\_update_lastkeys{} is provided for the former: to update \macro\K{}.
22 Simply pass \inlinecode|\_update_lastkeys \K{k}{v}|.
23 The simplest setter ({\it mapkey macro}) is \macro\_vanilla_mapkey\anchormacro\_vanilla_mapkey, which does exactly what was described and nothing more.
24 Its definition is simply:
25
26 \blisting
27 \def\_vanilla_mapkey#1#2#3{%
28 \_xp\def\csname key@\_id#2\endcsname{#3}%
29 \_update_lastkeys{#1}{#2}{#3}%
30 }
31 \elisting
32
33 You can use the macro \macro\getvalue\anchormacro\getvalue{} to get the value of a key: its definition is simply
34
35 \blisting
36 \def\getvalue#1{%
37 \csname key@#1\endcsname%
38 }
39 \elisting
40
41 Another macro is \macro\keyexists{} whose use is
42
43 \getmacrousage{\keyexists {<key>}<macro><key list>}
44 It checks if the key {\it key} is in {\it key list}, and if it is, defines {\it macro} to be equal to the key.
45 Otherwise {\it macro} is defined to be \macro\_nul.
46 For this reason, if you'd like a key to have no value, it is advised to use the \macro\novalue{} macro (whose definition is just \macro\novalue).
47
48 Another setter is \macro\_vardef_mapkey\anchormacro\_vardef_mapkey, whose only difference from \macro\_vanilla_mapkey{} is that instead of \macro\def ing \inlinecode|\key@k| to be equal to {\tt v}, \macro\_vardef_mapkey{} uses
49 \macro\_vardef{} instead of \macro\def{} (which can be set before calling \macro\_vardef_mapkey), and \macro\_vardef s \inlinecode|\key@k| to be the (once) expansion of \inlinecode|\_varmap{v}| (where \macro\_varmap) can also be
50 set before calling (\macro\_vardef_mapkey).
51
52 \macro\mapkeys{} is defined as follows:
53
54 \blisting
55 \def\mapkeys#1#2{%
56 \_mapkeys_with_setter\_vanilla_mapkey\_keymappings{#1}%
57 \_xp\_setdefaults\_xp{\_keymappings}%
58 \_mapkeys_with_setter\_protected_mapkey\lastkeys{#2}%
59 \_check_required_supplied%
60 }
61 \elisting
62
63 So first it gets the key-value pairs in {\it options} (\inlinecode|#1|) using \macro\_vanilla_mapkey; it places the results in \macro\_keymappings.
64 Then it sets the default values (this is what \macro\_setdefaults{} does; as well as figuring out which keys are required).
65 Then \macro\mapkeys{} calls \gotomacro\_mapkeys_with_setter{} using the setter \gotomacro\_protected_mapkey{} on {\it input} (\inlinecode|#2|).
66 It stores the results in \macro\lastkeys\anchormacro\lastkeys.
67 Then it checks that the required keys have been supplied (\macro\_check_required_supplied).
68
69 The setter \macro\_protected_mapkey\anchormacro\_protected_mapkey{} is more complicated than the previously-discussed setters.
70 Its use, like all setters, is
71
72 \getmacrousage{\_protected_mapkey <key list>{<key>}{<value>}}
73
74 But in this case, {\it key} has a value also in \macro\_keymappings{} as well; this value corresponds to another map containing the settings of {\it key} ({\tt name}, {\tt default}, {\tt required}, etc.).
75 So now \macro\_protected_mapkey{} will find the settings of {\it key}, and get the values of each field (via \macro\_mapkeys_with_setter).
76 Then it calls \macro\_vardef_mapkey{} with {\it key} and {\it value}, using the definitions of \macro\_vardef{} and \macro\_varmap{} according to the settings.
77 Finally it sets the macro {\tt name} (if provided in the settings) to be equal to the value.
78