summaryrefslogtreecommitdiff
path: root/macros/latex/contrib/graphbox/graphbox.dtx
blob: bff7c339560822b37b32629c6e411853dfaa53da (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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
% \iffalse
%
% graphbox.dtx Copyright (C) 2013-2018 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.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Niklas Beisert.
%
% This work consists of the files graphbox.dtx and graphbox.ins
% and the derived files graphbox.sty, gboxsamp.tex and gboxsamp.mps
%
%<package|sample>\NeedsTeXFormat{LaTeX2e}[1996/12/01]
%<package>\ProvidesPackage{graphbox}[2018/01/17 v1.1 extension for graphicx to adjust containing box]
%<sample>\ProvidesFile{gboxsamp.tex}[2018/01/17 v1.1 sample for graphbox]
%<figure>%!PS-Adobe-3.0 EPSF-3.0
%<*driver>
%\ProvidesFile{graphbox.drv}[2018/01/17 v1.1 graphbox Reference Manual file]
\PassOptionsToClass{10pt,a4paper}{article}
\documentclass{ltxdoc}

\usepackage[margin=35mm]{geometry}
\usepackage{hyperref}
\usepackage{hyperxmp}
\usepackage[usenames]{color}

\hypersetup{colorlinks=true}
\hypersetup{pdfstartview=FitH}
\hypersetup{pdfpagemode=UseNone}
\hypersetup{pdfsource={}}
\hypersetup{pdflang={en-UK}}
\hypersetup{pdfcopyright={Copyright 2013-2018 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.}}
\hypersetup{pdflicenseurl={http://www.latex-project.org/lppl.txt}}
\hypersetup{pdfcontactaddress={ETH Zurich, ITP, HIT K, Wolfgang-Pauli-Strasse 27}}
\hypersetup{pdfcontactpostcode={8093}}
\hypersetup{pdfcontactcity={Zurich}}
\hypersetup{pdfcontactcountry={Switzerland}}
\hypersetup{pdfcontactemail={nbeisert@itp.phys.ethz.ch}}
\hypersetup{pdfcontacturl={http://people.phys.ethz.ch/\xmptilde nbeisert/}}

\begin{document}

\title{The \textsf{graphbox} Package}
\hypersetup{pdftitle={The graphbox Package}}
\author{Niklas Beisert\\[2ex]
        Institut f\"ur Theoretische Physik\\
        Eidgen\"ossische Technische Hochschule Z\"urich\\
        Wolfgang-Pauli-Strasse 27, 8093 Z\"urich, Switzerland\\[1ex]
        \href{mailto:nbeisert@itp.phys.ethz.ch}{\texttt{nbeisert@itp.phys.ethz.ch}}}
\hypersetup{pdfauthor={Niklas Beisert}}
\hypersetup{pdfsubject={Manual for the LaTeX2e Package graphbox}}
\date{17 January 2018, \textsf{v1.1}}
\maketitle

\begin{abstract}\noindent
\textsf{graphbox} is an extension for the \LaTeXe{} package
\textsf{graphicx} to facilitate the placement of graphics
relative to the current position
using additional optional arguments |[...]|
of |\includegraphics|.
For example, changing the vertical alignment is convenient
for using graphics as elements of (mathematical) formulae.
Options for shifting, smashing and hiding the graphics
are mainly intended for designing presentations using,
e.g., the \textsf{beamer} framework.
\end{abstract}

\tableofcontents

% we do not have the sample graphics yet, so we use LaTeX internals:
\newcommand{\drawbox}[1]{%
 \setlength{\unitlength}{#1}%
 \begin{picture}(1, 1)%
 \put(0,0){\line(1,1){1}}%
 \put(1,0){\line(-1,1){1}}%
 \end{picture}%
}
\newcommand{\hidebox}[1]{%
 \setlength{\unitlength}{#1}%
 \begin{picture}(1, 1)%
 \end{picture}%
}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Introduction}

Changing the placement of graphics using |\includegraphics|
of the \textsf{graphicx} package is tedious.
The command allows to scale and even rotate a figure
by the optional arguments |[...]| of |\includegraphics|, namely |scale|
(|xscale|, |yscale|) and |rotate|.
However, it lacks options to change the vertical alignment,
shift the graphics or modify the containing {\TeX} box.
In order to position the graphics according to one's needs,
one would normally use the standard boxing tools of {\LaTeX} such as
|\makebox|,
|\parbox|,
|\raisebox|
or the
|minipage| and |picture| environments.
%
While practically anything can be achieved by a combination of these tools,
it has several disadvantages:
%
\begin{itemize}
\item
use of complex commands for standard situations;
\item
several boxing commands need to be combined to achieve the desired effect;
leads to several levels of nesting around the actual |\includegraphics| command;
\item
readability of the {\LaTeX} construction is low (what is going on?);
\item
adjusting the placement is tedious;
\item
the higher-level boxing commands of {\LaTeX} require to specify the box width;
however, the actual dimensions of the graphics are typically not known
(or they change as the graphics is modified);
furthermore the same number needs to be used in several places;
\item
guessing the width of the required boxes may lead to extra space
around the graphics or warning messages about an overfull box;
\item
\ldots
\end{itemize}
%
Therefore it would be desirable to specify the placement
along with other options in the |[...]| argument
of |\includegraphics|.
This may be helpful in the following situations:
%
\begin{itemize}
\item
presentations where several figure
need to be placed across the frames
without disturbing the flow of the text;
similarly, in the composition of posters;
\item
when graphics are used as elements
of (mathematical) formulae
one might prefer a central vertical alignment
over the default baseline alignment of
|\includegraphics|.
\end{itemize}

The following discusses these situations in more detail.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Vertical Alignment}

Suppose you want to show graphics files%
\footnote{a diagonal cross will serve as the sample figure in this documentation.}
of different height next to each other
(potentially accompanied by some text).
A plain inclusion via |\includegraphics| will produce
the output:
%
\[\drawbox{1cm}\qquad\drawbox{2cm}\qquad\mbox{some text}\]
%
This is because |\includegraphics| puts the graphics into a box
whose baseline is the lower bound of the box:
%
\[\underline{\qquad\fbox{\drawbox{1cm}}\qquad\fbox{\drawbox{2cm}}\qquad\fbox{\mbox{some text}}\qquad}\]
%
Instead, a central alignment of the graphics is desirable in many situations:
%
\[
\parbox{1cm}{\drawbox{1cm}}\qquad
\parbox{2cm}{\drawbox{2cm}}
\qquad\mbox{some text}
\]
%
This can be achieved by code such as:
%
\begin{verbatim}
  \parbox{1cm}{\includegraphics[width=1cm]{...}}
  \qquad
  \parbox{2cm}{\includegraphics[width=2cm]{...}}
  \qquad
  \mbox{some text}
\end{verbatim}
%
However, if the width of the graphics is not as evident
(e.g.\ when no width is specified or the graphics is scaled),
the resulting output may easily look like:%
\footnote{Boxes were added to display the size of the bounding boxes.}
%
\[
\fbox{\parbox{0.8cm}{\makebox[0cm][l]{\drawbox{1cm}}}}
\qquad
\fbox{\parbox{3cm}{\centering\drawbox{2cm}}}
\qquad\mbox{some text}
\]
%
The present extension \textsf{graphbox} adds the option |align| to
|\includegraphics| to simplify the declaration:
\begin{verbatim}
  \includegraphics[align=c,width=1cm]{...}
  \qquad
  \includegraphics[align=c,width=2cm]{...}
  \qquad
  \mbox{some text}
\end{verbatim}
%


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Graphics Placement}

A related issue is the fine-tuning of graphics placement:
In {\LaTeX} this can be achieved by the commands
|\raisebox| (vertically) and |\hspace| (horizontally).
Furthermore, one might want to place
the graphics into some free space relative to the present position.
This is commonly needed in designing presentations or posters,
where the flow of the text and the graphics is often fine-tuned.
For example, one may ignore the vertical height of the graphics
using |\smash|. Or one might place the graphics
at the present horizontal position without allocating space by
|\makebox[0pt]|, |\llap| or |\rlap|.

Each of these elementary operations can be handled well,
but their combination can become very involved:
%
\begin{verbatim}
  \smash{\raisebox{.1cm}{\makebox[0pt][l]{\hspace{1cm}{\includegraphics{...}}}}}
\end{verbatim}
%
For example, this may be used to produce the output:
\[
\begin{tabular}[b]{cccc}
  & A & B & C \\\hline
D & 1 & 2 & 3 \\
E & 4 & 5 & 6 \\
F & 7 & 8 & 9
\end{tabular}
\fbox{\smash{\raisebox{.1cm}{\makebox[0pt][l]{\hspace{1cm}\drawbox{2cm}}}}}
\]
%
Here, the graphics was put next to a table.
The small box represents the anchor of the graphics.
It occupies no space which allows
to centre the table irrespectively of
the size of the graphics.
Unfortunately, the command is not easily readable.
The \textsf{graphbox} extension abbreviates the declaration
and make it much more accessible:
%
\begin{verbatim}
  \includegraphics[smash=tr,hshift=1cm,vshift=.1cm]{...}
\end{verbatim}
%

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Hiding Graphics}\label{sec:hide}

Sometimes one might wish to hide a graphics while reserving the space
it would occupy.%
\footnote{In the \textsf{graphicx} package a
similar effect achieved by the option |draft|.
However, here the graphics are replaced by a box containing the file name.}
For example, this feature is needed in
presentations where the frames are successively uncovered.
In this \textsf{beamer} class the uncovering of frames is
conveniently achieved by the command |\pause|.
Unfortunately, the effect of |\pause| on graphics
is that they are either displayed or taken out of the text flow.
This has the effect that the formatting
can change drastically when graphics elements are uncovered:
%
\[
\fbox{
\mbox{\textcolor[gray]{0.5}{before}}
\
\mbox{\textcolor[gray]{0.5}{after}}
}
\quad\longrightarrow\quad
\fbox{
\mbox{before}\
\drawbox{1cm}
\mbox{after}\
}
\]
%


The \textsf{graphbox} extension adds the option |hide|
to |\includegraphics| to hide the corresponding
graphics while reserving the space it would otherwise occupy:
%
\[
\fbox{\hidebox{1.5cm}}
\quad\longleftrightarrow\quad
\fbox{\drawbox{1.5cm}}
\]
%
Moreover, in conjunction with the \textsf{beamer} class,
the definition of the |\includegraphics| command
is altered such that it uses the same amount of
space in all visibility modes (specified through the
|\pause| mechanism and the |<...>| extension).
Visibility is handled by automatically setting the |hide| option:
%
\[
\fbox{
\mbox{\textcolor[gray]{0.5}{before}}\
\hidebox{1cm}\
\mbox{\textcolor[gray]{0.5}{after}}
}
\quad\longrightarrow\quad
\fbox{
\mbox{before}\
\drawbox{1cm}\
\mbox{after}
}
\]


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Usage}

To use \textsf{graphbox} simply add the command
\begin{center}|\usepackage{graphbox}|\end{center}
to the preamble of your {\LaTeX} document.
If not yet present,
the package \textsf{graphicx} will automatically be loaded.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Extensions}

The package mainly extends the functionality of
the |\includegraphics| command of the \textsf{graphicx} package
by allowing several additional optional arguments |[...]| as follows:

\begin{itemize}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|hide|[|=|\textit{bool}]

hides the graphics (unless \textit{bool}=|false|) but reserves the space
it would have occupied.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|align|[|=|\textit{valign}]

adjusts the vertical alignment of the graphics where \textit{valign} is one of the following:
\begin{itemize}
\item[|b|:]
baseline aligned to bottom of graphics;\\
default behaviour when |align| is not specified;
\item[|c|:]
centre of current line aligned to centre of graphics;%
\footnote{The centre of the line appears to be (18/31)ex above the baseline
which is at the centre of a capital letter for the default font.}\\
default behaviour when no parameter is given;
\item[|t|:]
top of current line aligned to top of graphics;%
\footnote{The top of the line is defined as (36/31)ex above the baseline
which is the height of a capital letter for the default font.}
\item[|l|:]
baseline aligned to bottom of graphics; same as |b|;
\item[|m|:]
baseline aligned to centre of graphics;
\item[|u|:]
baseline aligned to top of graphics.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|vsmash|[|=|\textit{vpos}]

reduces the height of the bounding box to zero
(equivalent to |\smash|);
places the graphics according to
\textit{vpos} which can take the following values:
\begin{itemize}
\item[|b|:]
positions top of graphics below top of current line;
\item[|c|:]
positions centre of graphics at centre of current line;\\
default behaviour when no parameter is given;
\item[|t|:]
positions bottom of graphics at baseline;
\item[|l|:]
positions top of graphics at baseline;
\item[|m|:]
positions centre of graphics at baseline;
\item[|u|:]
 positions bottom of graphics at baseline; same as |t|;
\item[|n|:]
no vertical smashing.
\end{itemize}
%
Note that the parameter \textit{vpos}
has the opposite effect
of the parameter \textit{valign} of |align|.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|hsmash|[|=|\textit{hpos}]

reduces the width of the bounding box to zero
(equivalent to |\makebox[0pt]|);
places the graphics according to
\textit{hpos} which can take the following values
\begin{itemize}
\item[|r|:]
positions graphics right of current position;
\item[|c|:]
positions centre of the graphics at current position;
default behaviour when no parameter is given;
\item[|l|:]
positions graphics left of current position;
\item[|n|:]
no horizontal smashing;
default behaviour when |hsmash| is not specified.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|smash|[|=|\textit{vpos}\,\textit{hpos}]

combination of |vsmash=|\textit{vpos} and
|hsmash=|\textit{hpos};
default behaviour is |cc|.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|vshift=|\textit{len}

shifts the graphics up by \textit{len}.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|hshift=|\textit{len}

shifts the graphics to the right by \textit{len};
has no effect unless |hsmash| is activated.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|tmargin=|\textit{len}

adds a top margin of height \textit{len};
has no effect when |vsmash| is activated.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|bmargin=|\textit{len}

adds a bottom margin of height \textit{len}
below the baseline;
has no effect when |vsmash| is activated.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|vmargin=|\textit{len}

adds a bottom and top margin of height \textit{len};
has no effect when |vsmash| is activated.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|lmargin=|\textit{len}

adds a left margin of width \textit{len};
has no effect when |hsmash| is activated.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|rmargin=|\textit{len}

adds a right margin of width \textit{len};
has no effect when |hsmash| is activated.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|hmargin=|\textit{len}

adds a left and right margin of width \textit{len};
has no effect when |hsmash| is activated.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\item
|margin=|\textit{len}

adds an overall margin of length \textit{len}
around the graphics;
has no effect when |smash| is activated.

\end{itemize}
%
In specifying lengths in the above arguments,
there are two additional dimensions |\gwidth| and |\gheight|
representing the actual width and height of the included graphics.
For example, one can add a horizontal margin of 10\%
of the size of the graphics by specifying |hmargin=0.1\gwidth|.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Package Options}

