git.iko.soy/typeable/pandoc
on master help sign in
Use \setkeys{Gin}{} to set appropriate defaults for \includegraphics, instead of entirely redefining this command.

Note we also consider the height of images; if an image is too high, 0.8\textheight will be used for beamer slides, and \textheight is used for articles (see http://tex.stackexchange.com/q/11954/9128). If the user has explicitly provided the width/height options in \includegraphics[], our defaults will be overwritten, and this approach is better than the check `\@ifnextchar[` after \includegraphics because the latter approach simply gives up everything once it sees [, whereas \setkeys{Gin} can keep the good defaults unless they are explicitly overwritten in []. closes #30, closes #28, and closes #26

commita3cce8d3594fd5da7a83c9926e39eb3ec210b83b authorYihui Xie <xie@yihui.name> dateFri 11 Apr 2014, 17:22 (13 years ago) parent2afb079
2 files changed+11−22
default.beamer+5−6 default.latex+6−16
default.beamer+5−6
@@ -69,16 +69,15 @@ $if(url)$
6969\usepackage{url}
7070$endif$
7171$if(graphics)$
72−\usepackage{letltxmacro}
72+\usepackage{graphicx}
7373\makeatletter
7474\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
7575\def\maxheight{\ifdim\Gin@nat@height>\textheight0.8\textheight\else\Gin@nat@height\fi}
7676\makeatother
77−\AtBeginDocument{
78− \LetLtxMacro\Oldincludegraphics\includegraphics
79− \renewcommand{\includegraphics}[2][]{%
80− \Oldincludegraphics[#1,width=\maxwidth,height=\maxheight,keepaspectratio]{#2}}
81−}
77+% Scale images if necessary, so that they will not overflow the page
78+% margins by default, and it is still possible to overwrite the defaults
79+% using explicit options in \includegraphics[width, height, ...]{}
80+\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
8281$endif$
8382
8483% Comment these out if you don't want a slide with just the
default.latex+6−16
@@ -65,24 +65,14 @@ $if(tables)$
6565$endif$
6666$if(graphics)$
6767\usepackage{graphicx}
68−% Redefine \includegraphics so that, unless explicit options are
69−% given, the image width will not exceed the width of the page.
70−% Images get their normal width if they fit onto the page, but
71−% are scaled down if they would overflow the margins.
7268\makeatletter
73−\def\ScaleIfNeeded{%
74− \ifdim\Gin@nat@width>\linewidth
75− \linewidth
76− \else
77− \Gin@nat@width
78− \fi
79−}
69+\def\maxwidth{\ifdim\Gin@nat@width>\linewidth\linewidth\else\Gin@nat@width\fi}
70+\def\maxheight{\ifdim\Gin@nat@height>\textheight\textheight\else\Gin@nat@height\fi}
8071\makeatother
81−\let\Oldincludegraphics\includegraphics
82−{%
83− \catcode`\@=11\relax%
84− \gdef\includegraphics{\@ifnextchar[{\Oldincludegraphics}{\Oldincludegraphics[width=\ScaleIfNeeded]}}%
85−}%
72+% Scale images if necessary, so that they will not overflow the page
73+% margins by default, and it is still possible to overwrite the defaults
74+% using explicit options in \includegraphics[width, height, ...]{}
75+\setkeys{Gin}{width=\maxwidth,height=\maxheight,keepaspectratio}
8676$endif$
8777\ifxetex
8878 \usepackage[setpagesize=false, % page size defined by xetex