trimclip.sty (7112B)
1 %% Copyright (C) 2011-2012 by Martin Scharrer <martin@scharrer-online.de> 2 %% ---------------------------------------------------------------------- 3 %% This work may be distributed and/or modified under the 4 %% conditions of the LaTeX Project Public License, either version 1.3 5 %% of this license or (at your option) any later version. 6 %% The latest version of this license is in 7 %% http://www.latex-project.org/lppl.txt 8 %% and version 1.3 or later is part of all distributions of LaTeX 9 %% version 2005/12/01 or later. 10 %% 11 %% This work has the LPPL maintenance status `maintained'. 12 %% 13 %% The Current Maintainer of this work is Martin Scharrer. 14 %% 15 %% This work consists of the files trimclip.dtx, adjustbox.ins 16 %% and the derived files trimclip.sty, 17 %% tc-dvips.def, tc-pdftex.def, tc-pgf.def and tc-xetex.def. 18 %% Further author information are located in the .def files. 19 %% 20 \ProvidesPackage{trimclip}[% 21 2012/05/16 22 v1.0 23 Trim and clip general TeX material] 24 \def\tc@driver{tc-\Gin@driver} 25 \DeclareOption{pgf}{\def\tc@driver{tc-pgf.def}\PassOptionsToPackage{pgf}{graphicx}} 26 \DeclareOption{pdftex}{\def\tc@driver{tc-pdftex.def}\PassOptionsToPackage{pdftex}{graphicx}} 27 \DeclareOption{xetex}{\def\tc@driver{tc-xetex.def}\PassOptionsToPackage{xetex}{graphicx}} 28 \DeclareOption{dvips}{\def\tc@driver{tc-dvips.def}\PassOptionsToPackage{dvips}{graphicx}} 29 \DeclareOption{dvipdfm}{\def\tc@driver{tc-xetex.def}\PassOptionsToPackage{xetex}{graphicx}} 30 \DeclareOption{dvipdf}{\def\tc@driver{tc-xetex.def}\PassOptionsToPackage{xetex}{graphicx}} 31 \DeclareOption*{% 32 \@ifpackageloaded{graphics}{% 33 \edef\tc@driver{tc-\CurrentOption.def}% 34 \begingroup 35 \edef\@tempa{\CurrentOption.def}% 36 \ifx\@tempa\Gin@driver\else 37 \let\on@line\@gobble 38 \PackageWarning{trimclip}{% 39 A different clipping driver was requested than the\MessageBreak 40 one used for 'graphics/x'! This is not recommended\MessageBreak 41 and can lead to defect output files.% 42 }% 43 \fi 44 \endgroup 45 }{% 46 \def\tc@driver{tc-\Gin@driver}% 47 \PassOptionsToPackage\CurrentOption{graphicx}% 48 }% 49 } 50 \ProcessOptions*\relax 51 \RequirePackage{graphicx}[1999/02/16] 52 \RequirePackage{collectbox}[2011/08/22] 53 \RequirePackage{adjcalc} 54 \def\tc@readvalues#1{% 55 \tc@@readvalues#1 {} {} {} \\% 56 } 57 \def\tc@@readvalues#1 #2 #3 #4 #5\\{% 58 \adjsetlengthdefault\tc@llx{#1}% 59 \ifx\@nnil#2\@nnil 60 \tc@lly\tc@llx 61 \tc@urx\tc@llx 62 \tc@ury\tc@llx 63 \else 64 \adjsetlengthdefault\tc@lly{#2}% 65 \ifx\@nnil#3\@nnil 66 \tc@urx\tc@llx 67 \tc@ury\tc@lly 68 \else 69 \adjsetlengthdefault\tc@urx{#3}% 70 \adjsetlengthdefault\tc@ury{#4}% 71 \fi 72 \fi 73 }% 74 \newdimen\tc@llx 75 \newdimen\tc@lly 76 \newdimen\tc@urx 77 \newdimen\tc@ury 78 \newcommand\trimbox{% 79 \collectboxcheckenv{trimbox}% 80 \@ifstar 81 \trimbox@s 82 \trimbox@ 83 } 84 \def\trimbox@#1{% 85 \collectbox{\@trimclip\@trimbox{#1}}% 86 } 87 \def\trimbox@s#1{% 88 \collectbox{\@trimclip\@viewportbox{#1}}% 89 } 90 \expandafter\newcommand\expandafter*\csname trimbox*\endcsname{% 91 \@collectboxisenv{trimbox*}% 92 \trimbox@s 93 } 94 \newcommand\clipbox{% 95 \collectboxcheckenv{clipbox}% 96 \@ifstar 97 \clipbox@s 98 \clipbox@ 99 } 100 \def\clipbox@#1{% 101 \collectbox{\@trimclip\@clipbox{#1}}% 102 } 103 \def\clipbox@s#1{% 104 \collectbox{\@trimclip\@clipvpbox{#1}}% 105 } 106 \expandafter\newcommand\expandafter*\csname clipbox*\endcsname{% 107 \@collectboxisenv{clipbox*}% 108 \clipbox@s 109 } 110 \newcommand\marginbox{% 111 \collectboxcheckenv{marginbox}% 112 \@ifstar 113 \marginbox@s 114 \marginbox@ 115 } 116 \def\marginbox@#1{% 117 \@collectbox{\@trimclip\@marginbox{#1}}% 118 } 119 \def\marginbox@s#1{% 120 \@collectbox{\@trimclip\@marginraisebox{#1}}% 121 } 122 \expandafter\newcommand\expandafter*\csname marginbox*\endcsname{% 123 \@collectboxisenv{marginbox*}% 124 \marginbox@s 125 } 126 \def\@trimclip#1#2{% 127 \tc@readvalues{#2}% 128 #1% 129 \collectedbox 130 \tc@llx 131 \tc@lly 132 \tc@urx 133 \tc@ury 134 \usebox\collectedbox 135 } 136 \def\tc@correctbaseline#1{% 137 \ifdim\dp#1<\z@ 138 \raise\dp#1% 139 \else 140 \ifdim\ht#1<\z@ 141 \lower\ht#1% 142 \fi\fi 143 \box#1% 144 }% 145 \def\tc@correctdims#1{% 146 \ifdim\dp#1<\z@ \dp#1=\z@ \fi 147 \ifdim\wd#1<\z@ \wd#1=\z@ \fi 148 \ifdim\ht#1<\z@ \ht#1=\z@ \fi 149 } 150 \def\@trimbox#1#2#3#4#5{% 151 \setbox#1=\hbox{% 152 % 153 \tc@llx=#2\relax 154 \tc@lly=#3\relax 155 \advance\tc@lly-\dp#1% 156 \tc@urx=#4\relax 157 \advance\tc@urx-\wd#1% 158 \tc@ury=#5\relax 159 \advance\tc@ury-\ht#1% 160 % 161 % Set dimensions now. 162 % This allows that the arguments can refer 163 % to the original dimensions without issues. 164 \hskip-\tc@llx 165 \dp#1-\tc@lly 166 \wd#1-\tc@urx 167 \ht#1-\tc@ury 168 % 169 \tc@correctbaseline{#1}% 170 }% 171 \tc@correctdims{#1}% 172 } 173 \def\@marginbox#1#2#3#4#5{% 174 \setbox#1=\hbox{% 175 % 176 \tc@llx=#2\relax 177 \tc@lly=#3\relax 178 \advance\tc@lly\dp#1% 179 \tc@urx=#4\relax 180 \advance\tc@urx\wd#1% 181 \tc@ury=#5\relax 182 \advance\tc@ury\ht#1% 183 % 184 % Set dimensions now. 185 % This allows that the arguments can refer 186 % to the original dimensions without issues. 187 \hskip\tc@llx 188 \dp#1\tc@lly 189 \wd#1\tc@urx 190 \ht#1\tc@ury 191 % 192 \box#1% 193 }% 194 \tc@correctdims{#1}% 195 } 196 \def\@marginraisebox#1#2#3#4#5{% 197 \setbox#1=\hbox{% 198 % 199 \tc@llx=#2\relax 200 \tc@lly=#3\relax 201 \tc@urx=#4\relax 202 \advance\tc@urx\wd#1% 203 \tc@ury=#5\relax 204 \advance\tc@ury\ht#1% 205 % 206 % Set dimensions now. 207 % This allows that the arguments can refer 208 % to the original dimensions without issues. 209 \hskip\tc@llx 210 \wd#1\tc@urx 211 \ht#1\tc@ury 212 % Copy original tty values (ury is taken as temp dimension) 213 \tc@ury=\tc@lly 214 \advance\tc@lly\dp#1% 215 \dp#1\tc@lly 216 % Raise bu original tty value (now in ury) 217 \raise\tc@ury\box#1% 218 }% 219 \tc@correctdims{#1}% 220 } 221 \def\@viewportbox#1#2#3#4#5{% 222 \setbox#1=\hbox{% 223 % 224 % Assign values 225 \tc@llx=#2\relax 226 \tc@lly=#3\relax 227 \tc@urx=#4\relax 228 \tc@ury=#5\relax 229 % 230 % Set dimensions now. 231 % This allows that the arguments can refer 232 % to the original dimensions without issues. 233 \hskip-\tc@llx 234 \dp#1-\tc@lly 235 \wd#1\tc@urx 236 \ht#1\tc@ury 237 % 238 \tc@correctbaseline{#1}% 239 }% 240 \tc@correctdims{#1}% 241 } 242 \def\@clipbox#1#2#3#4#5{% 243 \@trimbox{#1}{#2}{#3}{#4}{#5}% 244 \@cliptoboxdim{#1}% 245 } 246 \def\@clipvpbox#1#2#3#4#5{% 247 \@viewportbox{#1}{#2}{#3}{#4}{#5}% 248 \@cliptoboxdim{#1}% 249 } 250 \InputIfFileExists{\tc@driver}{% 251 {\let\on@line\@gobble 252 \PackageInfo{trimclip}{Using driver '\tc@driver'.}}% 253 }{% 254 \input{tc-pgf.def}% 255 {\let\on@line\@gobble 256 \PackageInfo{trimclip}{No clipping driver '\tc@driver' available.\MessageBreak Using fall-back PGF driver.}}% 257 } 258 \endinput 259 %% 260 %% End of file `trimclip.sty'.