[texhax] XeTeX : images as links

Heiko Oberdiek heiko.oberdiek at googlemail.com
Sat Sep 21 12:45:47 CEST 2013


On 20.09.2013 19:23, Philip Taylor wrote:
> In a forthcoming PDF catalogue of Greek MSS, a number of "thumbnail"
> images of folia, bindings, etc., will appear, many if not all of
> which will be expected to function as hyperlinks to full-sized
> (or perhaps pannable/zoomable) versions of the same.  However,
> endeavouring to achieve this functionality using either Eplain's
> \hyperref or Eplain's \hlstart/\hlend fails to produce the desired
> effect -- whilst text can act as a clickable region for a hyperlink,
> an image included using \XeTeXpicfile seemingly cannot.

It's a deficiency of XeTeX that non-character stuff is ignored for
links. The LaTeX package `hyperref' provides `\XeTeXLinkBox' as
workaround. It puts a space in the lower left and upper right
corner of the link box.

> The following, a verbatim copy from the test file, demonstrates
> the problem --

Now the following demonstrates the workaround from package `hyperref',
adapted to plain TeX (and using `tiger.jpg' from ghostscript's
`tiger.eps' as image):

\catcode`\@=11

% Workaround for links with XeTeX without character contents
% ----------------------------------------------------------
% The contents of the link is put in \XeTeXLinkBox.
% XeTeX ignores non-character stuff for links.
% As workaround \XeTeXLinkBox puts a space in the lower left
% and upper right corner of the link box.
% The margins of the link can be configured by \XeTeXLinkMargin

\newdimen\XeTeXLinkMargin
\XeTeXLinkMargin = 2pt

\font\XeTeXLink at font = pzdr at 1sp
\chardef\@xxxii=32 % from LaTeX
\def\XeTeXLink at space{%
  \begingroup
    \XeTeXLink at font
    \@xxxii
  \endgroup
}%
\long\def\XeTeXLinkBox#1{%
  \begingroup
    \leavevmode
    \setbox\z@ = \hbox{\begingroup #1\endgroup}% group in case of color
    \begingroup
      \dimen@=\dp\z@
      \advance\dimen@\XeTeXLinkMargin
      \setbox\tw@=\llap{%
        \hbox to \XeTeXLinkMargin{%
          \lower\dimen@\hbox{\XeTeXLink at space}%
          \hss
        }%
      }%
      \dp\tw@=\dp\z@
      \ht\tw@=\ht\z@
      \copy\tw@
    \endgroup
    \copy\z@
    \dimen@=\ht\z@
    \advance\dimen@\XeTeXLinkMargin
    \setbox\tw@=\rlap{%
      \hbox to \XeTeXLinkMargin{%
        \hss
        \raise\dimen@\hbox{\XeTeXLink at space}%
      }%
    }%
    \dp\tw@=\dp\z@
    \ht\tw@=\ht\z@
    \copy\tw@
  \endgroup
}%

\catcode`\@=12

\catcode `\< = \catcode `\@
        \input eplain
\catcode `\< = \active

\enablehyperlinks

\uselanguage {UKenglish}

\hlstart {url}{}{http://example.org/fullsize}
\XeTeXLinkBox{%
  \XeTeXpicfile tiger.jpg height 0,25\vsize
}%
\hlend

\vskip \baselineskip

\hbox
\bgroup
\hlstart {url}{}{http://example.org/fullsize}
\XeTeXLinkBox{%
  \XeTeXpicfile tiger.jpg height 0,25\vsize
}
\hlend
\egroup

\vskip \baselineskip

\href{http://example.org/fullsize}{%
  \XeTeXLinkBox{\XeTeXpicfile tiger.jpg height 0,25\vsize}%
}

\end

Yours sincerely
  Heiko Oberdiek


More information about the texhax mailing list