]> mj.ucw.cz Git - ucwmac.git/commitdiff
ucw-link: Better macros for URLs and URL links
authorMartin Mares <mj@ucw.cz>
Tue, 5 Jun 2018 20:09:07 +0000 (22:09 +0200)
committerMartin Mares <mj@ucw.cz>
Tue, 5 Jun 2018 20:09:07 +0000 (22:09 +0200)
test-ref.tex
ucw-link.tex

index 13f9e1cd4465a74fd79a09121d9bdfc107ca4ff0..95915ab9ca2650969a2a5e79ce1c8f2f6c5dc90c 100644 (file)
@@ -27,7 +27,9 @@
 
 \chapter[sec]{Caput secunda}
 
-\url{http://pruvodce.ucw.cz/errata.html}
+\url{http://pruvodce.ucw.cz/errata%21.html}
+
+\linkurl{http://pruvodce.ucw.cz/}{See the web page.}
 
 \chapter[ter]{Caput tertia}
 
index 58f498f9ab13d1304306ffa258651dc1515d297d..ef8959353a94d68725ef985e3c2f9df7e5925475 100644 (file)
 \def\linkpage#1#2{\ifclickable\pdfstartlink\commonlinkargs goto page #1 {/Fit}\relax #2\pdfendlink\else #2\fi}
 
 % Typeset a clickable URL
-% Currently, all weird characters must be properly escaped.
-\def\url#1{%
+% \url{http://example.com/}
+\def\url{\begingroup\allowurlchars\urlaux}
+\def\urlaux#1{\linkurlaux{#1}{\displayurl #1^^X}}
+
+% Typeset a clickable link to the given URL
+% \linkurl{http://example.com/}{text}
+\def\linkurl{\begingroup\allowurlchars\linkurlaux}
+\def\linkurlaux#1#2{\endgroup
        \leavevmode
        \ifclickable
                \pdfstartlink\commonlinkargs user {/Subtype/Link /A << /Type/Action /S/URI /URI(#1) >>}\relax
        \fi
-       \xurl #1^^X%
+       #2%
        \ifclickable
-               \pdfendlink\relax
+               \pdfendlink
        \fi
 }
-\def\xurl#1:#2#3^^X{{\I #1:#2\ifx#2/\kern-0.1em\fi#3}}
+
+% Catcode each special character valid in URL to 'other'
+\def\allowurlchars{\catcode`\#=12\catcode`\_=12\catcode`\%=12\catcode`\&=12\catcode`\$=12\catcode`\~=12\relax}
+
+% Style switches and the beginning/end of an URL
+\let\urlprefix\it
+\let\urlsuffix\/
+
+% Kern to place between "//" in an URL
+\newdimen\urlinterslashkern
+\urlinterslashkern=-0.1em
+
+% Internal macro for typesetting of URLs
+\def\displayurl#1:#2#3^^X{{\urlprefix #1:#2\ifx#2/\kern\urlinterslashkern\fi#3\urlsuffix}}