I find myself doing a lot of things like this below in order to compile document for both pdf and tex4ht
\ifdefined\HCode
\includegraphics[width=0.5\paperwidth]{foo.eps}
\else
\includegraphics[width=0.5\paperwidth]{foo.pdf}
\fi
So I said to myself on a bright moment, why not write a command called \includegraphicsX and implement this logic inside it? So the code will look like this:
\includegraphicsX[width=0.5\paperwidth]{foo}
The problem is that \newcommand only likes to accept arguments using {}{}, so I had to write the \newcommand like this: (MWE)
\documentclass[11pt,notitlepage]{article}%
\usepackage{graphicx}
\newcommand{\includegraphicsX}[2]
{
\ifdefined\HCode
\includegraphics[#1]{#2.eps}
\else
\includegraphics[#1]{#2.pdf}
\fi
}
\begin{document}
\includegraphicsX{width=0.1\paperwidth}{1_pic}
\end{document}
And the above works. But I would prefer to call the command using
\includegraphicsX[width=0.1\paperwidth]{1_pic}
and not as shown in the MWE which is
\includegraphicsX{width=0.1\paperwidth}{1_pic}
The reason is that, if I change my mind later (and I change my mind allot) and do not want to use the macro anymore, I would then only need to remove the one letter 'X' from the call using the editor find/replace, instead of also changing the brackets around the first argument which is harder to change automatically.
Is there a trick to define a command in Latex which accepts [] as first argument and not as {} ?
Using Tl 2015
\includegraphicsdirectly :) – Manuel Jul 22 '15 at 20:46Note that you can probably just usehumm... but this does not really work for me? I need new command in order to do theifdefined\...\else...\filogic in it. I am using your first method in your answer, and it is working well as it is. thanks again. – Nasser Jul 23 '15 at 01:27\includegraphics[]{}would do the same thing, slightly more efficiently. You may need that logic for things other than image inclusion, obviously. You just don't need it for image inclusion. – cfr Jul 23 '15 at 01:32