git.iko.soy/typeable/pandoc
on master help sign in
Give LaTeX images a maximum width using the prelude only
commite365c5950b1b6ee85123d4b376025a6bb0697f7d authorMax Bolingbroke <batterseapower@hotmail.com> dateSun 4 Apr 2010, 16:36 (17 years ago) parent15c3297
3 files changed+19−1
src/Text/Pandoc/Writers/LaTeX.hs+1−1 templates/latex.template+9 tests/writer.latex+9
src/Text/Pandoc/Writers/LaTeX.hs+1−1
@@ -338,7 +338,7 @@ inlineToLaTeX (Link txt (src, _)) =
338338 char '}'
339339inlineToLaTeX (Image _ (source, _)) = do
340340 modify $ \s -> s{ stGraphics = True }
341− return $ text $ "\\includegraphics{" ++ source ++ "}"
341+ return $ text $ "\\includegraphics{" ++ source ++ "}"
342342inlineToLaTeX (Note contents) = do
343343 st <- get
344344 put (st {stInNote = True})
templates/latex.template+9
@@ -50,6 +50,15 @@ $if(url)$
5050$endif$
5151$if(graphics)$
5252\usepackage{graphicx}
53+% We will generate all images so they have a width \maxwidth. This means
54+% that they will get their normal width if they fit onto the page, but
55+% are scaled down if they would overflow the margins.
56+\makeatletter
57+\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
58+\else\Gin@nat@width\fi}
59+\makeatother
60+\let\Oldincludegraphics\includegraphics
61+\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
5362$endif$
5463\usepackage[breaklinks=true,unicode=true]{hyperref}
5564\setlength{\parindent}{0pt}
tests/writer.latex+9
@@ -14,6 +14,15 @@
1414\newcommand{\textsubscr}[1]{\ensuremath{_{\scriptsize\textrm{#1}}}}
1515\usepackage{url}
1616\usepackage{graphicx}
17+% We will generate all images so they have a width \maxwidth. This means
18+% that they will get their normal width if they fit onto the page, but
19+% are scaled down if they would overflow the margins.
20+\makeatletter
21+\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth
22+\else\Gin@nat@width\fi}
23+\makeatother
24+\let\Oldincludegraphics\includegraphics
25+\renewcommand{\includegraphics}[1]{\Oldincludegraphics[width=\maxwidth]{#1}}
1726\usepackage[breaklinks=true,unicode=true]{hyperref}
1827\setlength{\parindent}{0pt}
1928\setlength{\parskip}{6pt plus 2pt minus 1pt}