Here is my MWE, I want to 'refactor' the code so that I do not need to write so much when I import source code into my document:
\documentclass[12pt,a4paper]{article}
\usepackage[demo]{graphicx}
\usepackage{caption}
\usepackage{wrapfig}
\usepackage{lipsum}
\begin{document}
\begin{wrapfigure}{r}{0.5\textwidth}
\begin{center}
\includegraphics[width=0.6\textwidth]{foo}
\end{center}
\caption{The foo describes the bar}
\label{img:foo}
\end{wrapfigure}
\lipsum
\end{document}
Ideally I would prefer to just do:
\begin{mygraphic}{r}{0.5\textwidth}{The foo describes the bar}{img:foo}
\includegraphics[width=0.6\textwidth]{foo}
\end{mygraphic}
I assume I need to do something like:
\makeatletter
\newenvironment{mygraphic}[4]
{%begin part
\begin{wrapfigure}{#1}{#2}
\begin{center}
}
{%end part
\end{center}
\caption{#3}
\label{#4}
\end{wrapfigure}}
\makeatother
However that doesn't work. It complains about caption and label parameters, so I moved those up into the begin part but that didn't work.