The package provides one option:
%
\begin{itemize}
\item
|nobeamer|

do not override the overlay processing
of the \textsf{beamer} class for |\includegraphics|;
as usual, graphics will occupy no space when covered.
\end{itemize}



%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\section{Information}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Copyright}

\begingroup
\parskip1ex
\parindent0pt

Copyright \copyright{} 2013--2018 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
  \url{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.

This work has the LPPL maintenance status `maintained'.

The Current Maintainer of this work is Niklas Beisert.

This work consists of the files |README.txt|, |graphbox.ins| and |graphbox.dtx|
as well as the derived files |graphbox.sty|, |gboxsamp.tex| with |gboxsamp.mps|
and |graphbox.pdf|.

\endgroup

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Files and Installation}

The package consists of the files
%
\begin{center}
\begin{tabular}{ll}
    |README.txt|   & readme file \\
    |graphbox.ins| & installation file \\
    |graphbox.dtx| & source file \\
    |graphbox.sty| & package file \\
    |gboxsamp.tex| & sample file \\
    |gboxsamp.mps| & sample figure \\
    |graphbox.pdf| & manual
\end{tabular}
\end{center}
%
The distribution consists of the files
|README.txt|, |graphbox.ins| and |graphbox.dtx|.
%
\begin{itemize}
\item
Run (pdf)\LaTeX{} on |graphbox.dtx|
to compile the manual |graphbox.pdf| (this file).
\item
Run \LaTeX{} on |graphbox.ins| to create the package |graphbox.sty|
and the sample consisting of |gboxsamp.tex| and |gboxsamp.mps|.
Copy the file |graphbox.sty| to an appropriate directory of your \LaTeX{}
distribution, e.g.\ \textit{texmf-root}|/tex/latex/graphbox|.
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Interaction with CTAN Packages}

The \textsf{graphbox} package extends the
package \href{http://ctan.org/pkg/graphicx}{\textsf{graphicx}}.
It also changes some functionality of the class
\href{http://ctan.org/pkg/beamer}{\textsf{beamer}}
if present:
%
\begin{itemize}
\item
Compatibility with the \textsf{graphicx} package
has been tested with
v1.0f (1999/02/16) and
v1.0g (2014/04/25).

\item
The changes of functionality are described
in section~\ref{sec:hide}.
Compatibility with the
\textsf{beamer} class
has been tested with v3.33 (2013/12/25).

\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\subsection{Feature Suggestions}
%
%\begin{itemize}
%\item
%Combine hshift and vshift into one definition. how? which order?
%\item
%negative bmargin
%\item
%change \includegraphics missing file error into a warning?
%\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\subsection{Revision History}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v1.1:} 2018/01/17

\begin{itemize}
\item
hooked deeper into |\includegraphics| chain
\item
manual rearranged
\item
minor internal changes
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v1.0:} 2014/08/31

\begin{itemize}
\item
added further placement options
\item
manual and installation package added
\item
first version published on CTAN
\end{itemize}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\paragraph{v0.8:} 2014/08/25

\begin{itemize}
\item
basic functionality
\end{itemize}


%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\appendix

\settowidth\MacroIndent{\rmfamily\scriptsize 000\ }
\parskip1ex
\parindent0pt

 \DocInput{graphbox.dtx}

\end{document}
%</driver>
% \fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Sample File}
%\iffalse
%<*sample>
%\fi
%
% In this section we provide a {\LaTeX} example how to use
% some of the \textsf{graphbox} extensions to \textsf{graphicx}.
% Preamble:
%
%    \begin{macrocode}
\documentclass[12pt]{article}

\usepackage[margin=2cm]{geometry}
\usepackage{graphicx}
\usepackage{graphbox}
%    \end{macrocode}

% The macro |\sample{|\textit{options}|}| prints a block demonstrating the flow of text
% testing the new |\includegraphics| arguments \textit{options}:
%
% \fbox{\parbox{0.6\textwidth}
% {\textbf{options:} \textit{options}\par\vspace{1ex}
% \parbox{0.6\textwidth}
% {
% XXXXXX\phantom{\fbox{}}XXXXXX\\
% XXXXXX\phantom{\fbox{}}XXXXXX\\
% XXXXXX\fbox{\drawbox{1cm}}XXXXXX\\
% XXXXXX\phantom{\fbox{}}XXXXXX\\
% XXXXXX\phantom{\fbox{}}XXXXXX
% }}}\par
%
% The box indicates the resulting bounding box of the
% |\includegraphics| command.
% It is defined as follows:
%    \begin{macrocode}
\newcommand{\sample}[1]{
\textbf{options:} \texttt{#1}\par\vspace{1ex}
\parbox{0.6\textwidth}{%
XXXXXX\phantom{\fbox{}}XXXXXX\\%
XXXXXX\phantom{\fbox{}}XXXXXX\\%
XXXXXX\fbox{\includegraphics[#1]{gboxsamp.mps}}XXXXXX\\%
XXXXXX\phantom{\fbox{}}XXXXXX\\%
XXXXXX\phantom{\fbox{}}XXXXXX%
}\vspace{1cm}\par}
%    \end{macrocode}

% In the document body we test the various new options for |\includegraphics|:
%    \begin{macrocode}
\begin{document}
\sample{}
\sample{hide}
\sample{hide=true}
\sample{hide=false}
\newpage
\sample{align=b}
\sample{align=c}
\sample{align=t}
\newpage
\sample{align=l}
\sample{align=m}
\sample{align=u}
\newpage
\sample{vshift=10pt}
\sample{vshift=-10pt}
\newpage
\sample{lmargin=10pt}
\sample{rmargin=10pt}
\sample{tmargin=10pt}
\sample{bmargin=10pt}
\newpage
\sample{lmargin=-10pt}
\sample{rmargin=-10pt}
\sample{tmargin=-10pt}
\sample{bmargin=-10pt}
\newpage
\sample{vsmash=b}
\sample{vsmash=c}
\sample{vsmash=t}
\newpage
\sample{vsmash=l}
\sample{vsmash=m}
\sample{vsmash=u}
\newpage
\sample{hsmash=l}
\sample{hsmash=c}
\sample{hsmash=r}
\newpage
\sample{smash=tl}
\sample{smash=cc}
\sample{smash=br}
\newpage
\sample{smash,vshift=10pt}
\sample{smash,hshift=10pt}
\sample{smash,hshift=-10pt,vshift=-10pt}
\end{document}
%    \end{macrocode}
%\iffalse
%</sample>
%\fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Sample Graphics.}
%\iffalse
%<*figure>
%\fi
%
% The following is a sample Metapost graphics file (|gboxsamp.mps|)
% for use in the sample {\LaTeX} file:
%
%    \begin{macrocode}
%!PS-Adobe-3.0 EPSF-3.0
%%BoundingBox: -21 -21 21 21
%%EndComments
%%Page: 1 1
 0 0 0 setrgbcolor 0 1.5 dtransform truncate idtransform setlinewidth pop []
 0 setdash 1 setlinecap 1 setlinejoin 10 setmiterlimit
newpath -20 20 moveto 20 -20 lineto stroke
newpath -20 -20 moveto 20 20 lineto stroke
%%EOF
%    \end{macrocode}
% It contains a black cross:
% \[\fbox{\drawbox{1.5cm}}\]
% The frame indicates the size of the graphics but it does not belong to it.
%
%\iffalse
%</figure>
%\fi
%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \section{Implementation}
%\iffalse
%<*package>
%\fi
%
% In this section we describe the package |graphbox.sty|.

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Package Options.}
%
% By default, the package overrides the overlay meachanism
% for includegraphics of the class beamer.
% The global option |nobeamer| disables the interaction.
%    \begin{macrocode}
\newif\ifGin@box@beamer\Gin@box@beamertrue
\DeclareOption{nobeamer}{\Gin@box@beamerfalse}
\ProcessOptions
%    \end{macrocode}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Required Packages.}
%
% The package loads \textsf{graphicx} if not yet present:
%    \begin{macrocode}
\RequirePackage{graphicx}
%    \end{macrocode}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Internal Definitions.}
%
% The package defines a box and several dimension registers:
%
%    \begin{macrocode}
\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}
%    \end{macrocode}

% The following macros store the parameters for the present graphics:
%
%    \begin{macrocode}
\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
%    \end{macrocode}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Additional Arguments.}
%
% The optional arguments of |\includegraphics| are parsed by \textsf{keyval}
% which calls the appropriate handlers. We add handlers to introduce additional
% optional arguments:
%
%    \begin{macrocode}
\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}}
%    \end{macrocode}
%
% The options are stored in internal registers for later processing.
% The arguments of |hsmash| and |vsmash| work in the opposite direction
% for conventional alignment of {\LaTeX} boxes. Therefore the parameters
% |t| and |b| as well as |r| and |l| are interchanged.

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% \paragraph{Argument Processing.}
%
% Next, we overwrite the function |\Gin@setfile| called by |\includegraphics|
% after the optional parameters have been processed
% by |\setkeys{Gin}{...}|:
%    \begin{macrocode}
\let\old@box@Gin@setfile\Gin@setfile
\def\Gin@setfile#1#2#3{%
%    \end{macrocode}
% We first save the graphics into the box |\Gin@box@box|
% and compute its width and height:
%    \begin{macrocode}
 \sbox{\Gin@box@box}{\old@box@Gin@setfile{#1}{#2}{#3}}%
 \settowidth{\Gin@box@width}{\usebox{\Gin@box@box}}%
 \settoheight{\Gin@box@height}{\usebox{\Gin@box@box}}%
%    \end{macrocode}
% Temporarily define the macros |\gwidth| and |\gheight|
% to represent the width and height of the graphics, respectively:
%    \begin{macrocode}
 \def\gwidth{\Gin@box@width}%
 \def\gheight{\Gin@box@height}%
%    \end{macrocode}
% Ignore top and bottom margin if vsmash is active:
%    \begin{macrocode}
 \ifGin@box@vsmash%
  \def\Gin@box@tmargin{0pt}\def\Gin@box@bmargin{0pt}\fi%
%    \end{macrocode}
% Compute the vertical box dimensions:
%    \begin{macrocode}
 \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%
%    \end{macrocode}
% Compute the horizontal box dimensions:
%    \begin{macrocode}
 \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%
%    \end{macrocode}
% Define the vertical box:
%    \begin{macrocode}
 \ifGin@box@vsmash\expandafter\smash\fi{%
  \raisebox{\Gin@box@raise}{%
   \parbox[b]{\Gin@box@bwidth}{%
    \rule[-\Gin@box@bmargin]{0pt}{\Gin@box@bheight}%
    \smash{%
%    \end{macrocode}
% Define the horizontal box:
%    \begin{macrocode}
     \makebox[0pt][l]{%
      \hspace*{\Gin@box@hspace}%
%    \end{macrocode}
% Print the graphics unless hidden:
%    \begin{macrocode}
      \ifGin@box@hide\else\usebox{\Gin@box@box}\fi%
     }%
    }%
   }%
  }%
 }%
}
%    \end{macrocode}

% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%\paragraph{Interaction with class beamer.}
%
% For the class \textsf{beamer} we want to override the overlay mechanism
% to always reserve the space the graphics would occupy.
% Here we have to overwrite the command |\includegraphics|.
%    \begin{macrocode}
\@ifclassloaded{beamer}{\ifGin@box@beamer
%    \end{macrocode}
% Save the original definition of |\includegraphics| and begin the new one:
%    \begin{macrocode}
 \let\old@box@includegraphics\includegraphics
 \newcommand<>{\fibox@includegraphics}[2][]{\Gin@box@hidefalse%
%    \end{macrocode}
% Check whether overlay parameters |<...>| are specified.
% If none, use the counter of the |\pause| mechanism to determine visibility.
% Call |\alt<...>| to set the |hide| argument according to visibility:
%    \begin{macrocode}
  \beamer@ifempty{#3}%
   {\alt<\c@beamerpauses->{}{\Gin@box@hidetrue}}%
   {\alt#3{}{\Gin@box@hidetrue}}%
%    \end{macrocode}
% Pass on to old definition:
%    \begin{macrocode}
  \old@box@includegraphics[#1]{#2}}
%    \end{macrocode}
% \textsf{beamer} overwrites |\includegraphics|
% at the beginning of the document body.
% We have to overwrite it again discarding
% the changes introduced by \textsf{beamer}:
%    \begin{macrocode}
 \AtBeginDocument{\let\includegraphics=\fibox@includegraphics}
\fi}{}
%    \end{macrocode}

%\iffalse
%</package>
%\fi
%
\endinput