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.

I wrote a small LaTeX file which describes the contents of some directories.

Now I try to provide a direct link to the described files and directories. I successfully use \href{filename.ext}{Link name} to provide a link for files. Unfortunately if I pass a directory name to \href the PDF reader (tried with Adobe Reader and Evince) doesn't recognize the link.

Examples of unrecognized links (a directory named abc exists in the same directory as the .pdf is):

\href{abc}{Open abc directory}
\href{abc/}{Open abc directory}
\href{./abc}{Open abc directory}
\href{./abc/}{Open abc directory}
\href{run:abc}{Open abc directory}
\href{run:abc/}{Open abc directory}
\href{run:./abc}{Open abc directory}
\href{run:./abc/}{Open abc directory}

Does anyone know if there is any chance to do this?

share|improve this question
    
Provide an example of your folder reference. For example, using backslashes \ is a problem, but using forward slashes / would work, even across OS's. –  Werner Nov 29 '11 at 20:10
    
So do you want to open the folder abc and that's it? Not a file contained within abc? –  Werner Nov 29 '11 at 20:27
    
@Werner: Exactly, just the folder. –  SecStone Nov 29 '11 at 20:33
add comment

2 Answers 2

up vote 4 down vote accepted

The root of the problem is that hyperref tries to be smart. If no file extension is found, hyperref adds .pdf, so the link becomes either abc.pdf or abc/.pdf depending on whether there is trailing / in the call.

You can define your own command, say, \HREF, which simply constructs the link and does not do anything else.

This works for me:

\documentclass{article}
\usepackage{hyperref}
\makeatletter
\newcommand\HREF[2]{\hyper@linkurl{#2}{#1}}
\makeatother

\begin{document}
\HREF{tmp}{open directory \texttt{tmp}}
\end{document}

Note that this works in xpdf. Acrobat disables such links by security reasons. evince works with absolute paths (file:///home/boris/scratch) but balks at relative ones: somehow ../tmp/ works, but ./tmp does not. I guess this is some bug in evince.

share|improve this answer
add comment

As Boris said in his answer, .pdf is appended if no extension is found.

To avoid this, use \href{abc/.}{Open directory}. The . (current directory) looks like a file extension.

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.