1

So in my text I have this code running

\centering
\includegraphics{right}
\end{figure}

However, when I compile the tex, I get this image: enter image description here

I don't have this image in my file directory and the folder looks like this: enter image description here

And the image that should show up is this: enter image description here

So can someone tell me if this is a latex thing (I am using texworks) or is something wrong with my computer. It only happens with this specific file and not anything else.

CampanIgnis
  • 4,624
AAAAAAA
  • 13

2 Answers2

6

The problem is that (1) several example images in the distribution like example-image or cow are in searchable paths and therefore can be loaded without a path, and (2) an image with the same name in the working directory has priority, but (3) if you don't specify the extension, LaTeX has to choose between all the available flavors of all available directories, and then the PDF images have priority.

Therefore, as showed in the other answer, you can specify the path or the extension to remove the ambiguity. But there are also two simple solutions with aside advantages:

  1. Whenever possible, use PDF outputs for plot programs. Then LaTeX will be always choose that of the working directory, but moreover, if the PDF is saved as vectorial draw (any plotting good program should do that) the quality is always better.

  2. Rename the file, preferably with a name more meaningful. After two months, reading the code even you will have no idea if "right" is an histogram or an icon with a right arrow. As more descriptive the name, less chance of conflicts with existing images and more understandable the code.

Fran
  • 80,769
1

Your engine loads the file right.pdf from the package https://ctan.org/pkg/pdfscreen. I have the same issue with my machine. We are likely not the first persons to get this unexpected behavior (edit: indeed: Embedding "left.pdf" produces front page of pdfscreen.sty manual). This is some clever package advertisement.

However, there are ways to solve the problem, just look at the following MWE:

\documentclass{article}

\usepackage{graphicx}

\begin{document}

\section{wrong images}

\includegraphics[width=5em]{right}

\section{same directory} Just specify the extension or the directory:

\includegraphics[width=5em]{right.png}

\includegraphics[width=5em]{./right}

\includegraphics[width=5em]{./right.png}

\section{image directory} Or create a new directory "images" and put all images in that directory, then do:

\includegraphics[width=5em]{images/right}

\includegraphics[width=5em]{images/right.png}

\end{document}

enter image description here

CampanIgnis
  • 4,624