git.iko.soy/typeable/pandoc
on master help sign in
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.

commitd90dc6b8b569805d2ffb36b6ad56da064343f13c authorJohn MacFarlane <jgm@berkeley.edu> dateThu 22 Jan 2015, 23:17 (12 years ago) parente88119f
1 file changed+8−2
src/Text/Pandoc/Readers/LaTeX.hs+8−2
src/Text/Pandoc/Readers/LaTeX.hs+8−2
@@ -898,6 +898,12 @@ backslash' = string "\\"
898898braced' :: IncludeParser
899899braced' = try $ char '{' *> manyTill (satisfy (/='}')) (char '}')
900900
901+maybeAddExtension :: String -> FilePath -> FilePath
902+maybeAddExtension ext fp =
903+ if null (takeExtension fp)
904+ then addExtension fp ext
905+ else fp
906+
901907include' :: IncludeParser
902908include' = do
903909 fs' <- try $ do
@@ -909,8 +915,8 @@ include' = do
909915 skipMany $ try $ char '[' *> (manyTill anyChar (char ']'))
910916 fs <- (map trim . splitBy (==',')) <$> braced'
911917 return $ if name == "usepackage"
912− then map (flip replaceExtension ".sty") fs
913− else map (flip replaceExtension ".tex") fs
918+ then map (maybeAddExtension ".sty") fs
919+ else map (maybeAddExtension ".tex") fs
914920 pos <- getPosition
915921 containers <- getState
916922 let fn = case containers of