1

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.

  • Does the real path of your image folders also contain _? – user36296 Jul 27 '18 at 19:11
  • 1
    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
  • 1
    \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
2

Solution to the first part of the problem:

Don't escape _ in the graphics path

1

Funny, 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/}}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.