1 .\" -*- mode: text; coding: utf-8; -*-
3 .\" Copyright (C) 2012-2018 Free Software Foundation, Inc.
5 .\" This file is part of mom, which is part of groff, a free software
8 .\" You can redistribute it and/or modify it under the terms of the
9 .\" GNU General Public License as published by the "Free Software
10 \" Foundation", version\~2.
12 .\" The license text is available on the internet at
13 .\" <http://www.gnu.org/licenses/gpl-2.0.html>
16 .\" Reference macros (metadata)
17 .TITLE "Producing PDFs" "with groff and mom"
18 .PDF_TITLE "\*[$TITLE]
19 .COPYRIGHT "20\*[BU3]1\*[BU2]5, 20\*[BU3]1\*[BU2]7 Free Software Foundation
20 .AUTHOR "Deri James" "\*[UP .5p]and" "Peter Schaffter"
21 .\" Cover author style
25 .\" Docheader author style
29 .ATTRIBUTE_STRING "" \" Don't print 'by'
32 .\" Formatting style, margins
42 .PARA_INDENT 0 \" No indent because we're spacing paragraphs.
49 This file is part of groff.
51 Groff is free software. You can redistribute it
52 and\*[FU3]/or modify it under the terms of the GNU
53 General Public License as published by the
54 Free Software Foundation, either version 3
55 of the License, or (at your option) any later
58 You should have received a copy of the GNU
59 General Public License along with this program.
62 .PDF_LINK_COLOR 0.0 0.3 0.9
63 .PDF_WWW_LINK http://www.gnu.org/licenses/
67 .\" Cover and page header
68 .COVER TITLE AUTHOR COPYRIGHT COVERTEXT
69 .HEADER_LEFT "James, Schaffter"
73 .\" Color for code snippets
74 .NEWCOLOUR dark-grey RGB #343434
75 .\" Make QUOTE look like CODE
87 .CONDENSE 87 \" Condense percentage used in COD
93 BASELINE_ADJUST \n[.v]/5
98 BASELINE_ADJUST \n[.v]/5
101 .\" Character definitions for program names, opts, etc.
102 .char \[ghostscript] \*[BD]ghostscript\*[PREV]
103 .char \[groff] \*[BD]groff\*[PREV]
104 .char \[gropdf] \*[BD]gropdf\*[PREV]
105 .char \[grops] \*[BD]grops\*[PREV]
106 .char \[man] \*[BD]man\*[PREV]
107 .char \[-mom] \*[BD]\-mom\*[PREV]
108 .char \[mom] \*[BD]mom\*[PREV]
109 .char \[-mpdfmark] \*[BD]\-mpdfmark\*[PREV]
110 .char \[ms] \*[BD]ms\*[PREV]
111 .char \[pdfmom] \*[BD]pdfmom\*[PREV]
112 .char \[pdfroff] \*[BD]pdfroff\*[PREV]
113 .char \[-P-e] \*[BD]\-P\-e\*[PREV]
114 .char \[-P-p<papersize>] \*[BD]\-P\-p<papersize>\*[PREV]
115 .char \[ps2pdf] \*[BD]ps2pdf\*[PREV]
116 .char \[psselect] \*[BD]psselect\*[PREV]
117 .char \[-T] \*[BD]\-T\*[PREV]
118 .char \[-Tpdf] \*[BD]\-Tpdf\*[PREV]
119 .char \[-Tps] \*[BD]\-Tps\*[PREV]
120 .\" Strings for inline code
121 .ds cod \E*[CODE]\&\E*[COND]
122 .ds codx \E*[CONDX]\E*[CODE off]\&
123 .\" Paragraph spacing
125 .\" Wrapper around QUOTE
128 . nop \*[COND]\\$*\*[CONDX]
133 . ie \\n[#NUM_ARGS]=1 .DBX .5 0 \\n[.l]u \\$1
134 . el .DBX .5 0 \\$1 \\$2
138 .\" Table of contents
142 .TOC_ENTRY_STYLE 2 FONT I
143 .TOC_LEAD 14.5 ADJUST
146 .DOCHEADER_ADVANCE 5c \" Begin docheader this distance down from top of page
152 .HEADING 1 NAMED intro "Introduction"
155 PDF documents are intended to be "electronic paper,\*[BU6]" and, as
156 such, take advantage of the digital medium in ways that PostScript
157 documents do not. Chief amongst these are clickable links that
158 point to named destinations, either within the documents themselves
159 .PDF_LINK internal PREFIX ( SUFFIX ) "internal links"
160 or to remote web pages
161 .PDF_LINK external PREFIX ( SUFFIX ), "external links"
162 and the generation of a clickable document outline that appears in
163 the Contents panel of most PDF viewers.
166 Using \[groff] and \[mom] to produce PDF documents results in the
167 automatic generation of clickable document outlines (discussed
169 .PDF_LINK outline SUFFIX ), +
170 and, if the \*[cod]TOC\*[codx] macro is included in the source file,
171 entries in the printable table of contents can be clicked on as well
172 when the document is viewed at the screen (see
173 .PDF_LINK toc SUFFIX ). +
175 .HEADING 1 NAMED generating "Using groff to generate PDF files"
177 Groff provides more than one way to generate PDF documents from
178 files formatted with the \[mom] macros. One is to call \[groff]
179 directly, either with
180 .COD "groff [\-Tps] \-mom \-m pdfmark doc.mom | ps2pdf \- doc.pdf
181 which pipes output from the \[grops] PostScript driver through
183 .COD "groff \-Tpdf \-mom doc.mom > doc.pdf
184 which uses the native PDF driver, \[gropdf]. Alternatively, one may
186 .COD "pdfroff \-mom \-mpdfmark \-\-no-toc doc.mom > doc.pdf
187 A fourth, preferred method is to use
188 .PDF_LINK pdfmom SUFFIX , "\[pdfmom]"
189 which is strongly recommended since it implements the full range
190 of PDF features available in \[mom].
191 .COD "pdfmom doc.mom > doc.pdf
192 One reason to prefer using the native PDF driver (via \[pdfmom] or
193 \[-Tpdf]) is that papersizes set within mom source files (see
194 .PDF_WWW_LINK http://www.schaffter.ca/mom/momdoc/typesetting.html#page-setup-intro SUFFIX ) \
195 "paper and page setup macros"
196 do not require a corresponding \[-P-p<papersize>] flag on the
199 There are other minor differences between the methods, discussed
200 .PDF_LINK pdf-diff SUFFIX . "here"
202 .HEADING 1 NAMED links "Creating PDF links with mom"
204 Often, but not always, links in the body of a PDF document point
205 to headings elsewhere in the same document. Creating these links
206 is a simple process. First, identify the places to link to
207 ("destinations"), then link to them from any place in the document.
208 .HEADING 2 NAMED naming "Creating destination points at headings"
210 The first step in creating links to a heading is to give the
211 heading a unique destination name. With mom, this is done by
212 adding \*[cod]NAMED\|<id>\*[codx] to the HEADING macro, where
213 \*[cod]<id>\*[codx] is a unique identifier for the heading. For
216 .COD "\&.HEADING 1 NAMED intro \[dq]Introduction\[dq]"
217 would, in addition to printing the head in the body of the document,
218 identify the introduction by the unique id, "intro"\*[BU6]. This
219 id, or name, can then be used to create links to the introduction
220 from any part of the document.
222 Furthermore, \*[cod]NAMED\|<id>\*[codx] stores the text of the
223 heading for use later on when linking to it (see
224 .PDF_LINK internal SUFFIX ). +
225 If headings are being numbered, the heading number is prepended.
226 .HEADING 2 NAMED target "Creating destination points at arbitrary locations"
228 Any part of a document can be a link destination, not just headings.
229 For example, say you create a table that needs to be referred to
230 from other parts of the document. You'd identify the location of
232 .COD "\&.PDF_TARGET <id> \[dq]<text>\[dq]"
233 just above the table in the source file. As with
234 \*[cod]HEADING\*[codx], \*[cod]<id>\*[codx] is any unique name.
235 \*[cod]<text>\*[codx] is optional. \*[cod]<id>\*[codx] can now be linked
236 to from anywhere in the document.
238 .HEADING 2 NAMED internal "Creating internal links"
240 Internal links are clickable text areas that allow you to jump to
241 named destinations within a document. (See
242 .PDF_LINK external "here"
243 for a description of external links.)
245 Internal links are created with the macro \*[cod]PDF_LINK\*[codx],
247 .COD "\&.PDF_LINK <id> [PREFIX <text>] [SUFFIX <text>] \
248 \[dq]<hotlink text>\[dq]"
249 where \*[cod]<id>\*[codx] is a named destination point elsewhere in
253 .PDF_LINK target SUFFIX ). +
255 \*[cod]PREFIX\|<text>\*[codx] and \*[cod]SUFFIX\|<text>\*[codx], both or
256 either of which are optional, are printed around the clickable area
257 but do not form part of the link itself.
259 \*[cod]<hotlink text>\*[codx] is the text that should be clickable,
260 identifiable in the PDF document by the colour assigned to links
262 .PDF_LINK colour SUFFIX ). +
265 If the hotlink text ends in \*[cod]\[dq]*\[dq]\*[codx]\*[BU9],
266 the asterisk is replaced by the text of the destination
267 point, assuming it's a heading. If the hotlink text ends in
268 \*[cod]\[dq]+\[dq]\*[codx]\*[BU9], the replacement text is surrounded
272 .PDF_LINK intro-ex SUFFIX , "HEADING example"
274 above, the following invocation of \*[cod]PDF_LINK\*[codx] would
275 produce a click\%able link to the introduction:
276 .COD "\&.PDF_LINK intro PREFIX ( SUFFIX ). \[dq]see: +\[dq]"
278 In the text, the link would look like this:
279 .PDF_LINK intro PREFIX ( SUFFIX ). "see: +"
280 .HEADING 2 NAMED external "Creating external links"
282 External links are clickable text areas whose destination is a
283 URL. Clicking on them causes a browser window to pop up with the
286 The format of the macro to create external links is similar to the
287 one for creating internal links:
288 .COD "\&.PDF_WWW_LINK <url> [PREFIX <text>] [SUFFIX <text>] [\[dq]<hotlink text>\[dq]]"
289 \*[cod]<url>\*[codx] is any valid URL, usually a web address;
290 \*[cod]PREFIX\|<text>\*[codx] and \*[cod]SUFFIX\|<text>\*[codx] have
291 exactly the same meaning, as does \*[cod]<hotlink text>\*[codx],
292 which furthermore accepts the same expandos, \*[cod]\[dq]+\[dq]\*[codx] and
293 \*[cod]\[dq]*\[dq]\*[codx].
296 If no hotlink text is given, then \*[cod]<url>\*[codx] is
297 used as the text. If hotlink text is given and ends in
298 \*[cod]\[dq]*\[dq]\*[codx]\*[BU9], the asterisk is replaced by the
299 URL. If it ends in \*[cod]\[dq]+\[dq]\*[codx]\*[BU9], the URL is
300 surrounded by quotes. As an example,
302 .COD "\&.PDF_WWW_LINK http://www.schaffter.ca/mom/momdoc/toc.html
303 would open mom's online documentation at
304 .PDF_WWW_LINK http://www.schaffter.ca/mom/momdoc/toc.html SUFFIX "."
305 The same, with \*[cod]\[dq]here\[dq]\*[codx] supplied as
306 hotlink text, lets you click
307 .PDF_WWW_LINK http://www.schaffter.ca/mom/momdoc/toc.html "here"
309 .HEADING 2 NAMED colour "Assigning a colour to links"
311 The colour of links is set with
312 .COD "\&.PDF_LINK_COLOR <xcolor> | <newcolor> | <r g b> | <#rrggbb>
313 where \*[cod]<xcolor>\*[codx] or \*[cod]<newcolor>\*[codx] are the names
314 of colours already initialized with
315 .PDF_WWW_LINK http://www.schaffter.ca/mom/momdoc/color.html#xcolor "XCOLOR"
317 .PDF_WWW_LINK http://www.schaffter.ca/mom/momdoc/color.html#newcolor SUFFIX . "NEWCOLOR"
318 If you prefer to define a new colour (using the RGB colour scheme),
319 enter it either as 3 numbers between
320 0.0 \*[UP 1p]\[->]\*[DOWN 1p] 1\*[BU4].0
321 or as a 6 character hex string. Thus
323 \*[FWD 6p]\*[cod].PDF_LINK_COLOR #ff0000\*[codx]
324 \ \*[SIZE -.5]and\*[SIZE]\ \"
325 \*[cod].PDF_LINK_COLOR 1.0 0 0\*[codx]
327 both lead to mom using
328 .PDF_LINK_COLOR 1 0 0
333 The default colour can be restored by calling
334 \*[cod]PDF_LINK_COLOR\*[codx] with no parameter.
339 The decimal scheme for creating colours must be used if a file is to
341 \[oq]\[groff]\~\[-Tps]\~\[-mpdfmark]\[cq],
342 \[oq]\[pdfroff]\[cq], or
343 \[oq]\[pdfmom]\~\[-Tps]\[cq].
347 .HEADING 1 NAMED outline "The PDF Outline"
349 Most PDF viewers provide a panel that displays a document's outline,
350 similar to a table of contents. Clicking on an entry navigates
351 directly to the appropriate place in the document.
353 Mom generates PDF outlines the same way she populates
354 her own table of contents: by intercepting calls to the
355 \*[cod]HEADING\*[codx] macro, as well as to the various title
356 and chapter macros used in namimg documents, and allocating each a
359 Covers, titles/chapters, and the table of contents are all
360 assigned to level 1\*[BU5]. Subsequent headings are assigned to
361 n\*[UP 1p]+\*[DOWN 1p]\*[BU4]1, where n is the level given to
362 \*[cod]HEADING\*[codx].
365 The PDF outline can sensibly recover from skipped or omitted heading
366 levels; the printed table of contents cannot. Users are therefore
367 advised to use headings in logical order, not for typographic
370 .HEADING 2 NAMED open-close "Opening and closing levels
372 A level is said to be open if one or more levels beneath it is
373 visible in the PDF outline. Closed \%levels have at least one level
374 beneath them that is not visible unless the closed link is clicked.
375 It is common for only the first two levels to be open so the outline
376 doesn't look cluttered.
378 To establish which levels should be open by default when a document
380 .COD "\&.PDF_BOOKMARKS_OPEN n
381 where \*[cod]n\*[codx] is a number specifying at which level all
382 subsequent ones should be closed.
384 If, at any point in the document, you specify
385 .COD "\&.PDF_BOOKMARKS_OPEN NO \e\[dq] or any other text argument
386 then all subsequent bookmarks will be closed until
387 \*[cod]PDF_BOOKMARKS_OPEN\*[codx] opens them again.
388 .HEADING 2 NAMED disabling "Suspending/disabling collection of outline entries
390 Suspending the collection of entries for the PDF outline is
392 .COD "\&.PDF_BOOKMARKS OFF
393 Mom's default is to collect entries, so if the command is placed at
394 the start of a document, it \%disables entry collection completely.
395 Elsewhere, it suspends collection until you re-enable it with
396 .COD "\&.PDF_BOOKMARKS \e\[dq] i.e. with no parameter
398 .HEADING 2 NAMED pdf:title "The PDF window title"
400 While not strictly part of the PDF outline, the title of a document
401 can be displayed as the document viewer's window title. The macro
402 to accomplish this is
403 .COD "\&.PDF_TITLE\ \[dq]<window title>\[dq]
404 It can take any text, so the viewer window title need not be the
405 same as the document's title.
409 \*[BD]Note:\*[PREV] The macro, \*[cod]DOC_TITLE\*[codx], always
410 invokes \*[cod]PDF_TITLE\*[codx]. If this is not what you want, you
411 can remove the window title by issuing
412 .COD ".PDF_TITLE \[dq]\[dq] \e\[dq] ie. with a blank argument
416 .HEADING 1 NAMED toc "Tables of Contents"
418 .HEADING 2 NAMED toc:gen "Generating a Table of Contents
421 To generate a printable Table of Contents for any document, simply
422 insert the macro, \*[cod]TOC\*[codx], as the last line of the source
423 file. (Formatting of the printable Table of Contents is discussed in
426 http://www.schaffter.ca/mom/momdoc/tables-of-contents.html#top \
427 SUFFIX ). "mom documentation"
428 When the file is processed and loaded in a viewer, entries in the
429 Table of Contents will be clickable links.
432 Whichever link colour is active at the end of the document, prior to
433 \*[cod]TOC\*[codx], will be used for the \%Table of Contents
435 .HEADING 2 NAMED toc:pos "Positioning the Table of Contents"
437 If \[groff]'s PostScript device (\[-Tps]) is used to process a mom
438 file, the Table of Contents is printed at the end of the document.
439 When this is not desirable, the PostScript output from \[groff]
440 must be processed with \[psselect] in order to place the TOC in the
443 When using mom and \[groff]'s native pdf device (via \[pdfmom] or
444 \[groff] \[-Tpdf]), positioning of the Table of Contents can be done
445 within the source file.
447 The command to control the placement of the TOC is
448 .COD "\&.AUTO_RELOCATE_TOC [<position>]
449 where the optional \*[cod]<position>\*[codx] can be one of these
454 \*[SIZE -.7]TOP\*[FU2]\*[UP .5p]\c
456 \*[BD]Note:\*[PREV] Documents without a COVER or DOC_COVER require
457 the \*[cod]TOP\*[codx] argument.
460 (ie. at the very start of the document)\*[SIZE -.2]\*[PREV]
468 It is normally not necessary to supply a keyword, since
469 \*[cod]AUTO_RELOCATE_TOC\*[codx] places the TOC after the DOC_COVER,
470 if there is one, or the first COVER when no DOC_COVER is present.
471 In rare instances where it is desirable to place the TOC somewhere
472 else in the document, there are two low-level commands,
473 \*[cod].TOC_BEFORE_HERE\*[codx]
474 \ \*[SIZE -.5]and\*[SIZE]\ \"
475 \*[cod].TOC_AFTER_HERE\*[codx]
476 which place the TOC either before or after the current page.
478 These last two commands have a small catch: although the TOC will
479 appear where specified, the \%"Contents" entry in the PDF outline,
480 which observes a hierarchy of levels, will assign the TOC to
481 level\~\*[BU4]1\*[BU4], possibly disrupting the visual ordering of
482 levels in the outline.
483 .HEADING 1 NAMED simplify "pdfmom: Simplifying PDF output"
485 As explained in the section
486 .PDF_LINK generating SUFFIX , *
488 there are two established methods
490 for creating PDF files with \[groff]: the original method, ie.
491 passing the \[-Tps] and \[-mpdfmark] options to \[groff] (or using
492 \[pdfroff], which does this for you); or the newer \[-Tpdf], which
493 produces PDF files natively.
494 .HEADING 2 NAMED fwd:ref "The problem of forward references"
497 Both methods encounter difficulties when dealing with forward
498 references; that is, when a link \*[IT]\%earlier\/\*[PREV] in a
499 document refers to a destination \*[IT]later\/\*[PREV] in the
500 document and the link text terminates
502 with one of the expandos,
503 \*[cod]\[dq]*\[dq]\*[codx] or \*[cod]\[dq]+\[dq]\*[codx]
505 .PDF_LINK expando SUFFIX ). "here"
506 Mom doesn't know what text to put in the expando because it has not
507 yet been defined. This means that \[groff] must be run multiple
508 times to find the unknown text.
511 The program \[pdfroff] exists to handle these multiple runs, but it
512 imposes some limitations on the PDF features available with \[mom].
514 .HEADING 2 NAMED pdfmom "pdfmom"
516 \[pdfmom] performs the same function as \[pdfroff], and is the
517 preferred, trouble-free way to generate PDF documents from a mom
518 source file. Like \[pdfroff], it is a frontend to \[groff] and
519 accepts all the same options (see \[man]\~\[groff]).
522 Called as-is, \[pdfmom] accepts all the same options as \[groff],
523 and requires no additional flags. PDF generation is performed by
524 \[gropdf], \[groff]'s native PDF driver:
526 .COD "pdfmom doc.mom [groff opts] > doc.pdf
527 If a \[-Tps] option is supplied, \[pdfmom] hands control over to
528 \[pdfroff], and both \[groff] and \[pdfroff] options may given.
529 The resulting PDF is produced from PostScript output fed into
531 .COD "pdfmom \-Tps [pdfroff opts [groff opts]] doc.mom > doc.pdf
532 For either invocation, it is not necessary to add \[-mom] or
533 \[-mpdfmark], as these are implied.
535 If Encapsulated PostScript or plain PostScript images have been
536 embedded in a document with
537 .PDF_WWW_LINK http://www.schaffter.ca/mom/momdoc/images.html#pspic SUFFIX , \
539 the \[-Tps] option must be used. In most other cases, \[pdfmom]
540 with no \[-T] flag is preferable.
541 .HEADING 2 NAMED papersize "Setting papersize within a source file"
543 A significant convenience afforded by using \[pdfmom] (or \[groff]
544 with the \[-Tpdf] flag) is that papersizes or page dimensions set
545 within mom source files (see
546 .PDF_WWW_LINK http://www.schaffter.ca/mom/momdoc/typesetting.html#page-setup-intro \
547 SUFFIX ) "paper and page setup macros"
548 do not require a corresponding \[-P-p<papersize>] option on the
549 command line. It is even possible to create documents with
551 .HEADING 2 NAMED pdf-diff \
552 "Differences between pdfmom and pdfroff"
554 Several features described in this manual are not available when
555 using \[pdfmom] with the \[-Tps] option, or when using \[pdfroff], or
556 \[groff]\~\[-Tps]\~\[-mpdfmark]:
563 .PDF_LINK toc:pos "Relocation of the Table of Contents"
564 is not supported. The TOC appears at the end of the document;
565 \[psselect] must be used to re-order pages.
567 If a link crosses a page boundary, it will stop being a clickable
568 hotspot on subsequent pages.
570 When establishing whether PDF outline levels are
571 .PDF_LINK open-close SUFFIX , "open or closed"
572 only the numerical parameter to \*[cod]PDF_BOOKMARKS_OPEN\*[codx] has
575 .PDF_LINK colour "PDF_LINK_COLOR"
576 only accepts colour definitions in decimal notation.
580 "Comparison of \-Tps\*[FU4]/\*[FU2]\-mpdfmark with \-Tpdf\*[FU4]/\*[FU2]\-mom
583 \[-Tps]\*[FU4]/\*[FU2]\[-mpdfmark]
587 does not support all the features described here
589 accepts images and graphics embedded with PSPIC
591 is mature and well-tested code
596 \[-Tpdf]\*[FU4]/\*[FU2]\[-mom]
600 facilitates embedding fonts directly in the PDF file (if the
601 \[-P-e] flag is given on the command line)
603 sets papersize from within the source file, circumventing the need
604 for the papersize flag (\[-P-p<papersize>]) on the command line
606 is not compatible with
608 http://www.schaffter.ca/mom/momdoc/docprocessing.html#printstyle \
609 "PRINTSTYLE TYPEWRITE"
610 underlining (e.g., of italics)
612 generally produces larger files; these can be reduced by piping
613 the output through \[ps2pdf]\*[B]
618 .BOX-NOTE (\n[.l]u-6P) 3P
620 \*[BD]Note:\*[PREV] Owing to a known bug, PDF files piped
621 through \[ps2pdf] lose some of
623 their metadata, notably the window title set with
624 \*[cod]PDF_TITLE\*[codx].
628 is newer code with less testing
634 .\" vim: filetype=groff: