From 9cc1cf1f4098ad6a22eedeaf8e6d846ce7fbf5c3 Mon Sep 17 00:00:00 2001
From: John MacFarlane <fiddlosopher@gmail.com>
Date: Sun, 20 Jan 2013 19:21:13 -0800
Subject: [PATCH] Fixed bug with escaped % in LaTeX reader.

Also added tests.  Closes #710.
---
 src/Text/Pandoc/Readers/LaTeX.hs | 2 ++
 tests/latex-reader.latex         | 4 ++++
 tests/latex-reader.native        | 4 +++-
 3 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 5362b1b53..05a71bd2b 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -690,6 +690,8 @@ handleIncludes = handleIncludes' []
 -- parents parameter prevents infinite include loops
 handleIncludes' :: [FilePath] -> String -> IO String
 handleIncludes' _ [] = return []
+handleIncludes' parents ('\\':'%':xs) =
+  ("\\%"++) `fmap` handleIncludes' parents xs
 handleIncludes' parents ('%':xs) = handleIncludes' parents
   $ drop 1 $ dropWhile (/='\n') xs
 handleIncludes' parents ('\\':xs) =
diff --git a/tests/latex-reader.latex b/tests/latex-reader.latex
index a1a4909d5..2ebdfed99 100644
--- a/tests/latex-reader.latex
+++ b/tests/latex-reader.latex
@@ -841,4 +841,8 @@ Notes can go in quotes.\footnote{ In quote.
 This paragraph should not be part of the note, as it is not
 indented.
 
+\section{Escaped characters}
+
+\$ \% \& \# \_ \{ \}
+
 \end{document}
diff --git a/tests/latex-reader.native b/tests/latex-reader.native
index 014852249..28bbad89c 100644
--- a/tests/latex-reader.native
+++ b/tests/latex-reader.native
@@ -370,4 +370,6 @@ Pandoc (Meta {docTitle = [Str "Pandoc",Space,Str "Test",Space,Str "Suite"], docA
  [Para [Str "Notes",Space,Str "can",Space,Str "go",Space,Str "in",Space,Str "quotes.",Note [Para [Str "In",Space,Str "quote."]]]]
 ,OrderedList (1,Decimal,Period)
  [[Para [Str "And",Space,Str "in",Space,Str "list",Space,Str "items.",Note [Para [Str "In",Space,Str "list."]]]]]
-,Para [Str "This",Space,Str "paragraph",Space,Str "should",Space,Str "not",Space,Str "be",Space,Str "part",Space,Str "of",Space,Str "the",Space,Str "note,",Space,Str "as",Space,Str "it",Space,Str "is",Space,Str "not",Space,Str "indented."]]
+,Para [Str "This",Space,Str "paragraph",Space,Str "should",Space,Str "not",Space,Str "be",Space,Str "part",Space,Str "of",Space,Str "the",Space,Str "note,",Space,Str "as",Space,Str "it",Space,Str "is",Space,Str "not",Space,Str "indented."]
+,Header 1 ("",[],[]) [Str "Escaped",Space,Str "characters"]
+,Para [Str "$",Space,Str "%",Space,Str "&",Space,Str "#",Space,Str "_",Space,Str "{",Space,Str "}"]]