LaTeX reader: Use kpsewhich to find paths for handleIncludes.

Fall back without an error if kpsewhich is not available.
This commit is contained in:
John MacFarlane 2012-02-04 13:10:48 -08:00
parent 253a9e32aa
commit 1f90c6d7e0

View file

@ -44,6 +44,8 @@ import Data.Char (isLetter)
import Control.Applicative
import Data.Monoid
import System.FilePath (replaceExtension)
import System.Exit (ExitCode(..))
import System.Process (readProcessWithExitCode)
import qualified Data.Map as M
-- | Parse LaTeX from string and return 'Pandoc' document.
@ -536,7 +538,7 @@ handleIncludes :: String -> IO String
handleIncludes [] = return []
handleIncludes ('\\':xs) =
case runParser include defaultParserState "input" ('\\':xs) of
Right (f, rest) -> do ys <- catch (readFile f)
Right (f, rest) -> do ys <- catch (kpsewhich f >>= readFile)
(\e -> warn
("could not open included file `" ++
f ++ "': " ++ show e) >> return "")
@ -568,6 +570,14 @@ verbatimEnv = do
rest <- getInput
return (r,rest)
kpsewhich :: FilePath -> IO FilePath
kpsewhich f = do
(ec, ou, _) <- catch (readProcessWithExitCode "kpsewhich" [f] "")
(\_ -> return (ExitFailure 1, f, ""))
if ec == ExitSuccess
then return $ trim ou
else return f
-- | Parse any LaTeX environment and return a string containing
-- the whole literal environment as raw TeX.
rawLaTeXBlock :: GenParser Char ParserState String