# Avoiding “\Url Error ->\url used in a moving argument.” in a custom environment

I have a document I'm trying to render using two classes -- my university's dissertation .cls, and tufte-latex (my uni's styleguide is ugly, and I want to make a pretty-print version for my own gratification). I've written a shim for tufte-latex's \sidefig command, which reads like so:

\newenvironment{sidefig}%
{\begin{figure}}%
{\end{figure}}%


This works, except in the case where I need to use \url inside \caption, to cite an image source, ie:

\begin{sidefig}
\centering
\includegraphics[width=1.5in]{graphics/foobar}
\caption{This is the foobar graphic. Source: \url{http://foo.bar/baz} \label{fig:foobar}}
\end{sidefig}


This renders fine through tufte-latex's own sidefig environment, but errors with the following error text using my shim.

[1] <graphics/foobar.png, id=34, 233.07076pt x 310.761pt>
<use graphics/foobar.png>
! Undefined control sequence.
\Url Error ->\url used in a moving argument.

l.36 ...p://foo.bar/baz} \label{fig:foobar}}


Any idea how I can modify my shim environment to avoid this error?

-

Moving argument entries may require protection. In this case, use \protect\url{...}:
\documentclass{article}