Debian Codegraph @

texmf-dist/tex/luatex/pdfextra/pdfextra.tex

raw
1 \ifdefined \pdfextraloaded \expandafter \endinput \fi
2 \chardef\pdfextraloaded=\catcode`\_
3 \catcode`\_=11
4
5 \long\def \_xargs #1#2{\ifx #2;\else
6 \expandafter#1\expandafter#2\expandafter\_xargs \expandafter #1\fi}
7
8 \def \_private {\_xargs \_privateA}
9 \def \_privateA #1{\expandafter\let\csname _\csstring #1\endcsname#1}
10
11 % primitives
12 \_private \detokenize \expanded \hbox \ht \wd \dp \copy \immediateassignment ;
13 \_private \escapechar \baselineskip \quitvmode \lastnamedcs ;
14
15 %
16 % prefixed.opm
17 %
18
19 \_private \expandafter \def \let \ifx \else \fi \undefined \wlog \endinput ;
20
21 \_let\_ea=\_expandafter
22
23 \_def \_codedecl #1#2{%
24 \_ifx #1\_undefined \_wlog{#2}%
25 \_else \_ea \_endinput \_fi
26 }
27
28 \_let \_endcode = \_endinput
29
30 \_def \_wterm {\_immediate \_write16 }
31
32 \_private \ifcsname \csname \endcsname \errmessage \gdef \csstring \directlua ;
33 \_let \_ea = \_expandafter
34
35 % modified
36 \_def \_pkglabel{}
37 \_def\_namespace #1{%
38 \_ifcsname namesp:#1\_endcsname \_errmessage
39 {The name space "#1" is used already, it cannot be used twice}%
40 \_endinput
41 \_else \_resetnamespace{#1}\_fi
42 }
43 \_def\_resetnamespace #1{%
44 \_unless \_ifx \_pkglabel\_empty \_endnamespace \_fi
45 \_ea \_gdef \_csname namesp:#1\_endcsname {}%
46 \_gdef \_pkglabel{_#1}%
47 \_directlua{
48 luatexbase.add_to_callback("process_input_buffer",
49 function (str)
50 return string.gsub(str, "\_nbb[.]([a-zA-Z])", "\_nbb _#1_\_pcent 1")
51 end, "_namespace")
52 }%
53 }
54 % modified
55 \_def\_endnamespace {%
56 \_directlua{ luatexbase.remove_from_callback("process_input_buffer", "_namespace") }%
57 \_gdef \_pkglabel{}%
58 }
59
60 \_def \_nspublic {\_xargs \_nspublicA}
61 \_def \_nspublicA #1{%
62 \_unless\_ifx #1\_undefined
63 \_opwarning{\_ea\_ignoreit\_pkglabel\_space redefines the meaning of \_string#1}\_fi
64 \_ea\_let \_ea#1\_csname \_pkglabel _\_csstring #1\_endcsname
65 }
66
67 % modified
68 \_def \_public {\_xargs \_publicA}
69 \_def \_publicA #1{\_ea\_let \_ea#1\_csname _\_csstring #1\_endcsname}
70
71 %
72 % basic-macros.opm
73 %
74
75 \_private \bgroup \egroup \empty \space \null \long ;
76
77 \_long\_def \_ignoreit #1{}
78 \_long\_def \_useit #1{#1}
79 \_long\_def \_ignoresecond #1#2{#1}
80 \_long\_def \_usesecond #1#2{#2}
81
82 \_private \the \inputlineno \edef ;
83
84 \_def \_opwarning #1{\_wterm{WARNING l.\_the\_inputlineno: pdfextra: #1.}}
85
86 \_edef \_bslash {\_csstring\\}
87 \_edef \_pcent {\_csstring\%}
88 \_edef \_nbb {\_bslash\_bslash}
89
90 \_private \xdef \begincsname ;
91
92 \_def \_sdef #1{\_ea\_def \_csname#1\_endcsname}
93 \_def \_sxdef #1{\_ea\_xdef \_csname#1\_endcsname}
94 \_def \_slet #1#2{\_ea\_let \_csname#1\_ea\_endcsname
95 \_ifcsname#2\_ea\_endcsname \_begincsname#2\_endcsname \_else \_undefined \_fi
96 }
97
98 % Make \sdef public, so users can customize without messing with catcodes.
99 \_public \sdef ;
100
101 \_def \_cs #1{\_csname#1\_endcsname}
102 \_def \_trycs#1#2{\_ifcsname #1\_endcsname \_csname #1\_ea\_endcsname \_else #2\_fi}
103
104 \_long\_def \_addto #1#2{\_ea\_def\_ea#1\_ea{#1#2}}
105
106 \_private \global \advance ;
107
108 \_def\_incr #1{\_global\_advance#1by1 }
109 \_def\_decr #1{\_global\_advance#1by-1 }
110
111 \_private \immediate \closeout \jobname ;
112
113 % modified
114 \_def\_byehook{%
115 \_immediate\_closeout\_reffile
116 \_edef\_tmp{\_mdfive{\_jobname.ref}}%
117 \_ifx\_tmp\_prevrefhash\_else \_opwarning{Try to rerun,
118 \_jobname.ref file was \_ifx\_prevrefhash\_empty created\_else changed\_fi}\_fi
119 }
120
121 %
122 % alloc.opm
123 %
124
125 \_private \newcount ;
126
127 %
128 % if-macros.opm
129 %
130
131 \_def\_afterfi#1#2\_fi{\_fi#1}
132
133 \_private \unless ;
134
135 \_def\_isdefined #1#2{\_ifcsname #1\_endcsname \_else \_ea\_unless \_fi #2}
136
137 \_private \newread \openin \relax \ifeof \closein ;
138
139 \_newread \_testin
140 \_def\_isfile #1{%
141 \_immediate\_openin\_testin ={#1}\_relax
142 \_ifeof\_testin \_ea\_unless
143 \_else \_immediate\_closein\_testin
144 \_fi
145 }
146
147 \_private \begingroup \toks \endgroup \futurelet ;
148
149 \_long\_def\_isnextchar#1#2#3{\_begingroup\_toks0={\_endgroup#2}\_toks1={\_endgroup#3}%
150 \_let\_tmp= #1\_futurelet\_next\_isnextcharA
151 }
152 \_def\_isnextcharA{\_the\_toks\_ifx\_tmp\_next0\_else1\_fi\_space}
153
154 %
155 % more-macros.opm
156 %
157
158 \_private \string \newtoks \romannumeral ;
159
160 \_newtoks\_opt
161 \_def\_optdef#1[#2]{%
162 \_def#1{\_opt={#2}\_isnextchar[{\_cs{_oA:\_csstring#1}}{\_cs{_oB:\_csstring#1}}}%
163 \_sdef{_oA:\_csstring#1}[##1]{\_opt={##1}\_cs{_oB:\_csstring#1\_nospaceafter}}%
164 \_sdef{_oB:\_csstring#1\_nospaceafter}%
165 }
166 \_def\_nospaceafter#1{\_ea#1\_romannumeral-`\.\_noexpand}
167
168 \_private \noexpand \catcode \toksapp ;
169
170 \_newtoks\_tmptoks
171 % modified
172 \_edef\_tmp{\_noexpand\_catcode`!=\_the\_catcode`! \_noexpand\_catcode`?=\_the\_catcode`?}
173 \_catcode`!=3 \_catcode`?=3
174 \_def\_replstring #1#2#3{% \replstring #1{stringA}{stringB}
175 \_long\_def\_replacestringsA##1#2{\_tmptoks{##1}\_replacestringsB}%
176 \_long\_def\_replacestringsB##1#2{\_ifx!##1\_relax \_else \_tmptoks\_ea{\_the\_tmptoks#3##1}%
177 \_ea\_replacestringsB\_fi}%
178 \_ea\_replacestringsA #1?#2!#2%
179 \_long\_def\_replacestringsA##1?{\_tmptoks{##1}\_edef#1{\_the\_tmptoks}}%
180 \_ea\_replacestringsA \_the\_tmptoks}
181 \_tmp % modified
182
183 % modified (no \_skiptoeol)
184 \_long\_def\_doc #1\_cod{}
185
186 %
187 % keyval.opm
188 %
189
190 \_def\_readkv#1{\_ea\_def\_ea\_tmpb\_ea{#1}%
191 \_replstring\_tmpb{= }{=}\_replstring\_tmpb{ =}{=}%
192 \_replstring\_tmpb{, }{,}\_replstring\_tmpb{,,}{,}%
193 \_ea \_kvscan \_tmpb,,=,}
194 \_def\_kvscan #1#2=#3,{\_ifx#1,\_else \_sdef{_kv:#1#2}{#3}\_ea\_kvscan\_fi}
195 \_def\_kv#1{\_trycs{_kv:#1}{\_kvunknown}}
196 \_def\_kvunknown{???}
197
198 %
199 % ref-file.opm
200 %
201
202 \_private \newwrite \write \iftrue \iffalse \input ;
203
204 % modified
205 \_newwrite\_reffile
206 \_def\_inputref {%
207 \_isfile{\_jobname.ref}\_iftrue
208 \_edef\_prevrefhash{\_mdfive{\_jobname.ref}}%
209 \_input {\_jobname.ref}%
210 \_openref
211 \_fi
212 }
213
214 \_private \luaescapestring ;
215
216 % modified
217 \_def\_mdfive#1{\_directlua{
218 local fh = io.open("\_luaescapestring{#1}", "rb")
219 if fh then
220 local data = fh:read("*a")
221 fh:close()
222 tex.print(md5.sumhexa(data))
223 end
224 }}
225 \_def\_prevrefhash{}
226
227 \_def\_wrefrelax#1#2{}
228 \_let\_wref=\_wrefrelax
229
230 \_private \openout ;
231
232 % modified
233 \_def\_openref {%
234 \_immediate\_openout\_reffile={\_jobname.ref}\_relax
235 \_gdef\_wref ##1##2{\_write\_reffile{\_bslash\_csstring##1##2}}%
236 \_immediate\_write\_reffile {\_pcent\_pcent\_space pdfextra - REF file}%
237 \_ifx\_refdecldata\_empty \_else \_refdeclwrite \_fi
238 \_gdef\_openref{}%
239 }
240 \_def\_ewref #1#2{\_edef\_ewrefA{#2}\_ea\_wref\_ea#1\_ea{\_ewrefA}}
241
242 \_private \ifnum ;
243
244 \_def\_refdecldata{}
245 \_def\_refdecl{\_bgroup \_catcode`\#=12 \_catcode`\\=12 \_catcode`\ =12 \_refdeclA}
246 \_def\_refdeclA#1{\_egroup
247 \_ifx\_refdecldata\_empty\_else \_global\_addto\_refdecldata{^^J}\_fi
248 \_global\_addto\_refdecldata{#1}%
249 \_ifx\_openref\_empty \_refdeclwrite \_fi
250 }
251 \_def\_refdeclwrite{%
252 \_immediate\_write\_reffile{\_pcent\_space \_string\refdecl:^^J\_detokenize\_ea{\_refdecldata}}%
253 \_gdef\_refdecldata{}%
254 }
255
256 %
257 % hyperlinks.opm
258 %
259
260 \_def\_pdfborder#1{\_ifcsname _#1border\_endcsname
261 /C [\_csname _#1border\_endcsname] /Border [0 0 .6]\_else /Border [0 0 0]\_fi
262 }
263
264 % modified
265 \_def\_hyperlinks#1#2{%
266 \_let\_ilinkcolor=#1\_empty
267 \_let\_elinkcolor=#2\_empty
268 }
269 \_public \hyperlinks ;
270
271 %
272 % pdfuni-string.opm
273 %
274
275 % modified
276 \_def\_pdfunidef#1#2{%
277 \_edef\_tmp{#2}%
278 \_edef#1{\_directlua{
279 local str = token.scan_string()
280 local out = { "<FEFF" }
281 for _, c in utf8.codes(str) do
282 if c < 0x10000 then
283 out[\_csstring\#out+1] = string.format("\_pcent04X", c)
284 else
285 c = c - 0x10000
286 local high = c >> 10 + 0xD800
287 local low = c \_csstring\& 0x3FF + 0xDC00
288 out[\_csstring\#out+1] = string.format("\_pcent04X\_pcent04X", high, low)
289 end
290 end
291 out[\_csstring\#out+1] = ">"
292 tex.print(table.concat(out, ""))}\_ea{\_tmp}%
293 }}
294
295 %
296 % optex.lua
297 %
298
299 \_private \setbox ;
300
301 % modified
302 \_def\_preshipout#1#2{\_setbox#1#2}
303
304 %
305 % luatex-ini.opm
306 %
307
308 \_private \protected \pdfextension \pdffeedback \pdfvariable ;
309 \_private \numexpr \saveboxresource \lastsavedboxresourceindex ;
310
311 \_protected\_def \_pdfobj {\_pdfextension obj }
312 \_protected\_def \_pdfrefobj {\_pdfextension refobj }
313 \_protected\_def \_pdflastobj {\_numexpr\_pdffeedback lastobj\_relax}
314 \_protected\_def \_pdfstartlink {\_pdfextension startlink }
315 \_protected\_def \_pdfendlink {\_pdfextension endlink\_relax}
316 \_protected\_def \_pdfcatalog {\_pdfextension catalog }
317 \_protected\_edef\_pdfpageattr {\_pdfvariable pageattr}
318 \_protected\_def \_pdfnames {\_pdfextension names }
319 \_protected\_def \_pdfannot {\_pdfextension annot }
320 \_protected\_def \_pdflastannot {\_numexpr\_pdffeedback lastannot\_relax}
321 \_def \_pdfpageref {\_pdffeedback pageref}
322 \_let \_pdfxform \_saveboxresource
323 \_let \_pdflastxform \_lastsavedboxresourceindex
324
325 %
326 % output.opm
327 %
328
329 \_let\_oldshipout=\shipout
330 \_def\shipout{\_begoutput\_oldshipout}
331
332 % modified
333 \_newcount\_gpageno
334 \_def \_begoutput{\_incr\_gpageno
335 % we try \folio, or nothing ({}), pdfextra only uses \gpageno
336 \_immediate\_wref\_Xpage{{\_the\_gpageno}{\_trycs{folio}{}}}%
337 }
338
339 %
340 % references.opm
341 %
342
343 % modified
344 \_def\_Xpage#1#2{\_def\_currpage{{#1}{#2}}}
345
346 %
347 % colors.opm
348 %
349
350 % modified
351 \_let\_localcolor\_relax
352
353 %
354 % \_byehook and \_inputref
355 %
356
357 \_private \ifdefined ;
358
359 \_ifdefined\AtEndDocument
360 % make sure all pages (and write whatsits) are flushed before we close files
361 \AtEndDocument{\clearpage\_byehook}%
362 \_else
363 % hope that usual \bye (\outer\def\bye{\par\vfill\supereject\end}) is used
364 \_let\_end\end
365 \_def\end{\_byehook \_end}%
366 \_fi
367
368 \_inputref
369
370 % continue with the real macros
371 \_input pdfextra.opm
372 \_catcode`\_=\pdfextraloaded