0

I want to include a figure example.pdf, contained in the folder figs in the same folder that my main.tex. The content of main.tex is as follows:

\documentclass{article}

\usepackage{graphicx}
\graphicspath{{./figs/}}

\begin{document}

\includegraphics{example.pdf} %%

\end{document}

However, the resulting pdf contains example.pdf from the folder c:\Program Files\MiKTeX 2.9\tex\latex\alertmessage\, and not example.pdf from the folder figs on my main-file folder. It was just a happy coincidence that I had not the package alertmessage installed and MiKTeX stopped the compilation process suggesting to install it. Otherwise, I would have had a tough time trying to find where the unknown "figure" was coming from.

A similar thing occurs with any pdf named as one of the many pdf files contained in the subfolders in ..\MiKTeX 2.9\tex\latex\.

I am using MiKTeX 2.9.7300 (64-bit) on Windows 7 (64-bit). The graphicx package is version v1.2a (2019/11/30).

Is that the intended behaviour of LaTeX and \includegraphics with \graphicspath? Or is that a bug in MiKTeX or perhaps graphicx?

2
  • 1
    try with \includegraphics{./example.pdf} Oct 21, 2022 at 12:29
  • Thanks for your answer. If you include it as an answer, I'd be glad to accept it. Oct 25, 2022 at 10:27

1 Answer 1

1

\includegraphics searches for graphics first with kpsewhich (which looks first in the current folder and then into the texmf trees) and after this tries the pathes in \graphicspath. To force it to use a local file, prepend the name with ./. This works for graphics in subfolders too. So for example this here

\documentclass{article}
\usepackage{graphicx}
\graphicspath{{chapters/}}
\begin{document}
\includegraphics{example-image}
\includegraphics{./example-image}
\includegraphics{./sub}
\includegraphics{./chapters/sub}
\end{document}

will input (assuming that the chapters folders contains the images example-image.pdf and sub.pdf, while the current folder has a sub.pdf too)

<c:/texlive/2022/texmf-dist/tex/latex/mwe/example-image.pdf> 
<./chapters//./example-image.pdf>
<sub.pdf>
<./chapters/sub.pdf>
1
  • Thanks for your detailed answer. Oct 26, 2022 at 9:09

You must log in to answer this question.

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