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 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?

share|improve this question
    
I guess one solution is: \section{\href{../somefile.pdf}{Section Title}} but is there a "better" way to do this? –  utdiscant Jan 7 '13 at 2:55
1  
Better in what respect? –  Stephan Lehmke Jan 7 '13 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 '13 at 3:14
add comment

1 Answer

up vote 3 down vote accepted

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}
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.