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