4

I want to make the section titles in my document link to external files on my machine, so that when you click on the section title, an external document (a pdf-file) is opened. What is the nicest way to do this?

3
  • I guess one solution is: \section{\href{../somefile.pdf}{Section Title}} but is there a "better" way to do this?
    – utdiscant
    Jan 7, 2013 at 2:55
  • 1
    Better in what respect? Jan 7, 2013 at 2:57
  • In the sense that often, some solution which works is deprecated or frowned upon. Like the use of double dollars for equations, where [ ] is a better solution. A solution is also better if it does not break other functionality.
    – utdiscant
    Jan 7, 2013 at 3:14

1 Answer 1

3

You could define a \hrefsection command:

\documentclass{article}
\usepackage{xparse}
\usepackage{hyperref}

\NewDocumentCommand{\hrefsection}{smom}{%
  \IfBooleanTF{#1}
   {\section*{\href{#2}{#4}}}
   {\IfNoValueTF{#3}
     {\section{\href{#2}{#4}}}
     {\section[#3]{\href{#2}{#4}}}%
   }}

which replicates the behavior of \section:

\hrefsection*{file}{Title}
\hrefsection{file}{Title}
\hrefsection{file}[toc entry]{Title}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .