
En versiones recientes de LuaTeX, la jerarquía del esquema PDF se puede configurar desde el lado de TeX con \pdfextension outline
; Por ejemplo:
\pdfextension outline goto page \the\c@page {} count 1 {Chapter 1}
\pdfextension outline attr{/F 1} goto name{label} {Section 1.1}
Me gustaría hacer esto desde Lua. Algo como:
pdf.setoutlines( whatever )
… pero no existe tal interfaz.
He pensado en utilizar objetos PDF sin formato usando pdf.immediateobj
, pero no sé cómo hacerlo. Si es posible lograr esto de esa manera, ¿podría mostrar un ejemplo de jerarquía?
Respuesta1
Sí, tendrías que escribir objetos PDF sin formato. A continuación se muestra un ejemplo mínimo, que consta de dos páginas marcadas.
El archivo outlines-example.tex
(compílelo con formato simple luatex
):
This is the first page.
\vfil\break
This is the second page.
\directlua{require('outline-examples')}
\bye
El archivo outlines-example.lua
:
-- Reserve all object numbers beforehand
local first, second, outlines =
pdf.reserveobj(), pdf.reserveobj(), pdf.reserveobj()
-- Write out the bookmarks
pdf.immediateobj(first, string.format(
'<< /Title (First page) /Parent %d 0 R /Next %d 0 R /Dest [0 /XYZ] >>',
outlines, second))
pdf.immediateobj(second, string.format(
'<< /Title (Second page) /Parent %d 0 R /Prev %d 0 R /Dest [1 /XYZ] >>',
outlines, first))
-- Write out the outline dictionary
pdf.immediateobj(outlines, string.format(
'<< /Type/Outlines /First %d 0 R /Last %d 0 R /Count 2 >>',
first, second))
-- Add the outline dictionary to the document catalog
pdf.setcatalog(string.format(
'%s /Outlines %d 0 R',
pdf.getcatalog() or '', outlines))