Add support for folded outlines in PDF documents.
[s-roff.git] / contrib / pdfmark / pdfmark.ms
blob762675ba9e47dcd65026b996b1940f9b70ff5d16
1 .\" vim: ft=groff
2 .CS
3 Portable Document Format
4 Publishing with GNU Troff
5 .AU Keith Marshall
6 .AI <keith.d.marshall@ntlworld.com>
7 .CE
8 .\" Set the PDF default document view attribute, to ensure that the document
9 .\" outline is visible, each time the document is opened in Acrobat Reader.
10 .\"
11 .pdfview /PageMode /UseOutlines
12 .\"
13 .\" Initialise the outline view to show only three heading levels,
14 .\" with additional subordinate level headings folded.
15 .\"
16 .nr PDFOUTLINE.FOLDLEVEL 3
17 .\"
18 .\" Add document identification meta-data
19 .\"
20 .pdfinfo /Title     Portable Document Format Publishing with GNU Troff
21 .pdfinfo /Author    Keith Marshall
22 .pdfinfo /Subject   Tips and Techniques for Exploiting PDF Features with GNU Troff
23 .pdfinfo /Keywords  groff troff PDF pdfmark
24 .\"
25 .\" Set the default cross reference format to indicate section numbers,
26 .\" rather than page numbers, when we insert a reference pointer.
27 .\"
28 .ds PDFHREF.INFO section \\*[SN-NO-DOT] \\$*
29 .\"
30 .\" Define a macro, to print reference links WITHOUT the usual "see" prefix.
31 .\"
32 .de XR-NO-PREFIX
33 .rn PDFHREF.PREFIX xx
34 .ds PDFHREF.PREFIX
35 .XR \\$@
36 .rn xx PDFHREF.PREFIX
38 .\"
39 .\" Define a string,
40 .\" to insert a Registered Trade Mark symbol as a superscript.
41 .\"
42 .ds rg \*{\(rg\*}
43 .\"
44 .\" Establish the page layout.
45 .\"
46 .nr PO  2.5c
47 .nr LL 17.0c
48 .nr LT 17.0c
49 .nr HY  0
50 .nr FF  3
51 .nr DI  5n
52 .\"
53 .\" Generate headers in larger point sizes, for NH levels < 4,
54 .\" with point size increasing by 1.5p, for each lesser NH level.
55 .\"
56 .nr GROWPS 4
57 .nr PSINCR 1.5p
58 .\"
59 .de EM
60 .\".I "\s'+0.3'\\$1\s0" "\\$2" "\\$3"
61 .I \\$@
63 .de CWB
64 \\$5\fC\\$3\fP\f(CB\\$1\fP\fC\\$2\fP\\$4
66 .de CWI
67 \\$5\fC\\$3\fP\f(CI\\$1\fP\fC\\$2\fP\\$4
69 .de CWBI
70 \\$5\fC\\$3\fP\f[CBI]\\$1\fP\fC\\$2\fP\\$4
72 .ds = \f(CB\\$1\f(CR\\$4\f[CBI]\\$2\f(CR\\$3
73 .\"
74 .NH 1
75 .\" When we use numbered section headings, we might like to automatically
76 .\" insert a table of contents entry, using the text of the heading itself.
77 .\" The "ms" macros don't provide any standard mechanism for doing this,
78 .\" but "spdf.tmac" adds the "XN" macro, which will do it for us.
79 .\"
80 .\" Here's a simple example of how we might use it.  In this case, the word
81 .\" "Introduction" will appear both in the body of the document, as the text
82 .\" of the heading, and it will be added to the table of contents, which is
83 .\" subsequently "printed" using the "TC" macro; in both locations, it will
84 .\" be prefixed by the section number.
85 .\"
86 .\" As an additional side effect, any use of "XN" will cause the table of
87 .\" contents entry to be automatically reproduced, with the exception of its
88 .\" page number reference, as a PDF document outline entry.  Thus, the use
89 .\" of "XN" to specify numbered section headings results in the automatic
90 .\" creation of a numbered PDF document outline.  This automatic creation
91 .\" of the outline is completely transparent, and will occur regardless
92 .\" of whether the "TC" macro is subsequently invoked, or not.
93 .\"
94 .XN Introduction
95 .\"
96 .\" If using an old s.tmac, without the SN-NO-DOT extension,
97 .\" make sure we get SOMETHING in section number references.
98 .\"
99 .if !dSN-NO-DOT .als SN-NO-DOT SN
101 It might appear that it is a fairly simple matter to
102 produce documents in Adobe\*(rg\~\(lqPortable\~Document\~Format\(rq,
103 commonly known as PDF, using
104 .CW groff ) GNU\~Troff\~(
105 as the document formatter.
106 Indeed,
107 .CW groff 's
108 default output format is the native Adobe\*(rg\~PostScript\*(rg format,
109 which PDF producers such as Adobe\*(rg Acrobat\*(rg Distiller\*(rg,
110 or GhostScript, expect as their input format.
111 Thus, the PDF production process would seem to entail simply
112 formatting the document source with
113 .CW groff ,
114 to produce a PostScript\*(rg version of the document,
115 which can subsequently be processed by Acrobat\*(rg Distiller\*(rg
116 or GhostScript, to generate the final PDF document.
118 For many PDF production requirements,
119 the production cycle described above may be sufficient.
120 However, this is a limited PDF production method,
121 in which the resultant PDF document represents no more than
122 an on screen image of the printed form of the document, if
123 .CW groff 's
124 PostScript\*(rg output were printed directly.
126 The Portable Document Format provides a number of features,
127 which significantly enhance the experience of reading a document on screen,
128 but which are of little or no value to a document which is merely printed.
130 .EM is
131 possible to exploit these PDF features, which are described in the Adobe\*(rg
133 .de pdfmark-manual
134 .\" This is an example of a resource reference specified by URI ...
135 .\" We may need to refer often to the Adobe pdfmark Reference Manual,
136 .\" so we create the internet link definition using a macro, to make
137 .\" it reusable.
139 .\" Note also, that we protect the description of the reference by
140 .\" preceding it with "--", to avoid "invalid character in name" type
141 .\" error messages from groff (caused by the use of "\~").
143 .pdfhref W -D http://partners.adobe.com/asn/acrobat/docs/pdfmark.pdf \
144     -P \(lq -A \(rq\\$1 -- pdfmark\~Reference\~Manual
146 .pdfmark-manual ,
147 with some refinement of the simple PDF production method, provided
148 appropriate \(lqfeature implementing\(rq instructions can be embedded into
149 .CW groff 's
150 PostScript\*(rg rendering of the document.
151 This, of course, implies that the original document source, which
152 .CW groff
153 will process to generate the PostScript\*(rg description of the document,
154 must include appropriate markup to exploit the desired PDF features.
155 It is this preparation of the
156 .CW groff
157 document source to exploit a number of these features,
158 which provides the principal focus of this document.
160 The markup techniques to be described have been utilised in the production of
161 the PDF version of this document itself.
162 This has been formatted using
163 .CW groff 's
164 .CW ms
165 macro package;
166 thus, usage examples may be found in the document source file,
167 .CW \n(.F ,
168 to which comments have been added,
169 to help identify appropriate markup examples for implementing PDF features,
170 such as:\(en
172 .IP \(bu
173 Selecting a default document view, which defines how the document will appear
174 when opened in the reader application; for example, when this document is
175 opened in Acrobat\*(rg\~Reader, it should display the top of the cover sheet,
176 in the document view pane, while a document outline should appear to the left,
177 in the \(lqBookmarks\(rq pane.
178 .IP \(bu
179 Adding document identification \(lqmeta\(hydata\(rq,
180 which can be accessed, in Acrobat\*(rg\~Reader,
181 by inspecting the \(lqFile\^/\^Document\~Properties\^/\^Summary\(rq.
182 .IP \(bu
183 Creating a document outline, which will be displayed in the \(lqBookmarks\(rq
184 pane of Acrobat\*(rg\~Reader, such that readers may quickly navigate to any
185 section of the document, simply by clicking on the associated heading
186 in the outline view.
187 .IP \(bu
188 Embedding active links in the body of the document, such that readers may
189 quickly navigate to related material at another location within the same
190 document, or in another PDF document, or even to a related Internet resource,
191 specified by its URI.
192 .IP \(bu
193 Adding annotations, in the form of \(lqsticky notes\(rq, at strategic
194 points within the PDF document.
197 All of the techniques described have been tested on
198 .EM both
199 GNU/Linux, and on Microsoft\*(rg Windows\(tm2000 operating platforms, using
200 .CW groff
201 .CW 1.19.1 ,\c
202 .pdfhref L -D footnote1 -- \**
204 .pdfhref M footnote1
205 Later versions should, and some earlier versions may, be equally suitable.
207 .pdfhref W http://groff.ffii.org
208 for information and availability of the latest version.
210 in association with
211 .CW AFPL
212 .CW GhostScript
213 .CW 8.14 .\c
214 .pdfhref L -D footnote2 -- \**
216 .pdfhref M footnote2
217 Again, other versions may be suitable.
219 .pdfhref W http://ghostscript.com
220 for information and availability.
222 Other tools employed, which should be readily available on
223 .EM any
225 UNIX\(tm
227 or GNU/Linux system, are
228 .CW sed ,
229 .CW awk
231 .CW make ,
232 together with an appropriate text editor, for creating and marking up the
233 .CW groff
234 input files.
235 These additional utilities are not provided, as standard,
236 on the Microsoft\*(rg Windows\(tm platform,
237 but several third party implementations are available.
238 Some worth considering include the MKS\*(rg\~Toolkit,\**
240 A commercial offering; see
241 .pdfhref W http://mkssoftware.com/products/tk/default.asp
242 for information.
244 Cygwin,\**
247 .EM free
248 but comprehensive
250 POSIX
252 emulation environment and
254 UNIX\(tm
256 toolkit for 32\(hybit Microsoft\*(rg Windows\(tm platforms; see
257 .pdfhref W http://cygwin.com
258 for information and download.
260 or MSYS.\**
262 Another free, but minimal suite of common
264 UNIX\(tm
266 tools for 32\(hybit Microsoft\*(rg Windows\(tm, available for download from
267 .pdfhref W -A ; http://www.mingw.org
269 .EM does 
270 include those tools listed above,
271 and is the package which was actually used when performing the Windows\(tm2000
272 platform tests referred to in the text.
274 This list is by no means exhaustive, and should in no way be construed as an
275 endorsement of any of these packages, nor to imply that other similar packages,
276 which may be available, are in any way inferior to them.
278 .NH 1
279 .\" We may wish a section heading to represent a named destination,
280 .\" so that we can create a linked reference to it, from some other 
281 .\" part of the PDF document, (or even from another PDF document).
283 .\" Here we use the "-N" option of the "XN" macro, to create a named
284 .\" PDF link destination, at the location of the heading.  Notice that
285 .\" we also use the "--" marker to separate the heading text from the
286 .\" preceding option specification; it is not strictly necessary in
287 .\" this case, but it does help to set off the heading text from the
288 .\" option specification.
290 .XN -N pdf-features -- Exploiting PDF Document Features
292 To establish a consistent framework for adding PDF features, a
293 .CW groff
294 macro package, named
295 .CW pdfmark.tmac ,
296 has been provided.
297 Thus, to incorporate PDF features in a document,
298 the appropriate macro calls, as described below, may be placed in the
299 .CW groff
300 document source, which should then be processed with a
301 .CW groff
302 command of the form
304 .fam C
305 groff -Tps [-m
306 .I name "] -m"
307 .B pdfmark
308 .I options \& [-
309 .I "file ..." \& "...] "
311 It may be noted that the
312 .CW pdfmark
313 macros have no dependencies on, and no known conflicts with,
314 any other
315 .CW groff
316 macro package;  thus, users are free to use any other macro package,
317 of their choice, to format their documents, while also using the
318 .CW pdfmark
319 macros to add PDF features.
320 .NH 2
321 .XN -N pdfmark-operator -- The \F[C]pdfmark\F[] Operator
323 All PDF features are implemented by embedding instances of the
324 .B \F[C]pdfmark\F[]
325 operator, as described in the Adobe\*(rg
326 .pdfmark-manual ,
327 into
328 .CW groff 's
329 PostScript\*(rg output stream.
330 To facilitate the use of this operator, the
331 .CW pdfmark
332 macro package defines the primitive
333 .CW pdfmark
334 macro; it simply emits its argument list,
335 as arguments to a
336 .CW pdfmark
337 operator, in the PostScript\*(rg output stream.
339 .pdfhref M -N pdfmark-example
340 To illustrate the use of the
341 .CW pdfmark
342 macro, the following is a much simplified example of how a bookmark
343 may be added to a PDF document outline
345 .CW ".pdfmark \e"
346 .RS 4
348 .fam C
349 /Count 2 \e
350 /Title (An Example of a Bookmark with Two Children) \e
351 /View  [/FitH \en[PDFPAGE.Y]] \e
352 /OUT
355 In general, users should rarely need to use the
356 .CW pdfmark
357 macro directly.
358 In particular, the above example is too simple for general use; it
359 .EM will
360 create a bookmark, but it does
361 .EM not
362 address the issues of setting the proper value for the
363 .CW /Count
364 key, nor of computing the
365 .CW PDFPAGE.Y
366 value used in the
367 .CW /View
368 key. The
369 .CW pdfmark
370 macro package includes a more robust mechanism for creating bookmarks,
372 .\" Here is an example of how a local reference may be planted,
373 .\" using the automatic formatting feature of the "pdfhref" macro.
375 .\" This is a forward reference to the named destination "add-outline",
376 .\" which is defined below, using the "XN" wrapper macro, from the
377 .\" "spdf.tmac" macro package.  The automatically formatted reference
378 .\" will be enclosed in parentheses, as specified by the use of
379 .\" "-P" and "-A" options.
381 .pdfhref L -P ( -A ), -D add-outline
383 which addresses these issues automatically.
384 Nevertheless, the
385 .CW pdfmark
386 macro may be useful to users wishing to implement more advanced PDF features,
387 than those currently supported directly by the
388 .CW pdfmark
389 macro package.
390 .NH 2
391 .XN -N docview -- Selecting an Initial Document View
393 By default,
394 when a PDF document is opened,
395 the first page will be displayed,
396 at the default magnification set for the reader,
397 and outline and thumbnail views will be hidden.
398 When using a PDF reader,
399 such as Acrobat\*(rg\~Reader,
400 which supports the
401 .CW /DOCVIEW
402 class of the
403 .CW pdfmark
404 operator,
405 these default initial view settings may be overridden,
406 using the
407 .CW pdfview
408 macro.
409 For example
411 .CW ".pdfview /PageMode /UseOutlines"
413 will cause Acrobat\*(rg\~Reader to open the document outline view,
414 to the left of the normal page view,
415 while
417 .CW ".pdfview /PageMode /UseThumbs"
419 will open the thumbnail view instead.
421 Note that the two
422 .CW /PageMode
423 examples, above, are mutually exclusive \(em it is not possible to have
424 .EM both
425 outline and thumbnail views open simultaneously.
426 However, it
427 .EM is
428 permitted to add
429 .CW /Page
431 .CW /View
432 keys, to force the document to open at a page other than the first,
433 or to change the magnification at which the document is initially displayed;
434 see the
435 .pdfmark-manual
436 for more information.
438 It should be noted that the view controlling meta\(hydata, defined by the
439 .CW pdfview
440 macro, is not written immediately to the PostScript\*(rg output stream,
441 but is stored in an internal meta\(hydata \(lqcache\(rq,
442 (simply implemented as a
443 .CW groff
444 diversion).
445 This \(lqcached\(lq meta\(hydata must be written out later, by invoking the
446 .CW pdfsync
447 macro,
449 .\" Here is another example of how we may introduce a forward reference.
450 .\" This time we are using the shorter notation afforded by the "XR" macro
451 .\" provided by "spdf.tmac"; this example is equivalent to the native
452 .\" "pdfmark.tmac" form
453 .\"     .pdfhref L -D pdfsync -P ( -A ).
455 .XR pdfsync ). (
457 .NH 2
458 .XN -N docinfo -- Adding Document Identification Meta-Data
460 In addition to the
461 .CW /DOCVIEW
462 class of meta\(hydata described above,
463 .XR docview ), (
464 we may also wish to include document identification meta\(hydata,
465 which belongs to the PDF
466 .CW /DOCINFO
467 class.
469 To do this, we use the
470 .CW pdfinfo
471 macro.
472 As an example of how it is used,
473 the identification meta\(hydata attached to this document
474 was specified using a macro sequence similar to:\(en
477 .fam C
478 \&.pdfinfo /Title     PDF Document Publishing with GNU Troff
479 \&.pdfinfo /Author    Keith Marshall
480 \&.pdfinfo /Subject   How to Exploit PDF Features with GNU Troff
481 \&.pdfinfo /Keywords  groff troff PDF pdfmark
484 Notice that the
485 .CW pdfinfo
486 macro is repeated, once for each
487 .CW /DOCINFO
488 record to be placed in the document.
489 In each case, the first argument is the name of the applicable
490 .CW /DOCINFO
491 key, which
492 .EM must
493 be named with an initial solidus character;
494 all additional arguments are collected together,
495 to define the value to be associated with the specified key.
497 As is the case with the
498 .CW pdfview
499 macro,
500 .XR docview ), (
502 .CW /DOCINFO
503 records specified with the
504 .CW pdfinfo
505 macro are not immediately written to the PostScript\*(rg output stream;
506 they are stored in the same meta\(hydata cache as
507 .CW /DOCVIEW
508 specifications, until this cache is explicitly flushed,
509 by invoking the
510 .CW pdfsync
511 macro,
512 .XR pdfsync ). (
513 .NH 2
514 .XN -N add-outline -- Creating a Document Outline
516 A PDF document outline comprises a table of references,
517 to \(lqbookmarked\(rq locations within the document.
518 When the document is viewed in an \(lqoutline\~aware\(rq PDF document reader,
519 such as Adobe\*(rg Acrobat\*(rg Reader,
520 this table of \(lqbookmarks\(rq may be displayed in a document outline pane,
521 or \(lqBookmarks\(rq pane, to the left of the main document view.
522 Individual references in the outline view may then be selected,
523 by clicking with the mouse,
524 to jump directly to the associated marked location in the document view.
526 The document outline may be considered as a collection of \(lqhypertext\(rq
527 references to \(lqbookmarked\(rq locations within the document.
529 .CW pdfmark
530 macro package provides a single generalised macro,
531 .CW pdfhref ,
532 for creating and linking to \(lqhypertext\(rq reference marks.
533 This macro will be described more comprehensively in a later section,
534 .XR pdfhref ); (
535 the description here is restricted to its use for defining document outline entries.
536 .NH 3
537 .XN -N basic-outline -- A Basic Document Outline
539 In its most basic form, the document outline comprises a structured list of headings,
540 each associated with a marked location, or \(lqbookmark\(rq, in the document text,
541 and a specification for how that marked location should be displayed,
542 when this bookmark is selected.
544 To create a PDF bookmark, the
545 .CW pdfhref
546 macro is used,
547 at the point in the document where the bookmark is to be placed,
548 in the form
550 .fam C
551 .B ".pdfhref O"
552 .I level > <
553 .I "descriptive text ..."
555 in which the reference class
556 .CWB O \& \& \(rq \(lq
557 stipulates that this is an outline reference.
559 Alternatively, for those users who may prefer to think of a document outline
560 simply as a collection of bookmarks, the
561 .CW pdfbookmark
562 macro is also provided \(em indeed,
563 .CW pdfhref
564 invokes it, when processing the
565 .CWB O \& \& \(rq \(lq
566 reference class operator.
567 It may be invoked directly, in the form
569 .fam C
570 .B .pdfbookmark
571 .I level > <
572 .I "descriptive text ..."
574 Irrespective of which of the above macro forms is employed, the
575 .CWI level > <
576 argument is required.
577 It is a numeric argument, defining the nesting level of the \(lqbookmark\(rq
578 in the outline hierarchy, with one being the topmost level.
579 Its function may be considered analagous to the
580 .EM "heading level"
581 of the document's section headings,
582 for example, as specified with the
583 .CW NH
584 macro, if using the
585 .CW ms
586 macros to format the document.
588 All further arguments, following the
589 .CWI level > <
590 argument, are collected together, to specify the heading text which will appear
591 in the document's outline view.
592 Thus, the outline entry for this section of this document,
593 which has a level three heading,
594 might be specified as
597 \&.pdfhref O 3 \*(SN A Basic Document Outline
599 or, in the alternative form using the
600 .CW pdfbookmark
601 macro, as
604 \&.pdfbookmark 3 \*(SN A Basic Document Outline
605 .NH 3
606 .XN Hierarchical Structure in a Document Outline
608 When a document outline is created, using the
609 .CW pdfhref
610 macro as described in
612 .\" Here is an example of how we can temporarily modify the format of
613 .\" a reference link, in this case to indicate only the section number
614 .\" of the link target, in the form "section #", (or, if we define
615 .\" "SECREF.BEGIN" before the call, its content followed by the
616 .\" section number).
618 .\" We first define a macro, which will get the reference data from
619 .\" pdfhref, as arguments, and will return the formatted output, as we
620 .\" require it, the string "PDFHREF.TEXT".
622 .de SECREF
623 .while \\n(.$ \{\
624 .   ie '\\$1'section' \{\
625 .      if !dSECREF.BEGIN .ds SECREF.BEGIN \\$1
626 .      ds PDFHREF.TEXT \\*[SECREF.BEGIN]\~\\$2
627 .      rm SECREF.BEGIN
628 .      shift \\n(.$
629 .      \}
630 .   el .shift
631 .   \}
633 .\" We now tell "pdfhref" to use our formatting macro, in place of
634 .\" its builtin default formatter, before we specify the reference.
636 .pdfhref F SECREF
637 .pdfhref L -A , -D basic-outline
639 .\" At this point, we would normally revert the "pdfhref" formatter
640 .\" to use its default, built in macro.  However, in this particular
641 .\" case, we want to use our custom format one more time, before we
642 .\" revert it, so we will omit the reversion step this time.
644 and any entry is added at a nesting level greater than one,
645 then a hierarchical structure is automatically defined for the outline.
646 However, as was noted in the simplified
647 .pdfhref L -D pdfmark-example -- example
649 .pdfhref L -A , -D pdfmark-operator
651 .\" And now, we revert to default "pdfhref" formatting behaviour,
652 .\" by completing the call we delayed above.
654 .pdfhref F
656 the data required by the
657 .CW pdfmark
658 operator to create the outline entry may not be fully defined,
659 when the outline reference is defined in the
660 .CW groff
661 document source.
662 Specifically, when the outline entry is created, its
663 .CW /Count
664 key must be assigned a value equal to the number of its subordinate entries,
665 at the next inner level of the outline hierarchy;
666 typically however,
667 these subordinate entries will be defined
668 .EM later
669 in the document source, and the appropriate
670 .CW /Count
671 value will be unknown, when defining the parent entry.
673 To resolve this paradox, the
674 .CW pdfhref
675 macro creates the outline entry in two distinct phases \(em
676 a destination marker is placed in the PostScript\*(rg output stream immediately,
677 when the outline reference is defined,
678 but the actual outline entry is stored in an internal \(lqoutline cache\(rq,
679 until its subordinate hierarchy has been fully defined;
680 it can then be inserted in the output stream, with its
681 .CW /Count
682 value correctly assigned.
683 Effectively, to ensure integrity of the document outline structure,
684 this means that each top level outline entry, and
685 .EM all
686 of its subordinates, are retained in the cache, until the
687 .EM next
688 top level entry is defined.
690 One potential problem, which arises from the use of the \(lqoutline cache\(rq,
691 is that, at the end of any document formatting run, the last top level outline entry,
692 and any subordinates defined after it, will remain in the cache, and will 
693 .EM not
694 be automatically written to the output stream.
695 To avoid this problem, the user should follow the guidelines given in
697 .\" Here is a more conventional example of how to temporarily change
698 .\" to the format used to display reference links.  We will again use
699 .\" the "SECREF" format, which we defined above, but on this occasion
700 .\" we will immediately revert to the default format, after the link
701 .\" has been placed.
703 .pdfhref F SECREF
704 .pdfhref L -D pdfsync -A ,
705 .pdfhref F
707 to synchronise the output state with the cache state,
708 .XR pdfsync ), (
709 at the end of the
710 .CW groff
711 formatting run.
712 .NH 3
713 .XN -N outline-view -- Associating a Document View with an Outline Reference
715 Each \(lqbookmark\(rq entry, in a PDF document outline,
716 is associated with a specific document view.
717 When the reader selects any outline entry,
718 the document view changes to display the document context
719 associated with that entry.
721 The document view specification,
722 to be associated with any document outline entry,
723 is established at the time when the outline entry is created.
724 However, rather than requiring that each individual use of the
725 .CW pdhref
726 macro, to create an outline entry,
727 should include its own view specification,
728 the actual specification assigned to each entry is derived from
729 a generalised specification defined in the string
730 .CW PDFBOOKMARK.VIEW ,
731 together with the setting of the numeric register
732 .CW PDFHREF.VIEW.LEADING ,
733 which determine the effective view specification as follows:\(en
735 .IP \*[= PDFBOOKMARK.VIEW]
736 Establishes the magnification at which the document will be viewed,
737 at the location of the \(lqbookmark\(rq; by default, it is defined by
740 .CW ".ds PDFBOOKMARK.VIEW /FitH \e\en[PDFPAGE.Y] u"
743 which displays the associated document view,
744 with the \(lqbookmark\(rq location positioned at the top of the display window,
745 and with the magnification set to fit the page width to the width of the window.
746 .IP \*[= PDFHREF.VIEW.LEADING]
747 Specifies additional spacing,
748 to be placed between the top of the display window
749 and the actual location of the \(lqbookmark\(rq on the displayed page view.
750 By default, it is set as
753 .CW ".nr PDFHREF.VIEW.LEADING 5.0p"
756 Note that
757 .CW PDFHREF.VIEW.LEADING
758 does not represent true \(lqleading\(rq, in the typographical sense,
759 since any preceding text, set in the specified display space,
760 will be visible at the top of the document viewing window,
761 when the reference is selected.
763 Also note that the specification of
764 .CW PDFHREF.VIEW.LEADING
765 is shared by
766 .EM all
767 reference views defined by the
768 .CW pdfhref
769 macro; whereas
770 .CW PDFBOOKMARK.VIEW
771 is applied exclusively to outline references,
772 there is no independent
773 .CW PDFBOOKMARK.VIEW.LEADING
774 specification.
777 If desired, the view specification may be changed, by redefining the string
778 .CW PDFBOOKMARK.VIEW ,
779 and possibly also the numeric register
780 .CW PDFHREF.VIEW.LEADING .
781 Any alternative definition for
782 .CW PDFBOOKMARK.VIEW
783 .EM must
784 be specified in terms of valid view specification parameters,
785 as described in the Adobe\*(rg
786 .pdfmark-manual .
788 Note the use of the register
789 .CW PDFPAGE.Y ,
790 in the default definition of
791 .CW PDFBOOKMARK.VIEW
792 above.
793 This register is computed by
794 .CW pdfhref ,
795 when creating an outline entry;
796 it specifies the vertical position of the \(lqbookmark\(rq,
797 in basic
798 .CW groff
799 units, relative to the
800 .EM bottom
801 edge of the document page on which it is defined,
802 and is followed, in the
803 .CW PDFBOOKMARK.VIEW
804 definition, by the
805 .CW grops
806 .CW u \(rq \(lq
807 operator, to convert it to PostScript\*(rg units on output.
808 It may be used in any redefined specification for
809 .CW PDFBOOKMARK.VIEW ,
810 (or in the analogous definition of
811 .CW PDFHREF.VIEW ,
812 described in
813 .XR-NO-PREFIX pdfhref-view ),
815 .EM not
816 in any other context,
817 since its value is undefined outside the scope of the
818 .CW pdfhref
819 macro.
821 Since
822 .CW PDFPAGE.Y
823 is computed relative to the
824 .EM bottom
825 of the PDF output page,
826 it is important to ensure that the page length specified to
827 .CW troff
828 correctly matches the size of the logical PDF page.
829 This is most effectively ensured,
830 by providing
831 .EM identical
832 page size specifications to
833 .CW groff ,
834 .CW grops
835 and to the PostScript\*(rg to PDF converter employed,
836 and avoiding any page length changes within the document source.
838 Also note that
839 .CW PDFPAGE.Y
840 is the only automatically computed \(lqbookmark\(rq location parameter;
841 if the user redefines
842 .CW PDFBOOKMARK.VIEW ,
843 and the modified view specification requires any other positional parameters,
844 then the user
845 .EM must
846 ensure that these are computed
847 .EM before
848 invoking the
849 .CW pdfhref
850 macro.
851 .NH 3
852 .XN -N outline-folding -- Folding the Outline to Conceal Less Significant Headings
854 When a document incorporates many subheadings,
855 at deeply nested levels,
856 it may be desirable to \(lqfold\(rq the outline
857 such that only the major heading levels are initially visible,
858 yet making the inferior subheadings accessible,
859 by allowing the reader to expand the view of any heading branch on demand.
862 .CW pdfmark
863 macros support this capability,
864 through the setting of the
865 .CW PDFOUTLINE.FOLDLEVEL
866 register.
867 This register should be set to the number of heading levels
868 which it is desired to show in expanded form, in the
869 .EM initial
870 document outline display;
871 all subheadings at deeper levels will still be added to the outline,
872 but will not become visible until the outline branch containing them is expanded.
873 'ne 5
874 For example, the setting used in this document:
877 .fam C
878 \&.\e" Initialise the outline view to show only three heading levels,
879 \&.\e" with additional subordinate level headings folded.
880 \&.\e"
881 \&.nr PDFOUTLINE.FOLDLEVEL 3
885 results in only the first three levels of headings being displayed
886 in the document outline,
887 .EM until
888 the reader chooses to expand the view,
889 and so reveal the lower level headings in any outline branch.
891 The initial default setting of
892 .CW PDFOUTLINE.FOLDLEVEL ,
893 if the document author does not choose to change it,
894 is 10,000.
895 This is orders of magnitude greater than the maximum heading level
896 which is likely to be used in any document;
897 thus the default behaviour will be to show document outlines fully expanded,
898 to display all headings defined,
899 at all levels within each document.
901 The setting of
902 .CW PDFOUTLINE.FOLDLEVEL
903 may be changed at any time;
904 however, the effect of each such change may be difficult to predict,
905 since it is applied not only to outline entries which are defined
906 .EM after
907 the setting is changed,
908 but also to any entries which remain in the outline cache,
909 .EM at
910 this time.
911 Therefore, it is recommended that
912 .CW PDFOUTLINE.FOLDLEVEL
913 should be set
914 .EM once ,
915 at the start of each document;
916 if it
917 .EM is
918 deemed necessary to change it at any other time,
919 the outline cache should be flushed,
920 .XR pdfsync ), (
921 .EM immediately
922 before the change,
923 which should immediately preceed a level one heading.
924 .NH 3
925 .XN -N multipart-outline -- Outlines for Multipart Documents
927 When a document outline is created, using the
928 .CW pdfhref
929 macro, each reference mark is automatically assigned a name,
930 composed of a fixed stem followed by a serially generated numeric qualifier.
931 This ensures that, for each single part document, every outline reference
932 has a uniquely named destination.
934 As the overall size of the PDF document increases,
935 it may become convenient to divide it into smaller,
936 individually formatted PostScript\*(rg components,
937 which are then assembled, in the appropriate order,
938 to create a composite PDF document.
939 While this strategy may simplify the overall process of creating and
940 editing larger documents, it does introduce a problem in creating
941 an overall document outline,
942 since each individual PostScript\*(rg component will be assigned
943 duplicated sequences of \(lqbookmark\(rq names,
944 with each name ultimately referring to multiple locations in the composite document.
945 To avoid such reference naming conflicts, the
946 .CW pdfhref
947 macro allows the user to specify a \(lqtag\(rq,
948 which is appended to the automatically generated \(lqbookmark\(rq name;
949 this may be used as a discriminating mark, to distinguish otherwise
950 similarly named destinations, in different sections of the composite document.
952 To create a \(lqtagged\(rq document outline,
953 the syntax for invocation of the
954 .CW pdfhref
955 macro is modified, by the inclusion of an optional \(lqtag\(rq specification,
956 .EM before
957 the nesting level argument, i.e.
959 .fam C
960 .B ".pdfhref O"
961 .B -T \& [
962 .I tag >] <
963 .I level > <
964 .I "descriptive text ..."
966 The optional
967 .CWI tag > <
968 argument may be composed of any characters of the user's choice;
969 however, its initial character
970 .EM "must not"
971 be any decimal digit, and ideally it should be kept short
972 \(em one or two characters at most.
974 By employing a different tag in each section,
975 the user can ensure that \(lqbookmark\(rq names remain unique,
976 throughout all the sections of a composite document.
977 For example, when using the
978 .CW spdf.tmac
979 macro package, which adds
980 .CW pdfmark
981 capabilities to the standard
982 .CW ms
983 package,
984 .XR using-spdf ), (
985 the table of contents is collected into a separate PostScript\*(rg section
986 from the main body of the document.
987 In the \(lqbody\(rq section, the document outline is \(lquntagged\(rq,
988 but in the \(lqTable\~of\~Contents\(rq section, a modified version of the
989 .CW TC
990 macro adds an outline entry for the start of the \(lqTable\~of\~Contents\(rq,
991 invoking the
992 .CW pdfhref
993 macro as
995 .CW ".pdfhref O -T T 1 \e\e*[TOC]"
997 to tag the associated outline destination name with the single character suffix,
998 .CW T \(rq. \(lq
999 Alternatively, as in the case of the basic outline,
1000 .XR basic-outline ), (
1001 this may equally well be specified as
1003 .CW ".pdfbookmark -T T 1 \e\e*[TOC]"
1004 .NH 3
1005 .XN Delegation of the Outline Definition
1007 Since the most common use of a document outline
1008 is to provide a quick method of navigating through a document,
1009 using active \(lqhypertext\(rq links to chapter and section headings,
1010 it may be convenient to delegate the responsibility of creating the outline
1011 to a higher level macro, which is itself used to
1012 define and format the section headings.
1013 This approach has been adopted in the
1014 .CW spdf.tmac
1015 package, to be described later,
1016 .XR using-spdf ). (
1018 When such an approach is adopted,
1019 the user will rarely, if ever, invoke the
1020 .CW pdfhref
1021 macro directly, to create a document outline.
1022 For example, the structure and content of the outline for this document
1023 has been exclusively defined, using a combination of the
1024 .CW NH
1025 macro, from the
1026 .CW ms
1027 package, to establish the structure, and the
1028 .CW XN
1029 macro from
1030 .CW spdf.tmac ,
1031 to define the content.
1032 In this case,
1033 the responsibility for invoking the
1034 .CW pdfhref
1035 macro, to create the document outline,
1036 is delegated to the
1037 .CW XN
1038 macro.
1039 .NH 2
1040 .XN -N pdfhref -- Adding Reference Marks and Links
1042 .pdfhref F SECREF
1043 .ds SECREF.BEGIN Section
1044 .pdfhref L -D add-outline
1045 .pdfhref F
1046 has shown how the
1047 .CW pdfhref
1048 macro may be used to create a PDF document outline.
1049 While this is undoubtedly a powerful capability,
1050 it is by no means the only trick in the repertoire of this versatile macro.
1052 The macro name,
1053 .CW pdfhref ,
1054 which is a contraction of \(lqPDF HyperText Reference\(rq,
1055 indicates that the general purpose of this macro is to define
1056 .EM any
1057 type of dynamic reference mark, within a PDF document.
1058 Its generalised usage syntax takes the form
1060 .fam C
1061 .B .pdfhref
1062 .BI class > <
1063 .I "-options ...\&" ] [
1064 [--]
1065 .I "descriptive text ...\&" ] [
1067 where
1068 .CW <\f(CIclass\fP>
1069 represents a required single character argument,
1070 which defines the specific reference operation to be performed,
1071 and may be selected from:\(en
1073 .IP \*[= O]
1074 Add an entry to the document outline.
1075 This operation has been described earlier,
1076 .XR add-outline ). (
1077 .IP \*[= M]
1078 Place a \(lqnamed destination\(rq reference mark at the current output position,
1079 in the current PDF document,
1080 .XR mark-dest ). (
1081 .IP \*[= L]
1082 Insert an active link to a named destination,
1083 .XR link-named ), (
1084 at the current output position in the current PDF document,
1085 such that when the reader clicks on the link text,
1086 the document view changes to show the location of the named destination.
1087 .IP \*[= W]
1088 Insert an active link to a \(lqweb\(rq resource,
1089 .XR add-weblink ), (
1090 at the current output position in the current PDF document.
1091 This is effectively the same as using the
1092 .CWB L \& \& \(rq \(lq
1093 operator to establish a link to a named destination in another PDF document,
1094 .XR link-extern ), (
1095 except that in this case, the destination is specified by a
1096 \(lquniform resource identifier\(rq, or
1097 .CW URI ;
1098 this may represent any Internet or local resource
1099 which can be specified in this manner.
1100 .IP \*[= F]
1101 Specify a user defined macro, to be called by
1102 .CW pdfhref ,
1103 when formatting the text in the active region of a link,
1104 .XR set-format ). (
1105 .IP \*[= I]
1106 Initialise support for
1107 .CW pdfhref
1108 features.
1109 The current
1110 .CW pdfhref
1111 implementation provides only one such feature which requires initialisation
1112 \(em a helper macro which must be attached to a user supplied page trap handler,
1113 in order to support mapping of reference \(lqhot\(hyspots\(rq
1114 which extend through a page transition;
1115 .XR page-trap ). (
1117 .NH 3
1118 .XN Optional Features of the \F[C]pdfhref\F[] Macro
1120 The behaviour of a number of the
1121 .CW pdfhref
1122 macro operations can be modified,
1123 by including
1124 .EM "option specifiers" \(rq \(lq
1125 after the operation specifying argument,
1127 .EM before
1128 any other arguments normally associated with the operation.
1130 .EM all
1131 cases, an option is specified by an
1132 .EM "option flag" \(rq, \(lq
1133 comprising an initial hyphen,
1134 followed by one or two option identifying characters.
1135 Additionally,
1136 .EM some
1137 options require
1138 .EM "exactly one"
1139 option argument;
1140 for these options, the argument
1141 .EM must
1142 be specified, and it
1143 .EM must
1144 be separated from the preceding option flag by one or more
1145 .EM spaces ,
1146 (tabs
1147 .EM "must not"
1148 be used).
1149 It may be noted that this paradigm for specifying options
1150 is reminiscent of most
1152 UNIX\(tm
1154 shells; however, in the case of the
1155 .CW pdfhref
1156 macro, omission of the space separating an option flag from its argument is
1157 .EM never
1158 permitted.
1160 A list of
1161 .EM all
1162 general purpose options supported by the
1163 .CW pdfhref
1164 macro is given below.
1165 Note that not all options are supported for all
1166 .CW pdfhref
1167 operations; the operations affected by each option are noted in the list.
1169 .EM most
1170 operations, if an unsupported option is specified,
1171 it will be silently ignored; however, this behaviour should
1172 not be relied upon.
1174 The general purpose options, supported by the
1175 .CW pdfhref
1176 macro, are:\(en
1178 .IP \*[= -N\0 name > <]
1179 Allows the
1180 .CWI name > <
1181 associated with a PDF reference destination
1182 to be defined independently from the following text,
1183 which describes the reference.
1184 This option affects only the
1185 .CWB M \& \& \(rq \(lq
1186 operation of the
1187 .CW pdfhref
1188 macro,
1189 .XR mark-dest ). (
1190 .IP \*[= -E]
1191 Also used exclusively with the
1192 .CWB M \& \& \(rq \(lq
1193 operator, the
1194 .CWB -E
1195 option causes any specified
1196 .CWI descriptive \& \& \~\c
1197 .CWI text
1198 arguments,
1199 .XR mark-dest ), (
1200 to be copied, or
1201 .EM echoed ,
1202 in the body text of the document,
1203 at the point where the reference mark is defined;
1204 (without the
1205 .CWB -E
1206 option, such
1207 .CWI descriptive \& \& \~\c
1208 .CWI text
1209 will appear
1210 .EM only
1211 at points where links to the reference mark are placed,
1212 and where the standard reference display format,
1213 .XR set-format ), (
1214 is used).
1215 .IP \*[= -D\0 dest > <]
1216 Specifies the
1217 .CW URI ,
1218 or the destination name associated with a PDF active link,
1219 independently of the following text,
1220 which describes the link and demarcates the link \(lqhot\(hyspot\(rq.
1221 This option affects the behaviour of the
1222 .CW pdfhref
1223 macro's
1224 .CWB L \& \& \(rq \(lq
1226 .CWB W \& \& \(rq \(lq
1227 operations.
1229 When used with the
1230 .CWB L \& \& \(rq \(lq
1231 operator, the
1232 .CWI dest > <
1233 argument must specify a PDF \(lqnamed destination\(rq,
1234 as defined using
1235 .CW pdfhref
1236 with the
1237 .CWB M \& \& \(rq \(lq
1238 operator.
1240 When used with the
1241 .CWB W \& \& \(rq \(lq
1242 operator,
1243 .CWI dest > <
1244 must specify a link destination in the form of a
1245 \(lquniform resource identifier\(rq, or
1246 .CW URI ,
1247 .XR add-weblink ). (
1248 .IP \*[= -F\0 file > <]
1249 When used with the
1250 .CWB L \& \& \(rq \(lq
1251 .CW pdfhref
1252 operator,
1253 .CWI file > <
1254 specifies an external PDF file in which the named destination
1255 for the link reference is defined.
1256 This option
1257 .EM must
1258 be specified with the
1259 .CWB L \& \& \(rq \(lq
1260 operator,
1261 to create a link to a destination in a different PDF document;
1262 when the
1263 .CWB L \& \& \(rq \(lq
1264 operator is used
1265 .EM without
1266 this option, the link destination is assumed to be defined
1267 within the same document.
1268 .IP \*[= -P\0 \(dqprefix\(hytext\(dq > <]
1269 Specifies
1270 .CWI \(dqprefix\(hytext\(dq > <
1271 to be attached to the
1272 .EM start
1273 of the text describing an active PDF document link,
1274 with no intervening space, but without itself being included in the
1275 active area of the link \(lqhot\(hyspot\(rq;
1276 it is effective with the
1277 .CWB L \& \& \(rq \(lq
1279 .CWB W \& \& \(rq \(lq
1280 .CW pdfhref
1281 operators.
1283 Typically, this option would be used to insert punctuation before
1284 the link \(lqhot\(hyspot\(rq.
1285 Thus, there is little reason for the inclusion of spaces in
1286 .CWI \(dqprefix\(hytext\(dq > < ;
1287 however, if such space is required, then the enclosing double quotes
1288 .EM must
1289 be specified, as indicated.
1290 .IP \*[= -A\0 \(dqaffixed\(hytext\(dq > <]
1291 Specifies
1292 .CWI \(dqaffixed\(hytext\(dq > <
1293 to be attached to the
1294 .EM end
1295 of the text describing an active PDF document link,
1296 with no intervening space, but without itself being included in the
1297 active area of the link \(lqhot\(hyspot\(rq;
1298 it is effective with the
1299 .CWB L \& \& \(rq \(lq
1301 .CWB W \& \& \(rq \(lq
1302 .CW pdfhref
1303 operators.
1305 Typically, this option would be used to insert punctuation after
1306 the link \(lqhot\(hyspot\(rq.
1307 Thus, there is little reason for the inclusion of spaces in
1308 .CWI \(dqaffixed\(hytext\(dq > < ;
1309 however, if such space is required, then the enclosing double quotes
1310 .EM must
1311 be specified, as indicated.
1312 .IP \*[= -T\0 tag > <]
1313 When specified with the
1314 .CWB O \& \& \(rq \(lq
1315 operator,
1316 .CWI tag > <
1317 is appended to the \(lqbookmark\(rq name assigned to the generated outline entry.
1318 This option is
1319 .EM required ,
1320 to distinguish between the series of \(lqbookmark\(rq names generated in
1321 individual passes of the
1322 .CW groff
1323 formatter, when the final PDF document is to be assembled
1324 from a number of separately formatted components;
1325 .XR multipart-outline ). (
1326 .IP \*[= -X]
1327 This
1328 .CW pdfhref
1329 option is used with either the
1330 .CWB M \& \& \(rq \(lq
1331 operator, or with the
1332 .CWB L \& \& \(rq \(lq
1333 operator.
1335 When used with the
1336 .CWB M \& \& \(rq \(lq
1337 operator,
1338 .XR mark-dest ), (
1339 it ensures that a cross reference record for the marked destination
1340 will be included in the document reference map,
1341 .XR export-map ). (
1343 When used with the
1344 .CWB L \& \& \(rq \(lq
1345 operator,
1346 .XR link-named ), (
1347 it causes the reference to be displayed in the standard cross reference format,
1348 .XR set-format ), (
1349 but substituting the
1350 .CWI descriptive \& \& \~\c
1351 .CWI text
1352 specified in the
1353 .CW pdfhref \& \(lq
1354 .CW L \(rq
1355 argument list,
1356 for the description specified in the document reference map.
1357 .IP \*[= --]
1358 Marks the end of the option specifiers.
1359 This may be used with all
1360 .CW pdfhref
1361 operations which accept options, to prevent
1362 .CW pdfhref
1363 from interpreting any following arguments as option specifiers,
1364 even if they would otherwise be interpreted as such.
1365 It is also useful when the argument list to
1366 .CW pdfhref
1367 contains special characters \(em any special character,
1368 which is not legal in a
1369 .CW groff
1370 macro name, will cause a parsing error, if
1371 .CW pdfhref
1372 attempts to match it as a possible option flag;
1373 using the
1374 .CW -- \(rq \(lq
1375 flag prevents this, so suppressing the
1376 .CW groff
1377 warning message, which would otherwise ensue.
1379 Using this flag after
1380 .EM all
1381 sequences of macro options is recommended,
1382 even when it is not strictly necessary,
1383 if only for the entirely cosmetic benefit of visually separating
1384 the main argument list from the sequence of preceding options.
1387 In addition to the
1388 .CW pdfhref
1389 options listed above, a supplementary set of two character options are defined.
1390 These supplementary options, listed below, are intended for use with the
1391 .CWB L \& \& \(rq \(lq
1392 operator, in conjunction with the
1393 .CWB -F \& \& \~\c
1394 .CWBI file > <
1395 option, to specify alternate file names,
1396 in formats compatible with the file naming conventions
1397 of alternate operating systems;
1398 they will be silently ignored, if used in any other context.
1400 The supported alternate file name options,
1401 which are ignored if the
1402 .CWB -F \& \& \~\c
1403 .CWBI file > <
1404 option is not specified, are:\(en
1406 .IP \*[= -DF\0 dos\(hyfile > <]
1407 Specifies the name of the file in which a link destination is defined,
1408 using the file naming semantics of the
1409 .CW MS\(hyDOS \*(rg
1410 operating system.
1411 When the PDF document is read on a machine
1412 where the operating system uses the
1413 .CW MS\(hyDOS \*(rg
1414 file system, then
1415 .CWI dos\(hyfile > <
1416 is used as the name of the file containing the reference destination,
1417 overriding the
1418 .CWI file > <
1419 argument specified with the
1420 .CWB -F
1421 option.
1422 .IP \*[= -MF\0 mac\(hyfile > <]
1423 Specifies the name of the file in which a link destination is defined,
1424 using the file naming semantics of the
1425 .CW Apple \*(rg
1426 .CW Macintosh \*(rg
1427 operating system.
1428 When the PDF document is read on a machine
1429 where the operating system uses the
1430 .CW Macintosh \*(rg
1431 file system, then
1432 .CWI mac\(hyfile > <
1433 is used as the name of the file containing the reference destination,
1434 overriding the
1435 .CWI file > <
1436 argument specified with the
1437 .CWB -F
1438 option.
1439 .IP \*[= -UF\0 unix\(hyfile > <]
1440 Specifies the name of the file in which a link destination is defined,
1441 using the file naming semantics of the
1442 .CW UNIX \(tm
1443 operating system.
1444 When the PDF document is read on a machine
1445 where the operating system uses
1446 .CW POSIX
1447 file naming semantics, then
1448 .CWI unix\(hyfile > <
1449 is used as the name of the file containing the reference destination,
1450 overriding the
1451 .CWI file > <
1452 argument specified with the
1453 .CWB -F
1454 option.
1455 .IP \*[= -WF\0 win\(hyfile > <]
1456 Specifies the name of the file in which a link destination is defined,
1457 using the file naming semantics of the
1458 .CW MS\(hyWindows \*(rg
1459 32\(hybit operating system.
1460 When the PDF document is read on a machine
1461 where the operating system uses any of the
1462 .CW MS\(hyWindows \*(rg
1463 file systems, with long file name support, then
1464 .CWI win\(hyfile > <
1465 is used as the name of the file containing the reference destination,
1466 overriding the
1467 .CWI file > <
1468 argument specified with the
1469 .CWB -F
1470 option.
1472 .NH 3
1473 .XN -N mark-dest -- Marking a Reference Destination
1476 .CW pdfhref
1477 macro may be used to create active links to any Internet resource,
1478 specified by its
1479 .CW URI ,
1480 or to any \(lqnamed destination\(rq,
1481 either within the same document, or in another PDF document.
1482 Although the PDF specification allows link destinations to be defined
1483 in terms of a page number, and an associated view specification,
1484 this style of reference is not currently supported by the
1485 .CW pdfhref
1486 macro, because it is not possible to adequately bind the specification
1487 for the destination with the intended reference context.
1489 References to Internet resources are interpreted in accordance with the
1490 .CW W3C
1491 standard for defining a
1492 .CW URI ;
1493 hence the only prerequisite, for creating a link to any Internet resource,
1494 is that the
1495 .CW URI
1496 be properly specified, when declaring the reference;
1497 .XR add-weblink ). (
1498 In the case of references to \(lqnamed destinations\(rq in PDF documents,
1499 however, it is necessary to provide a mechanism for creating such
1500 \(lqnamed destinations\(rq.
1501 This may be accomplished, by invoking the
1502 .CW pdfhref
1503 macro in the form
1505 .fam C
1506 .B ".pdfhref M"
1507 .B -N \& [
1508 .I name >] <
1509 .B -X ] [
1510 .B -E ] [
1511 .I "descriptive text ...\&" ] [
1513 This creates a \(lqnamed destination\(rq reference mark, with its name specified by
1514 .CWI name > < ,
1515 or, if the
1516 .CWB -N
1517 option is not specified, by the first word of
1518 .CWI descriptive \& \& \~\c
1519 .CWI text \& \& ;
1520 (note that this imposes the restriction that,
1521 if the
1522 .CWB -N
1523 option is omitted, then
1524 .EM "at least"
1525 one word of
1526 .CWI descriptive \& \& \~\c
1527 .CWI text
1528 .EM must
1529 be specified).
1530 Additionally, a reference view will be automatically defined,
1531 and associated with the reference mark,
1532 .XR pdfhref-view ), (
1533 .\" and, if any
1534 .\" .CWI descriptive
1535 .\" .CWI text
1536 .\" is specified, or the
1537 and, if the
1538 .CWB -X
1539 option is specified, and no document cross reference map has been imported,
1540 .XR import-map ), (
1541 then a cross reference mapping record,
1542 .XR export-map ), (
1543 will be written to the
1544 .CW stdout
1545 stream;
1546 this may be captured, and subsequently used to generate a cross reference map
1547 for the document,
1548 .XR create-map ). (
1550 When a \(lqnamed destination\(rq reference mark is created, using the
1551 .CW pdfhref
1552 macro's
1553 .CWB M \& \& \(rq \(lq
1554 operator, there is normally no visible effect in the formatted document; any
1555 .CWI descriptive \& \& \~\c
1556 .CWI text
1557 which is specified will simply be stored in the cross reference map,
1558 for use when a link to the reference mark is created.
1559 This default behaviour may be changed, by specifying the
1560 .CWB -E
1561 option, which causes any specified
1562 .CWI descriptive \& \& \~\c
1563 .CWI text
1564 to be \(lqechoed\(rq in the document text,
1565 at the point where the reference mark is placed,
1566 in addition to its inclusion in the cross reference map.
1567 .NH 4
1568 .XN -N export-map -- Mapping a Destination for Cross Referencing
1570 Effective cross referencing of
1571 .EM any
1572 document formatted by
1573 .CW groff
1574 requires multiple pass formatting.
1575 Details of how this multiple pass formatting may be accomplished,
1576 when working with the
1577 .CW pdfmark
1578 macros, will be discussed later,
1579 .XR do-xref ); (
1580 at this stage, the discussion will be restricted to the initial preparation,
1581 which is required at the time when the cross reference destinations are defined.
1583 The first stage, in the process of cross referencing a document,
1584 is the generation of a cross reference map.
1585 Again, the details of
1586 .EM how
1587 the cross reference map is generated will be discussed in
1588 .pdfhref F SECREF L -D do-xref -A ;
1589 .pdfhref F
1590 however, it is important to recognise that
1591 .EM what
1592 content is included in the cross reference map is established
1593 when the reference destination is defined \(em it is derived
1594 from the reference data exported on the
1595 .CW stderr
1596 stream by the
1597 .CW pdfhref
1598 macro, when it is invoked with the
1599 .CWB M \& \& \(rq \(lq
1600 operator, and is controlled by whatever definition of the string
1601 .CW PDFHREF.INFO
1602 is in effect, when the
1603 .CW pdfhref
1604 macro is invoked.
1606 The initial default setting of
1607 .CW PDFHREF.INFO
1610 .CW ".ds PDFHREF.INFO page \e\en% \e\e$*"
1612 which ensures that the cross reference map will contain
1613 at least a page number reference, supplemented by any
1614 .CWI descriptive \& \& \~\c
1615 .CWI text
1616 which is specified for the reference mark, as defined by the
1617 .CW pdfhref
1618 macro, with its
1619 .CWB M \& \& \(rq \(lq
1620 operator; this may be redefined by the user,
1621 to export additional cross reference information,
1622 or to modify the default format for cross reference links,
1623 .XR set-format ). (
1624 .NH 4
1625 .XN -N pdfhref-view -- Associating a Document View with a Reference Mark
1627 In the same manner as each document outline reference, defined by the
1628 .CW pdfhref
1629 macro with the
1630 .CWB O \& \& \(rq \(lq
1631 operator,
1632 .XR add-outline ), (
1633 has a specific document view associated with it,
1634 each reference destination marked by
1635 .CW pdfhref
1636 with the
1637 .CWB M \& \& \(rq \(lq
1638 operator, requires an associated document view specification.
1640 The mechanism whereby a document view is associated with a reference mark
1641 is entirely analogous to that employed for outline references,
1642 .XR outline-view ), (
1643 except that the
1644 .CW PDFHREF.VIEW
1645 string specification is used, in place of the
1646 .CW PDFBOOKMARK.VIEW
1647 specification.
1648 Thus, the reference view is defined in terms of:\(en
1650 .IP \*[= PDFHREF.VIEW]
1651 A string,
1652 establishing the position of the reference mark within the viewing window,
1653 and the magnification at which the document will be viewed,
1654 at the location of the marked reference destination;
1655 by default, it is defined by
1658 .CW ".ds PDFHREF.VIEW /FitH \e\en[PDFPAGE.Y] u"
1661 which displays the reference destination at the top of the viewing window,
1662 with the magnification set to fit the page width to the width of the window.
1663 .IP \*[= PDFHREF.VIEW.LEADING]
1664 A numeric register,
1665 specifying additional spacing, to be placed between the top of the display
1666 window and the actual position at which the location of the reference
1667 destination appears within the window.
1668 This register is shared with the view specification for outline references,
1669 and thus has the same default initial setting,
1672 .CW ".nr PDFHREF.VIEW.LEADING 5.0p"
1675 as in the case of outline reference views.
1677 Again, notice that
1678 .CW PDFHREF.VIEW.LEADING
1679 does not represent true typographic \(lqleading\(rq,
1680 since any preceding text, set in the specified display space,
1681 will be visible at the top of the viewing window,
1682 when the reference is selected.
1685 Just as the view associated with outline references may be changed,
1686 by redefining
1687 .CW PDFBOOKMARK.VIEW ,
1688 so the view associated with marked reference destinations may be changed,
1689 by redefining
1690 .CW PDFHREF.VIEW ,
1691 and, if desired,
1692 .CW PDFHREF.VIEW.LEADING ;
1693 such changes will become effective for all reference destinations marked
1694 .EM after
1695 these definitions are changed.
1696 (Notice that, since the specification of
1697 .CW PDFHREF.VIEW.LEADING
1698 is shared by both outline reference views and marked reference views,
1699 if it is changed, then the views for
1700 .EM both
1701 reference types are changed accordingly).
1703 It may again be noted, that the
1704 .CW PDFPAGE.Y
1705 register is used in the definition of
1706 .CW PDFHREF.VIEW ,
1707 just as it is in the definition of
1708 .CW PDFBOOKMARK.VIEW ;
1709 all comments in
1710 .pdfhref F SECREF L -D outline-view
1711 .pdfhref F
1712 relating to its use, and indeed to page position computations in general,
1713 apply equally to marked reference views and to outline reference views.
1714 .NH 3
1715 .XN -N link-named -- Linking to a Marked Reference Destination
1717 Any named destination, such as those marked by the
1718 .CW pdfhref
1719 macro, using it's
1720 .CWB M \& \& \(rq \(lq
1721 operator, may be referred to from any point in
1722 .EM any
1723 PDF document, using an
1724 .EM "active link" ;
1725 such active links are created by again using the
1726 .CW pdfhref
1727 macro, but in this case, with the
1728 .CWB L \& \& \(rq \(lq
1729 operator.
1730 This operator provides support for two distinct cases,
1731 depending on whether the reference destination is defined in 
1732 the same document as the link,
1733 .XR link-intern ), (
1734 or is defined as a named destination in a different PDF document,
1735 .XR link-extern ). (
1736 .NH 4
1737 .XN -N link-intern -- References within a Single PDF Document
1739 The general syntactic form for invoking the
1740 .CW pdfhref
1741 macro,
1742 when creating a link to a named destination within the same PDF document is
1744 .fam C
1745 .B .pdfhref
1746 .B L
1747 .B -D \& [
1748 .BI dest-name >] <
1749 .B -P \& [
1750 .BI prefix-text >] <
1751 .B -A \& [
1752 .BI affixed-text >] <
1755 \0\0\0
1756 .B -X ] [
1757 .B -- ] [
1758 .I "descriptive text ...\&" ] [
1760 where
1761 .CWI dest-name > <
1762 specifies the name of the link destination,
1763 as specified using the
1764 .CW pdfhref
1765 .CWB M \& \& \(rq \(lq
1766 operation; (it may be defined either earlier in the document,
1767 to create a backward reference, or later, to create a forward reference).
1769 .\" Here's a example of how to add an iconic annotation.
1771 .\".pdfnote -T "Internal Cross References" \
1772 .\"   This description is rather terse, and could benefit from \
1773 .\"   the inclusion of an example.
1775 If any
1776 .CWI descriptive \& \& \~\c
1777 .CWI text
1778 arguments are specified, then they will be inserted into the
1779 .CW groff
1780 output stream, to define the text appearing in the \(lqhot\(hyspot\(rq
1781 region of the link;
1782 this will be printed in the link colour specified by the string,
1783 .CW PDFHREF.TEXT.COLOUR ,
1784 which is described in
1785 .XR-NO-PREFIX set-colour .
1786 If the
1787 .CWB -X
1788 option is also specified, then the
1789 .CWI descriptive \& \& \~\c
1790 .CWI text
1791 will be augmented, by prefacing it with page and section number indicators,
1792 in accordance with the reference formatting rules which are in effect,
1793 .XR set-format ); (
1794 such indicators will be included within the active link region,
1795 and will also be printed in the link colour.
1797 Note that
1798 .EM either
1800 .CWB -D \& \& \~\c
1801 .CWBI dest\(hyname > <
1802 option,
1803 .EM or
1805 .CWI descriptive \& \& \~\c
1806 .CWI text
1807 arguments,
1808 .EM "but not both" ,
1809 may be omitted.
1810 If the
1811 .CWB -D \& \& \~\c
1812 .CWBI dest\(hyname > <
1813 option is omitted, then the first word of
1814 .CWI descriptive \& \& \~\c
1815 .CWI text \& \& ,
1816 i.e.\~all text up to but not including the first space,
1817 will be interpreted as the
1818 .CWBI dest\(hyname > <
1819 for the link; this text will also appear in the running text of the document,
1820 within the active region of the link.
1821 Alternatively, if the
1822 .CWB -D \& \& \~\c
1823 .CWBI dest\(hyname > <
1824 option
1825 .EM is
1826 specified, and
1827 .CWI descriptive \& \& \~\c
1828 .CWI text
1829 is not,
1830 then the running text which defines the reference,
1831 and its active region,
1832 will be derived from the reference description which is specified
1833 when the named destination is marked,
1834 .XR mark-dest ), (
1835 and will be formatted according to the reference formatting rules
1836 which are in effect, when the reference is placed,
1837 .XR set-format ); (
1838 in this case, it is not necessary to specify the
1839 .CWB -X
1840 option to activate automatic formatting of the reference \(em it is implied,
1841 by the omission of all
1842 .CWI descriptive \& \& \~\c
1843 .CWI text
1844 arguments.
1847 .CWB -P \& \& \~\c
1848 .CWBI prefix\(hytext > <
1850 .CWB -A \& \& \~\c
1851 .CWBI affixed\(hytext > <
1852 options may be used to specify additional text
1853 which will be placed before and after the linked text respectively,
1854 with no intervening space.
1855 Such prefixed and affixed text will be printed in the normal text colour,
1856 and will not be included within the active region of the link.
1857 This feature is mostly useful for creating parenthetical references,
1858 or for placing punctuation adjacent to,
1859 but not included within,
1860 the text which defines the active region of the link.
1862 The operation of the
1863 .CW pdfhref
1864 macro, when used with its
1865 .CWB L \& \& \(rq \(lq
1866 operator to place a link to a named PDF destination,
1867 may best be illustrated by an example.
1868 However, since the appearance of the link will be influenced by
1869 factors established when the named destination is marked,
1870 .XR mark-dest ), (
1871 and also by the formatting rules in effect when the link is placed,
1872 the presentation of a suitable exanple will be deferred,
1873 until the formatting mechanism has been explained,
1874 .XR set-format ). (
1875 .NH 4
1876 .XN -N link-extern -- References to Destinations in Other PDF Documents
1879 .CW pdfhref
1880 macro's
1881 .CWB L \& \& \(rq \(lq
1882 operator is not restricted to creating reference links
1883 within a single PDF document.
1884 When the link destination is defined in a different document,
1885 then the syntactic form for invoking
1886 .CW pdfhref
1887 is modified, by the addition of options to specify the
1888 name and location of the PDF file in which the destination is defined.
1889 Thus, the extended
1890 .CW pdfhref
1891 syntactic form becomes
1893 .fam C
1894 .B .pdfhref
1895 .B L
1896 .B -F
1897 .BI file > <
1898 .B -D \& [
1899 .BI dest-name >] <
1902 \0\0\0
1903 .B -DF \& [
1904 .BI dos-file >] <
1905 .B -MF \& [
1906 .BI mac-file >] <
1907 .B -UF \& [
1908 .BI unix-file >] <
1911 \0\0\0
1912 .B -WF \& [
1913 .BI win-file >] <
1914 .B -P \& [
1915 .BI prefix-text >] <
1916 .B -A \& [
1917 .BI affixed-text >] <
1920 \0\0\0
1921 .B -X ] [
1922 .B -- ] [
1923 .I "descriptive text ...\&" ] [
1925 where the
1926 .CWB -F \& \& \~\c
1927 .CWBI file > <
1928 option serves
1929 .EM two
1930 purposes: it both indicates to the
1931 .CW pdfhref
1932 macro that the specified reference destination
1933 is defined in an external PDF file,
1934 and it also specifies the normal path name,
1935 which is to be used to locate this file,
1936 when a user selects the reference.
1938 In addition to the
1939 .CWB -F \& \& \~\c
1940 .CWBI file > <
1941 option, which
1942 .EM must
1943 be specified when referring to a destination in an external PDF file,
1945 .CWB -DF \& \& \~\c
1946 .CWBI dos\(hyfile > < ,
1947 .CWB -MF \& \& \~\c
1948 .CWBI mac\(hyfile > < ,
1949 .CWB -UF \& \& \~\c
1950 .CWBI unix\(hyfile > <
1952 .CWB -WF \& \& \~\c
1953 .CWBI win\(hyfile > <
1954 options may be used to specify the location of the file
1955 containing the reference destination,
1956 in a variety of operating system dependent formats.
1957 These options assign their arguments to the
1958 .CW /DosFile ,
1959 .CW /MacFile ,
1960 .CW /UnixFile
1962 .CW /WinFile
1963 keys of the generated
1964 .CW pdfmark
1965 respectively; thus when any of these options are specified,
1966 .EM "in addition to"
1968 .CWB -F \& \& \~\c
1969 .CWBI file > <
1970 option, and the document is read on the appropriate operating systems,
1971 then the path names specified by
1972 .CWBI dos\(hyfile > < ,
1973 .CWBI mac\(hyfile > < ,
1974 .CWBI unix\(hyfile > <
1976 .CWBI win\(hyfile > <
1977 will be searched,
1978 .EM instead
1979 of the path name specified by
1980 .CWBI file > < ,
1981 for each of the
1982 .CW MS\(hyDOS \*(rg,
1983 .CW Apple \*(rg
1984 .CW Macintosh \*(rg,
1985 .CW UNIX \(tm
1987 .CW MS\(hyWindows \*(rg
1988 operating systems, respectively; see the
1989 .pdfmark-manual ,
1990 for further details.
1992 Other than the use of these additional options,
1993 which specify that the reference destination is in an external PDF file,
1994 the behaviour of the
1995 .CW pdfhref
1996 .CWB L \& \& \(rq \(lq
1997 operator, with the
1998 .CWB -F \& \& \~\c
1999 .CWBI file > <
2000 option, remains identical to its behaviour
2001 .EM without
2002 this option,
2003 .XR link-intern ), (
2004 with respect to the interpretation of other options,
2005 the handling of the
2006 .CWI descriptive \& \& \~\c
2007 .CWI text
2008 arguments, and the formatting of the displayed reference.
2010 Once again, since the appearance of the reference is determined by
2011 factors specified in the document reference map,
2012 and also by the formatting rules in effect when the reference is placed,
2013 the presentation of an example of the placing of
2014 a reference to an external destination will be deferred,
2015 until the formatting mechanism has been explained,
2016 .XR set-format ). (
2017 .NH 3
2018 .XN -N add-weblink -- Linking to Internet Resources
2020 In addition to supporting the creation of cross references
2021 to named destinations in PDF documents, the
2022 .CW pdfhref
2023 macro also has the capability to create active links to Internet resources,
2024 or indeed to
2025 .EM any
2026 resource which may be specified by a Uniform Resource Identifier,
2027 (which is usually abbreviated to the acronym \(lqURI\(rq,
2028 and sometimes also referred to as a Uniform Resource Locator,
2029 or \(lqURL\(rq).
2031 Since the mechanism for creating a link to a URI differs somewhat
2032 from that for creating PDF references, the
2033 .CW pdfhref
2034 macro is invoked with the
2035 .CWB W \& \& \(rq \(lq
2036 (for \(lqweb\(hylink\(rq) operator, rather than the
2037 .CWB L \& \& \(rq \(lq
2038 operator; nevertheless, the invocation syntax is similar, having the form
2040 .fam C
2041 .B .pdfhref
2042 .B W
2043 .B -D \& [
2044 .BI URI >] <
2045 .B -P \& [
2046 .BI prefix-text >] <
2047 .B -A \& [
2048 .BI affixed-text >] <
2051 \0\0\0
2052 .B -- ] [
2053 .I "descriptive text ...\&"
2055 where
2056 .NH 3
2057 .XN -N set-format -- Establishing a Format for References
2059 There are two principal aspects to be addressed,
2060 when defining the format to be used when displaying references.
2061 Firstly, it is desirable to provide a visual cue,
2062 to indicate that the text describing the reference is imbued
2063 with special properties \(em it is dynamically linked to the reference
2064 destination \(em and secondly, the textual content should
2065 describe where the link leads, and ideally,
2066 it should also describe the content of the reference destination.
2068 The visual cue,
2069 that a text region defines a dynamically linked reference,
2070 is most commonly provided by printing the text within the active
2071 region in a distinctive colour.
2072 This technique will be employed automatically by the
2073 .CW pdfhref
2074 macro \(em
2075 .XR set-colour
2076 \(em unless the user specifically chooses to adopt, and implement,
2077 some alternative strategy.
2078 .NH 4
2079 .XN -N set-colour -- Using Colour to Demarcate Link Regions
2081 Typically, when a PDF document contains
2082 .EM active
2083 references to other locations, either within the same document,
2084 or even in other documents, or on the World Wide Web,
2085 it is usually desirable to make the regions
2086 where these active links are placed stand out from the surrounding text.
2087 .NH 4
2088 .XN -N user-format -- Specifying Reference Text Explicitly
2089 .NH 4
2090 .XN -N auto-format -- Using Automatically Formatted Reference Text
2091 .NH 4
2092 .XN -N custom-format -- Customising Automatically Formatted Reference Text
2094 It is incumbent on the user,
2095 if employing automatic formatting of the displayed reference,
2096 .XR set-format ), (
2097 to ensure that an appropriate reference definition
2098 is created for the reference destination,
2099 and is included in the reference map for the document
2100 in which the reference will appear;
2101 thus, it may be easiest to
2102 .EM always
2103 use manual formatting for external references.
2104 .NH 3
2105 .XN Problematic Links
2107 Irrespective of whether a
2108 .CW pdfhref
2109 reference is placed using the
2110 .CWB L \& \& \(rq \(lq
2111 operator, or the
2112 .CWB W \& \& \(rq \(lq
2113 operator, there may be occasions when the resulting link
2114 does function as expected.
2115 A number of scenarios, which are known to be troublesome,
2116 are described below.
2117 .NH 4
2118 .XN -N page-trap -- Links with a Page Transition in the Active Region
2120 When a link is placed near the bottom of a page,
2121 it is possible that its active region, or \(lqhot\(hyspot\(rq,
2122 may extend on to the next page.
2123 In this situation, a page trap macro is required
2124 to intercept the page transition, and to restart the mapping of
2125 the \(lqhot\(hyspot\(rq boundary on the new page.
2128 .CW pdfmark
2129 macro package includes a suitable page trap macro, to satisfy this requirement.
2130 However, to avoid pre\(hyempting any other requirement the user may have for
2131 a page transition trap, this is
2132 .EM not
2133 installed as an active page trap,
2134 unless explicitly requested by the user.
2136 To enable proper handling of page transitions,
2137 which occur within the active regions of reference links,
2138 the user should:\(en
2140 .nr ITEM 0 1
2141 .IP \n+[ITEM].
2142 Define a page transition macro, to provide whatever features may be required,
2143 when a page transition occurs \(em e.g.\& printing footnotes,
2144 adding page footers and headers, etc.
2145 This macro should end by setting the output position at the correct
2146 vertical page offset, where the printing of running text is to restart,
2147 following the page transition.
2148 .IP \n+[ITEM].
2149 Plant a trap to invoke this macro, at the appropriate vertical position
2150 marking the end of normal running text on each page.
2152 .IP \n+[ITEM].
2153 Initialise the
2154 .CW pdfhref
2155 hook into this page transition trap, by invoking
2158 .fam C
2159 .B "pdfhref I -PT"
2160 .BI macro-name > <
2162 where
2163 .CWBI macro-name > <
2164 is the name of the user supplied page trap macro,
2165 to ensure that
2166 .CW pdfhref
2167 will correctly restart mapping of active link regions,
2168 at the start of each new page.
2173 It may be observed that this initialisation of the
2174 .CW pdfhref
2175 page transition hook is, typically, required only once
2176 .EM before
2177 document formatting begins.
2178 Users of document formatting macro packages may reasonably expect that
2179 this initialisation should be performed by the macro package itself.
2180 Thus, writers of such macro packages which include
2181 .CW pdfmark
2182 bindings, should provide appropriate initialisation,
2183 so relieving the end user of this responsibility.
2184 The following example, abstracted from the sample
2185 .CW ms
2186 binding package,
2187 .CW spdf.tmac ,
2188 illustrates how this may be accomplished:\(en
2189 .DS I
2191 \&.\e" groff "ms" provides the "pg@bottom" macro, which has already
2192 \&.\e" been installed as a page transition trap.  To ensure proper
2193 \&.\e" mapping of "pdfhref" links which overflow the bottom of any
2194 \&.\e" page, we need to install the "pdfhref" page transition hook,
2195 \&.\e" as an addendum to this macro.
2197 \&.pdfhref I -PT pg@bottom
2199 .NH 2
2200 .XN -N add-note -- Annotating a PDF Document using Pop-Up Notes
2201 .NH 2
2202 .XN -N pdfsync -- Synchronising Output and \F[C]pdfmark\F[] Contexts
2204 It has been noted previously, that the
2205 .CW pdfview
2206 macro,
2207 .XR docview ), (
2209 .CW pdfinfo
2210 macro,
2211 .XR docinfo ), (
2212 and the
2213 .CW pdfhref
2214 macro, when used to create a document outline,
2215 .XR add-outline ), (
2216 do not immediately write their
2217 .CW pdfmark
2218 output to the PostScript\*(rg data stream;
2219 instead, they cache their output, in a
2220 .CW groff
2221 diversion, in the case of the
2222 .CW pdfview
2224 .CW pdfinfo
2225 macros, or in an ordered collection of strings and numeric registers,
2226 in the case of the document outline,
2227 until a more appropriate time for copying it out.
2228 In the case of
2229 .CW pdfview
2231 .CW pdfinfo
2232 \(lqmeta\(hydata\(rq,
2233 this \(lqmore appropriate time\(rq is explicitly chosen by the user;
2234 in the case of document outline data,
2235 .EM some
2236 cached data may be implicitly written out as the document outline is compiled,
2237 but there will
2238 .EM always
2239 be some remaining data, which must be explicitly flushed out, before the
2240 .CW groff
2241 formatting process is allowed to complete.
2243 To allow the user to choose when cached
2244 .CW pdfmark
2245 data is to be flushed to the output stream, the
2246 .CW pdfmark
2247 macro package provides the
2248 .CW pdfsync
2249 macro, (to synchronise the cache and output states).
2250 In its simplest form, it is invoked without arguments, i.e.
2252 .fam C
2253 .B .pdfsync
2255 This form of invocation ensures that
2256 .EM both
2257 the \(lqmeta\(hydata cache\(rq, containing
2258 .CW pdfview
2260 .CW pdfinfo
2261 data,
2262 .EM and 
2263 the \(lqoutline cache\(rq,
2264 containing any previously uncommitted document outline data,
2265 are flushed; ideally, this should be included in a
2266 .CW groff
2267 \(lqend macro\(rq, to ensure that
2268 .EM both
2269 caches are flushed, before
2270 .CW groff
2271 terminates.
2273 Occasionally,
2274 it may be desirable to flush either the \(lqmeta\(hydata cache\(rq,
2275 without affecting the \(lqoutline cache\(rq, or vice\(hyversa,
2276 at a user specified time, prior to reaching the end of the document.
2277 This may be accomplished, by invoking the
2278 .CW pdfsync
2279 macro with an argument, i.e.
2281 .fam C
2282 .B ".pdfsync M"
2284 to flush only the \(lqmeta\(hydata cache\(rq, or
2286 .fam C
2287 .B ".pdfsync O"
2289 to flush only the \(lqoutline cache\(rq.
2291 The \(lqmeta\(hydata cache\(rq can normally be safely flushed
2292 in this manner, at any time
2293 .EM after
2294 output of the first page has started;
2295 (it may cause formatting problems,
2296 most notably the appearance of unwanted white space, if flushed earlier,
2297 or indeed, if flushed immediately after a page transition,
2298 but before the output of the content on the new page has commenced).
2299 Caution is required, however, when explicitly flushing the
2300 \(lqoutline cache\(rq, since if the outline is to be
2301 subsequently extended, then the first outline entry after flushing
2302 .EM must
2303 be specified at level 1.
2304 Nevertheless, such explict flushing may occasionally be necessary;
2305 for example, the
2306 .CW TC
2307 macro in the
2308 .CW spdf.tmac
2309 package,
2310 .XR using-spdf ), (
2311 invokes
2312 .CW ".pdfsync\ O" \(rq \(lq
2313 to ensure that the outline for the \(lqbody\(rq section of the document
2314 is terminated,
2315 .EM before
2316 it commences the formatting of the table of contents section.
2318 .NH 1
2319 .XN -N pdf-layout -- PDF Document Layout
2322 .CW pdfmark
2323 macros described in the preceding section,
2324 .XR pdf-features ), (
2325 provide no inherent document formatting capability of their own.
2326 However,
2327 they may be used in conjunction with any other
2328 .CW groff
2329 macro package of the user's choice,
2330 to add such capability.
2332 In preparing this document, the standard
2333 .CW ms
2334 macro package, supplied as a component of the GNU Troff distribution,
2335 has been employed.
2336 To facilitate the use of the
2337 .CW pdfmark
2338 macros with the
2339 .CW ms
2340 macros,
2341 a binding macro package,
2342 .CW spdf.tmac ,
2343 has been created.
2344 The use of this binding macro package is described in the following section,
2345 .XR using-spdf ); (
2346 it may also serve as an example to users of other standard
2347 .CW groff
2348 macro packages,
2349 as to how the
2350 .CW pdfmark
2351 macros may be employed with their chosen primary macro package.
2352 .NH 2
2353 .XN -N using-spdf -- Using \F[C]pdfmark\F[] Macros with the \F[C]ms\F[] Macro Package
2355 The use of the binding macro package,
2356 .CW spdf.tmac ,
2357 allows for the use of the
2358 .CW pdfmark
2359 macros in conjunction with the
2360 .CW ms
2361 macros,
2362 simply by issuing a
2363 .CW groff
2364 command of the form
2366 .fam C
2367 groff -Tps
2368 .B -mspdf
2369 .I "-options ...\&" ] [
2370 file(s) ...
2372 When using the
2373 .CW spdf.tmac
2374 package, the
2375 .CW groff
2376 input files may be marked up using any of the standard
2377 .CW ms
2378 macros to specify document formatting,
2379 while PDF features may be added,
2380 using any of the
2381 .CW pdfmark
2382 macros described previously,
2383 .XR pdf-features ). (
2384 Additionally,
2385 .CW spdf.tmac
2386 defines a number of convenient extensions to the
2387 .CW ms
2388 macro set, to better accomodate the use of PDF features within the
2389 .CW ms
2390 formatting framework,
2391 and to address a number of
2392 .CW ms
2393 document layout issues,
2394 which require special handling when producing PDF documents.
2395 These additional macros,
2396 and the issues they are intended to address,
2397 are described below.
2398 .NH 3
2399 .XN \F[C]ms\F[] Section Headings in PDF Documents
2401 Traditionally,
2402 .CW ms
2403 provides the
2404 .CW NH
2406 .CW SH
2407 macros, to specify section headings.
2408 However,
2409 there is no standard mechanism for generating a
2410 table of contents entry based on the text of the section heading;
2411 neither is there any recognised standard method for establishing a
2412 cross reference link to the section.
2414 To address this
2415 .CW ms
2416 limitation,
2417 .CW spdf.tmac
2418 defines the
2419 .CW XN
2420 macro,
2421 .XR xn-macro ), (
2422 to be used in conjunction with the
2423 .CW NH
2424 macro.
2425 .NH 4
2426 .XN -N xn-macro -- The \F[C]XN\F[] Macro
2427 .NH 1
2428 .XN The PDF Publishing Process
2429 .NH 2
2430 .XN -N do-xref -- Resolving Cross References
2431 .NH 3
2432 .XN -N create-map -- Creating a Document Reference Map
2433 .NH 3
2434 .XN -N import-map -- Deploying a Document Reference Map