42

I write my text in Mac OS X and every thing was fine but when I want compile my code with Winedt in Windows 7 Environment I got this error:

undefined control sequence \includegraphics[width=0.30/textwidth]{Hypercube}

I change \ to / but Still got the error. And also I use package graphicx.

% GRAPHICS RELATED PACKAGES   
%  
 \ifCLASSINFOpdf   
   \usepackage[pdftex]{graphicx}     
 % declare the path(s) where your graphic files are       
   \graphicspath{{../pdf/}{../jpeg/}{./image/}}    
  % and their extensions so you won't have to specify these with    
  % every instance of \includegraphics      
 \DeclareGraphicsExtensions{.pdf,.jpeg,.png,.jpg}   
 \else   
   % or other class option (dvipsone, dvipdf, if not using dvips). graphicx     
 % will default to the driver specified in the system graphics.cfg if no   % driver is specified.    
  % \usepackage[dvips]{graphicx}   
   % declare the path(s) where your graphic files are     
 % \graphicspath{{../eps/}}    
  % and their extensions so you won't have to specify these with   
   % every instance of \includegraphics    
  % \DeclareGraphicsExtensions{.eps}   
\fi

\begin{figure}[htpb]   
    \label{Figure::Hypercube}      
  \begin{center}    
 \includegraphics[width=0.30/textwidth]{Hypercube}    
    \caption{a Hypercube with 8 nodes}      
  \end{center}     
   \end{figure}
Leo Liu
  • 77,365
Am1rr3zA
  • 645

2 Answers2

57

You can replace that whole block of code with just

\usepackage{graphicx}

and give the path with the image name

\includegraphics{pdf/image}

Or use the block this way:

\ifCLASSINFOpdf   
   \usepackage[pdftex]{graphicx}     
   % declare the path(s) where your graphic files are       
   \graphicspath{{../pdf/}{../jpeg/}{./image/}}    
   % and their extensions so you won't have to specify these with    
   % every instance of \includegraphics      
   \DeclareGraphicsExtensions{.pdf,.jpeg,.png,.jpg}   
 \else   
   % or other class option (dvipsone, dvipdf, if not using dvips). graphicx     
   % will default to the driver specified in the system graphics.cfg if no   % driver is specified.    
   \usepackage[dvips]{graphicx}   
   % declare the path(s) where your graphic files are     
   \graphicspath{{../eps/}}    
  % and their extensions so you won't have to specify these with   
  % every instance of \includegraphics    
  % \DeclareGraphicsExtensions{.eps}   
\fi
Johannes_B
  • 24,235
  • 10
  • 93
  • 248
  • 3
    it doesn't solve my problem. – Am1rr3zA Aug 14 '11 at 06:30
  • 13
    then make a complete example and do not show only fragments of the code ... –  Aug 14 '11 at 06:49
  • 1
    @Am1rr3zA: Herbert's answer allows the compiler to switch between certain settings/options used by the graphicx package. This depends on whether you compile following a latex->dvips or pdflatex sequence. Which are you using? – Werner Aug 14 '11 at 06:58
  • @Herbert I can't put all the code here, and also when I open the file with TeXWork everything is ok. I just have problem with WinWdt. – Am1rr3zA Aug 14 '11 at 06:59
  • @Werner I use pdflatex – Am1rr3zA Aug 14 '11 at 06:59
  • 2
    @Am1rr3zA: Then it is assumed that Hypercube has an extension .pdf, .jpeg, .png, .jpg and is located in the main .tex folder, or in ../pdf/, ../jpeg/, or image/. If this is the case, then undefined control sequence could refer to something else. Either way, as always, provide more context by means of an MWE. – Werner Aug 14 '11 at 07:07
  • 1
    You might want to start putting your image file and tex file in the same folder and simply comment out the code above. Just include \usepackage[pdftex]{graphicx} and try so we can understand that it is this code or the image file causing the problem. – percusse Aug 14 '11 at 09:51
  • the option pdftex is not needed and superflous –  Aug 14 '11 at 10:04
  • I solved this problem by just including the \usepackage{graphicx} package. – one Jun 08 '22 at 03:01
8

I faced the same problem. I wrote the \usepackage command after the \begin{document}, which was giving this error.

\documentclass[a4paper,12pt]{article}
\usepackage{graphicx}
\graphicspath{ {images/} }
\begin{document}

is the right way.

Werner
  • 603,163