Tell me more ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to abstract code to make an image by making a macro. Could someone please explain why this does not work?

\newcommand[1]{\custpic}{\begin{figure}[H]\begin{center}\includegraphics[width=0.5\textwidth]{#1}\end{center}\caption{}\end{figure}} % url

\custpic{4b.png}

What is confusing me is that this does work as expected.

\newcommand[1]{\custpic}{\begin{figure}[H]\begin{center}\includegraphics[width=0.5\textwidth]{4b.png}\end{center}\caption{}\end{figure}}

\custpic

Thank you very much

share|improve this question
2  
Try with \newcommand{\custpic}[1]{...} instead of \newcommand[1]{\custpic}{...}... – Paul Gaborit Mar 6 at 0:26
Yes, in the definition, the optional argument, which indicates the number of arguments of your new command, comes after the name of your command. – Jubobs Mar 6 at 0:29
It does indeed fix it. Thank you very much PaulGaborit and Jubobs. – superbriggs Mar 6 at 0:30
1  
\centering is usually better than \begin{center}... for figures: tex.stackexchange.com/questions/23650/… – Ethan Bolker Mar 6 at 1:01
@PaulGaborit please either post an answer, or vote to close – cmhughes Mar 6 at 1:48

closed as too localized by Paul Gaborit, Kurt, Thorsten, Martin Schröder, lockstep Mar 6 at 6:44

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, see the FAQ.

Browse other questions tagged or ask your own question.