@@ -42,6 +42,7 @@ import Text.Pandoc.Error (PandocError (PandocPDFProgramNotFoundError))
4242import Text.Pandoc.MIME (getMimeType)
4343import Text.Pandoc.Options (HTMLMathMethod (..), WriterOptions (..))
4444import Text.Pandoc.Process (pipeProcess)
45+import System.Process (readProcessWithExitCode)
4546import Text.Pandoc.Shared (inDirectory, stringify)
4647import qualified Text.Pandoc.UTF8 as UTF8
4748import Text.Pandoc.Walk (walkM)
@@ -89,7 +90,13 @@ makePDF program pdfargs writer opts doc =
8990 -- user names (see #777)
9091 let withTempDir templ action = do
9192 tmp <- getTemporaryDirectory
92− if '~' `elem` tmp
93+ uname <- E.catch
94+ (do (ec, sout, _) <- readProcessWithExitCode "uname" ["-o"] ""
95+ if ec == ExitSuccess
96+ then return $ Just sout
97+ else return Nothing)
98+ (\(_ :: E.SomeException) -> return Nothing)
99+ if '~' `elem` tmp || uname == Just "Cygwin" -- see #5451
93100 then withTempDirectory "." templ action
94101 else withSystemTempDirectory templ action
95102 (newCommonState, res) <- liftIO $ withTempDir "tex2pdf." $ \tmpdir' -> do