groff
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Groff macro to make .UR and .UE links clickable in PDF?


From: B 9
Subject: Re: Groff macro to make .UR and .UE links clickable in PDF?
Date: Tue, 16 Jun 2020 18:45:48 -0700
User-agent: s-nail v14.9.11

On Tue, Jun 16, 2020, Steve Izma wrote:
> Anyway, my strategies for typesetting for a printed document:

I'm always impressed by people who know how to typeset AND how to
write! Thank you for the clear and concise rules.


Steve Izma <sizma@golden.net> wrote:

> - don't set the URL at all in the body of the text but use a
>   footnote or endnote marker and set the URL in the footnote or
>   endnote, since these are usually set in a smaller point size
>   and gives you more flexibility for fitting on lines; if a text
>   contains a lot of URLS, then set the notes as endnotes in a
>   longer line length, if possible;

This would be an ideal solution, if it is possible with groff. When I
must have a URL visible in the text, I'd love for it to be in small
text as a footnote. How hard is it to add footnotes to a package like
mdoc in groff? 


Thank you, Deri, for providing your pdfman program! I am hoping to
find a solution using a groff macro instead of a Perl preprocessing
step, but it does do what I want.

For those who didn't try pdfman yet, it turns troff like this:

    The GNU Project of the Free Software Foundation hosts the
    .UR https://\:www.gnu.org/\:software/\:groff/
    Groff home page
    .UE .

into something like this:

    .ds PDFHREF.COLOUR 0.0 0.0 0.3
    .defcolor pdf:href.colour rgb \*[PDFHREF.COLOUR]
    .ds PDFHREF.TEXT.COLOUR pdf:href.colour
    The GNU Project of the Free Software Foundation hosts the
    .pdfhref W -D "https://www.gnu.org/software/groff/"; -A "." -- Groff home 
page

This makes the phrase "Groff home page" in the PDF a blue clickable
link to the proper URL. The URL itself is not shown in the PDF text.

--b9



Deri <deri@chuzzlewit.myzen.co.uk> wrote:
> if ($l=~m/^\.UR (\S+)/)
> {
>       my $desc='';
>       my $dest=$1;
>       $dest=~s/\\\://g;
>       my $affix='';
>       $foundur=1;
> 
>       for (my $i=$j+1;$i<$j+4;$i++)
>       {
>           if ($lines[$i]=~m/^\.(?:ME|UE) ?(.*)/)
>           {
>               $affix=" -A \"$1\"" if $1;
>               $lines[$i]=undef;
>               last;
>           }
>           else
>           {
>               $desc.=' ' if $desc;
>               $desc.=$lines[$i];
>               $lines[$i]=undef;
>           }
>       }
> 
>       $l=qq(.pdfhref W -D "$dest"${affix} -- $desc);
>       Put($l);
>       next;
> }

P.S. Deri, your code is using a regex to find the URL and it breaks on
this input:

    The main home page for the x86 port of Madness is
    .UR http://\:www.frijid.net/\:madness/\:madness.html
    http://www.frijid.net/madness/madness.html
    .UE .





reply via email to

[Prev in Thread] Current Thread [Next in Thread]