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:
		
							parent
							
								
									7f1f1aeeb0
								
							
						
					
					
						commit
						f7a6482447
					
				
							
								
								
									
										11
									
								
								app/Main.hs
									
									
									
									
									
								
							
							
						
						
									
										11
									
								
								app/Main.hs
									
									
									
									
									
								
							@ -75,7 +75,9 @@ processMermaidBlock (SourceDir sourceDir) (OutputPath outputPath) (CodeBlock (id
 | 
				
			|||||||
            then void $ callProcess mermaidCommand ["-i", mmdFile, "-o", outputFile]
 | 
					            then void $ callProcess mermaidCommand ["-i", mmdFile, "-o", outputFile]
 | 
				
			||||||
            else void $ callProcess mermaidCommand ["-i", mmdFile, "-o", outputFile, "--scale", "3"]
 | 
					            else void $ callProcess mermaidCommand ["-i", mmdFile, "-o", outputFile, "--scale", "3"]
 | 
				
			||||||
          putStrLn $ successEmoji <> " Generated " <> outputFile
 | 
					          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
 | 
					processMermaidBlock _ _ block = return block
 | 
				
			||||||
 | 
					
 | 
				
			||||||
-- | Check if output is HTML format based on file extension
 | 
					-- | Check if output is HTML format based on file extension
 | 
				
			||||||
@ -93,6 +95,7 @@ latexTemplate bodyContent = T.unlines
 | 
				
			|||||||
  , "\\usepackage[utf8]{inputenc}"
 | 
					  , "\\usepackage[utf8]{inputenc}"
 | 
				
			||||||
  , "\\usepackage{fontspec}"
 | 
					  , "\\usepackage{fontspec}"
 | 
				
			||||||
  , "\\usepackage{graphicx}"
 | 
					  , "\\usepackage{graphicx}"
 | 
				
			||||||
 | 
					  , "\\usepackage{adjustbox}"
 | 
				
			||||||
  , "\\usepackage{geometry}"
 | 
					  , "\\usepackage{geometry}"
 | 
				
			||||||
  , "\\geometry{margin=1in}"
 | 
					  , "\\geometry{margin=1in}"
 | 
				
			||||||
  , "\\usepackage{hyperref}"
 | 
					  , "\\usepackage{hyperref}"
 | 
				
			||||||
@ -106,6 +109,12 @@ latexTemplate bodyContent = T.unlines
 | 
				
			|||||||
  , syntaxHighlightingCommands
 | 
					  , syntaxHighlightingCommands
 | 
				
			||||||
  , "\\providecommand{\\tightlist}{%"
 | 
					  , "\\providecommand{\\tightlist}{%"
 | 
				
			||||||
  , "  \\setlength{\\itemsep}{0pt}\\setlength{\\parskip}{0pt}}"
 | 
					  , "  \\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}"
 | 
					  , "\\begin{document}"
 | 
				
			||||||
  , bodyContent
 | 
					  , bodyContent
 | 
				
			||||||
  , "\\end{document}"
 | 
					  , "\\end{document}"
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user