@@ -38,8 +38,9 @@ import Text.Pandoc.BCP47 (renderLang)
3838import Text.Pandoc.Builder as B
3939import Text.Pandoc.Class.PandocPure (PandocPure)
4040import Text.Pandoc.Class.PandocMonad (PandocMonad (..), getResourcePath,
41− report, setResourcePath)
42−import Text.Pandoc.Error (PandocError (PandocParsecError))
41+ readFileFromDirs, report,
42+ setResourcePath)
43+import Text.Pandoc.Error (PandocError (PandocParseError, PandocParsecError))
4344import Text.Pandoc.Highlighting (languagesByExtension)
4445import Text.Pandoc.ImageSize (numUnit, showFl)
4546import Text.Pandoc.Logging
@@ -60,8 +61,6 @@ import Text.Pandoc.Readers.LaTeX.Lang (inlineLanguageCommands,
6061 enquoteCommands,
6162 babelLangToBCP47, setDefaultLanguage)
6263import Text.Pandoc.Readers.LaTeX.SIunitx (siunitxCommands)
63−import Text.Pandoc.Readers.LaTeX.Include (insertIncluded,
64− readFileFromTexinputs)
6564import Text.Pandoc.Readers.LaTeX.Inline (acronymCommands, refCommands,
6665 nameCommands, charCommands,
6766 accentCommands,
@@ -236,10 +235,19 @@ mkImage options (T.unpack -> src) = do
236235 _ -> return src
237236 return $ imageWith attr (T.pack src') "" alt
238237
238+doxspace :: PandocMonad m => LP m Inlines
239+doxspace =
240+ (space <$ lookAhead (satisfyTok startsWithLetter)) <|> return mempty
241+ where startsWithLetter (Tok _ Word t) =
242+ case T.uncons t of
243+ Just (c, _) | isLetter c -> True
244+ _ -> False
245+ startsWithLetter _ = False
246+
239247
240248removeDoubleQuotes :: Text -> Text
241249removeDoubleQuotes t =
242− fromMaybe t $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
250+ Data.Maybe.fromMaybe t $ T.stripPrefix "\"" t >>= T.stripSuffix "\""
243251
244252doubleQuote :: PandocMonad m => LP m Inlines
245253doubleQuote =
@@ -398,8 +406,8 @@ inlineCommands = M.unions
398406 link (unescapeURL $ untokenize url) "" <$> tok)
399407 , ("includegraphics", do options <- option [] keyvals
400408 src <- braced
401− mkImage options . unescapeURL .
402− removeDoubleQuotes $ untokenize src)
409+ mkImage options . unescapeURL . removeDoubleQuotes $
410+ untokenize src)
403411 , ("hyperlink", hyperlink)
404412 , ("hypertarget", hypertargetInline)
405413 -- hyphenat
@@ -409,6 +417,8 @@ inlineCommands = M.unions
409417 -- LaTeX colors
410418 , ("textcolor", coloredInline "color")
411419 , ("colorbox", coloredInline "background-color")
420+ -- xspace
421+ , ("xspace", doxspace)
412422 -- etoolbox
413423 , ("ifstrequal", ifstrequal)
414424 , ("newtoggle", braced >>= newToggle)
@@ -688,6 +698,39 @@ include name = do
688698 mapM_ (insertIncluded defaultExt) fs
689699 return mempty
690700
701+readFileFromTexinputs :: PandocMonad m => FilePath -> LP m (Maybe Text)
702+readFileFromTexinputs fp = do
703+ fileContentsMap <- sFileContents <$> getState
704+ case M.lookup (T.pack fp) fileContentsMap of
705+ Just t -> return (Just t)
706+ Nothing -> do
707+ dirs <- map T.unpack . splitTextBy (==':') . fromMaybe "."
708+ <$> lookupEnv "TEXINPUTS"
709+ readFileFromDirs dirs fp
710+
711+insertIncluded :: PandocMonad m
712+ => FilePath
713+ -> FilePath
714+ -> LP m ()
715+insertIncluded defaultExtension f' = do
716+ let f = case takeExtension f' of
717+ ".tex" -> f'
718+ ".sty" -> f'
719+ _ -> addExtension f' defaultExtension
720+ pos <- getPosition
721+ containers <- getIncludeFiles <$> getState
722+ when (T.pack f `elem` containers) $
723+ throwError $ PandocParseError $ T.pack $ "Include file loop at " ++ show pos
724+ updateState $ addIncludeFile $ T.pack f
725+ mbcontents <- readFileFromTexinputs f
726+ contents <- case mbcontents of
727+ Just s -> return s
728+ Nothing -> do
729+ report $ CouldNotLoadIncludeFile (T.pack f) pos
730+ return ""
731+ getInput >>= setInput . (tokenize f contents ++)
732+ updateState dropLatestIncludeFile
733+
691734authors :: PandocMonad m => LP m ()
692735authors = try $ do
693736 bgroup