# package graphicx and ifthen problem

\documentclass{article}
\usepackage{ifthen}
\usepackage[final,pdftex]{graphicx}
\newboolean{GraphicsDraft}
\setboolean{GraphicsDraft}{true}
\newcommand{\nograph}{%
\ifthenelse{\boolean{GraphicsDraft}}
{true}%
{false}%
}%nograph

\begin{document}
\includegraphics*[draft=\nograph]{pic} % This gives an error
%
\renewcommand\nograph{\ifGraphicsDraft true\else false\fi}
\includegraphics*[draft=\nograph]{pic} % This is OK
\end{document}


An ifthenelse is problematic whereas the \ifGraphicsDraft works

Am I doing something stupid or is this a real bug

• It appears that \nograph is \protected. \edef\test{\nograph} fails while \def\test{\nograph} can be printed. – John Kormylo Jul 18 '17 at 22:07
• It's not a bug; it's how \ifthenelse works. – egreg Jul 18 '17 at 22:13

You need an expandable test, which \ifthenelse isn't.

\documentclass{article}
\usepackage[final]{graphicx}
\usepackage{etoolbox}

\newtoggle{GraphicsDraft}
\togglefalse{GraphicsDraft}

\newcommand{\nograph}{%
\iftoggle{GraphicsDraft}{true}{false}%
}

\begin{document}

\includegraphics[draft=\nograph]{example-image-a}

\toggletrue{GraphicsDraft}

\includegraphics[draft=\nograph]{example-image-b}

\end{document}



The value of the draft key has to expand to true or false, and \ifthenelse does not work via expansion. It fails for the same reason that

\includegraphics[draft=\def\tmp{true}\tmp]


fails, even though \def\tmp{true}\tmp would typeset true.

You could, as you indicate use

\renewcommand\nograph{\ifGraphicsDraft true\else false\fi}


or simpler not have a switch at all and instead of having

\setboolean{GraphicsDraft}{true}


or

\setboolean{GraphicsDraft}{true}


Just have

\newcommand\nograph{true}


or

\newcommand\nograph{false}


Then \nograph directly expands to true or false.