git.iko.soy/typeable/pandoc
on master help sign in
PDF: Only run latex twice if \tableofcontents is present.

Note: This will pick up on \tableofcontents even if it's in a verbatim environment. But the worst that can happen is that the document takes a bit longer to build.

commit12aa83f70eb5d5fa9f472be2347b4cefa7975b62 authorJohn MacFarlane <fiddlosopher@gmail.com> dateTue 7 Feb 2012, 22:00 (15 years ago) parent328c91e
1 file changed+4−1
src/Text/Pandoc/PDF.hs+4−1
src/Text/Pandoc/PDF.hs+4−1
@@ -43,6 +43,7 @@ import System.IO (hClose)
4343import Control.Concurrent (putMVar, takeMVar, newEmptyMVar, forkIO)
4444import Text.Pandoc.UTF8 as UTF8
4545import Control.Monad (unless)
46+import Data.List (isInfixOf)
4647
4748tex2pdf :: String -- ^ tex program (pdflatex, lualatex, xelatex)
4849 -> String -- ^ latex source
@@ -55,7 +56,9 @@ tex2pdf' :: FilePath -- ^ temp directory for output
5556 -> String -- ^ tex source
5657 -> IO (Either ByteString ByteString)
5758tex2pdf' 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
5962 (exit, log', mbPdf) <- runTeXProgram program numruns tmpDir source
6063 let msg = "Error producing PDF from TeX source."
6164 case (exit, mbPdf) of