3

When I try to embed a link to a local file in a LaTeX document via \href{file://./path-to-file}{filename} it's typeset as a remote link, so http:// is prepended. How can I link to a local file, with a path relative to the location of the PDF produced?

6 Answers 6

4

you should be able to put the URL in the \url tag:

\url{file://./path-to-file}

pdflatex will (I believe) do the right thing, so it appears as a link in the resulting PDF. Whether your computer will know how to open the file is another question.

3

You can try using \href{run:<file>}. For example:

\href{run:./myfile.png}{%

This is the link (Can be also a figure)

} 
  • Put the myfile.png (or whatever extension) to the same folder as the .tex file.
2

I for sure that this works:

The test plan is \href{run:test_plan.pdf}{here}.

Where the file test_plan.pdf is in the same directory as the latex file that refers to it.

1

In Windows, this format worked for me with a network drive. Note the three backslashes at the front.

\url{file:\\\zfs\\server$\\folder\\sub_folder\\title with spaces_and_underscores.pptx}
0

have you tried the \include{}command? Like \include{chapters/filename} you can include a .tex file. But don't write the .tex in the command. There is a page in the StackExchange network, which is only about TeX.

My base TeX project looks like this:

My projectname.tex

\input{header}
\begin{document}
\hyphenation{}          % Words where LaTex-hyphenation fails 
\maketitle          % Creates a page with the title
\newpage
%  \onehalfspacing              % This uses the package setspace
\tableofcontents        % This creates the table of contents
\include{chapter/acronym}   % Acronyms i use
\include{chapter/chapter_1}
% ...
\include{chapter/chapter_n}

\include{chapter/glossary}  % My glossary
\bibliography{bibliography/bibliography}  % Literature database
\end{document}

A chapter_x.tex looks like this:

\section[section short title]{section title}

And my header.tex looks like this:

%
% Document preamble
%
  \documentclass[  %
    12pt,          % default font size
    a4paper,       % papersize
    twoside,       % printout will be two sided
%    txt,           % 
    ]{article}

  \usepackage{ulem}          % all words have the underline at the same height \uline statt \underline

  \usepackage[     %
    T1             % T1 font has european sigs
    ]{fontenc}

  \usepackage[     %
    utf8           % Depends on the operating system
    ]{inputenc}    %

  \usepackage[     %
    dvips,         %
    usenames       % allows to use blue yellow etc for font colors
    ]{color}

  \usepackage{hyperref} % allows hyperlings in the table of contents

  \usepackage{amsmath} % math stuff
  \usepackage{amssymb}  % even more math stuff
  \usepackage{extpfeil}
  \usepackage[     % 
    style=long,   % 
%    toc=true,      % Boolean; if true the glossary will be shown in the table of contents
    hypertoc=true, % Hyperlinks in the glossary
    hyper=true,    % 
    number=none,   % 
    acronym=true   % 
    ]{glossary}
  \setacronymnamefmt{\gloshort}

  \usepackage{makeidx}
%  \usepackage{xymtexps}
%  \usepackage{cite} % Used for citing
  \usepackage{bibgerm}
  \usepackage[numbers,square]{natbib}
  \bibliographystyle{dinat}
  \usepackage{textcomp} % Allows to set a ° for example
  \usepackage[     % 
    german         % You may not need this *g*
    ]{babel}

  \usepackage{setspace} % allows to easily change the space between lines
  \usepackage{pstricks} % Used to create graphs
  \usepackage{pst-plot} % Used to create graphs

  \renewcommand{\acronymname}{Abkürzungsverzeichnis} % Sets the name for acronymepage (I'm from germany)
  \makeindex
  \makeacronym
  \makeglossary


  \author{Autor name}
  \title{Document title}
  \date{\copyright\ \today}

This setup works good for me.

Sorry for typos in the comments of the files. I just translated my comments from german and I'm too lazy to fix them g

2
  • @aresnick Try asking at tex.stackexchange.com
    – Auron
    Feb 19, 2011 at 23:57
  • Does this let me link to a file so that it could be opened with another program? I'm not looking to embed it--just provide a hyperlink to a file:/// url.
    – aresnick
    Feb 20, 2011 at 2:22
0

if you want to access directory on a network \href command will work please use slash not back slash even on windows systems:

don't forget to add . after the last slash if you are only directing your link to a directory not a pdf or a file.

\href{//network/path-to-your-dir/.}{ex: click here}

please look at this line of the documentation. see here

You must log in to answer this question.

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