From a9bffcfef2760e395611e468b2068cc7be665bb9 Mon Sep 17 00:00:00 2001 From: Martin Mares Date: Tue, 5 Jun 2018 18:43:35 +0200 Subject: [PATCH] References: Fixed a couple of bugs and added a test case --- test-ref.tex | 33 +++++++++++++++++++++++++++++++++ ucw-ref.tex | 11 ++++++----- 2 files changed, 39 insertions(+), 5 deletions(-) create mode 100644 test-ref.tex diff --git a/test-ref.tex b/test-ref.tex new file mode 100644 index 0000000..6dd327a --- /dev/null +++ b/test-ref.tex @@ -0,0 +1,33 @@ +\input ucwmac.tex +\input ucw-ref.tex +\input ucw-ofs.tex + +% \clickablefalse + +\newcount\chapcount +\chapcount=0 +\optdef\chapter#1{ + \vfill\eject + \advance\chapcount by 1 + \addid{chap}{\the\chapcount} + \leftline{\the\chapcount. #1} + \medskip +} + +\def\chapref{\ref{chap}} + +\pageid{pri} + +\chapter[pri]{Caput prima} + +\chapter[sec]{Caput secunda} + +\url{http://pruvodce.ucw.cz/errata.html} + +\chapter[ter]{Caput tertia} + +See also chapter~\chapref{pri} at page \ref{page}{pri}. + +Hard link to page~\pagelink{1}. + +\bye diff --git a/ucw-ref.tex b/ucw-ref.tex index 7bee45c..66b6372 100644 --- a/ucw-ref.tex +++ b/ucw-ref.tex @@ -5,7 +5,6 @@ % Should clickable links be produced? \newif\ifclickable \clickabletrue -\fi % We maintain a collection of objects. Each object has: % - type (namespace -- e.g., chapter) @@ -33,7 +32,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 @@ -58,11 +57,11 @@ % 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 ??}% + {\ifx\bo\undefined\bf\else\bo\fi ??}% \immediate\write16{*** Warning: Reference #1 undefined ***}% \else \ifclickable - \pdfstartlink\commonlinkargs goto name {#1}\relax + \pdfstartlink\commonlinkargs goto name {#1#2}\relax \fi #3{\csname id:#1#2\endcsname}% \ifclickable @@ -73,13 +72,14 @@ % Common style of all clickable links \pdflinkmargin=1pt -\def\commonlinkargs{height 8pt depth 2pt attr {/C [0 0 0.5] /Border [0 0 2]}} +\def\commonlinkargs{height \the\dimexpr\ht\strutbox-0.5pt\relax depth \the\dimexpr\dp\strutbox-0.5pt\relax 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} +\def\pageref{\ref{page}} % Typeset a reference to the given page number (used in tables of contents and indices, % where we know the page number from other sources). @@ -88,6 +88,7 @@ % Typeset a clickable URL % Currently, all weird characters must be properly escaped. \def\url#1{% + \leavevmode \ifclickable \pdfstartlink\commonlinkargs user {/Subtype/Link /A << /Type/Action /S/URI /URI(#1) >>}\relax \fi -- 2.39.2