Fix PDF diagram truncation with LaTeX auto-scaling

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 <noreply@anthropic.com>
This commit is contained in:
Willem van den Ende 2025-07-29 20:15:24 +02:00
parent 7f1f1aeeb0
commit f7a6482447

View File

@ -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}"