18

I want to add hyperlinks to external pdfs (which are saved in the local file system) and to specific pages of these pdfs to a LaTeX document on MacOS X and opening them with Skim.app (default).

My problem is: it works, if the pdf is in the same path as the latex document and I use a \href{./filename.pdf} (However, the [page=2] option does not work then.)

But if I try to use an asolute path like \href{/Users/myaccount/folder/test.pdf} or {/Volumes/Data/folder/folder/test.pdf}, a click on the link in the pdf created by LaTeX does not open the linked file.

I also tried to use "file:///Volumes/.." and "run:///volumes..", but it does not work. However, I can successfully open a link like "file:///Volumes/Data/Folder/file.pdf" in Safari!

How can I fix that?

I'm using TeXLive 2010 on OS X 10.6.5 and pdflatex for compiling.

minimal example:

\documentclass[11pt]{scrreprt}

\usepackage{hyperref}
\hypersetup{bookmarksopenlevel={2}, bookmarksopen = true, 
colorlinks= false, linkbordercolor = 0 1 0.5, urlbordercolor = 0 0 1
}

\begin{document}


that works, but it opens on page 1 and not on page 3
\href[page=3]{run://test.pdf}{relative path}

that does not work:
\href[]{/Volumes/Daten/test.pdf}{absolute path}


\end{document}

4 Answers4

7

After some hours with Skim, I have these conclusions

  1. I presume that Skim is defined to be the default PDF viewer, and Preview is the default PNG and JPG viewer.

  2. \href{file://absolute path to/calledfile.png}{link} works fine with Skim, instead of PNG you can use JPG. Examples: \href{file:///Users/altermundus/Desktop/bosch2.jpg}{jpg abs link} or \href{file:///Users/altermundus/Desktop/Einstein.png}{png abs link}

  3. But \href{file://absolute path to/calledfile.pdf}{link} does not work with Skim. Example: \href{file:///Users/altermundus/Desktop/Newton.pdf}{Newton.pdf absolute path}

  4. It's possible to use \href{run:calledfile.pdfor \href{run:calledfile.png but the file called must be in the same folder that your initial PDF. Remark: with Skim we can see that the link is: file://localhost/.../calledfile.pdf localhost/... is the absolute path for your main.pdf file.

  5. Possible: \href{run:/tmp/file.pdf you need to put the calledfile inside tmp/ The path of called file is relative to main.pdf file: <path to the main file>/tmp/calledfile.pdf.

  6. A new try for the PDF file. \href{run:myscript.sh}{myscript}. You can create a script file name myscript.sh with

    \#!/bin/bash 
    
    open -a skim /Users/altermundus/Desktop/Newto.pdf
    

    This script must be executable : $ chmod +x /Users/altermundus/Desktop/myscript.sh Then, in main.pdf you write

    \href{run:myscript.sh}{myscript}
    

    This script must be in the same folder than main.pdf or a subfolder .

    My test file is :

    % the file is compiled inside a folder named : myfolder 
    %   /Users/altermundus/myfolder 
    \documentclass{scrartcl}
    \usepackage{graphicx}
    \usepackage{hyperref}
    \begin{document}
    
    % absolute path problem with pdf file     
    \href{file:///Users/altermundus/Desktop/bosch.jpg}{bosch.jpg absolute path}\par
    % relative path  
    \href{run:Einstein.png}{Einstein in the same folder}\par %  myfolder/Einstein.png  
    \href{run:tmp/Einstein.png}{Einstein in a subfolder}\par 
      % myfolder/tmp/Einstein.png
    \href{run:texteinv.pdf}{Newton.pdf}\par % myfolder/Newton.pdf 
    \href{run:bosch.jpg}{run:bosch.jpg}\par % myfolder/bosch.jpg
    \href{run:/tmp/myscript.sh}{Newton.pdf}\par % myfolder/tmp/myscript.sh
    % but myscript calls /Users/altermundus/Desktop/Newton.pdf
    \href{file:///Users/altermundus/Desktop/myscript.sh}{Newton.pdf absolute path}\par
    
    \end{document}
    

    Final remarks: With Preview, only \href[]{run:texteinv.pdf}{Newton.pdf} works and only Adobe Reader and Adobe Acrobat Pro are able to open \href{file:///Users/altermundus/Desktop/Newton.pdf}{Newton.pdf absolute path}.

I await an answer from Christiaan Hofman (the author of Skim).

Werner
  • 603,163
Alain Matthes
  • 95,075
  • thanks for your efforts. I read a post on the skim users mailinglist - I suppose it's yours. – MostlyHarmless Mar 09 '11 at 19:25
  • @Altermundus: When trying something similar SKIM opens the script in a text editor. How can I tell it to run the script? – Dror Dec 09 '11 at 16:17
  • @Dror Your script must be executable : $ chmod +x – Alain Matthes Dec 09 '11 at 23:21
  • @Altermundus: It is. In any case, what worked for me is http://tex.stackexchange.com/a/37737/412. Thanks! – Dror Dec 10 '11 at 05:26
  • I had to change the suffix of the shell script to .command on OS X in order to make it work. .sh was assigned to a text editor which was opened instead. (Skim, OS X 10.10.1, run:script.command) – Lenar Hoyt Jan 10 '15 at 16:26
  • Eventually I switched to launching the command (mplayer) with Automator’s "Run shell script" action to avoid Terminal.app from launching. I had to do some tricks to bring the mplayer to the front when Skim was in full-screen mode: mplayer myvideo.avi &; osascript -e 'tell application "System Events" to set frontmost of the first process whose displayed name is "mplayer" to true' – Lenar Hoyt Jan 20 '15 at 15:25
4

I poked around and found the same information as you:

  • \href{run:file.pdf}{file} will open the pdf in the default application for pdfs
  • \href{run:///global/path/to/file.pdf} will attempt to open a file at the path point given by the current directory with ///global/path/to/file.pdf appended. Obviously this file doesn't exist, so you get an error.
  • \href{file:///global/path/to/file.pdf} creates a file link in the PDF with location "Macintosh HD:Volumes:global:path:to:file.pdf" Note the colons. I'm not sure if this is the correct path, though, since in POSIX style paths the Volumes comes first, then Macintosh HD. In any case, the link doesn't open anything.

    Edit: I opened the PDF in Acrobat (Pro) to verify the link's location. When I manually edited the link in Acrobat to have it open the file I wanted, the location was changed to "Macintosh HD:global:path:to:file.pdf" (no Volumes). So some agent is miswriting or misreading that location.

No solution from me, but one workaround is to make a symbolic link of the target file into your document's directory. Then you can use the \href{run:test.pdf}{local} syntax you describe above.

Matthew Leingang
  • 44,937
  • 14
  • 131
  • 195
  • @Matthew: with \href{file:///global/path/to/file.pdf} do you have try with "adobe reader" ? – Alain Matthes Mar 06 '11 at 17:47
  • @Altermundus: Tried with with Adobe Acrobat Pro, which was how I was able to examine the created link. – Matthew Leingang Mar 07 '11 at 02:45
  • @Matthew: thank you. So it seems to be a special problem of OS X and the pdf readers?! :-( Your hint on the paths is a big step into the right direction, thank you for that. Is there a way to see the "real" file path of the link without having Acrobat Pro? but adding symbolic links for my >800 pdfs is also not an option for me. – MostlyHarmless Mar 07 '11 at 06:05
  • @Altermundus: using Adobe Reader is not an option for me. :-( I need the features of Skim. – MostlyHarmless Mar 07 '11 at 07:04
  • @Martin: me too :( I need to post on the OS TEX list to get a specific answer and at the author of Skim. But I think Skim and Preview use the same engine. – Alain Matthes Mar 07 '11 at 07:43
  • @Altermundus: ok, thanks - I hope there'll be a solution soon. Which version of TeX(Live) and hyperref do you use? – MostlyHarmless Mar 07 '11 at 07:47
  • TL 2010 and I update the distribution with TeX Live Utility. Hyperref [2010/12/16 v6.81] – Alain Matthes Mar 07 '11 at 07:51
  • @Martin: could be a bug somewhere in the MacTeX distribution? Don't know. You can probably see the path of the link without Pro, but I don't know an application off the top of my head that can. – Matthew Leingang Mar 07 '11 at 14:05
  • @Altermundus, @Matthew: interestingly, in Adobe Reader (version 7!, quite old), the relative link does not (!) work, but the absolute one does work! In 'preview' it's the opposite... – MostlyHarmless Mar 07 '11 at 21:55
3

I proceed like this

\href[]{file:///Users/ego/Desktop/bosch2.jpg}{absolute path}

This works fine with Skim and not with Previewbut if the link is with a pdf file, I need to open the first pdf with adobe reader. The problem seems specific to Mac os x and the pdf viewers.

Alain Matthes
  • 95,075
2

I found a very short but very hacky solution. Just abuse the nice and working relative links:

\href{../../../../../../../../../../../../home/juve/phd/papers/my-linked-paper.pdf}{file}

I generate such links into my bib files and can now quickly jump from my references to the paper itself.

Juve
  • 303