From f7a64824477efa3802b8b39b7fe30ed541fd67e7 Mon Sep 17 00:00:00 2001 From: Willem van den Ende Date: Tue, 29 Jul 2025 20:15:24 +0200 Subject: [PATCH] Fix PDF diagram truncation with LaTeX auto-scaling MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Replace manual size constraints with LaTeX's built-in image scaling mechanism. - Remove artificial width/height constraints that caused diagram truncation - Add adjustbox package and auto-scaling macros to LaTeX template - Images now scale intelligently: natural size if they fit, auto-scaled if oversized - Maintains aspect ratio and prevents page rotation issues 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- app/Main.hs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/app/Main.hs b/app/Main.hs index 203546a..1511f28 100644 --- a/app/Main.hs +++ b/app/Main.hs @@ -75,7 +75,9 @@ processMermaidBlock (SourceDir sourceDir) (OutputPath outputPath) (CodeBlock (id then void $ callProcess mermaidCommand ["-i", mmdFile, "-o", outputFile] else void $ callProcess mermaidCommand ["-i", mmdFile, "-o", outputFile, "--scale", "3"] putStrLn $ successEmoji <> " Generated " <> outputFile - return $ Para [Image nullAttr [] (T.pack imagePath, "Mermaid diagram")]) + -- Let images scale naturally - LaTeX will handle oversized images with adjustbox + let imageAttrs = nullAttr -- Constrain size and maintain aspect ratio for PDF + return $ Para [Image imageAttrs [] (T.pack imagePath, "Mermaid diagram")]) processMermaidBlock _ _ block = return block -- | Check if output is HTML format based on file extension @@ -93,6 +95,7 @@ latexTemplate bodyContent = T.unlines , "\\usepackage[utf8]{inputenc}" , "\\usepackage{fontspec}" , "\\usepackage{graphicx}" + , "\\usepackage{adjustbox}" , "\\usepackage{geometry}" , "\\geometry{margin=1in}" , "\\usepackage{hyperref}" @@ -106,6 +109,12 @@ latexTemplate bodyContent = T.unlines , syntaxHighlightingCommands , "\\providecommand{\\tightlist}{%" , " \\setlength{\\itemsep}{0pt}\\setlength{\\parskip}{0pt}}" + , "% Auto-scale oversized images to fit page" + , "\\makeatletter" + , "\\def\\maxwidth{\\ifdim\\Gin@nat@width>\\linewidth\\linewidth\\else\\Gin@nat@width\\fi}" + , "\\def\\maxheight{\\ifdim\\Gin@nat@height>\\textheight\\textheight\\else\\Gin@nat@height\\fi}" + , "\\makeatother" + , "\\setkeys{Gin}{width=\\maxwidth,height=\\maxheight,keepaspectratio}" , "\\begin{document}" , bodyContent , "\\end{document}"