Skip to content

Commit

Permalink
PDF via LaTeX: always do max runs if toc is present.
Browse files Browse the repository at this point in the history
Closes #10308.

The old method (checking to see if toc hash had changed) is not
completely reliable; there are cases where an additional run is
needed anyway to get the correct "logical" page
numbers (especially when different pagination is used for
front matter). See #10308 for an example.
  • Loading branch information
jgm committed Oct 22, 2024
1 parent 79dfe1a commit 71d73f8
Showing 1 changed file with 6 additions and 14 deletions.
20 changes: 6 additions & 14 deletions src/Text/Pandoc/PDF.hs
Original file line number Diff line number Diff line change
Expand Up @@ -411,11 +411,11 @@ runTeXProgram program args tmpDir outDir = do
, k /= "TEXINPUTS" && k /= "TEXMFOUTPUT"]
liftIO (UTF8.readFile file) >>=
showVerboseInfo (Just tmpDir) program programArgs env''
go env'' programArgs (1 :: Int) Nothing
go env'' programArgs (1 :: Int)
where
file = tmpDir ++ "/input.tex"
outfile = outDir ++ "/input.pdf"
go env'' programArgs runNumber oldTocHash = do
go env'' programArgs runNumber = do
let maxruns = 4 -- stop if warnings present after 4 runs
report $ MakePDFInfo ("LaTeX run number " <> tshow runNumber) mempty
(exit, out) <- liftIO $ E.catch
Expand All @@ -429,23 +429,15 @@ runTeXProgram program args tmpDir outDir = do
then BL.fromStrict <$> readFileStrict logFile
else return mempty
let rerunWarnings = checkForRerun logContents
tocHash <- do
let tocFile = replaceExtension outfile ".toc"
tocFileExists <- fileExists tocFile
if tocFileExists
then do
tocContents <- readFileStrict tocFile
pure $ Just $! hashWith SHA1 tocContents
else pure Nothing
-- compare hash of toc to former hash to see if it changed (#9295)
let rerunWarnings' = rerunWarnings ++
["TOC changed" | tocHash /= oldTocHash ]
tocFileExists <- fileExists (replaceExtension outfile ".toc")
-- if we have a TOC we always need 3 runs, see #10308
let rerunWarnings' = rerunWarnings ++ ["TOC is present" | tocFileExists]
if not (null rerunWarnings') && runNumber < maxruns
then do
report $ MakePDFInfo "Rerun needed"
(T.intercalate "\n"
(map (UTF8.toText . BC.toStrict) rerunWarnings'))
go env'' programArgs (runNumber + 1) tocHash
go env'' programArgs (runNumber + 1)
else do
(log', pdf) <- getResultingPDF (Just logFile) outfile
return (exit, fromMaybe out log', pdf)
Expand Down

0 comments on commit 71d73f8

Please sign in to comment.