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:



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.

  • 2
    Unrelated to the error: \usepackage[pdftex]{graphics,graphicx} should be a plain \usepackage{graphicx}. – campa Nov 7 '19 at 7: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 tex.stackexchange.com/q/511138/35864, but I can't be sure. Update MikTeX in Admin and User mode at least twice. – moewe Nov 7 '19 at 7: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 7 '19 at 7: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 7 '19 at 7:51
  • 1
    Very good. In that case it would make sense to simply close this question here as a duplicate of tex.stackexchange.com/q/511138/35864. Do you agree? – moewe Nov 7 '19 at 7:58

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.

|improve this answer|||||
  • 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 sourceforge.net/p/texstudio/feature-requests/1068 – David Carlisle Nov 7 '19 at 8:08

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