I would like a shorthand command to include a figure.
- Description and filename are mandatory
- Short caption is optional
- Optional arguments can be passed to
\includegraphics
Here's the snippet I am trying to write:
\newcommand\figH[4][]{
\begin{figure}[H]
\begin{center}
\caption[#4]{\label{#2}#3}
\includegraphics[#1]{#2}
\end{center}
\end{figure}%
}
\figH[width=\linewidth]{filename}{description}{short-description}
\figH{filename}{description}{short-description}
\figH{filename}{description}
I am still confused with the optional arguments in commands.
Best Answer
Instead of defining many arguments you could also define a key=value interface that sets the
label
,short
-caption, orplace
for the float's placement. Withexpkv-cs
you can use the...
handler to get all the unknown key=value pairs (and the keys without values) in a single argument to forward them to\includegraphics
(resulting in a single optional key=value argument and two mandatory arguments).