| 1 |
% \iffalse meta-comment |
| 2 |
% |
| 3 |
% Copyright (C) 2011 by Martin Scharrer <[email protected]> |
| 4 |
% ----------------------------------------------------------------- |
| 5 |
% |
| 6 |
% This work may be distributed and/or modified under the |
| 7 |
% conditions of the LaTeX Project Public License, either version 1.3c |
| 8 |
% of this license or (at your option) any later version. |
| 9 |
% The latest version of this license is in |
| 10 |
% |
| 11 |
% http://www.latex-project.org/lppl.txt |
| 12 |
% |
| 13 |
% and version 1.3c or later is part of all distributions of LaTeX |
| 14 |
% version 2008/05/04 or later. |
| 15 |
% |
| 16 |
% This work has the LPPL maintenance status `maintained'. |
| 17 |
% |
| 18 |
% The Current Maintainer of this work is Martin Scharrer. |
| 19 |
% |
| 20 |
% This work consists of the files gincltex.dtx, gincltex.ins |
| 21 |
% and the derived file gincltex.sty. |
| 22 |
% |
| 23 |
% $Id: skeleton.dtx 1057 2009-05-04 11:11:37Z martin $ |
| 24 |
% \fi |
| 25 |
% |
| 26 |
% \iffalse |
| 27 |
\RequirePackage{svn-prov} |
| 28 |
%<package>\ProvidesPackage{gincltex} |
| 29 |
%<*driver> |
| 30 |
\ProvidesFile{gincltex.dtx} |
| 31 |
%</driver> |
| 32 |
[2011/09/04 v0.3 Include external LaTeX files like graphics] |
| 33 |
%<*driver> |
| 34 |
\documentclass{ydoc}[2011/03/17] |
| 35 |
\usepackage{gincltex} |
| 36 |
\EnableCrossrefs |
| 37 |
%\CodelineIndex |
| 38 |
\RecordChanges |
| 39 |
%\OnlyDescription |
| 40 |
\begin{document} |
| 41 |
\DocInput{\jobname.dtx} |
| 42 |
\PrintChanges |
| 43 |
%\newpage\PrintIndex |
| 44 |
\end{document} |
| 45 |
%</driver> |
| 46 |
% \fi |
| 47 |
% |
| 48 |
% \CheckSum{161} |
| 49 |
% |
| 50 |
% \CharacterTable |
| 51 |
% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z |
| 52 |
% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z |
| 53 |
% Digits \0\1\2\3\4\5\6\7\8\9 |
| 54 |
% Exclamation \! Double quote \" Hash (number) \# |
| 55 |
% Dollar \$ Percent \% Ampersand \& |
| 56 |
% Acute accent \' Left paren \( Right paren \) |
| 57 |
% Asterisk \* Plus \+ Comma \, |
| 58 |
% Minus \- Point \. Solidus \/ |
| 59 |
% Colon \: Semicolon \; Less than \< |
| 60 |
% Equals \= Greater than \> Question mark \? |
| 61 |
% Commercial at \@ Left bracket \[ Backslash \\ |
| 62 |
% Right bracket \] Circumflex \^ Underscore \_ |
| 63 |
% Grave accent \` Left brace \{ Vertical bar \| |
| 64 |
% Right brace \} Tilde \~} |
| 65 |
% |
| 66 |
% |
| 67 |
% \changes{v0.1}{2011/01/23}{Packaged code} |
| 68 |
% \changes{v0.1}{2011/03/06}{First release} |
| 69 |
% \changes{v0.2}{2011/03/18}{Added explicit 'draft' and 'final' options.} |
| 70 |
% \changes{v0.3}{2011/09/04}{Clipping and trimming are now done using the \pkg{adjustbox} package.} |
| 71 |
% |
| 72 |
% \GetFileInfo{\jobname.dtx} |
| 73 |
% |
| 74 |
% \DoNotIndex{\newcommand,\newenvironment,\def,\edef,\xdef,\let} |
| 75 |
% |
| 76 |
% \author{Martin Scharrer} |
| 77 |
% \email{[email protected]} |
| 78 |
% \maketitle |
| 79 |
% |
| 80 |
% \begin{abstract} |
| 81 |
% This small package builds on the standard \LaTeX{} package \pkg{graphicx} |
| 82 |
% and allows external \LaTeX{} source files to be included like graphic files, i.e. adds support for the ".tex" |
| 83 |
% extension. |
| 84 |
% Some of the lower level operations like clipping and trimming are implemented using the \pkg{pgf} package which supports |
| 85 |
% both DVI/PS and PDF output. |
| 86 |
% This package uses a very similar technique than the author's other package \pkg{adjustbox}, but provides a different |
| 87 |
% interface. |
| 88 |
% \\[\medskipamount] |
| 89 |
% \textbf{Please note} that this package is new and the implementation might change in future revisions. |
| 90 |
% This might cause minor rounding differences in the exact size of the resulting \TeX{} box around the included files. |
| 91 |
% \end{abstract} |
| 92 |
% |
| 93 |
% \section{Introduction} |
| 94 |
% This small package builds on the standard \LaTeX{} package \pkg{graphicx} |
| 95 |
% and allows external \LaTeX{} source files to be included like graphic files: |
| 96 |
% |
| 97 |
% \begin{macroquote} |
| 98 |
% \includegraphics[<options>]{<\/file>'.tex'} |
| 99 |
% \end{macroquote} |
| 100 |
% |
| 101 |
% \noindent |
| 102 |
% A \LaTeX{} file included this way should result in an identical display as a tightly cropped EPS or PDF image |
| 103 |
% of the same file (apart smaller rounding differences). |
| 104 |
% Usually such files hold a picture environment like |
| 105 |
% \env{picture}, \env{pspicture}, \env{pgfpicture} or \env{tikzpicture}, which may take advantage |
| 106 |
% from the \cls{standalone} class. |
| 107 |
% In fact \pkg{gincltex} is used in newer versions of \pkg{standalone} to seamlessly switch between source and image files. |
| 108 |
% |
| 109 |
% All options of \Macro\includegraphics described in the manual of \pkg{graphicx} (the \texttt{grfguide}) |
| 110 |
% should be supported. Therefore it is possible to resize, rotate and clip the content |
| 111 |
% of the \LaTeX{} source file in the same way as for images. |
| 112 |
% |
| 113 |
% |
| 114 |
% An alternative is the \pkg{adjustbox} package from the same author which allows the same options |
| 115 |
% as for \Macro\includegraphics for arbitrary TeX material: |
| 116 |
% \begin{macroquote} |
| 117 |
% \adjustbox{<includegraphics options>}{'\input{'<\/file>'}'} |
| 118 |
% \end{macroquote} |
| 119 |
% |
| 120 |
% \section{Usage} |
| 121 |
% After loading the package the ".tex" extension is supported by \Macro\includegraphics |
| 122 |
% and the macro can be used in its normal form for \LaTeX{} files. |
| 123 |
% The content of the file is typeset first inside an |\hbox| (the primitive version of |\mbox|) |
| 124 |
% and then modified according to the given macro options. |
| 125 |
% The \pkg{graphicx} package is automatically loaded. |
| 126 |
% |
| 127 |
% \subsection{Draft support} |
| 128 |
% The package supports the \opt{draft} option of \pkg{graphicx} which only displays an empty box |
| 129 |
% with the file name for all included graphics. |
| 130 |
% In this mode the source file should not be processed to reduce compile time. |
| 131 |
% However the size of the resulting box from the source file must be know in order |
| 132 |
% to reserve the required space. Therefore the \emph{bounding box} information is |
| 133 |
% cached for future runs with active \opt{draft} option. The location where the information |
| 134 |
% is cached can be controlled with the \opt{bb} option. |
| 135 |
% |
| 136 |
% \subsection{Package options} |
| 137 |
% The \opt*{draft} and \opt*{final} options are directly passed to the loaded \pkg{graphicx} package. |
| 138 |
% Having a different draft setting is not supported and the one used by the \pkg{graphicx} package will always take affect for \pkg{gincltex}. |
| 139 |
% |
| 140 |
% The place where the bounding box information is cached can be adjusted with the |
| 141 |
% \opt*{bb} option. By default |bb=aux| is active which stores the bounding box information |
| 142 |
% in the |.aux| file. With |bb=file| this information is written in EPS format into |
| 143 |
% |.tex.bb| files, e.g. for each source file "name.tex" a file "name.tex.bb" is created. |
| 144 |
% |
| 145 |
% |
| 146 |
% \StopEventually{} |
| 147 |
% \iffalse |
| 148 |
%<*package> |
| 149 |
% \fi |
| 150 |
% \section{Implementation} |
| 151 |
% \subsection{Package Option} |
| 152 |
% At the moment the key=value format is simply hard coded. |
| 153 |
% \begin{macrocode} |
| 154 |
\newif\if@gincltex@bbfile |
| 155 |
\DeclareOption{bb=file}{\@gincltex@bbfiletrue} |
| 156 |
\DeclareOption{bb=aux}{\@gincltex@bbfilefalse} |
| 157 |
\DeclareOption{draft}{\PassOptionsToPackage{draft}{graphicx}} |
| 158 |
\DeclareOption{draft=true}{\PassOptionsToPackage{draft}{graphix}} |
| 159 |
\DeclareOption{draft=false}{\PassOptionsToPackage{final}{graphicx}} |
| 160 |
\DeclareOption{final}{\PassOptionsToPackage{final}{graphicx}} |
| 161 |
\DeclareOption{final=true}{\PassOptionsToPackage{final}{graphicx}} |
| 162 |
\DeclareOption{final=false}{\PassOptionsToPackage{draft}{graphicx}} |
| 163 |
\DeclareOption*{\PassOptionsToPackage\CurrentOption{adjustbox}} |
| 164 |
\ProcessOptions*\relax |
| 165 |
% \end{macrocode} |
| 166 |
% |
| 167 |
% \subsection{Requirements} |
| 168 |
% The \pkg{graphicx} package is required. |
| 169 |
% The \pkg{pgf} package is required for the graphic manipulations. |
| 170 |
% \begin{macrocode} |
| 171 |
\RequirePackage{adjustbox} |
| 172 |
% \end{macrocode} |
| 173 |
% |
| 174 |
% \subsection{Graphics Rule Macros} |
| 175 |
% The following macro implement a \emph{graphics rule} for \LaTeX{} source code files. |
| 176 |
% |
| 177 |
% \begin{macro}{\Gin@[email protected]} |
| 178 |
% This macro declares the graphics rule to the \pkg{graphicx} package. |
| 179 |
% \begin{macrocode} |
| 180 |
\DeclareGraphicsRule{.tex}{tex}{.tex}{} |
| 181 |
% \end{macrocode} |
| 182 |
% \end{macro} |
| 183 |
% |
| 184 |
% \begin{macro}{\gincltex@box} |
| 185 |
% A savebox required to transfer material from the `read' macro to the `include' macro. |
| 186 |
% Note that |\@tempboxa| is not used here because it might be used otherwise between the |
| 187 |
% two macros. |
| 188 |
% \begin{macrocode} |
| 189 |
\newsavebox\gincltex@box |
| 190 |
% \end{macrocode} |
| 191 |
% \end{macro} |
| 192 |
% |
| 193 |
% \begin{macro}{\gincltex@boxfile} |
| 194 |
% Macro to box the \LaTeX{} source file. |
| 195 |
% Because \Macro\includegraphics can be used inside this file certain internal \pkg{graphicx} macros |
| 196 |
% must be reset to there default value. |
| 197 |
% The argument is expanded first because it could include |\Gin@ext|. |
| 198 |
% The content is stored with zero depth to achieve the same result as with included graphics. |
| 199 |
% \begin{macrocode} |
| 200 |
\def\gincltex@boxfile#1{% |
| 201 |
\sbox\gincltex@box{{% |
| 202 |
\hbox{\vbox{% |
| 203 |
\hbox{% |
| 204 |
\edef\@tempa{{#1}}% |
| 205 |
\let\Gin@ext\relax |
| 206 |
\expandafter\input\@tempa |
| 207 |
}% |
| 208 |
\vskip\z@ |
| 209 |
}}% |
| 210 |
}}% |
| 211 |
} |
| 212 |
% \end{macrocode} |
| 213 |
% \end{macro} |
| 214 |
% |
| 215 |
% \begin{macro}{\Ginclude@tex} |
| 216 |
% This driver macro is called from the standard \Macro\includegraphics macro to include the \LaTeX{} source file. |
| 217 |
% Some \Macro\includegraphics options like |angle| are handled by wrapping this macro in the appropriate |
| 218 |
% \pkg{graphicx} macro like \Macro\rotatebox, but others must be handled here. |
| 219 |
% \begin{macrocode} |
| 220 |
\def\Ginclude@tex#1{% |
| 221 |
\begingroup |
| 222 |
% \end{macrocode} |
| 223 |
% The content of the source file might have been already saved into the |\gincltex@box| by the |\Gread@tex| macro. |
| 224 |
% If not it is saved here. |
| 225 |
% \begin{macrocode} |
| 226 |
\ifvoid\gincltex@box |
| 227 |
\gincltex@boxfile{#1}% |
| 228 |
\fi |
| 229 |
% \end{macrocode} |
| 230 |
% The |height|, |totalheight| and |width| options are already processed and the final requested height and width |
| 231 |
% to which the `graphic' should be scaled to are provided. The internal form of the \Macro\resizebox macro is used for |
| 232 |
% this. |
| 233 |
% \begin{macrocode} |
| 234 |
\resizebox*{\Gin@req@width}{\Gin@req@height}{% |
| 235 |
\ifGin@clip\expandafter\clipbox\else\expandafter\clipbox\fi*{{\Gin@llx} {\Gin@lly} {\Gin@urx} {\Gin@ury}}{\usebox\gincltex@box}% |
| 236 |
}% |
| 237 |
\endgroup |
| 238 |
} |
| 239 |
% \end{macrocode} |
| 240 |
% \end{macro} |
| 241 |
% |
| 242 |
% The |\Gread@tex| macro is defined in two different ways depending how the bounding box information is preserved. |
| 243 |
% This information is required to support the \opt{draft} option of the \pkg{graphicx} package. |
| 244 |
% \begin{macrocode} |
| 245 |
\if@gincltex@bbfile |
| 246 |
% \end{macrocode} |
| 247 |
% Use a |.tex.bb| file to store the bounding box information. The standardised EPS format is used here, so that the |
| 248 |
% |\Gread@eps| macro can be used. |
| 249 |
% |
| 250 |
% An output register is required to write the |.tex.bb| files. Advanced users are allowed to predefine it manually |
| 251 |
% in order to save a write register. Note that the writing is done inside the |.aux| file, therefore the |\@mainaux| |
| 252 |
% handle could be used here, because it is closed while reading the |.aux| file. |
| 253 |
% \begin{macrocode} |
| 254 |
\@ifundefined{gincltex@bbout}{\newwrite\gincltex@bbout}{} |
| 255 |
% \end{macrocode} |
| 256 |
% |
| 257 |
% \begin{macro}{\gincltex@bb} |
| 258 |
% Write the bounding box information to the |.tex.bb| file. The hi-resolution version is used to be more accurate. |
| 259 |
% The code to write the normal version is disabled for now because it is unneeded and requires some non-trivial |pgfmath| calls. |
| 260 |
% |
| 261 |
% Because this macro is executed inside the |.aux| file, which is read before the begin AND at the end of the document, the macro |
| 262 |
% is defined as a no-op first two avoid unnecessary double execution. |
| 263 |
% \begin{macrocode} |
| 264 |
\def\gincltex@bb#1#2#3#4#5{} |
| 265 |
\AtBeginDocument{\let\gincltex@bb\gincltex@@bb} |
| 266 |
\def\gincltex@@bb#1#2#3#4#5{% |
| 267 |
\begingroup |
| 268 |
\immediate\openout\gincltex@bbout=#1.bb\relax |
| 269 |
\immediate\write\gincltex@bbout{\@percentchar |
| 270 |
\@percentchar HiResBoundingBox: #2 #3 #4 #5}% |
| 271 |
\immediate\closeout\gincltex@bbout |
| 272 |
\endgroup |
| 273 |
} |
| 274 |
% \end{macrocode} |
| 275 |
% \end{macro} |
| 276 |
% |
| 277 |
% Storing the bounding box information in the |.aux| file. |
| 278 |
% \begin{macrocode} |
| 279 |
\else |
| 280 |
% \end{macrocode} |
| 281 |
% |
| 282 |
% \begin{macro}{\Gread@tex@setbb} |
| 283 |
% Auxiliary macro to set the bounding box macros. |
| 284 |
% \begin{macrocode} |
| 285 |
\def\Gread@tex@setbb#1#2#3#4{% |
| 286 |
\def\Gin@llx{#1}% |
| 287 |
\def\Gin@lly{#2}% |
| 288 |
\def\Gin@urx{#3}% |
| 289 |
\def\Gin@ury{#4}% |
| 290 |
} |
| 291 |
% \end{macrocode} |
| 292 |
% \end{macro} |
| 293 |
% |
| 294 |
% \begin{macro}{\Gread@tex} |
| 295 |
% Read the bounding box information. The only way to do this is to actually typeset the source file into a box. |
| 296 |
% The box is then reused in the |\Ginclude@tex| macro, so there is no overhead. |
| 297 |
% The bounding box information is written into the |.aux| file to avoid processing the source file in \opt{draft} mode. |
| 298 |
% However if the corresponding macro is not define yet (e.g.\ \opt{draft} run without |.aux| file) the file must be |
| 299 |
% read anyway. |
| 300 |
% \begin{macrocode} |
| 301 |
\def\Gread@tex#1{% |
| 302 |
\ifcase0\ifGin@draft\@ifundefined{gincltex@bb@#1}{0}{1}\fi\relax |
| 303 |
\gincltex@boxfile{#1}% |
| 304 |
\def\Gin@llx{0}% |
| 305 |
\let\Gin@llx\Gin@lly |
| 306 |
\Gin@defaultbp\Gin@urx{\wd\gincltex@box}% |
| 307 |
\Gin@defaultbp\Gin@ury{\ht\gincltex@box}% |
| 308 |
\expandafter\xdef\csname gincltex@bb@#1\endcsname |
| 309 |
{{\Gin@llx}{\Gin@lly}{\Gin@urx}{\Gin@ury}}% |
| 310 |
\else |
| 311 |
\expandafter\expandafter\expandafter\Gread@tex@setbb |
| 312 |
\csname gincltex@bb@#1\endcsname |
| 313 |
\setbox\gincltex@box=\box\voidb@x |
| 314 |
\fi |
| 315 |
\if@filesw |
| 316 |
\immediate\write\@auxout{\string\gincltex@bb{#1}% |
| 317 |
\csname gincltex@bb@#1\endcsname}% |
| 318 |
\fi |
| 319 |
} |
| 320 |
% \end{macrocode} |
| 321 |
% \end{macro} |
| 322 |
% |
| 323 |
% \begin{macro}{\gincltex@bb} |
| 324 |
% Simply define the corresponding bounding box macro. |
| 325 |
% \begin{macrocode} |
| 326 |
\def\gincltex@bb#1#2#3#4#5{% |
| 327 |
\global\@namedef{gincltex@bb@#1}{{#2}{#3}{#4}{#5}}% |
| 328 |
} |
| 329 |
% \end{macrocode} |
| 330 |
% \end{macro} |
| 331 |
% |
| 332 |
% \begin{macrocode} |
| 333 |
\fi |
| 334 |
\endinput |
| 335 |
% \end{macrocode} |
| 336 |
% |
| 337 |
% \Finale |
| 338 |
% \iffalse |
| 339 |
%</package> |
| 340 |
% \fi |
| 341 |
|