0

I know there are a gazillion of threads addressing the error

Undefined control sequence \includegraphics

but I couldn't find the answer to my problem in any of them. So here it goes.

I am trying to use the command \includegraphics, like I have always done so for the past years, but somehow it doesn't work anymore. I am using TeXstudio 2.12.16. Below is a MWE:

\documentclass[12pt]{article}
\usepackage[pdftex]{graphics,graphicx}

\begin{document}
    \includegraphics[width=\linewidth]{photo.png}
\end{document}

When I try to compile, it returns the error

Undefined control sequence. \includegraphics[width=\linewidth]{photo}
Undefined control sequence. \includegraphics[width=\linewidth]{photo}
Undefined control sequence. \includegraphics[width=\linewidth]{photo}
Undefined control sequence. \includegraphics[width=\linewidth]{photo}
Undefined control sequence. \includegraphics[width=\linewidth]{photo}
File `photo' not found. \includegraphics[width=\linewidth]{photo}

I have made sure that the file photo is in the same directory.

This started happening after I updated TeXstudio, and it happens both in my laptop and desktop. I have reinstalled MiKTeX and TeXstudio countless times in both, but to no avail. I think TeXstudio is unable to detect the graphicx package somehow? The reason why I think it's because of TeXstudio is when I upload this project to Overleaf, there are no issues with it.

Henri Menke
  • 109,596
  • 2
    Unrelated to the error: \usepackage[pdftex]{graphics,graphicx} should be a plain \usepackage{graphicx}. – campa Nov 07 '19 at 07:04
  • 3
    Can you open the .log file and copy the complete error message. The messages posted in the question seem to be the shortened versions displayed by your editor. Usually the messages are longer and indicate more clearly which command is undefined. Without seeing the error, my money would be on https://tex.stackexchange.com/q/511138/35864, but I can't be sure. Update MikTeX in Admin and User mode at least twice. – moewe Nov 07 '19 at 07:19
  • 4
    Since texstudio is just editing text files and afterwards running latex on these, this issue have nothing to do with texstudio. As moewe states we'd like more information from the real log, not the filtered log that texstudio gives you as it often filters away important information. I agree with moewe, most likely an incomplete miktex update – daleif Nov 07 '19 at 07:24
  • @moewe You were right, you can have your money back. It was indeed the same problem, I just had to update MikTeX – Bernardo Nov 07 '19 at 07:51
  • 1
    Very good. In that case it would make sense to simply close this question here as a duplicate of https://tex.stackexchange.com/q/511138/35864. Do you agree? – moewe Nov 07 '19 at 07:58
  • Yes I totally agree. I am sorry for opening a new question, but I really couldn't find the answer that you indicated before... Thanks! – Bernardo Nov 09 '19 at 08:13

1 Answers1

0

Thank you @moewe for pointing me to the thread with the answer: tex.stackexchange.com/q/511138/35864

Just had to update MikTeX and it's working fine. If someone wants more info on the problem, please check the link above.

  • 2
    Note that you were confused becaue texstudio totally scrambled the error message. TeX would have reported which command was undefined, and texstudio mangles that and makes it look as if \includegraphics was defined. There is a long standing bug report open, you could comment there and ask for any updates https://sourceforge.net/p/texstudio/feature-requests/1068/ – David Carlisle Nov 07 '19 at 08:08