# including graphics from multiple directories

I have tried two approaches to including graphics from multiple directories, one using graphicspath and another using macros.

The graphics path approach is:

\documentclass{beamer}
\usepackage{graphicx}
\graphicspath{{/path\_1/figs/}{/path\_2/figs}}
\begin{document}
\begin{frame}
\includegraphics[options]{fig.png} % where fig.png is in one of the two directories
\end{frame}
\end{document}


The error from the graphicspath approach is as follows:

[1{/home/user/.texlive2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
LaTeX Warning: File fig.png' not found on input line [x].


The macro approach consists in defining "variables" (macros/commands) holding the paths to the images and then building the full path using the variable (directory) and the filename (string literal). I have tried using def and newcommand and have also tried using expandafter to ensure that the argument to includegraphics is first expanded (1, 2).

\documentclass{beamer}
\usepackage{graphicx}
\def\mydir{/path\_1/figs/} % defining via \def
\begin{document}
\begin{frame}
% all the following fail
\includegraphics[options]{\mydir{}fig.png}% 1
\expandafter\includegraphics[options]{\mydir{}fig.png}% 2
\expandafter\includegraphics\expandafter[options]{\mydir{}fig.png}% 3
\expandafter{\includegraphics[options]}{\mydir{}fig.png}% 4
\end{frame}
\end{document}


The error from the macro approach varies; errors below are numbered according to the comments in each of the lines above.

error for #1-3:

[1{/home/user/.texlive2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
! Missing number, treated as zero.
N
l.[x]  \end{frame}


error for #4:

[1{/home/user/.texlive2016/texmf-var/fonts/map/pdftex/updmap/pdftex.map}]
! Argument of \beamer@readarg has an extra }.
<inserted text>
\par
l.[x]  \end{frame}


I would be interested in seeing how to get both approaches to work, as well as suggestions for alternative approaches. One advantage of using "variables" (macros) is that identically named files can be present in the various image directories without causing ambiguity since the desired directory is explicitly specified.

• Does the real path of your image folders also contain _? – user36296 Jul 27 '18 at 19:11
• Off-topic: you don't need \usepackage{graphicx} with beamer – user36296 Jul 27 '18 at 19:12
• @samcarter: Yes, I deliberately used an underscore because my paths contain underscores and I wasn't sure if that was contributing to the problem; I have tried escaping them and using them unescaped (the latter almost always seems to cause additional problems). Thanks for the note about the non-necessity of loading the graphicx package for beamer documents. – user001 Jul 27 '18 at 19:18
• \graphicspath{{/path_1/figs/}{/path_2/figs}} works fine for me with pdflatex from TL18 – user36296 Jul 27 '18 at 19:21
• Can you tell use which engine and tex distribution you use – user36296 Jul 27 '18 at 19:23

Don't escape _ in the graphics path
\graphicspath{{/path_1/figs/}{/path_2/figs/}}