Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Fix includegraphics #28

Closed
wants to merge 4 commits into from

1 participant

@bwl21

Retain options for \includegraphics (solution by Dr. Reinhard Jahraus)

Problem: "beamer" changes within \begin{document} the behavior of many standard commands, amongst others also \includegraphics. This removed the option to scale the included image. In addition to this, "beamer" ignores everything in \begin{document} which is not \begin{frame}. This os not that easy to find. However the solution looks more easy than one can expect based on the problem analysis. The solution is to wrap the redefinition into \AtBeginDocument. This should work in the other latex classes as well.

For sake of consistency, I ported the solution also to default.latex. As Reinhard pointed out, it really works.

Thanks a lot to Reinhard Jahraus. He is a real TeX expert. In the past 2 decades, I never experienced a TeX issue which Reinhard could not solve.

bwl21 added some commits
@bwl21 bwl21 always include long table
always include graphics

improved redefinition of include graphics such that it still can be used with options. This is to allow specific includegraphics embedded in markdown.
e29853d
@bwl21 bwl21 Merge branch 'master' into HEAD e6232e5
@bwl21 bwl21 Retain options for \includegraphics (solution by Dr. Reinhard Jahraus)
Problem: "beamer" changes within  \begin{document}   the behavior of many standard commands, amongst others also \includegraphics. This removed the option to scale the included image. In addition to this, "beamer" ignores everything in \begin{document} which is not \begin{frame}. This os not that easy to find. However the solution looks more easy than one can expect based on the problem analysis. The solution is to wrap the redefinition into \AtBeginDocument. This should work in the other latex classes as well.

Die Klasse "beamer"  \begin{document} verbiegt innerhalb von \begin{document} viele Standardbefehle. U.a. auch \includegraphics. Dadurch ging die Skalierungsoption verloren. Zusätzliche Probleme bei der Analyse entstanden dadurch, dass in der beamer-Klasse nach \begin{document} alles was nicht \begin{frame} heißt, ignoriert wird. Darauf muss man erstmal kommen. Nun, die Lösung sieht einfacher aus, als aufgrund der Komplexität zu erwarten wäre. Ich habe es nicht getestet, aber ich erwarte, dass diese Zeilen so auch in anderen Klassen funktionieren.
daf9871
@bwl21 bwl21 Retain options for \includegraphics (solution by Dr. Reinhard Jahraus)
Problem: "beamer" changes within  \begin{document}   the behavior of many standard commands, amongst others also \includegraphics. This removed the option to scale the included image. In addition to this, "beamer" ignores everything in \begin{document} which is not \begin{frame}. This os not that easy to find. However the solution looks more easy than one can expect based on the problem analysis. The solution is to wrap the redefinition into \AtBeginDocument. This should work in the other latex classes as well.

For sake of consistency, I ported the solution also to default.latex. As Reinhard pointed out, it really works.
ef68115
@jgm jgm closed this pull request from a commit
@yihui yihui 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
a3cce8d
@jgm jgm closed this in a3cce8d
@jrbing jrbing referenced this pull request from a commit in jrbing/pandoc-templates
@yihui yihui 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
05ce16e
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 4, 2013
  1. @bwl21

    always include long table

    bwl21 authored
    always include graphics
    
    improved redefinition of include graphics such that it still can be used with options. This is to allow specific includegraphics embedded in markdown.
Commits on May 8, 2013
  1. @bwl21

    Merge branch 'master' into HEAD

    bwl21 authored
Commits on May 10, 2013
  1. @bwl21

    Retain options for \includegraphics (solution by Dr. Reinhard Jahraus)

    bwl21 authored
    Problem: "beamer" changes within  \begin{document}   the behavior of many standard commands, amongst others also \includegraphics. This removed the option to scale the included image. In addition to this, "beamer" ignores everything in \begin{document} which is not \begin{frame}. This os not that easy to find. However the solution looks more easy than one can expect based on the problem analysis. The solution is to wrap the redefinition into \AtBeginDocument. This should work in the other latex classes as well.
    
    Die Klasse "beamer"  \begin{document} verbiegt innerhalb von \begin{document} viele Standardbefehle. U.a. auch \includegraphics. Dadurch ging die Skalierungsoption verloren. Zusätzliche Probleme bei der Analyse entstanden dadurch, dass in der beamer-Klasse nach \begin{document} alles was nicht \begin{frame} heißt, ignoriert wird. Darauf muss man erstmal kommen. Nun, die Lösung sieht einfacher aus, als aufgrund der Komplexität zu erwarten wäre. Ich habe es nicht getestet, aber ich erwarte, dass diese Zeilen so auch in anderen Klassen funktionieren.
  2. @bwl21

    Retain options for \includegraphics (solution by Dr. Reinhard Jahraus)

    bwl21 authored
    Problem: "beamer" changes within  \begin{document}   the behavior of many standard commands, amongst others also \includegraphics. This removed the option to scale the included image. In addition to this, "beamer" ignores everything in \begin{document} which is not \begin{frame}. This os not that easy to find. However the solution looks more easy than one can expect based on the problem analysis. The solution is to wrap the redefinition into \AtBeginDocument. This should work in the other latex classes as well.
    
    For sake of consistency, I ported the solution also to default.latex. As Reinhard pointed out, it really works.
This page is out of date. Refresh to see the latest.
Showing with 22 additions and 13 deletions.
  1. +11 −5 default.beamer
  2. +11 −8 default.latex
View
16 default.beamer
@@ -59,15 +59,21 @@ $if(graphics)$
% are scaled down if they would overflow the margins.
\makeatletter
\def\ScaleIfNeeded{%
- \ifdim\Gin@nat@width>\linewidth
- \linewidth
+ \ifdim\Gin@nat@width>\linewidth%
+ \linewidth\relax%
\else
- \Gin@nat@width
+ \Gin@nat@width\relax%
\fi
}
+\AtBeginDocument%
+ {%
+ \let\Oldincludegraphics\includegraphics%
+ \gdef\includegraphics%
+ {%
+ \@ifnextchar[{\Oldincludegraphics}{\Oldincludegraphics[width=\ScaleIfNeeded]}%
+ }%
+ }%
\makeatother
-\let\Oldincludegraphics\includegraphics
-\renewcommand{\includegraphics}[2][]{\Oldincludegraphics[width=\ScaleIfNeeded]{#2}}
$endif$
% Comment these out if you don't want a slide with just the
View
19 default.latex
@@ -71,18 +71,21 @@ $if(graphics)$
% are scaled down if they would overflow the margins.
\makeatletter
\def\ScaleIfNeeded{%
- \ifdim\Gin@nat@width>\linewidth
- \linewidth
+ \ifdim\Gin@nat@width>\linewidth%
+ \linewidth\relax%
\else
- \Gin@nat@width
+ \Gin@nat@width\relax%
\fi
}
+\AtBeginDocument%
+ {%
+ \let\Oldincludegraphics\includegraphics%
+ \gdef\includegraphics%
+ {%
+ \@ifnextchar[{\Oldincludegraphics}{\Oldincludegraphics[width=\ScaleIfNeeded]}%
+ }%
+ }%
\makeatother
-\let\Oldincludegraphics\includegraphics
-{%
- \catcode`\@=11\relax%
- \gdef\includegraphics{\@ifnextchar[{\Oldincludegraphics}{\Oldincludegraphics[width=\ScaleIfNeeded]}}%
-}%
$endif$
\ifxetex
\usepackage[setpagesize=false, % page size defined by xetex
Something went wrong with that request. Please try again.