3

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].
! Package pdftex.def Error: File `fig.png' not found.

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
%\newcommand{\mydir}{/path\_1/figs/} % also tried defining via \newcommand
\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.

user001
  • 7,964

2 Answers2

5

I had the exact same problem. Fixed it by adding a trailing slash to the second directory name.

Should be:

\graphicspath{{/path_1/figs/}{/path_2/figs/}}
2

Solution to the first part of the problem:

Don't escape _ in the graphics path