Hyperref and QR-code turn whole page into clickable hyperlink

I followed this link to introduce a clickable QR-code in my document. Something like:

\documentclass[a4paper,10pt]{article}
\usepackage{pst-barcode}
\usepackage{hyperref}

\begin{document}

\href{https://github.com/alrdebugne}{%
\begin{pspicture}(25mm,25mm)
\psbarcode{https://github.com/alrdebugne}{}{qrcode}
\end{pspicture}}

\end{document}


The above snippet links the whole page to the url. Regardless of where my mouse hovers, if I click I'll land on the url. This is annoying. How can I confine the hyperlink to the QR-code 'box' only?

P.S.: I tried adding \leavevmode before the the \ref as suggested here but this didn't work either.

• I don't experience the described problem running your MWE. In fact the cursor changes as it crosses the boundary. Try updating your packages. – John Kormylo Sep 17 '17 at 16:37
• @JohnKormylo Did you compile with xelatex? – Ulrike Fischer Sep 17 '17 at 16:38
• That does make a difference. Now I get no visible boundary to cross. Alas, I try to avoid pspicture (and XeLaTeX). – John Kormylo Sep 17 '17 at 16:42
• I should add: compiled with xelatex version 3.14159265-2.6-0.99996 (according to \listfiles), hyperref v6.83n on macOS 10.12.6. – A. Debugne Sep 17 '17 at 16:43

With xetex (xdvipdfmx) is rather complicated to put a link around such pictures, as the link area is calculated only from glyphs. As a example

\documentclass[a4paper,10pt]{article}

\usepackage{hyperref}

\begin{document}
\href{https://github.com/alrdebugne}{x\rule{1cm}{1cm}x\rule{1cm}{1cm}}

\end{document}


pstricks code adds additional complication. Imho it is better to create the qrcode as external pictures (pdf) e.g. with the standalone package and include them with \includegraphics. This normally work fine.

Edit

Heiko reminded me of \XeTeXLinkBox. It works together with qrcode:

\documentclass[a4paper,10pt]{article}

\usepackage{qrcode,hyperref}

\begin{document}
\href{https://github.com/alrdebugne}

\end{document}


^

• Thanks for the clarification Ulrike. I'll probably revert to just that. – A. Debugne Sep 17 '17 at 17:41
• hyperref provides a workaround for XeTeX via \XeTeXLinkBox that adds an invisible space glyph to get the correct link box: \href{https://github.com/alrdebugne}{\XeTeXLinkBox{\rule{1cm}{1cm}}}. However, this does not work for \psbarcode. – Heiko Oberdiek Sep 17 '17 at 17:51
• @HeikoOberdiek, ah yes I had forgotten. I will edit the answer with a solution with qrcode (if it works ...). – Ulrike Fischer Sep 17 '17 at 17:52
• @HeikoOberdiek This just works exquisitely. Thanks to both! – A. Debugne Sep 17 '17 at 18:35

Run it with pdflatex

\documentclass[a4paper,10pt]{article}
\usepackage{pst-barcode}
\usepackage{auto-pst-pdf}
\usepackage{hyperref}
\begin{document}

\href{https://github.com/alrdebugne}{%
\begin{pspicture}(25mm,25mm)
\psbarcode{https://github.com/alrdebugne}{}{qrcode}
\end{pspicture}}

\end{document}


• Thanks for your answer, @Herbert. If only! I'm using the fontspec package, which doesn't compile under pdflatex. – A. Debugne Sep 17 '17 at 17:38
• then simply run ma example with class standalone and without hypperef and you'll get an image which can be included by \includegraphics – user2478 Sep 17 '17 at 17:56