Debian Codegraph @

texmf-dist/tex/latex/newpax/newpax.lua

raw
1 --
2 -- This is file `newpax.lua',
3 -- generated with the docstrip utility.
4 --
5 -- The original source files were:
6 --
7 -- newpax.dtx (with options: `lua')
8 --
9 -- Copyright (C) 2021-2025 Ulrike Fischer
10 --
11 -- It may be distributed and/or modified under the conditions of
12 -- the LaTeX Project Public License (LPPL), either version 1.3c of
13 -- this license or (at your option) any later version. The latest
14 -- version of this license is in the file:
15 --
16 -- https://www.latex-project.org/lppl.txt
17 --
18 -- This file is part of the "newpax bundle" (The Work in LPPL)
19 -- and all files in that bundle must be distributed together.
20 --
21 local ProvidesLuaModule = {
22 name = "newpax",
23 version = "0.58", --TAGVERSION
24 date = "2026-05-09", --TAGDATE
25 description = "newpax lua code",
26 license = "The LATEX Project Public License 1.3c"
27 }
28
29 if luatexbase and luatexbase.provides_module then
30 luatexbase.provides_module (ProvidesLuaModule)
31 end
32
33 local OPEN = pdfe.open
34 local GETSIZE = pdfe.getsize
35 local GETINFO = pdfe.getinfo
36 local GETPAGE = pdfe.getpage
37 local GETNAME = pdfe.getname
38 local GETARRAY = pdfe.getarray
39 local GETDICTIONARY = pdfe.getdictionary
40 local GETFROMDICTIONARY = pdfe.getfromdictionary
41 local GETFROMARRAY = pdfe.getfromarray
42 local PAGESTOTABLE = pdfe.pagestotable
43 local DICTIONARYTOTABLE = pdfe.dictionarytotable
44 local ARRAYTOTABLE = pdfe.arraytotable
45 local TYPE = pdfe.type
46 local GETFROMREFERENCE = pdfe.getfromreference
47 local FILENAMEONLY = file.nameonly
48
49 local strENTRY_BEG = "\\["
50 local strENTRY_END = "\\\\\n"
51 local strCMD_BEG = "{"
52 local strCMD_END = "}"
53 local strARG_BEG = "{"
54 local strARG_END = "}"
55 local strKVS_BEG = "{"
56 local strKVS_END = "\n}"
57 local strKVS_EMPTY = "{}"
58 local strKV_BEG = "\n "
59 local strKV_END = ","
60 local strKEY_BEG = ""
61 local strKEY_END = ""
62 local strVALUE_BEG = "={"
63 local strVALUE_END = "}"
64 local strHEX_STR_BEG = "\\<"
65 local strHEX_STR_END = "\\>"
66
67 local strLIT_STR_BEG = "("
68 local strLIT_STR_END = ")"
69 local strDICT_BEG= "<<"
70 local strDICT_END= ">>"
71 local strNAME= "/"
72 local strARRAY_BEG= "["
73 local strARRAY_END= "]"
74 local strARRAY_SEP = " "
75 local strRECT_SEP = " "
76
77 local constCMD_ANNOT = "annot"
78 local constCMD_BASEURL = "baseurl" -- unused
79 local constCMD_DEST = "dest"
80 local constCMD_FILE = "file"
81 local constCMD_INFO = "info" -- unused
82 local constCMD_PAGENUM = "pagenum"
83 local constCMD_PAGE = "page"
84 local constCMD_PAX = "pax"
85
86 -- cmd file
87 local constKEY_SIZE = "Size"
88 local constKEY_DATE = "Date"
89
90 -- cmd annot attributes
91 local constKEY_C = "C"
92 local constKEY_BORDER = "Border"
93 local constKEY_BS = "BS"
94 local constKEY_H = "H"
95
96 -- cmd annot/link/URI
97 local constKEY_URI = "URI"
98 local constKEY_IS_MAP = "IsMap" -- not handled by pax, consider later
99
100 -- cmd annot/link/GoToR
101 local constKEY_FILE = "File"
102 local constKEY_DEST_NAME = "DestName" -- handle??
103 local constKEY_DEST_PAGE = "DestPage" --ok
104 local constKEY_DEST_VIEW = "DestView" --ok
105
106 -- cmd annot/link/GoTo
107 local constKEY_DEST_RECT = "DestRect"
108 local constKEY_DEST_X = "DestX"
109 local constKEY_DEST_Y = "DestY"
110 local constKEY_DEST_ZOOM = "DestZoom"
111 local constKEY_DEST_LABEL = "DestLabel" --ok
112
113 -- cmd annot/link/Named
114 local constKEY_NAME = "Name"
115
116 -- destination views
117 local constDEST_XYZ = "XYZ"
118 local constDEST_FIT = "Fit"
119 local constDEST_FITH = "FitH"
120 local constDEST_FITV = "FitV"
121 local constDEST_FITR = "FitR"
122 local constDEST_FITB = "FitB"
123 local constDEST_FITBH = "FitBH"
124 local constDEST_FITBV = "FitBV"
125
126 -- get/build data
127 -- returns table,pagecount where table objref ->page number
128 local function getpagesdata (pdfedoc)
129 local type,pagecount,detail = GETFROMDICTIONARY (pdfedoc.Catalog.Pages,"Count")
130 local pagestable = PAGESTOTABLE (pdfedoc)
131 local pagereftonum ={}
132 for i=1,#pagestable do
133 pagereftonum[pagestable[i][3]]=i
134 end
135 return pagereftonum, pagecount
136 end
137
138 -- builds a table destination name -> obj reference (pdfedict) from the Names tree
139
140 local function processnamesarray (pdfearray,targettable)
141 local tkey={}
142 for i=1,#pdfearray do
143 local type,value,detail= GETFROMARRAY(pdfearray,i)
144 if (i % 2 == 1) then
145 tkey = value
146 else
147 tvalue = value
148 targettable[tkey]=tvalue
149 end
150 end
151 end
152
153 local function findallnamesarrays (pdfedict,deststable)
154 local namesarray = GETARRAY(pdfedict,"Names")
155 if namesarray then
156 processnamesarray (namesarray,deststable)
157 else
158 local kidsarray = GETARRAY(pdfedict,"Kids")
159 if kidsarray then
160 for i=1,#kidsarray do
161 findallnamesarrays (kidsarray[i],deststable)
162 end
163 end
164 end
165 end
166
167 -- returns destnames -> objref table
168 local function getdestreferences (pdfedoc)
169 local deststable= {}
170 local catnames = GETDICTIONARY (pdfedoc.Catalog, "Names")
171 if catnames then
172 local destsdict = GETDICTIONARY (catnames, "Dests")
173 if destsdict then
174 findallnamesarrays (destsdict,deststable)
175 end
176 end
177 return deststable
178 end
179
180 -- destinations can be an dict (/D [array]) or only an array!
181
182 local function getdestdata (name,pagereftonum,destnamestoref)
183 local destref
184 local type,ref,pagenum,destx,desty = nil, nil, 1,0,0
185 local data = {{0,0}, {5,constDEST_XYZ}}
186 -- if we get directly an array
187 if (TYPE(name) == "pdfe.array") then
188 data = ARRAYTOTABLE(name)
189 type, ref, pageref = GETFROMARRAY(name,1)
190 pagenum = pagereftonum[pageref]
191 else
192 destref = destnamestoref[name]
193 end
194 if destref then
195 type,value,detail = GETFROMREFERENCE(destref)
196 if TYPE(value) == "pdfe.dictionary" then
197 local destarray = GETARRAY(value,"D")
198 if destarray then
199 data = ARRAYTOTABLE(destarray)
200 type, ref, pageref = GETFROMARRAY(destarray,1)
201 pagenum = pagereftonum[pageref]
202 end
203 elseif TYPE(value) == "pdfe.array" then
204 data = ARRAYTOTABLE(value)
205 type, ref, pageref = GETFROMARRAY(value,1)
206 pagenum = pagereftonum[pageref]
207 end
208 end
209 -- print("XXXXXXXXXX",table.serialize(data),pagenum)
210 return pagenum, data
211 end
212
213 -- output functions
214 -- write the info
215 -- XXXXXX encode/escape the file name?
216 local function outputENTRY_file (file, pdfedoc)
217 local bytes = GETSIZE(pdfedoc)
218 local date = (GETINFO(pdfedoc) and GETINFO(pdfedoc).CreationDate) or "D:22222222222222"
219 -- file
220 local a = strENTRY_BEG
221 a = a .. strCMD_BEG .. constCMD_FILE .. strCMD_END
222 a = a .. strARG_BEG .. strLIT_STR_BEG .. file .. strLIT_STR_END .. strARG_END
223 a = a .. strKVS_BEG
224 a = a .. strKV_BEG .. constKEY_SIZE .. strVALUE_BEG .. bytes .. strVALUE_END .. strKV_END
225 a = a .. strKV_BEG .. constKEY_DATE .. strVALUE_BEG .. date .. strVALUE_END.. strKV_END
226 a = a .. strKVS_END
227 a = a .. strENTRY_END
228 return a
229 end
230
231 local function outputENTRY_pagenum (pages)
232 local a = strENTRY_BEG
233 a = a .. strCMD_BEG .. constCMD_PAGENUM .. strCMD_END
234 a = a .. strARG_BEG .. pages .. strARG_END
235 a = a .. strENTRY_END
236 return a
237 end
238
239 local function outputENTRY_page (pdfedoc,page) -- page=integer
240 -- trimbox, bleedbox, cropbox,artbox,rotate etc could be put in
241 -- the second argument as keyval:
242 -- TrimBox={0 0 300 350},
243 -- but pax skips the argument anyway, so not really useful
244 local mediabox = pdfe.getbox(GETPAGE(pdfedoc,page),"MediaBox")
245 local a=""
246 if mediabox then
247 a = strENTRY_BEG
248 a = a .. strCMD_BEG .. constCMD_PAGE .. strCMD_END
249 a = a .. strARG_BEG .. page .. strARG_END
250 a = a .. strARG_BEG
251 a = a .. mediabox[1]
252 for j = 2, 4 do
253 a = a .. strRECT_SEP.. mediabox[j]
254 end
255 a = a .. strARG_END
256 a = a .. strKVS_EMPTY
257 a = a .. strENTRY_END
258 end
259 return a
260 end
261
262 local function outputCMD_annot (pdfedict,page,type)
263 local rectangle = ARRAYTOTABLE(GETARRAY(pdfedict,"Rect"))
264 local a = strCMD_BEG .. constCMD_ANNOT .. strCMD_END
265 a = a .. strARG_BEG .. page .. strARG_END
266 a = a .. strARG_BEG .. GETNAME(pdfedict,"Subtype") .. strARG_END
267 a = a .. strARG_BEG
268 a = a .. rectangle[1][2]
269 for k = 2, 4 do
270 a = a.. strRECT_SEP..rectangle[k][2]
271 end
272 a = a .. strARG_END
273 a = a .. strARG_BEG .. type .. strARG_END
274 return a
275 end
276
277 local function outputKV_color (pdfedict)
278 local color = GETARRAY(pdfedict,constKEY_C)
279 local a =""
280 if color then
281 local colortable = ARRAYTOTABLE(color)
282 a = strKV_BEG .. constKEY_C .. strVALUE_BEG .. strARRAY_BEG
283 for i=1,#colortable do
284 a = a.. colortable[i][2] .. strARRAY_SEP
285 end
286 a = a .. strARRAY_END .. strVALUE_END .. strKV_END
287 end
288 return a
289 end
290
291 local function outputKV_key (pdfedict,key)
292 local name = GETNAME(pdfedict,key)
293 local a = ""
294 if name then
295 a = strKV_BEG .. key .. strVALUE_BEG .. strNAME .. name .. strVALUE_END .. strKV_END
296 end
297 return a
298 end
299
300 -- XXX handle fourth argument
301 local function outputKV_Border (pdfedict)
302 local border = GETARRAY(pdfedict,constKEY_BORDER)
303 local a =""
304 if border then
305 local bordertable = ARRAYTOTABLE(border)
306 a = strKV_BEG .. constKEY_BORDER .. strVALUE_BEG .. strARRAY_BEG
307 for i=1,3 do
308 a = a .. bordertable[i][2] .. strARRAY_SEP
309 end
310 -- fourth argument later, it is an array (type 7)
311 a = a ..strARRAY_END .. strVALUE_END .. strKV_END
312 end
313 return a
314 end
315
316 local function outputKV_BS (pdfedict)
317 local bsstyle = GETDICTIONARY(pdfedict,constKEY_BS)
318 local a =""
319 if bsstyle then
320 local bsstyledict = DICTIONARYTOTABLE(bsstyle)
321 a = strKV_BEG .. constKEY_BS .. strVALUE_BEG ..strDICT_BEG
322 for k,v in pairs (bsstyledict) do
323 a = a .. strNAME.. k
324 if v[1]== 5 then
325 a = a .. strNAME .. v[2]
326 else
327 a = a ..strRECT_SEP .. v[2]
328 end
329 end
330 a = a .. strDICT_END .. strVALUE_END .. strKV_END
331 end
332 return a
333 end
334
335 local function outputKV_uri (pdfedict)
336 local type, value, hex = GETFROMDICTIONARY(pdfedict,constKEY_URI)
337 if TYPE(value) == "pdfe.reference" then
338 type,value,hex = GETFROMREFERENCE(value)
339 end
340 local a= strKV_BEG .. constKEY_URI .. strVALUE_BEG
341 if hex then
342 a = a .. strHEX_STR_BEG .. value .. strHEX_STR_END
343 else
344 a = a .. strLIT_STR_BEG ..value .. strLIT_STR_END
345 end
346 a = a .. strVALUE_END .. strKV_END
347 return a
348 end
349
350 local function outputKV_N (pdfedict)
351 local name = GETNAME(pdfedict,"N")
352 local a= strKV_BEG .. constKEY_NAME .. strVALUE_BEG .. name .. strVALUE_END .. strKV_END
353 return a
354 end
355
356 -- if a gotoR has a filespec filespec we use this
357 -- to output the reference. It is rather crude and handles only names and strings
358 local function outputDICT (dictionary)
359 local tkeys = {}
360 local dict = DICTIONARYTOTABLE(dictionary)
361 for name,value in pairs(dict) do
362 table.insert(tkeys,name)
363 end
364 table.sort(tkeys)
365 local a = "<<"
366 for _,k in ipairs (tkeys) do
367 v=dict[k]
368 a = a .. strNAME.. k
369 if v[1]== 5 then -- it is a name
370 b = string.gsub(v[2], "/", "#2F")
371 a = a .. strNAME .. b
372 elseif v[1] == 6 then -- it is a string
373 local b
374 if v[3] then
375 b = "<" .. v[2] .. ">"
376 else
377 b = "(" .. v[2] .. ")"
378 end
379 a = a ..strRECT_SEP .. b
380 -- everything else is ignored for now!
381 end
382 end
383 a = a .. ">>"
384 return a
385 end
386
387 local function outputKV_gotor (pdfedict) -- action dictionary
388 local type, value, hex = GETFROMDICTIONARY(pdfedict,"F")
389 local desttype, destvalue, destdetail = GETFROMDICTIONARY(pdfedict,"D")
390 local a = strKV_BEG .. constKEY_FILE .. strVALUE_BEG
391 if TYPE(value) == "pdfe.reference" then
392 local x,dictionary = GETFROMREFERENCE(value)
393 if TYPE(dictionary) == "pdfe.dictionary" then
394 a = a .. outputDICT (dictionary)
395 else
396 print("ERROR!? this is not a dictionary!!")
397 end
398 else
399 if hex then
400 a = a .. strHEX_STR_BEG .. value .. strHEX_STR_END
401 else
402 a = a .. strLIT_STR_BEG .. value .. strLIT_STR_END
403 end
404 end
405 a = a .. strVALUE_END .. strKV_END
406 if desttype == 7 then
407 local type, pagenum = GETFROMARRAY(GETARRAY (pdfedict,"D"),1)
408 local type, fittype = GETFROMARRAY(GETARRAY (pdfedict,"D"),2)
409 a = a .. strKV_BEG .. constKEY_DEST_PAGE .. strVALUE_BEG .. pagenum .. strVALUE_END .. strKV_END
410 a = a .. strKV_BEG .. constKEY_DEST_VIEW .. strVALUE_BEG .. strNAME .. fittype .. strVALUE_END .. strKV_END
411 elseif desttype == 6 then
412 a = a .. strKV_BEG .. constKEY_DEST_NAME .. strVALUE_BEG ..
413 strLIT_STR_BEG .. destvalue .. strLIT_STR_END .. strVALUE_END .. strKV_END
414 end
415 return a
416 end
417
418 -- this outputs the key DestLabel with a count
419
420 local function outputKV_goto (count)
421 local a = strKV_BEG .. constKEY_DEST_LABEL .. strVALUE_BEG .. count .. strVALUE_END .. strKV_END
422 return a
423 end
424
425 -- this outputs the key DestName with a name
426 local function outputKV_goto_name (name)
427 local a = strKV_BEG .. constKEY_DEST_NAME .. strVALUE_BEG .. name .. strVALUE_END .. strKV_END
428 return a
429 end
430
431 local function outputENTRY_dest (destcount,name,pagereftonum,destnamestoref,pdfedoc)
432 local pagenum, data = getdestdata(name,pagereftonum,destnamestoref)
433 local mediabox = pdfe.getbox(GETPAGE(pdfedoc,pagenum),"MediaBox")
434 local a = strENTRY_BEG
435 a = a .. strCMD_BEG .. constCMD_DEST .. strCMD_END
436 a = a .. strARG_BEG .. pagenum .. strARG_END
437 a = a .. strARG_BEG .. destcount .. strARG_END
438 -- name
439 a = a .. strARG_BEG .. data[2][2] .. strARG_END
440 a = a .. strKVS_BEG
441 if data[2][2] == constDEST_XYZ then
442 if data[3] and data[3][2] then
443 a = a .. strKV_BEG .. constKEY_DEST_X .. strVALUE_BEG .. data[3][2] .. strVALUE_END .. strKV_END
444 else
445 a = a .. strKV_BEG .. constKEY_DEST_X .. strVALUE_BEG .. mediabox[1] .. strVALUE_END .. strKV_END
446 end
447 if data[4] and data[4][2] then
448 a = a .. strKV_BEG .. constKEY_DEST_Y .. strVALUE_BEG .. data[4][2] .. strVALUE_END .. strKV_END
449 else
450 a = a .. strKV_BEG .. constKEY_DEST_Y .. strVALUE_BEG .. mediabox[4] .. strVALUE_END .. strKV_END
451 end
452 if data[5] and data[5][2] then
453 a = a .. strKV_BEG .. constKEY_DEST_ZOOM .. strVALUE_BEG .. data[5][2] .. strVALUE_END .. strKV_END
454 end
455 elseif data[2][2] == constDEST_FIT then -- nothing to do
456 elseif data[2][2] == constDEST_FITB then -- nothing to do
457 elseif data[2][2] == constDEST_FITH then
458 if data[3] and data[3][2] then
459 a = a .. strKV_BEG .. constKEY_DEST_Y .. strVALUE_BEG .. data[3][2] .. strVALUE_END .. strKV_END
460 end
461 elseif data[2][2] == constDEST_FITBH then
462 if data[3] and data[3][2] then
463 a = a .. strKV_BEG .. constKEY_DEST_Y .. strVALUE_BEG .. data[3][2] .. strVALUE_END .. strKV_END
464 end
465 elseif data[2][2] == constDEST_FITV then
466 if data[3] and data[3][2] then
467 a = a .. strKV_BEG .. constKEY_DEST_X .. strVALUE_BEG .. data[3][2] .. strVALUE_END .. strKV_END
468 end
469 elseif data[2][2] == constDEST_FITBV then
470 if data[3] and data[3][2] then
471 a = a .. strKV_BEG .. constKEY_DEST_X .. strVALUE_BEG .. data[3][2] .. strVALUE_END .. strKV_END
472 end
473 elseif data[2][2] == constDEST_FITR and data[6] then
474 a = a .. strKV_BEG .. constKEY_DEST_RECT .. strVALUE_BEG
475 a = a .. data[3][2] .. strRECT_SEP
476 a = a .. data[4][2] .. strRECT_SEP
477 a = a .. data[5][2] .. strRECT_SEP
478 a = a .. data[6][2] .. strVALUE_END .. strKV_END
479 end
480 -- output also the name. This perhaps need a check if the name exists
481 -- print("DEBUG TYPE name", TYPE(name))
482 -- if name is a reference, resolve it once, issue #30
483 if (TYPE(name) == "pdfe.reference") then
484 _,name = GETFROMREFERENCE(name)
485 end
486 -- check also if name is still a reference issue #30
487 if not (TYPE(name) == "pdfe.array" or TYPE(name) == "pdfe.reference") then
488 a = a .. strKV_BEG .. constKEY_DEST_NAME .. strVALUE_BEG .. name .. strVALUE_END .. strKV_END
489 end
490 a = a .. strKVS_END .. strENTRY_END
491 return a
492 end
493
494 -- the main function
495
496 local function __writepax (ext,file)
497 local fileVAR = assert(kpse.find_file(file ..".pdf"),"file `"..file..".pdf` not found")
498 local filebaseVAR = FILENAMEONLY(fileVAR)
499 -- getting the data for the concrete document:
500 local writeVAR = io.open (filebaseVAR .."."..ext,"w") -- always in current directory
501 local function WRITE(content)
502 writeVAR:write(content)
503 end
504 local docVAR = OPEN (fileVAR)
505 local pagereftonumVAR, pagecountVAR = getpagesdata (docVAR)
506 local destcountVAR = 0
507 -- build from names table:
508 local destnamestorefVAR = getdestreferences (docVAR)
509 local collected_destinations = {}
510 local useddestnames = {}
511 -- output ...
512 WRITE(strENTRY_BEG .. "{pax}{0.1l}" .. strENTRY_END)
513 WRITE(outputENTRY_file(fileVAR,docVAR))
514 WRITE(outputENTRY_pagenum(pagecountVAR))
515 for i=1, pagecountVAR do
516 WRITE(outputENTRY_page(docVAR,i))
517 local annots=GETPAGE(docVAR,i).Annots
518 if annots then
519 for j = 0,#annots-1 do
520 local annot = GETDICTIONARY (annots,j)
521 annottable = DICTIONARYTOTABLE (annot)
522 if annottable.Dest then
523 destcountVAR=destcountVAR + 1
524 WRITE (strENTRY_BEG)
525 WRITE (outputCMD_annot(annot,i,"GoTo"))
526 WRITE (strKVS_BEG) -- begin KVS data
527 WRITE ( outputKV_color(annot) )
528 WRITE ( outputKV_key(annot,constKEY_H) )
529 WRITE ( outputKV_Border (annot) )
530 WRITE ( outputKV_BS (annot) )
531 WRITE ( outputKV_goto (destcountVAR) )
532 local type,annotgoto,hex = GETFROMDICTIONARY(annot,"Dest")
533 -- if the Dest is a string add the string as a name:
534 if type == 6 then
535 WRITE ( outputKV_goto_name(annotgoto) )
536 end
537 WRITE(strKVS_END) -- end KVS
538 WRITE(strENTRY_END) -- end annot data
539 table.insert(collected_destinations, outputENTRY_dest(destcountVAR,
540 annotgoto,pagereftonumVAR,destnamestorefVAR,docVAR))
541 else
542 local annotaction = GETDICTIONARY(annot,"A")
543 -- print("DEBUG A:",table.serialize(DICTIONARYTOTABLE(annotaction)))
544 local annotactiontype =""
545 if annotaction then
546 annotactiontype = GETNAME(annotaction,"S")
547 WRITE (strENTRY_BEG)
548 WRITE (outputCMD_annot(annot,i,annotactiontype))
549 WRITE (strKVS_BEG) -- begin KVS data
550 WRITE ( outputKV_color(annot) )
551 WRITE ( outputKV_key(annot,constKEY_H) )
552 WRITE ( outputKV_Border (annot) )
553 WRITE ( outputKV_BS (annot) )
554 if annotactiontype == constKEY_URI then
555 WRITE ( outputKV_uri(annotaction) )
556 elseif annotactiontype =="GoTo" then
557 local desttype, destname, destdetail = GETFROMDICTIONARY(annotaction,"D")
558 -- print("DEBUG annotaction", desttype, destname, destdetail)
559 destcountVAR=destcountVAR + 1
560 WRITE ( outputKV_goto (destcountVAR) )
561 -- this needs perhaps a check if destname actually exists.
562 if desttype == 6 then
563 WRITE ( outputKV_goto_name(destname) )
564 end
565 elseif annotactiontype=="GoToR" then
566 WRITE ( outputKV_gotor(annotaction) )
567 elseif annotactiontype=="Named" then
568 WRITE ( outputKV_N (annotaction) )
569 end
570 WRITE(strKVS_END) -- end KVS
571 WRITE(strENTRY_END) -- end annot data
572 if annotactiontype =="GoTo" then
573 local type,annotactiongoto,hex = GETFROMDICTIONARY(annotaction,"D")
574 if type==6 then
575 -- record used name
576 useddestnames[annotactiongoto] = 1
577 end
578 table.insert(collected_destinations, outputENTRY_dest(destcountVAR,annotactiongoto,pagereftonumVAR,destnamestorefVAR,docVAR))
579 end
580 end
581 end
582 end
583 end
584 end
585 for i=1,#collected_destinations do
586 WRITE (collected_destinations[i])
587 end
588 -- write out the rest of the destinations.
589 -- We order first the table so that the newpax file doesn't change between
590 -- compilations, see issue #25 and PR #25
591 local destnamessorted = {}
592 for k,v in pairs (destnamestorefVAR) do
593 -- ignore use dests and page destinations.
594 i=string.find(k,"page.",1)
595 if not useddestnames[k] and not i then
596 table.insert (destnamessorted,k)
597 end
598 end
599 table.sort(destnamessorted)
600 for i = 1, #destnamessorted do
601 k=destnamessorted[i]
602 destcountVAR=destcountVAR + 1
603 WRITE(outputENTRY_dest(destcountVAR,k,pagereftonumVAR,destnamestorefVAR,docVAR))
604 end
605 io.close(writeVAR)
606 end
607
608 local function writepax (file)
609 __writepax ("pax",file)
610 end
611
612 local function writenewpax (file)
613 __writepax ("newpax",file)
614 end
615
616 newpax = {}
617 newpax.writepax = writepax
618 newpax.writenewpax = writenewpax
619
620 return newpax
621
622 --
623 -- End of File `newpax.lua'.