git.iko.soy/typeable/pandoc
on master help sign in
PDF: Only run latex twice if \tableofcontents is present.
12aa83fJohn MacFarlane
src/Text/Pandoc/PDF.hs+4−1
@@ -43,6 +43,7 @@ import System.IO (hClose)
43import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
43import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
44import Text.Pandoc.UTF8 as UTF8
44import Text.Pandoc.UTF8 as UTF8
45import Control.Monad (unless)
45import Control.Monad (unless)
46+import Data.List (isInfixOf)
46
47
47tex2pdf :: String -- ^ tex program (pdflatex, lualatex, xelatex)
48tex2pdf :: String -- ^ tex program (pdflatex, lualatex, xelatex)
48 -> String -- ^ latex source
49 -> String -- ^ latex source
@@ -55,7 +56,9 @@ tex2pdf' :: FilePath -- ^ temp directory for output
55 -> String -- ^ tex source
56 -> String -- ^ tex source
56 -> IO (Either ByteString ByteString)
57 -> IO (Either ByteString ByteString)
57tex2pdf' tmpDir program source = do
58tex2pdf' tmpDir program source = do
58− let numruns = 2 -- should suffice for toc and hyperrefs
59+ let numruns = if "\\tableofcontents" `isInfixOf` source
60+ then 2
61+ else 1
59 (exit, log', mbPdf) <- runTeXProgram program numruns tmpDir source
62 (exit, log', mbPdf) <- runTeXProgram program numruns tmpDir source
60 let msg = "Error producing PDF from TeX source."
63 let msg = "Error producing PDF from TeX source."
61 case (exit, mbPdf) of
64 case (exit, mbPdf) of