# How to deal with relative paths in input files?

Say I have a a file File1.tex that I input in a file like Foo.tex:

folder1/File1.tex:

\begin{frame}
This is file 1.
\end{frame}


Foo.tex:

\documentclass{beamer}

\usepackage{graphicx}

\begin{document}

\input{folder1/File1.tex}

\end{document}


All works fine. But if I include a graphic in File1 the relative path does not work in Foo.tex":

Say I add a file image1.jpg to folder folder1/images/.

Now I can extend folder1/File1.tex:

\begin{frame}
This is file 1.
\includegraphics{images/image1}
\end{frame}


But now, Foo.tex could not find the graphic, because of its point of view, the path of \includegraphics should be folder1/images/image1.

How can I manage such things?

• paths are relative to the working directory of the latex process, not relative to any file Mar 24, 2021 at 15:27
• Yeah, I know.. But I am looking for an elegant way to extend the solution (to mention the folder name folder1 within the File1.tex). What is, if I change the folder name, I would have to edit all include graphics tags. Mar 24, 2021 at 15:35
• I would just use \includegraphics{image1} just as you use \documentclass{article} keep the ppaths out of the documemnt and just use teh TEXINPUTS path Mar 24, 2021 at 15:44

You could either

1. Always type the directory starting from the position of Foo.tex, since the relative path in \includegraphics from an input file cannot be used anywhere anyways.

or

2. Declare all the possible image folders at the beginning of your main file using

...
\usepackage{graphicx)
\graphicspath{ {./folder1/images/}{./folder2/images/}... }
...


and later only specify the files' names

\includegraphics{image1}

• The first approach isn't perfect, because if I would rename a folder, I have to edit each \includegraphics` tag.. But the second one is really good. Did not know this one.. Perfect solution. Thanks! Mar 24, 2021 at 15:43