Take the 2-minute tour ×
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 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?

share|improve this question

1 Answer 1

up vote 10 down vote accepted

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}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.