![]() |
Links, bookmarks and metadata in PDF output | ![]() |
The renderer interface has two methods for links, which only printers implement: href (dest, x1, y1, x2, y2) makes the rectangle a link to dest, and anchor (label, x1, y1, x2, y2) makes it the target of a label. The boxes call them while they are drawn, in two ways:
A locus whose body is not accessible in the document (the body is generated by a macro, as for reference, pageref or label) is typeset as a locus_box (
concat_active.cpp:205
). build_locus takes the destination from the (url dest) vertex of its links (ref), and the anchor from an (id name) vertex (anchor). The label macro carries a link (link anchor (id "#name")) and reference a link to (url "#name") (
env_default.cpp:381
), so anchors and internal destinations have the same form. After drawing, locus_box_rep::post_display calls href and anchor with the box of each word (
change_boxes.cpp:740
).
For accessible bodies, typically hlink, nothing is stored in the boxes. When a box is drawn on a printer, box_rep::display_links (
boxes.cpp:829
) walks up the path of the box in the edit tree, looks up the identifiers of each subtree and their links in the global link tables, and calls href for every link of type hyperlink with a url vertex. These tables are filled by the typesetting for the screen (see links, loci and references), so this only works for a buffer which has been typeset on screen.
In both cases each box gets its own link: a link of three words becomes three annotations.
href (
pdf_hummus_renderer.cpp:2297
) writes a /Link annotation for the rectangle, slightly enlarged. Its border is invisible unless the preference locus-on-paper is preserve. A destination #label becomes a named destination /labeln, where n is the number which get_label_id gives to the label; anything else becomes a /URI action with the destination as it is, so relative links to other files are written unchanged. The annotations are written by the destructor, but registered with the page they belong to through RegisterAnnotationReferenceForNextPageWrite.
anchor records the label, the page and the position just above the box; flush_dests writes the dictionary of named destinations, each with an /XYZ view of its page, and the DestinationsWriter adds it to the catalog as /Dests.
The PDF outline is built from the table of contents. The macros of
std-automatic.ts
which add an entry to the table of contents also call toc-notify with the kind of the entry (toc-strong-1, toc-strong-2, toc-1, …, toc-5) and its title. typeset_toc_notify (
concat_active.cpp:316
) converts the title to plain text, replacing the TeX, LaTeX and TeXmacs logos by their names, and produces an invisible toc_box; when this box is drawn, it calls toc_entry with the kind and title.
toc_entry (
pdf_hummus_renderer.cpp:2355
) turns the kind into a level from 1 (toc-strong-1, chapters in books) to 7 (toc-5) and records the entry with its page and position. flush_outlines and recurse build the tree of outline items from this flat list of levels: an entry with a higher level than the previous one becomes its child. Each item has a /Title written as a UTF-16 hex string, links to its parent and siblings, the number of its children (negative, so that the items are closed), and a destination on its page.
set_metadata stores the title, author and subject passed by print_doc (see from the menu to the file), and flush_metadata (
pdf_hummus_renderer.cpp:2464
) writes them to the information dictionary of the trailer, together with /Creator (TeXmacs version), /Producer (the same followed by + Hummus 4.0) and the creation date. There is no XMP metadata stream, and nothing more (keywords, language, tagged structure) is written.