On Saturday, 23 November 2019 14:02:26 GMT Ralph Corderoy wrote:
> The mom macros have a method of moving the table of contents with -Tpdf
> that depends on gropdf(1)'s .pdfpagename and .pdfswitchtopage.  (Deri,
> I don't think they're documented?)  mom uses them with the page name
> MOM:TOC.  Perhaps mm, or an mm user, could also benefit from them for
> .TC.  Hard to say without more investigation.

Apologies for the oversite, I will be adding this to the man page for gropdf.

==============================================================================

     \X'pdf: pagename name 
             This gives the current page a name. 

             There  are  two default names for any document which do not need 
             to be declared ‘top’ and ‘bottom’. 

             The convenience command for this is .pdfpagename. 

      \X'pdf: switchtopage when name 
             Normally each new page is appended to the end of  the  document, 
             this  command allows following pages to be inserted at a ‘named’ 
             position within  the  document  (see  pagename  command  above). 
             ‘when’  can be either ‘after’ or ‘before’.  If it is ommitted it 
             defaults to ‘before’. 

             The convenience command for this is .pdfswitchtopage.  It should 
             be  used  at  the  end of the page before you want the switch to 
             happen. 

             This allows pages such as a TOC to be moved to elsewhere in  the 
             document, but more esoteric uses are possible.

===============================================================================

Also I attach an example using the calls to relocate a pseudo TOC. Note that 
the definitions of PDFTARGET and PDFLINK are based on the equivalent 
definitions in the om.tmac file. Just to make less typing.

Note that the TOC page is moved to after the title page, and all the clickable 
links in the TOC still work properly. Also, although it looks like the TOC 
page contains forward references it can be produced with just a standard:-

groff -T pdf switch.trf

Rather than having to do multiple passes to resolve forward references.

Cheers

Deri




\#
\# PDFLINK
\# --------
\# *Arguments:
\#    $1 = named link
\#    [PREFIX text] : text to prefix link
\#    [SUFFIX text] : text after link
\#    text
\#
\# *Notes
\#    Text is output as a hotspot link to named destination.
\#    If text has final '*' it is replaced with the text associated with the 
link
\#
de PDFLINK END
    ds PDF_NM \\$1
    shift
    ie '\\$1'PREFIX' \{\
       ds PDF_PRE -P "\&\\$2"
       shift 2
    \}
    el .ds PDF_PRE
    ie '\\$1'SUFFIX' \{\
       ds PDF_POST -A "\\$2"
       shift 2
    \}
    el .ds PDF_POST
    ds PDF_AST_Q
    ds PDF_TXT \&\\$1
    ds PDF_AST \\*[PDF_TXT]
    substring PDF_AST -1 -1
    if '\\*[PDF_AST]'+' \{\
       ds PDF_AST *
       ds PDF_AST_Q ""
    \}
    if '\\*[PDF_AST]'*' \{\
        chop PDF_TXT
        ie '\\*[.T]'pdf' \{\
           ie d pdf:look(\\*[PDF_NM]) \
               as PDF_TXT 
\&\\*[PDF_AST_Q]\\*[pdf:look(\\*[PDF_NM])]\\*[PDF_AST_Q]
           el \{\
               as PDF_TXT Unknown
               if !rPDF_UNKNOWN .tm \
\\n[.F]:\\n[.c]: forward reference detected (please run using 'pdfmom')
               nr PDF_UNKNOWN 1
           \}
        \}
        el \{\
            ie d pdf:href(\\*[PDF_NM]).info \
               as PDF_TXT 
\&\\*[PDF_AST_Q]\\*[pdf:href(\\*[PDF_NM]).info]\\*[PDF_AST_Q]
            el .as PDF_TXT Unknown
       \}
    \}
    pdfhref L \\*[PDF_PRE] \\*[PDF_POST] -D \\*[PDF_NM] -- \\*[PDF_TXT]
    rm PDF_NM
    rm PDF_PRE
    rm PDF_POST
    rm PDF_TXT
    rm PDF_AST
    rm PDF_AST_Q
END
\#
de PDFTARGET END
    ds ARG_1 \\$1
    shift
    fl
    ie '\\$*'' .pdfhref M -N \\*[ARG_1] -- \\$*
    el .pdfhref M -N \\*[ARG_1] -E -- \\$*
    if '\\*[.T]'ps' .if !dpdf:href.map .tm gropdf-info:href \\*[ARG_1] \\$*
END
\#
de BP END
    bp \\$*
    sp |1i
END
.
sp 1i
Title
pdfpagename TITLE
BP 1
PDFTARGET One One \n%
BP
PDFTARGET Two Two \n%
BP
PDFTARGET Three Three \n%
pdfswitchtopage after TITLE
BP
TOC
nf
PDFLINK One *
PDFLINK Two *
PDFLINK Three *

Reply via email to