]> mj.ucw.cz Git - ucwmac.git/blobdiff - ucw-ref.tex
ucw-link: "--" in URLs should not produce a ligature
[ucwmac.git] / ucw-ref.tex
index 7bee45cb44b4231d186a98a46b2795491bb18b89..86d41a19c3dc67d14a68ef7dc9c231ec1012e952 100644 (file)
@@ -2,10 +2,8 @@
 % Written by Martin Mares <mj@ucw.cz> in 2018 and placed into public domain
 % -------------------------------------------------------------------------
 
-% Should clickable links be produced?
-\newif\ifclickable
-\clickabletrue
-\fi
+\ucwdefmodule{ref}
+\ucwmodule{link}
 
 % We maintain a collection of objects. Each object has:
 %    - type (namespace -- e.g., chapter)
@@ -24,7 +22,7 @@
 \def\delayedwriteid#1#2{\write\ids{\string\iddef{#1}{#2}{\refcurrentfile}}}
 
 % Used in auxiliary files
-\def\iddef#1#2#3{\ifcsname id:#1\endcsname\immediate\write16{*** Warning: Identifier #1 re-defined ***}\else
+\def\iddef#1#2#3{\ifcsname id:#1\endcsname\ucwwarn{Identifier #1 re-defined}\else
 \expandafter\def\csname id:#1\endcsname{#2}%
 \expandafter\def\csname ff:#1\endcsname{#3}%
 \fi}
@@ -33,7 +31,7 @@
 \immediate\openin\ids=\jobname.ids.aux
 \ifeof\ids
 \else
-\input ids.aux
+\input \jobname.ids.aux
 \fi
 \immediate\closein\ids
 \immediate\openout\ids=\jobname.ids.aux
        \ifx\optarg\relax
                \let\currentid\relax
        \else
-               \edef\currentid{#1\optarg}%
+               \edef\currentid{#1:\optarg}%
                \writeid{\currentid}{#2}%
-               \ifclickable
-                       \pdfdest name {\currentid} xyz\relax
-               \fi
+               \destpos{\currentid}%
        \fi
 }
 
 % A low-level interface for typesetting references: produces a clickable link
 % to the identifier #2 of type #1 with a label translated by macro #3 (use \relax
 % for no translation).
-\def\reflink#1#2#3{\expandafter\ifx\csname id:#1#2\endcsname\relax
-       {\bo ??}%
-       \immediate\write16{*** Warning: Reference #1 undefined ***}%
+\def\reflink#1#2#3{\expandafter\ifx\csname id:#1:#2\endcsname\relax
+       {\ifx\bo\undefined\bf\else\bo\fi ??}%
+       \immediate\write16{*** Warning: Reference #1:#2 undefined ***}%
 \else
-       \ifclickable
-               \pdfstartlink\commonlinkargs goto name {#1}\relax
-       \fi
-       #3{\csname id:#1#2\endcsname}%
-       \ifclickable
-               \pdfendlink\relax
-       \fi
+       \link{#1:#2}{#3{\csname id:#1:#2\endcsname}}%
 \fi
 }
 
-% Common style of all clickable links
-\pdflinkmargin=1pt
-\def\commonlinkargs{height 8pt depth 2pt attr {/C [0 0 0.5] /Border [0 0 2]}}
-
 % Typeset a link to identifier #2 of type #1
 \def\ref#1#2{\reflink{#1}{#2}\relax}
 
 % Define an identifier of type page pointing to the current page
-\def\pageid#1{\delayedwriteid{page#1}{\the\count0}\ifclickable\pdfdest name {page#1} fit\relax\fi}
-
-% Typeset a reference to the given page number (used in tables of contents and indices,
-% where we know the page number from other sources).
-\def\pagelink#1{\ifclickable\pdfstartlink\commonlinkargs goto page #1 {/Fit}\relax #1\pdfendlink\else #1\fi}
-
-% Typeset a clickable URL
-% Currently, all weird characters must be properly escaped.
-\def\url#1{%
-       \ifclickable
-               \pdfstartlink\commonlinkargs user {/Subtype/Link /A << /Type/Action /S/URI /URI(#1) >>}\relax
-       \fi
-       \xurl #1^^X%
-       \ifclickable
-               \pdfendlink\relax
-       \fi
-}
-\def\xurl#1:#2#3^^X{{\I #1:#2\ifx#2/\kern-0.1em\fi#3}}
+\def\pageid#1{\delayedwriteid{page#1}{\the\count0}\destpage{page#1}}
+\def\pageref{\ref{page}}