# Postscript commands in TeX using \special

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]
/ANN pdfmark
}
\end{figure}
\clearpage

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

\end{document}

-

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
{\includegraphics[width=.5\textwidth]{example-image}}
\caption{My Child}
\end{figure}

\lipsum

\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}
\begin{picture}(\wd\chrisbox,\ht\chrisbox)
\end{picture}\makebox[0pt][r]{\usebox{\chrisbox}}%
}
\begin{document}

\lipsum[2]

\begin{figure}[htp]
\centering
\sbox\chrisbox{\includegraphics[width=.5\textwidth]{example-image}}
\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}

-
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
@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

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]