summaryrefslogtreecommitdiff
path: root/src/Text
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2024-01-06 11:10:05 -0800
committerJohn MacFarlane <jgm@berkeley.edu>2024-01-06 11:10:05 -0800
commit2dd98b967b8615d4d67ec9c62d7a33d16012241b (patch)
tree09c1e1ab059d074c8405f9010f424052557e2c6f /src/Text
parent9f58a552800b52def52ce2a69c5e7eb8269e4d5b (diff)
T.P.PDF: reliably detect when TOC has changed.
Sometimes the TOC changes but there are no warnings: this happens when no labels are present. In this case we must rerun LaTeX. So we now take the sha1 hash of the TOC file and rerun LaTeX if it changes between runs. Closes #9295.
Diffstat (limited to 'src/Text')
-rw-r--r--src/Text/Pandoc/PDF.hs22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/Text/Pandoc/PDF.hs b/src/Text/Pandoc/PDF.hs
index 521f8c14c..a684eebd2 100644
--- a/src/Text/Pandoc/PDF.hs
+++ b/src/Text/Pandoc/PDF.hs
@@ -411,9 +411,10 @@ runTeXProgram program args tmpDir = do
, k /= "TEXINPUTS" && k /= "TEXMFOUTPUT"]
liftIO (UTF8.readFile file) >>=
showVerboseInfo (Just tmpDir) program programArgs env''
- go file env'' programArgs (1 :: Int)
+ go file env'' programArgs (1 :: Int) Nothing
where
- go file env'' programArgs runNumber = do
+ go file env'' programArgs runNumber oldTocHash = do
+ let maxruns = 4 -- stop if warnings present after 4 runs
report $ MakePDFInfo ("LaTeX run number " <> tshow runNumber) mempty
(exit, out) <- liftIO $ E.catch
(pipeProcess (Just env'') program programArgs BL.empty)
@@ -426,12 +427,23 @@ runTeXProgram program args tmpDir = do
then readFileLazy logFile
else return mempty
let rerunWarnings = checkForRerun logContents
- if not (null rerunWarnings) && runNumber < 4
+ tocHash <- do
+ let tocFile = replaceExtension file ".toc"
+ tocFileExists <- fileExists tocFile
+ if tocFileExists
+ then do
+ tocContents <- readFileLazy tocFile
+ pure $ Just $! 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 ]
+ if not (null rerunWarnings') && runNumber < maxruns
then do
report $ MakePDFInfo "Rerun needed"
(T.intercalate "\n"
- (map (UTF8.toText . BC.toStrict) rerunWarnings))
- go file env'' programArgs (runNumber + 1)
+ (map (UTF8.toText . BC.toStrict) rerunWarnings'))
+ go file env'' programArgs (runNumber + 1) tocHash
else do
let pdfFile = replaceExtension file ".pdf"
(log', pdf) <- getResultingPDF (Just logFile) pdfFile