# How to replace a command with a dummy one?

On the question How to create a dummy generic environment replacement? I learned how to replace an generic envinronment with a dummy one. Until now I had success replacing then as replacing \currenttime from datetime package with \def\currenttime{Current Time}.

But when I tried this strategy with \includegraphics:

\documentclass[10pt,a5paper,twoside]{memoir}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[brazil]{babel}
\usepackage[showframe,pass]{geometry}

\newif\ifdebug
\debugtrue
% \debugfalse

\ifdebug
% \def\includegraphics{includegraphics}
\newcommand{\includegraphics}{includegraphics}
\else\fi

\begin{document}

\includegraphics[width=\linewidth]{pictures/ex01}

\end{document}


It does not worked:

! Missing number, treated as zero.
<to be read again>
]
l.86     \includegraphics[width=\linewidth]
{pictures/ex01}
A number should have been here; I inserted 0'.
(If you can't figure out why I needed to see a number,
look up weird error' in the index to The TeXbook.)

! Illegal unit of measure (pt inserted).
<to be read again>
]
l.86     \includegraphics[width=\linewidth]
{pictures/ex01}
Dimensions can be in units of em, ex, in, pt, pc,
cm, mm, dd, cc, nd, nc, bp, or sp; but yours is a new one!
I'll assume that you meant to say pt, for printer's points.
To recover gracefully from this error, it's best to
delete the erroneous units; e.g., type 2' to delete
two letters. (See Chapter 27 of The TeXbook.)


Can I wrap the command contents as \includegraphics[width=\linewidth]{pictures/ex01} on verbatim environment as done for environments?

\@ifundefined{longtable}
{
\newenvironment{longtable}[0]
{longtable environment \par\verbatim\tiny}
{\endverbatim\endgraf\normalfont replacement for debug mode}
}{}


# Update

Trying to do:

\newcommand{\includegraphics}[2]{\par\verbatim\tiny includegraphics #1 #2 \endverbatim\endgraf\normalfont}


Throws a new error:

File: t1cmtt.fd 2014/09/29 v2.5h Standard LaTeX font definitions
)
Runaway argument?
! Paragraph ended before \next was complete.
<to be read again>
\par
l.87

I suspect you've forgotten a }', causing me to apply this
control sequence to too much text. How can we recover?
My plan is to forget the whole thing and hope for the best.


But it is printing something on the PDF:

Related:

• Why not just pass the draft or demo option to graphicx? – Alan Munn Aug 20 '17 at 19:27
• My idea is not to load it, only treat its instructions as plain text or perhaps hide it. – user Aug 20 '17 at 19:30
• Did you try what I suggested? – Alan Munn Aug 20 '17 at 19:41
• You need to handle the arguments, e.g. with \renewcommand\includegraphics[2][]{....} – Ulrike Fischer Aug 20 '17 at 19:42
• Don't believe that you can use the same dummy for everything. In general you need to have an idea about the type of arguments a command can receive to write a good dummy command. – Ulrike Fischer Aug 20 '17 at 20:48

Something like this??

\documentclass[10pt,a5paper,twoside]{memoir}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

%\usepackage[brazil]{babel}
\usepackage[showframe,pass]{geometry}
\usepackage{graphicx}

\newif\ifdebug
\debugtrue
% \debugfalse

\ifdebug
\renewcommand{\includegraphics}[2][]{\detokenize{\includegraphics[#1]{#2}}}
\else\fi

\begin{document}
\sloppy% can be used to avoid overfull boxes

\includegraphics[width=\linewidth]{pictures/ex01}

\includegraphics[width=\linewidth]{pictures/long-directory-name/ex01}

\end{document}


• @user how about \ifdebug \newcommand{\includegraphics}[2][]{\detokenize{\includegraphics[#1]{#2}}} \else \usepackage{graphicx} \fi – Steven B. Segletes Aug 21 '17 at 0:33
• Basically, it is what I am doing, but for now I manually disable the \usepackage{graphicx} and set the \ifdebugtrue. – user Aug 21 '17 at 0:40

Looks like a job of xparse ;-)

\documentclass[10pt,a5paper,twoside]{memoir}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}

\usepackage[brazil]{babel}
\usepackage[showframe,pass]{geometry}

\usepackage{xparse}
\usepackage{graphicx}

\newif\ifdebug
\debugtrue
% \debugfalse

\ifdebug
\RenewDocumentCommand\includegraphics{s+O{}om}{includegraphics}
\else\fi

\begin{document}

\includegraphics[width=\linewidth]{pictures/ex01}

\end{document}

• Why +O{}? som suffices – egreg Aug 21 '17 at 8:26
• @egreg Original graphics syntax allows two optional arguments, and one (probably) needs to allow for \par tokens in keys (someone is bound to do that): on the O{} I was allowing for not needing a NoValue test if passing to key setting (so one only needs to check #3). – Joseph Wright Aug 21 '17 at 8:36