From d90dc6b8b569805d2ffb36b6ad56da064343f13c Mon Sep 17 00:00:00 2001
From: John MacFarlane <jgm@berkeley.edu>
Date: Thu, 22 Jan 2015 23:17:25 -0800
Subject: [PATCH] LaTeX reader:  don't limit includes to .tex extension.

Previously `\input` and `\include` would only work if the
included files had the extension `.tex`.  This change relaxes
that restriction, though if the extension is not `.tex`, it
must be given explicitly in the `\input` or `\include`.

Closes #1882.
---
 src/Text/Pandoc/Readers/LaTeX.hs | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/src/Text/Pandoc/Readers/LaTeX.hs b/src/Text/Pandoc/Readers/LaTeX.hs
index 6f3090e10..942b9f3b3 100644
--- a/src/Text/Pandoc/Readers/LaTeX.hs
+++ b/src/Text/Pandoc/Readers/LaTeX.hs
@@ -898,6 +898,12 @@ backslash' = string "\\"
 braced' :: IncludeParser
 braced' = try $ char '{' *> manyTill (satisfy (/='}')) (char '}')
 
+maybeAddExtension :: String -> FilePath -> FilePath
+maybeAddExtension ext fp =
+  if null (takeExtension fp)
+     then addExtension fp ext
+     else fp
+
 include' :: IncludeParser
 include' = do
   fs' <- try $ do
@@ -909,8 +915,8 @@ include' = do
               skipMany $ try $ char '[' *> (manyTill anyChar (char ']'))
               fs <- (map trim . splitBy (==',')) <$> braced'
               return $ if name == "usepackage"
-                          then map (flip replaceExtension ".sty") fs
-                          else map (flip replaceExtension ".tex") fs
+                          then map (maybeAddExtension ".sty") fs
+                          else map (maybeAddExtension ".tex") fs
   pos <- getPosition
   containers <- getState
   let fn = case containers of