5

I'm am trying to create some cross references between two documents. I'm using alltt in both docs to control the layout of some of the content. For the cross reference links, I am defining the anchor with \hyperdef. For references in the same document, I use \hyperlink to create the link. For external references, I use \hyperref.

I found that depending on whether I place the various \hyper* commands on then inside or outside of an alltt block, the links will either work or fail. Being curious I opened the generated PDF file in a text editor and I found that when the \hyper* commands are placed inside an alltt block, it's being mangled.

Outside of alltt:  /Subtype/Link/A<</F(external\040doc.pdf)/S/GoToR/D(EXTERNAL\040TARGET\0401.EXTERNAM\040TARGET\0401)>>

Inside of alltt:  /Subtype/Link/A<</F(external\\unhbox\040\\voidb@x\040\\penalty\040\\@M\040\\\040doc.pdf)/S/GoToR/D(EXTERNAL\\unhbox\040\\voidb@x\040\\penalty\040\\@M\040\\\040TARGET\\unhbox\040\\voidb@x\040\\penalty\040\\@M\040\\\0401.EXTERNAM\\unhbox\040\\voidb@x\040\\penalty\040\\@M\040\\\040TARGET\\unhbox\040\\voidb@x\040\\penalty\040\\@M\040\\\0401)>>

For links in the same manual, that's not a big deal. I just create the link and anchor in alltt blocks. I don't have a solution or workaround for external links. Any ideas on how to prevent that mangling from happening? The external links must work inside an alltt block.

Below is a sample I create to demonstrate the problem.



test1.text

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


\begin{document}
\section{Source a}

Outisde alltt

\hyperref{external doc.pdf}{EXTERNAL TARGET 1}{EXTERNAM TARGET 1}{\textbf{ To external  target }}  \newline

\hyperlink{INSIDE ALLTT}{LINK \#1}


\begin{alltt}
Inside alltt

\hyperref{external doc.pdf}{EXTERNAL TARGET 1}{EXTERNAM TARGET 1}{\textbf{ To external  target }}  \newline
\hyperlink{INSIDE ALLTT}{lINK \#2}

\end{alltt}

\lipsum

\section{Source b}

\begin{alltt}
\hypertarget{INSIDE ALLTT}{}
\end{alltt}
Fu baz

\end{document}


external doc.text

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

\begin{document}
\section{Source a}
\lipsum

\hyperdef{EXTERNAL TARGET 1}{EXTERNAM TARGET 1}{External Target \#1} \newline

\end{document}
4

Environment alltt makes the space active and its definition is not appropriate for \hypertarget or \hyperref or \hyperlink.

Workaround: The space can be masked:

\documentclass{article}
\usepackage{lipsum}
\usepackage{alltt}
\usepackage[verbose]{hyperref}

\def\SPACE/{ }


\begin{document}
\section{Source a}

Outside alltt

\hyperref{external doc.pdf}{EXTERNAL TARGET 1}{EXTERNAM TARGET 1}{\textbf{ To external  target }}  \newline

\hyperlink{INSIDE ALLTT}{LINK \#1}

\begin{alltt}
Inside alltt

\hyperref{external\SPACE/doc.pdf}{EXTERNAL\SPACE/TARGET\SPACE/1}{EXTERNAM\SPACE/TARGET\SPACE/1}{\textbf{ To external  target }}  \newline
\hyperlink{INSIDE\SPACE/ALLTT}{lINK \#2}

\end{alltt}

\lipsum

\section{Source b}

\begin{alltt}
\hypertarget{INSIDE\SPACE/ALLTT}{}
\end{alltt}
Fu baz

\end{document}

\space cannot be used, because it would need a space (active in alltt) to get it separated from the following letters. Therefore \SPACE uses / as parameter text. Then an additional space is not needed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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