From 1e2b20f8bc97965bbe98b318185b2b58a1d46845 Mon Sep 17 00:00:00 2001
From: John MacFarlane <fiddlosopher@gmail.com>
Date: Sun, 16 Sep 2012 11:20:53 -0700
Subject: [PATCH] LaTeX writer: Properly escape strings inside \url{}.

Closes #576.
---
 src/Text/Pandoc/Writers/LaTeX.hs | 3 ++-
 tests/writer.latex               | 2 +-
 2 files changed, 3 insertions(+), 2 deletions(-)

diff --git a/src/Text/Pandoc/Writers/LaTeX.hs b/src/Text/Pandoc/Writers/LaTeX.hs
index 2b5c7e84b..54c112b09 100644
--- a/src/Text/Pandoc/Writers/LaTeX.hs
+++ b/src/Text/Pandoc/Writers/LaTeX.hs
@@ -577,7 +577,8 @@ inlineToLaTeX (Link txt (src, _)) =
   case txt of
         [Code _ x] | x == src ->  -- autolink
              do modify $ \s -> s{ stUrl = True }
-                return $ text $ "\\url{" ++ x ++ "}"
+                src' <- stringToLaTeX True x
+                return $ text $ "\\url{" ++ src' ++ "}"
         _ -> do contents <- inlineListToLaTeX txt
                 src' <- stringToLaTeX True src
                 return $ text ("\\href{" ++ src' ++ "}{") <>
diff --git a/tests/writer.latex b/tests/writer.latex
index bab23cd64..c3dbcb3fd 100644
--- a/tests/writer.latex
+++ b/tests/writer.latex
@@ -834,7 +834,7 @@ Here's an \href{/script?foo=1\&bar=2}{inline link in pointy braces}.
 
 \subsection{Autolinks}
 
-With an ampersand: \url{http://example.com/?foo=1&bar=2}
+With an ampersand: \url{http://example.com/?foo=1\&bar=2}
 
 \begin{itemize}
 \item