38

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?

Werner
  • 603,163

2 Answers2

48

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

enter image description here

\documentclass{article}
\usepackage{url}% http://ctan.org/pkg/url
\begin{document}
\begin{figure}[ht]
  \centering\rule{150pt}{100pt}
  \caption{This is the foobar graphic. Source: \protect\url{http://foo.bar/baz} \label{fig:foobar}}
\end{figure}
\end{document}
Werner
  • 603,163
1

Works in the IEEE paper footnote as well.

\thanks{This letter has supplementary downloadable material available at \protect\url{https://}, provided by the authors.} enter image description here

Zachary
  • 111