summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/graphbox/graphbox.sty
blob: 2b5d25a577f739301163842dc836927ed175fa69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
%%
%% This is file `graphbox.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% graphbox.dtx  (with options: `package')
%% 
%% Copyright (C) 2013-2014 Niklas Beisert
%% 
%% This work may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either version 1.3
%% of this license or (at your option) any later version.
%% The latest version of this license is in
%%   http://www.latex-project.org/lppl.txt
%% and version 1.3 or later is part of all distributions of LaTeX
%% version 2005/12/01 or later.
%% 
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\ProvidesPackage{graphbox}[2014/08/31 v1.0 extension for graphicx to adjust containing box]
\newif\ifGin@box@beamer\Gin@box@beamertrue
\DeclareOption{nobeamer}{\Gin@box@beamerfalse}
\ProcessOptions

\RequirePackage{graphicx}

\newsavebox{\Gin@box@box}
\newlength{\Gin@box@width}
\newlength{\Gin@box@height}
\newlength{\Gin@box@raise}
\newlength{\Gin@box@hspace}
\newlength{\Gin@box@bwidth}
\newlength{\Gin@box@bheight}

\def\Gin@box@align{b}
\def\Gin@box@hsmash{n}
\def\Gin@box@hshift{0pt}
\def\Gin@box@vshift{0pt}
\def\Gin@box@lmargin{0pt}
\def\Gin@box@rmargin{0pt}
\def\Gin@box@tmargin{0pt}
\def\Gin@box@bmargin{0pt}
\newif\ifGin@box@hide\Gin@box@hidefalse
\newif\ifGin@box@vsmash\Gin@box@vsmashfalse

\define@key{Gin}{hide}[true]{\lowercase{\Gin@boolkey{#1}}{box@hide}}
\define@key{Gin}{align}[c]{\def\Gin@box@align{#1}}
\define@key{Gin}{hsmash}[c]{\edef\Gin@box@hsmash{#1}}
\define@key{Gin}{vsmash}[c]{\if#1n\Gin@box@vsmashfalse\else%
                             \Gin@box@vsmashtrue\edef\Gin@box@align{%
                             \if#1bt\else\if#1tb\else%
                             \if#1lu\else\if#1ul\else#1\fi\fi\fi\fi\fi}}
\define@key{Gin}{smash}[cc]{\expandafter\KV@Gin@vsmash\@firstoftwo#1%
                            \expandafter\KV@Gin@hsmash\@secondoftwo#1}
\define@key{Gin}{hshift}{\def\Gin@box@hshift{#1}}
\define@key{Gin}{vshift}{\def\Gin@box@vshift{#1}}
\define@key{Gin}{lmargin}{\def\Gin@box@lmargin{#1}}
\define@key{Gin}{rmargin}{\def\Gin@box@rmargin{#1}}
\define@key{Gin}{tmargin}{\def\Gin@box@tmargin{#1}}
\define@key{Gin}{bmargin}{\def\Gin@box@bmargin{#1}}
\define@key{Gin}{hmargin}{\def\Gin@box@lmargin{#1}\def\Gin@box@rmargin{#1}}
\define@key{Gin}{vmargin}{\def\Gin@box@tmargin{#1}\def\Gin@box@bmargin{#1}}
\define@key{Gin}{margin}{\def\Gin@box@lmargin{#1}\def\Gin@box@rmargin{#1}%
                         \def\Gin@box@tmargin{#1}\def\Gin@box@bmargin{#1}}

\let\old@box@Ginclude@graphics\Ginclude@graphics
\def\Ginclude@graphics#1{%
 \sbox{\Gin@box@box}{\old@box@Ginclude@graphics{#1}}%
 \settowidth{\Gin@box@width}{\usebox{\Gin@box@box}}%
 \settoheight{\Gin@box@height}{\usebox{\Gin@box@box}}%
 \def\gwidth{\Gin@box@width}%
 \def\gheight{\Gin@box@height}%
 \ifGin@box@vsmash%
  \def\Gin@box@tmargin{0pt}\def\Gin@box@bmargin{0pt}\fi%
 \setlength{\Gin@box@raise}{\Gin@box@vshift}%
 \setlength{\Gin@box@bheight}{\Gin@box@height}%
 \addtolength{\Gin@box@bheight}{\Gin@box@tmargin}%
 \addtolength{\Gin@box@bheight}{\Gin@box@bmargin}%
 \if\Gin@box@align t%
  \addtolength{\Gin@box@raise}{-\Gin@box@height}%
  \addtolength{\Gin@box@raise}{1.161290323ex}\fi%
 \if\Gin@box@align u%
  \addtolength{\Gin@box@raise}{-\Gin@box@height}\fi%
 \if\Gin@box@align c%
  \addtolength{\Gin@box@raise}{-0.5\Gin@box@height}%
  \addtolength{\Gin@box@raise}{0.580645161ex}\fi%
 \if\Gin@box@align m%
  \addtolength{\Gin@box@raise}{-0.5\Gin@box@height}\fi%
 \setlength{\Gin@box@hspace}{0pt}%
 \if\Gin@box@hsmash n%
  \setlength{\Gin@box@bwidth}{\Gin@box@width}%
  \addtolength{\Gin@box@bwidth}{\Gin@box@lmargin}%
  \addtolength{\Gin@box@bwidth}{\Gin@box@rmargin}%
  \setlength{\Gin@box@hspace}{\Gin@box@lmargin}%
 \else%
  \setlength{\Gin@box@bwidth}{0pt}%
  \setlength{\Gin@box@hspace}{\Gin@box@hshift}%
  \if\Gin@box@hsmash l%
   \addtolength{\Gin@box@hspace}{-\Gin@box@width}\fi%
  \if\Gin@box@hsmash c%
   \addtolength{\Gin@box@hspace}{-0.5\Gin@box@width}\fi%
 \fi%
 \ifGin@box@vsmash\expandafter\smash\fi{%
  \raisebox{\Gin@box@raise}{%
   \parbox[b]{\Gin@box@bwidth}{%
    \rule[-\Gin@box@bmargin]{0pt}{\Gin@box@bheight}%
    \smash{%
     \makebox[0pt][l]{%
      \hspace*{\Gin@box@hspace}%
      \ifGin@box@hide\else\usebox{\Gin@box@box}\fi%
     }%
    }%
   }%
  }%
 }%
}

\@ifclassloaded{beamer}{\ifGin@box@beamer
 \let\old@box@includegraphics\includegraphics
 \newcommand<>{\fibox@includegraphics}[2][]{\Gin@box@hidefalse%
  \beamer@ifempty{#3}%
   {\alt<\c@beamerpauses->{}{\Gin@box@hidetrue}}%
   {\alt#3{}{\Gin@box@hidetrue}}%
  \old@box@includegraphics[#1]{#2}}
 \AtBeginDocument{\let\includegraphics=\fibox@includegraphics}
\fi}{}
\endinput
%%
%% End of file `graphbox.sty'.