4

I try to link to my local html-files with \href from hyperref package.

\documentclass{article}
\usepackage{hyperref}
\begin{document}
\href{run:relative_path/filename.html#anchor}{test}
\end{document}

It also works quite well only for the file itself. The anchor is cut off from the link in several pdf viewers such as Evince and Okular.

Interestingly, substituting run: by http://

\href{http://relative_path/filename.html#anchor}{hhh}

offers the anchor in Evince's and Okular's views.

Is there any way to get the run: to also provide the anchor?

  • 1
    \# works for me, but you might try spelling ancor or anchor consistently. – John Kormylo Feb 25 '15 at 15:46
  • @John Yeah Typos, you'r right. For me it doesn't work \#. don't know why. – Roman B. Mar 2 '15 at 10:07
  • One of the references I want to use: \href{run:html/classtest_framework_1_1firmwareupdate_1_1_firmwareupdate_factory_1_1_firmwareupdate_factory.html#a31e1daca3d8db1b65844b8cce35daaf4}{FirmwareupdateFactory} – Roman B. Mar 2 '15 at 10:15
  • Oh, for web access I set \hyperbaseurl to the local folder. I don't know any way to do local files AND html at the same time. See tex.stackexchange.com/questions/128087/… – John Kormylo Mar 2 '15 at 15:13
  • 1
    I'm not sure about run: but certainly the related file: protocol doesn't officially support # and hyperref removes it, with run the pdfviewer has to pass a local filename to the application, and # isn't [art of a filename, so I suspect this is by design – David Carlisle Jan 23 '20 at 13:26
2

If you modify the test to

\pdfcompresslevel=0
\pdfobjcompresslevel=0
\documentclass{article}
\usepackage{hyperref}
\begin{document}
\href{run:relative_path/filename.html#anchor}{test}


\href{http:relative_path2/filename.html#anchor2}{test}
\end{document}

Then you can look at the links hyperref is adding, which are:


/Subtype/Link/A<</F(relative_path/filename.html)/S/Launch/Win<</P(anchor)/F(relative_path/filename.html)
/Subtype/Link/A<</Type/Action/S/URI/URI(http:relative_path2/filename.html#anchor2)

Note that the # fragid syntax is really part of the http: URI scheme. The file: and PDF-specific run: schemes really expect a filename to pass to the local application to open a file on the local system and # is not part of the filename and so hyperref removes it.

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.