Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

It is possible to include a graphic image and place a hyperlink reference within it, directly in TeX? I've created a M(non)WE example below to try and demonstrate what I'm thinking. (This becomes a MWE if you remove the \special statement in the first \figure).

Basically I want to include graphics and create hyperlinks between them (note the hypertarget in the second figure). I can add hyperlinks to PDF using Ghostscript, so wondered if the same could be achieved using the \special command in TeX? Currently I'm using pdfLaTeX.

\documentclass{article}

\usepackage[a3paper,landscape]{geometry}
\usepackage{graphicx}
\usepackage{hyperref}

\begin{document}

\begin{figure}[p]
   \centering
   \includegraphics[viewport=597 1069 1088 1320,clip=true]{parent.pdf}
   \caption{My Image Caption}
   \special{ps:
      [ /Rect [602 1083 1087 1320]
        /Border [0 0 2]
        /Color [1 0 0]
        /Dest link_child_page
        /Subtype /Link
        /ANN pdfmark
   }
\end{figure}
\clearpage


\begin{figure}[p]
   \centering
   \includegraphics[viewport=750 1166 935 1223,clip=true]{child.pdf}
   \caption{My Child}
\end{figure}
\hypertarget{link_child_page}{}
\clearpage

\end{document}
share|improve this question
add comment

2 Answers

There's no need of explicit \special commands, as you can put \includegraphics as argument to \hyperlink.

\documentclass{article}
\usepackage{graphicx}
\usepackage{lipsum}
\usepackage{hyperref}

\begin{document}

\lipsum[2]

\begin{figure}[htp]
\centering
\hyperlink{link}
  {\includegraphics[width=.5\textwidth]{example-image}}
\caption{My Child}
\end{figure}

\lipsum

\hypertarget{link}{Some text for the link}

\lipsum
\end{document}

Here is a proof of concept for splitting the links; here the image is split into four parts; the hyperlinks are realized as empty boxes, placed with the help of the picture environments and the image is superimposed to them.

\documentclass{article}
\usepackage{graphicx,picture}
\usepackage{lipsum}
\usepackage{hyperref}

\newsavebox{\chrisbox}
\newcommand{\linkbox}{\makebox[.5\wd\chrisbox]{\rule{0pt}{.5\ht\chrisbox}}}
\newcommand{\fourlinks}[4]{%
  \begin{picture}(\wd\chrisbox,\ht\chrisbox)
  \put(0,.5\ht\chrisbox){\hyperlink{#1}{\linkbox}}
  \put(.5\wd\chrisbox,.5\ht\chrisbox){\hyperlink{#2}{\linkbox}}
  \put(0,0){\hyperlink{#3}{\linkbox}}
  \put(.5\wd\chrisbox,0){\hyperlink{#4}{\linkbox}}
  \end{picture}\makebox[0pt][r]{\usebox{\chrisbox}}%
}
\begin{document}

\lipsum[2]

\begin{figure}[htp]
\centering
\sbox\chrisbox{\includegraphics[width=.5\textwidth]{example-image}}
\fourlinks{ul}{ur}{ll}{lr}
\caption{My Child}
\end{figure}

\lipsum

\hypertarget{ul}{Some text for the upper left link}

\lipsum[2]

\hypertarget{ur}{Some text for the upper right link}

\lipsum[2]

\hypertarget{ll}{Some text for the lower left link}

\lipsum[2]

\hypertarget{lr}{Some text for the lower right link}

\lipsum
\end{document}
share|improve this answer
    
Thanks for the reply. I don't want to whole graphic to be hyperlinked, just a portion bounded by the /Rect [602 1083 1087 1320] command. (My MWE is poor as the viewport almost matches the Rect bounding box for the hyperlink!). There are cases where the parent graphic will link to multiple children.. –  chris Feb 13 '13 at 16:43
2  
@chris: You could add the link after the graphics with something like this: \raisebox{3cm}[0pt][0pt]{\hspace{-3cm}\hyperlink{link}{\makebox[2cm]{\rule{0pt}‌​{3cm}}}} –  Ulrike Fischer Feb 13 '13 at 17:10
add comment
up vote 1 down vote accepted

Its taken a while but found a way to achieve a workable solution. Thanks to the answers above, which I played with for quite some time, but ended up resorting to editing the postscript images files directly and including with \includegraphics. I've had to move from pdflatex to divps as now including the postscript images directly.

My perl script adds pdfmark information to the input postscript files before generating a TeX file. The /includegraphics package is working fine and honors the pdfmark information. I played with /psbox a little but couldn't get it to work as wanted.

TeX:

\begin{figure}[p]
   \centering
   \includegraphics[viewport=35 272 556 579,clip=true]{image.ps}
   \caption{my caption}
\end{figure}
\clearpage

Postscript:

%%EndObject
[ /Rect [ 50 529 70 569 ]
/Dest /box1
/Border [0 0 2]
/Color [.7 0 0]
/Subtype /Link
/ANN pdfmark

[ /Rect [ 197 273 250 362 ]
/Dest /box2
/Border [0 0 2]
/Color [.7 0 0]
/Subtype /Link
/ANN pdfmark

[ /Dest /box0 /DEST pdfmark
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.