Debian Codegraph @

texmf-dist/source/latex/combinedgraphics/combinedgraphics.dtx

raw
1 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2 % \iffalse meta-comment
3 %
4 % DocStrip file for combinedgraphics package
5 %
6 % Copyright 2009,2011,2012 Christian Schneider <software(at)chschneider(dot)eu>
7 %
8 % cgr@addto@macro: identical to l@addto@macro from koma-script
9 % bundle v2.9t
10 % Copyright 1994-2004 Markus Kohm and Frank Neukam
11 %
12 % Thanks to Markus Kohm for permitting to use his code in this package.
13 % Please do not bother Markus with questions or bugs concering this package!
14 %
15 % This file is part of combinedgraphics.
16 %
17 % combinedgraphics is free software: you can redistribute it and/or modify
18 % it under the terms of the GNU General Public License version 3 as
19 % published by the Free Software Foundation, not any later version.
20 %
21 % combinedgraphics is distributed in the hope that it will be useful,
22 % but WITHOUT ANY WARRANTY; without even the implied warranty of
23 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 % GNU General Public License for more details.
25 %
26 % You should have received a copy of the GNU General Public License
27 % along with combinedgraphics. If not, see <http://www.gnu.org/licenses/>.
28 %
29 % WARNING: THIS IS ALPHA SOFTWARE AND MAY CONTAIN SERIOUS BUGS!
30 %
31 % \fi
32 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33 %
34 % \iffalse
35 %<package>\NeedsTeXFormat{LaTeX2e}[1999/12/01]
36 %<package>\ProvidesPackage{combinedgraphics}
37 %<package> [2012/07/13 v0.2.2 inclusion of combined EPS/LaTeX graphics]
38 %<*driver>
39 \documentclass[a4paper]{ltxdoc}
40 \usepackage{combinedgraphics}
41 \EnableCrossrefs
42 \CodelineIndex
43 \RecordChanges
44 %
45 % modified description environment
46 \newcommand{\listmark}{$\bullet$}
47 \newcommand{\listlengths}{%
48 \setlength{\parsep}{0pt}%
49 \setlength{\itemsep}{0pt}%
50 \setlength{\leftmargin}{10.5em}%
51 \setlength{\rightmargin}{0pt}%
52 \setlength{\labelsep}{1em}%
53 \setlength{\labelwidth}{9.5em}}
54 \newenvironment{mydescription}{%
55 \begin{list}{\listmark}{\listlengths}%
56 }{%
57 \end{list}%
58 }
59 %
60 \begin{document}
61 \DocInput{combinedgraphics.dtx}
62 \end{document}
63 %</driver>
64 % \fi
65 %
66 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
67 %
68 % \changes{v0.0.1-alpha}{2009/10/04}{initial .dtx version}
69 % \changes{v0.0.2-alpha}{2009/11/01}{initial release}
70 % \changes{v0.1.0-alpha}{2011/06/12}{added options for changing the inclusion
71 % order of \LaTeX{} and vector graphics parts}
72 % \changes{v0.1.1-alpha}{2011/06/15}{fix in Makefiles of package}
73 % \changes{v0.2.0}{2012/01/04}{added options for scaling vector graphics
74 % part to a certain width or height, respectively, plus removed ``alpha''
75 % from version}
76 % \changes{v0.2.1}{2012/01/07}{simplified a macro}
77 % \changes{v0.2.2}{2012/07/12}{added comments to test file}
78 %
79 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 %
81 % \CheckSum{704}
82 %
83 % \CharacterTable
84 % {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
85 % 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
86 % Digits \0\1\2\3\4\5\6\7\8\9
87 % Exclamation \! Double quote \" Hash (number) \#
88 % Dollar \$ Percent \% Ampersand \&
89 % Acute accent \' Left paren \( Right paren \)
90 % Asterisk \* Plus \+ Comma \,
91 % Minus \- Point \. Solidus \/
92 % Colon \: Semicolon \; Less than \<
93 % Equals \= Greater than \> Question mark \?
94 % Commercial at \@ Left bracket \[ Backslash \\
95 % Right bracket \] Circumflex \^ Underscore \_
96 % Grave accent \` Left brace \{ Vertical bar \|
97 % Right brace \} Tilde \~}
98 %
99 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
100 %
101 % \GetFileInfo{combinedgraphics.sty}
102 %
103 % \DoNotIndex{\#,\$,\%,\&,\@,\\,\{,\},\^,\_,\~,\ }
104 % \DoNotIndex{\@ne}
105 % \DoNotIndex{\advance,\begingroup,\catcode,\closein}
106 % \DoNotIndex{\closeout,\day,\def,\edef,\else,\empty,\endgroup}
107 %
108 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
109 %
110 % \title{The \textsf{combinedgraphics} package\thanks{This document corresponds
111 % to \textsf{combinedgraphics}~\fileversion, dated~\filedate. Copyright
112 % 2009,2011,2012 Christian Schneider \texttt{<software(at)chschneider(dot)eu>}.}}
113 % \author{Christian Schneider\\ \texttt{<software(at)chschneider(dot)eu>}}
114 %
115 % \maketitle
116 %
117 % \tableofcontents
118 % \clearpage
119 %
120 % \begin{abstract}
121 % This package provides a macro (|\includecombinedgraphics|) for the
122 % inclusion of combined EPS/\LaTeX{} and PDF/\LaTeX{} graphics (an export
123 % format of Gnuplot, Xfig, and maybe other programs). Instead of including
124 % the graphics with a simple |\input|, the |\includecombinedgraphics| macro
125 % has some benefits:
126 %
127 % \begin{itemize}
128 % \item changing the font and color of the text of the \LaTeX{} parts
129 % \item rescaling the graphics without affecting the font of the \LaTeX{}
130 % parts
131 % \item automatic inclusion of the vector graphics parts, as far as \LaTeX{}
132 % parts do not do it (e.\,g., for files exported from Gnuplot before
133 % version 4.2 or Xfig)
134 % \item changing the inclusion order of \LaTeX{} and vector graphics
135 % parts (e.\,g., Gnuplot 4.4 exports files in a way that the vector
136 % graphics part overlays the \LaTeX{} part, which means that text may be
137 % hidden under shaded areas)
138 % \item rescaling and rotating of complete graphics (similar to
139 % |\includegraphics| from \textsf{graphicx} package)
140 % \item scaling the vector graphics part (without affecting the font) to
141 % a defined width or height of the graphics, which might, e.g., be of
142 % importance for graphics that are intended for publication in a journal
143 % requesting a certain size of graphics
144 % \end{itemize}
145 %
146 % A test PDF file with extensively commented examples is shipped with this
147 % package and a BASH script (\texttt{texpic2epspdf.sh}) to convert combined
148 % EPS/\LaTeX{} and PDF/\LaTeX{} graphics to EPS or PDF files with text part
149 % included.
150 % \end{abstract}
151 %
152 % \section{The Combined EPS/\LaTeX{} format}
153 %
154 % Graphics in combined EPS/\LaTeX{} or PDF/\LaTeX{} format consist of two files:
155 % \begin{enumerate}
156 % \item an EPS or PDF file containing the vector graphics part
157 % \item an \LaTeX{} file containing the text part
158 % \end{enumerate}
159 %
160 % This format has the advantage that it is possible to generate a high-quality
161 % vector graphics with text containing all symbols, macros and other stuff
162 % provided by \LaTeX{}. The text is formatted by \LaTeX{} itsself when including
163 % the graphics (\emph{not} during creation of the graphics!) and thus it is
164 % possible to use everything provided by \LaTeX{} up to the font of the
165 % document for text inside the graphics.
166 %
167 % Typically, the \LaTeX{} part of the graphics is included by |\input|.
168 % The vector graphics part is either included automatically by the \LaTeX{}
169 % part with an |\includegraphics| command (or something similar) and overlayed
170 % by the text or the user will have to combine both parts manually like this
171 % (e.\,g., for gnuplot before version 4.2 or Xfig) for a pair of files
172 % |foobar.tex|/|foobar.eps|:
173 %
174 % \begin{verbatim}
175 % \begin{picture}(0,0)%
176 % \includegraphics{foobar}%
177 % \end{picture}%
178 % \input{foobar}
179 % \end{verbatim}
180 %
181 % Although the format has some nice advantages compared to other formats, the
182 % user has to know whether to include the vector graphics part for (some of)
183 % his graphics or not, font changes sometimes require some knowledge of the
184 % internal commands of the \LaTeX{} part (depending on the tool that generated
185 % the graphics), and the user is not intended to change the scaling of just
186 % the vector graphics part without affecting the text format. Furthermore,
187 % rotating, scaling and resizing the whole graphics requires extra-macros,
188 % e.\,g. |\rotatebox|, |\scalebox|, or |\resizebox| from the
189 % \textsf{graphics}/\textsf{graphicx} package.
190 %
191 % The intention of this package is to provide a macro for easier handling of
192 % combined EPS/\LaTeX{} or PDF/\LaTeX{} graphics, just as easy as
193 % |\includegraphics|, and removing the limitations mentioned above.
194 %
195 % \section{Usage}
196 %
197 % \subsection{The macro}
198 %
199 % \DescribeMacro{\includecombinedgraphics}
200 % The macro |\includecombinedgraphics|\oarg{option list}\marg{graphics file}
201 % is used to include a combined EPS/\LaTeX{} or PDF/\LaTeX{} file, where
202 % \meta{graphics file} is the name of the \LaTeX{} part of the graphics
203 % (\emph{without} |.tex| extension) and \meta{option list} is an optional list
204 % of \meta{key}|=|\meta{value} pairs (see below).
205 %
206 % \subsection{Basic macro options}
207 % \label{sec:basic}
208 %
209 % The following options are processed first. If an option is specified
210 % several times, the last appearance will overwrite the previous ones.
211 %
212 % \begin{mydescription}
213 % \item[\texttt{textfont}=\meta{value}] one or more commands for reformatting
214 % the text in \LaTeX{} part (e.\,g., |textfont=\Large\bfseries| for large
215 % bold-face font or |textfont={}| for default font of graphics overwriting
216 % package option)
217 % \item[\texttt{textcolor}=\meta{value}] one or more commands for recoloring
218 % the text in \LaTeX{} part (e.\,g., |textcolor=\color{red}| for red text
219 % or |textcolor={}| for default text color of graphics overwriting
220 % package option)
221 % \item[\texttt{vecscale}=\meta{value}] scaling factor for rescaling the
222 % graphics without affecting the font of the \LaTeX{} part
223 % (Note that this will overwrite |vecwidth| or |vecheight|, if they are
224 % specified before.)
225 % \item[\texttt{vecwidth}=\meta{value}] analogous to |vecscale|, but
226 % the scaling factor will be calculated such that the new width of the
227 % total graphics will be \meta{value}; the aspect ratio will be preserved
228 % (Note that this will overwrite |vecscale| or |vecheight|, if they are
229 % specified before.)
230 % \item[\texttt{vecheight}=\meta{value}] analogous to |vecscale|, but
231 % the scaling factor will be calculated such that the new (total) height of
232 % the total graphics will be \meta{value}; the aspect ratio will be
233 % preserved
234 % (Note that this will overwrite |vecscale| or |vecwidth|, if they are
235 % specified before.)
236 % \item[\texttt{vecinclude}=\meta{value}] generate code to include the vector
237 % graphics part; \meta{value}s are: |auto| to automatically determine if
238 % code is required (default), |true|/|false| to always/never generate
239 % that code, or |overwrite| to disable any inclusion of a vector graphics
240 % part in the \LaTeX{} part and generate new code
241 % \item[\texttt{vecfirst}=\meta{value}] inclusion order of vector
242 % graphics part; valid \meta{value}s are: |true| (default) or |false| to
243 % include the vector graphics part before or after the \LaTeX{} part,
244 % respectively
245 % \item[\texttt{vecfile}=\meta{value}] filename of vector graphics part, if
246 % different from filename of \LaTeX{} part (except for extension); implies
247 % |vecinclude=overwrite|
248 % \end{mydescription}
249 %
250 % Note: If the vector graphics part is already included by the \LaTeX{} part,
251 % |vecinclude| and |vecscale| will require the vector graphics part to be
252 % included by an |\includegraphics| command for proper functioning. Other
253 % graphics inclusion macros will not be detected. Furthermore,
254 % |vecscale| also requires that the \LaTeX{} part puts its text inside a
255 % |picture| environment whose scaling is set with
256 % |\setlength{\unitlength}|\marg{some length}. These two prerequisites are
257 % fulfilled by graphics exported from Gnuplot and Xfig.
258 %
259 % \subsection{Extended macro options}
260 %
261 % The following options are processed \emph{after} the basic options \emph{in
262 % the order} of their appearances and affect the \emph{whole} graphics
263 % (\LaTeX{} and vector graphics part). They may be specified several times.
264 %
265 % \subsubsection*{Rotating}
266 %
267 % Rotating is basically performed with the means of |\rotatebox| from the
268 % \textsf{graphics}/\textsf{graphicx} package.
269 %
270 % \begin{mydescription}
271 % \item[\texttt{angle}=\meta{value}] angle of rotation
272 % \end{mydescription}
273 %
274 % The following options can be used to fine adjust the effect of a rotation and
275 % apply to only the next |angle| value specified in the options list.
276 %
277 % \begin{mydescription}
278 % \item[\texttt{origin}=\meta{value}] up to two of |lrctbB| (|B| stands for
279 % the baseline)
280 % \item[\texttt{x}=\meta{value}] the |x| coordinate of the center of rotation
281 % \item[\texttt{y}=\meta{value}] the |y| coordinate of the center of rotation
282 % \item[\texttt{units}=\meta{value}] units of rotation angle (e.\,g., |-360|
283 % denotes clockwise rotation)
284 % \end{mydescription}
285 %
286 % \subsubsection*{Rescaling}
287 %
288 % Rescaling is performed with the means of |\scalebox| from the
289 % \textsf{graphics} package.
290 %
291 % \begin{mydescription}
292 % \item[\texttt{scale}=\meta{value}] scaling factor
293 % \item[\texttt{hscale}=\meta{value}] horizontal scaling factor
294 % \item[\texttt{vscale}=\meta{value}] vertical scaling factor
295 % \end{mydescription}
296 %
297 % Note: A scaling via |hscale| and |vscale| will only be performed, if a pair
298 % of both values is specified.
299 %
300 % \subsubsection*{Resizing}
301 %
302 % Resizing is performed with the means of |\resizebox| from the
303 % \textsf{graphics} package.
304 %
305 % \begin{mydescription}
306 % \item[\texttt{height}=\meta{value}] height of graphics
307 % \item[\texttt{totalheight}=\meta{value}] height + depth of graphics
308 % \item[\texttt{width}=\meta{value}] width of graphics
309 % \item[\texttt{keepaspectratio}] if only one of the values
310 % for |height|/|totalheight| or |width| is specified, the other one will
311 % be calculated to keep the aspect ratio
312 % \end{mydescription}
313 %
314 % Note: Resizing will only be performed, if a pair of |height|/|totalheight|
315 % and |width| is specified or one of them is specified followed by
316 % |keepaspectratio|.
317 %
318 % \subsection{Package options}
319 %
320 % The following options can be passed to the package as defaults for the
321 % macro options. If an option is specified several times, the last appearance
322 % will overwrite the previous ones.
323 %
324 % \begin{mydescription}
325 % \item[\texttt{textfontcmd}=\meta{value}] name of a command (\emph{without}
326 % leading backslash) for reformatting text in \LaTeX{} part
327 % \item[\texttt{textcolorcmd}=\meta{value}] name of a command (\emph{without}
328 % leading backslash) for recoloring text in \LaTeX{} part
329 % \item[\texttt{vecscale}=\meta{value}] see section~\ref{sec:basic}
330 % \item[\texttt{vecwidth}=\meta{value}] see section~\ref{sec:basic}; in
331 % contrast to the macro options, you must not use a length as \meta{value}
332 % here (workaround: use |\the\somelength|)
333 % \item[\texttt{vecheight}=\meta{value}] see section~\ref{sec:basic}; in
334 % contrast to the macro options, you must not use a length as \meta{value}
335 % here (workaround: use |\the\somelength|)
336 % \item[\texttt{vecinclude}=\meta{value}] see section~\ref{sec:basic}
337 % \item[\texttt{vecfirst}=\meta{value}] see section~\ref{sec:basic}
338 % \end{mydescription}
339 %
340 % \section{Bugs, problems, and suggestions}
341 %
342 % Please report bugs and problems or send suggestions for this package to
343 % Christian Schneider. Check for updates before reporting bugs at the website
344 % mentioned above.
345 %
346 % \StopEventually{\PrintChanges\PrintIndex}
347 %
348 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
349 %
350 % \section{Implementation}
351 %
352 % Load required packages for graphics, color and \meta{key}|=|\meta{value}
353 % pairs:
354 % \begin{macrocode}
355 \RequirePackage{keyval}
356 \RequirePackage{graphicx}
357 \RequirePackage{color}
358 % \end{macrocode}
359 %
360 % \subsection{Package options}
361 %
362 % This |if| is required to remember the inclusion order. The macro specifies
363 % the package option from |vecscale|, |vecwidth|, |vecheight| used last.
364 % \begin{macrocode}
365 \newif\ifcgr@vecfirst
366 \def\cgr@vecscale@type{0}
367 % \end{macrocode}
368 %
369 % Definitions of package options as \meta{key}|=|\meta{value} pairs. The
370 % \meta{value}s are saved in the specified macros that are undefined by default.
371 % \begin{macrocode}
372 \newcommand*\cgr@defopts{\define@key{cgr}}
373 \newcommand*\cgr@setopts{\setkeys{cgr}}
374 \cgr@defopts{textfontcmd}{\gdef\cgr@textfont@default{\@nameuse{#1}}}
375 \cgr@defopts{textcolorcmd}{\gdef\cgr@textcolor@default{\@nameuse{#1}}}
376 \cgr@defopts{vecscale}{\gdef\cgr@vecscale@default{#1}%
377 \gdef\cgr@vecscale@type{0}}
378 \cgr@defopts{vecwidth}{\gdef\cgr@vecwidth@default{#1}%
379 \gdef\cgr@vecscale@type{1}}
380 \cgr@defopts{vecheight}{\gdef\cgr@vecheight@default{#1}%
381 \gdef\cgr@vecscale@type{2}}
382 \cgr@defopts{vecinclude}{\gdef\cgr@vecinclude@default{#1}}
383 \cgr@defopts{vecfirst}{\gdef\cgr@vecfirst@default{#1}}
384 % \end{macrocode}
385 %
386 % Next the package options are processed.
387 % \begin{macrocode}
388 \DeclareOption*{%
389 \expandafter\cgr@setopts\expandafter{\CurrentOption}%
390 }
391 \ProcessOptions\relax
392 % \end{macrocode}
393 %
394 % \subsection{Basic macro options}
395 %
396 % Now the \meta{key}|=|\meta{value} pairs for the optional argument of
397 % |\includecombinedgraphics| are defined. The following two macro are just
398 % shortcuts for this purpose.
399 % \begin{macrocode}
400 \newcommand*\cgr@defopts@combgrphcs{\define@key{cgr@combgrphcs}}
401 \newcommand*\cgr@setopts@combgrphcs{\setkeys{cgr@combgrphcs}}
402 % \end{macrocode}
403 %
404 % The basic macro options set some macros that are executed while tinkering the
405 % graphics from its two parts.
406 %
407 % |textfont| and |textcolor| set |\cgr@textfont| and |\cgr@textcolor| macro,
408 % respectively, that will be applied to the text in the \LaTeX{} part of
409 % graphics \emph{and} disable further formatting of fonts and colors inside the
410 % \LaTeX{} part by overwriting some macros afterwards (if not empty).
411 % \begin{macrocode}
412 \cgr@defopts@combgrphcs{textfont}{%
413 \def\@tempa{#1}%
414 \ifx\@tempa\@empty%
415 \def\cgr@textfont{}%
416 \else%
417 \def\cgr@textfont{%
418 #1%
419 \def\SetFigFont{\cgr@gobblefive}% %% Xfig <= 3.2.4
420 \def\SetFigFontNFSS{\cgr@gobblefive}% %% Xfig >= 3.2.5-alpha
421 }%
422 \fi%
423 }
424 \cgr@defopts@combgrphcs{textcolor}{%
425 \def\@tempa{#1}%
426 \ifx\@tempa\@empty%
427 \def\cgr@textcolor{}%
428 \else%
429 \def\cgr@textcolor{%
430 #1%
431 \def\color{\cgr@gobble@optone}%
432 }%
433 \fi%
434 }
435 % \end{macrocode}
436 %
437 % |vecscale| sets the macro |\cgr@vecscale| to the scaling factor. Furthermore,
438 % it overwrites |\setlength| and |\includegraphics| in order to apply the
439 % scaling factor to the |picture| environment inside the \LaTeX{} part (via
440 % |\setlength{\unitlength}...|) and to the |\includegraphics| command for
441 % inclusion of the vector graphics part, respectively.
442 % \begin{macrocode}
443 \cgr@defopts@combgrphcs{vecscale}{%
444 \def\cgr@vecscale{#1}%
445 \def\setlength{\cgr@setlength}%
446 \def\includegraphics{\cgr@includegraphics}%
447 }
448 % \end{macrocode}
449 %
450 % |vecwidth| and |vecheight|, respectively, calculate the scaling factor for
451 % |vecscale| such that the width or (total) height of the vector graphics part
452 % equals the specified \meta{dimen}. |\vecscale| is set to |-1| to indicate
453 % that the factor shall be calculated.
454 % \begin{macrocode}
455 \cgr@defopts@combgrphcs{vecwidth}{%
456 \cgr@vecscale@wd{\cgr@texfile}{\cgr@vecfile}{#1}%
457 \def\setlength{\cgr@setlength}%
458 \def\includegraphics{\cgr@includegraphics}%
459 }
460 \cgr@defopts@combgrphcs{vecheight}{%
461 \cgr@vecscale@ht{\cgr@texfile}{\cgr@vecfile}{#1}%
462 \def\setlength{\cgr@setlength}%
463 \def\includegraphics{\cgr@includegraphics}%
464 }
465 % \end{macrocode}
466 %
467 % |vecinclude| switches between the different \meta{value}s by setting
468 % |\cgr@vecinclude| to one of the for macros
469 % |\cgr@requires@graphics|\meta{value}.
470 % \begin{macrocode}
471 \cgr@defopts@combgrphcs{vecinclude}{%
472 \def\cgr@vecinclude{\@nameuse{cgr@requires@graphics#1}}%
473 }
474 % \end{macrocode}
475 %
476 % |vecfirst| switches between the \meta{value}s |true| and |false| by setting
477 % |\cgr@vecfirsttrue| or |\cgr@vecfirstfalse|, respectively.
478 % \begin{macrocode}
479 \cgr@defopts@combgrphcs{vecfirst}{%
480 \@nameuse{cgr@vecfirst#1}%
481 }
482 % \end{macrocode}
483 %
484 % |vecfile| resets |\cgr@vecfile| that defaults to the mandatory argument of
485 % |\includecombinedgraphics| to something else \emph{and} sets |vecinclude| to
486 % |overwrite|.
487 % \begin{macrocode}
488 \cgr@defopts@combgrphcs{vecfile}{%
489 \def\cgr@vecfile{#1}%
490 \cgr@setopts@combgrphcs{vecinclude=overwrite}%
491 }
492 % \end{macrocode}
493 %
494 % \subsection{Extended macro options}
495 %
496 % |\includecombinedgraphics| first tinkers the graphics applying the basic macro
497 % options and saves the result in |\cgr@curr@pic|. The extended macro options
498 % will redefine |\cgr@curr@pic| in the order of their occurance and put a
499 % |\rotatebox|, |\scalebox| or |\resizebox| around it, if all information is
500 % already available to do so: |\cgr@curr@pic|
501 % $\rightarrow$ |\...box{\cgr@curr@pic}|. Otherwise the \meta{value} will be
502 % saved in a macro for later processing (e.\,g., if |hscale| is set without
503 % |vscale| being set before).
504 %
505 % \begin{macrocode}
506 \cgr@defopts@combgrphcs{angle}{%
507 \ifx\cgr@curr@scaleopts\@empty%
508 \cgr@raddto@macro[groupfirst]{\cgr@curr@pic}{\rotatebox{#1}}%
509 \else%
510 \cgr@raddto@macro[groupfirst]{\cgr@curr@pic}{]}%
511 \cgr@raddto@macro[expand]{\cgr@curr@pic}{\cgr@curr@scaleopts}%
512 \cgr@raddto@macro{\cgr@curr@pic}{\rotatebox[}%
513 \def\cgr@curr@scaleopts{}%
514 \fi%
515 }
516 \cgr@defopts@combgrphcs{origin}{\cgr@addto@macro{\cgr@curr@scaleopts}{%
517 origin=#1,}%
518 }
519 \cgr@defopts@combgrphcs{x}{\cgr@addto@macro{\cgr@curr@scaleopts}{x=#1,}}
520 \cgr@defopts@combgrphcs{y}{\cgr@addto@macro{\cgr@curr@scaleopts}{y=#1,}}
521 \cgr@defopts@combgrphcs{units}{\cgr@addto@macro{\cgr@curr@scaleopts}{units=#1,}}
522 \cgr@defopts@combgrphcs{scale}{%
523 \cgr@raddto@macro[groupfirst]{\cgr@curr@pic}{\scalebox{#1}}%
524 }
525 \cgr@defopts@combgrphcs{hscale}{%
526 \def\cgr@curr@hscale{#1}%
527 \ifx\cgr@curr@vscale\@empty%
528 \else%
529 \cgr@raddto@macro[groupfirst]{\cgr@curr@pic}{]}%
530 \cgr@raddto@macro[expand]{\cgr@curr@pic}{\cgr@curr@vscale}%
531 \cgr@raddto@macro{\cgr@curr@pic}{[}%
532 \cgr@raddto@macro[expand,groupsecond]{\cgr@curr@pic}{\cgr@curr@hscale}%
533 \cgr@raddto@macro{\cgr@curr@pic}{\scalebox}%
534 \def\cgr@curr@hscale{}%
535 \def\cgr@curr@vscale{}%
536 \fi%
537 }
538 \cgr@defopts@combgrphcs{vscale}{%
539 \def\cgr@curr@vscale{#1}%
540 \ifx\cgr@curr@hscale\@empty%
541 \else%
542 \cgr@raddto@macro[groupfirst]{\cgr@curr@pic}{]}%
543 \cgr@raddto@macro[expand]{\cgr@curr@pic}{\cgr@curr@vscale}%
544 \cgr@raddto@macro{\cgr@curr@pic}{[}%
545 \cgr@raddto@macro[expand,groupsecond]{\cgr@curr@pic}{\cgr@curr@hscale}%
546 \cgr@raddto@macro{\cgr@curr@pic}{\scalebox}%
547 \def\cgr@curr@hscale{}%
548 \def\cgr@curr@vscale{}%
549 \fi%
550 }
551 \cgr@defopts@combgrphcs{height}{%
552 \def\cgr@curr@height{#1}%
553 \ifx\cgr@curr@width\@empty%
554 \else%
555 \cgr@raddto@macro[groupfirst,groupsecond,expand]{\cgr@curr@pic}{%
556 \cgr@curr@height%
557 }%
558 \cgr@raddto@macro[groupsecond,expand]{\cgr@curr@pic}{\cgr@curr@width}%
559 \cgr@raddto@macro{\cgr@curr@pic}{\resizebox}%
560 \def\cgr@curr@height{}%
561 \def\cgr@curr@width{}%
562 \fi%
563 }
564 \cgr@defopts@combgrphcs{totalheight}{%
565 \def\cgr@curr@totalheight{#1}%
566 \ifx\cgr@curr@width\@empty%
567 \else%
568 \cgr@raddto@macro[groupfirst,groupsecond,expand]{\cgr@curr@pic}{%
569 \cgr@curr@totalheight%
570 }%
571 \cgr@raddto@macro[groupsecond,expand]{\cgr@curr@pic}{\cgr@curr@width}%
572 \cgr@raddto@macro{\cgr@curr@pic}{\resizebox*}%
573 \def\cgr@curr@totalheight{}%
574 \def\cgr@curr@width{}%
575 \fi%
576 }
577 \cgr@defopts@combgrphcs{width}{%
578 \def\cgr@curr@width{#1}%
579 \ifx\cgr@curr@height\@empty%
580 \ifx\cgr@curr@totalheight\@empty%
581 \else%
582 \cgr@raddto@macro[groupfirst,groupsecond,expand]{\cgr@curr@pic}{%
583 \cgr@curr@totalheight%
584 }%
585 \cgr@raddto@macro[groupsecond,expand]{\cgr@curr@pic}{\cgr@curr@width}%
586 \cgr@raddto@macro{\cgr@curr@pic}{\resizebox*}%
587 \def\cgr@curr@totalheight{}%
588 \def\cgr@curr@width{}%
589 \fi%
590 \else%
591 \cgr@raddto@macro[groupfirst,groupsecond,expand]{\cgr@curr@pic}{%
592 \cgr@curr@height%
593 }%
594 \cgr@raddto@macro[groupsecond,expand]{\cgr@curr@pic}{\cgr@curr@width}%
595 \cgr@raddto@macro{\cgr@curr@pic}{\resizebox}%
596 \def\cgr@curr@height{}%
597 \def\cgr@curr@totalheight{}%
598 \def\cgr@curr@width{}%
599 \fi%
600 }
601 \cgr@defopts@combgrphcs{keepaspectratio}[]{%
602 \ifx\cgr@curr@height\@empty%
603 \ifx\cgr@curr@totalheight\@empty%
604 \ifx\cgr@curr@width\@empty%
605 \else%
606 \cgr@setopts@combgrphcs{height=!}%
607 \fi%
608 \else%
609 \cgr@setopts@combgrphcs{width=!}%
610 \fi%
611 \else%
612 \cgr@setopts@combgrphcs{width=!}%
613 \def\cgr@curr@totalheight{}%
614 \fi%
615 }
616 % \end{macrocode}
617 %
618 % \subsection{The macro}
619 %
620 % First of all, |\cgr@curr@pic| and the |\cgr@requires@graphics...| macros are
621 % initialized.
622 % \begin{macrocode}
623 \long\def\cgr@curr@pic{}
624 \newif\ifcgr@requires@graphics\cgr@requires@graphicstrue
625 \def\cgr@requires@graphicsauto{}
626 \def\cgr@requires@graphicsoverwrite{%
627 \cgr@requires@graphicstrue%
628 \def\includegraphics{\cgr@gobble@optone}%
629 }
630 % \end{macrocode}
631 %
632 % Now the macros and |if| for the basic macro options and for temporarily saving
633 % \meta{value}s of the extended macro options are initialized.
634 % \begin{macrocode}
635 \def\cgr@textfont{}
636 \def\cgr@textcolor{}
637 \def\cgr@vecscale{1}
638 \def\cgr@vecinclude{\cgr@requires@graphicsauto}
639 \cgr@vecfirsttrue
640 \def\cgr@texfile{}
641 \def\cgr@vecfile{}
642 \def\cgr@curr@hscale{}
643 \def\cgr@curr@vscale{}
644 \def\cgr@curr@scaleopts{}
645 \def\cgr@curr@height{}
646 \def\cgr@curr@width{}
647 \def\cgr@curr@totalheight{}
648 % \end{macrocode}
649 %
650 % At this point the macro itself is defined.
651 % \begin{macrocode}
652 \newcommand{\includecombinedgraphics}[2][]{%
653 \begingroup%
654 % \end{macrocode}
655 %
656 % To get to know, whether the vector graphics are already included in the
657 % \LaTeX{} parts or not, a check for an appearance of |\includegraphics| in the
658 % \LaTeX{} part is performed: the \LaTeX{} parts are expanded inside a box with
659 % |\includegraphics| being redefined to set an appropriate conditional (and eat
660 % the arguments of |\includegraphics|).
661 % \begin{macrocode}
662 \global\cgr@requires@graphicstrue%
663 \setbox\@tempboxa\hbox{%
664 \def\includegraphics{%
665 \global\cgr@requires@graphicsfalse\cgr@gobble@optone%
666 }%
667 \input{#2}%
668 }%
669 % \end{macrocode}
670 %
671 % Now the the macros resulting from the basic macro options, the vector
672 % graphics part and the \LaTeX{} part are added to the (empty) |\cgr@curr@pic|
673 % macro. We have to distinguish between two cases:
674 % (1) If the vector graphics part is included before the \LaTeX{} part
675 % (|vecfirst=true|), the vector graphics file will simply be loaded by
676 % |\includegraphics| inside a picture environment followed by the \LaTeX{} part
677 % included by |\input|. (2) If the vector graphics part is included after the
678 % \LaTeX{} part (|vecfirst=false|), the |\includegraphics| macro will be put
679 % inside the |picture| environment of the \LaTeX{} part at the offset position
680 % passed to the |picture| environment. Therefore, we will have to wrap the
681 % |\picture| macro to gain access to the offsets passed to the |picture|
682 % environment in the \LaTeX{} part and wrap the |\endpicture| macro to add
683 % |\includegraphics| into this |picture| environment.
684 % \begin{macrocode}
685 \cgr@addto@macro{\cgr@curr@pic}{%
686 %% from basic macro options
687 \cgr@vecinclude\cgr@textfont\cgr@textcolor%
688 %% inclusion of vector graphics part
689 \ifcgr@requires@graphics%
690 \ifcgr@vecfirst%
691 \begin{picture}(0,0)%
692 \cgr@includegraphics@orig[scale=\cgr@vecscale]{\cgr@vecfile}%
693 \end{picture}%
694 \else%
695 \def\picture{\cgr@picture}%
696 \def\endpicture{%
697 \put(\cgr@picture@xoffs,\cgr@picture@yoffs)%
698 {\cgr@includegraphics@orig[scale=\cgr@vecscale]{\cgr@vecfile}}%
699 \cgr@endpicture@orig%
700 }%
701 \fi%
702 \fi%
703 %% inclusion of \LaTeX{} part
704 \input{#2}%
705 }%
706 % \end{macrocode}
707 %
708 % Afterwards, a macro containing the name of the \LaTeX{} and vector graphics
709 % part, respectively, is initialized.
710 % \begin{macrocode}
711 \def\cgr@vecfile{#2}%
712 \def\cgr@texfile{#2}%
713 % \end{macrocode}
714 %
715 % If set, the package options will be processed. (Suggestions for easier
716 % handling of package options are welcome.)
717 % \begin{macrocode}
718 \if0\cgr@vecscale@type%
719 \@ifundefined{cgr@vecscale@default}{}{%
720 \cgr@setopts@combgrphcs{vecscale=\cgr@vecscale@default}%
721 }%
722 \fi%
723 \if1\cgr@vecscale@type%
724 \@ifundefined{cgr@vecwidth@default}{}{%
725 \cgr@setopts@combgrphcs{vecwidth=\cgr@vecwidth@default}%
726 }%
727 \fi%
728 \if2\cgr@vecscale@type%
729 \@ifundefined{cgr@vecheight@default}{}{%
730 \cgr@setopts@combgrphcs{vecheight=\cgr@vecheight@default}%
731 }%
732 \fi%
733 \@ifundefined{cgr@textfont@default}{}{%
734 \cgr@setopts@combgrphcs{textfont=\cgr@textfont@default}%
735 }%
736 \@ifundefined{cgr@textcolor@default}{}{%
737 \cgr@setopts@combgrphcs{textcolor=\cgr@textcolor@default}%
738 }%
739 \@ifundefined{cgr@vecinclude@default}{}{%
740 \cgr@setopts@combgrphcs{vecinclude=\cgr@vecinclude@default}%
741 }%
742 \@ifundefined{cgr@vecfirst@default}{}{%
743 \cgr@setopts@combgrphcs{vecfirst=\cgr@vecfirst@default}%
744 }%
745 % \end{macrocode}
746 %
747 % Now, the options passed the the macro are processed.
748 % \begin{macrocode}
749 \cgr@setopts@combgrphcs{#1}%
750 % \end{macrocode}
751 %
752 % Finally, the macro |\cgr@curr@pic| is complete and can be output.
753 % \begin{macrocode}
754 \cgr@curr@pic%
755 \endgroup%
756 }
757 % \end{macrocode}
758 %
759 % \subsection{Helper macros}
760 %
761 % This macro eats five arguments (analogous to |\@gobble| or |\@gobbletwo| from
762 % the \LaTeX{} kernel).
763 % \begin{macrocode}
764 \long\def\cgr@gobblefive#1#2#3#4#5{}
765 % \end{macrocode}
766 %
767 % This macro eats all stars (if any), all arguments in square brackets (if any)
768 % and one mandatory argument.
769 % \begin{macrocode}
770 \long\def\cgr@gobble@optone{\@ifstar{\cgr@gobble@optone}{\cgr@gobble@optone@}}
771 \long\def\cgr@gobble@optone@{\@ifnextchar [{\cgr@gobble@optone@@}{\@gobble}}
772 \long\def\cgr@gobble@optone@@[#1]{\cgr@gobble@optone@}
773 % \end{macrocode}
774 %
775 % In order to rescale the |picture| environment inside the \LaTeX{} part, the
776 % |\setlength{\unitlength}{|\meta{some dimen}|}| must be changed to scale
777 % \meta{some dimen} by |\cgr@vecscale| at its first appearance in the \LaTeX{}
778 % part. This is the |\setlength| substitute to do so.
779 % \begin{macrocode}
780 \let\cgr@setlength@orig=\setlength
781 \def\cgr@setlength#1#2{%
782 \ifx#1\unitlength%
783 \@tempdima=#2%
784 \cgr@setlength@orig{#1}{\cgr@vecscale\@tempdima}%
785 \def\setlength{\cgr@setlength@orig}%
786 \else%
787 \cgr@setlength@orig{#1}{#2}%
788 \fi%
789 }
790 % \end{macrocode}
791 %
792 % Additionally, a |scale=\cgr@vecscale| option must be passed to the
793 % |\includegraphics| macro inside the \LaTeX{} part. This is the substitute of
794 % |\includegraphics| for this purpose.
795 % \begin{macrocode}
796 \let\cgr@includegraphics@orig=\includegraphics
797 \def\cgr@includegraphics{%
798 \@ifstar{%
799 \cgr@includegraphics@s@%
800 }{%
801 \cgr@includegraphics@%
802 }%
803 }
804 \def\cgr@includegraphics@{%
805 \@ifnextchar [{%
806 \cgr@includegraphics@@%
807 }{%
808 \cgr@includegraphics@orig[scale=\cgr@vecscale]%
809 }%
810 }
811 \def\cgr@includegraphics@@[#1]{%
812 \@ifnextchar [{%
813 \cgr@includegraphics@@@[#1]%
814 }{%
815 \cgr@includegraphics@orig[#1,scale=\cgr@vecscale]%
816 }%
817 }
818 \def\cgr@includegraphics@@@[#1][#2]{%
819 \cgr@includegraphics@orig[#1][#2,scale=\cgr@vecscale]%
820 }
821 \def\cgr@includegraphics@s@{%
822 \@ifnextchar [{%
823 \cgr@includegraphics@s@@%
824 }{%
825 \cgr@includegraphics@orig*[scale=\cgr@vecscale]%
826 }%
827 }
828 \def\cgr@includegraphics@s@@[#1]{%
829 \@ifnextchar [{%
830 \cgr@includegraphics@s@@@[#1]%
831 }{%
832 \cgr@includegraphics@orig*[#1,scale=\cgr@vecscale]%
833 }%
834 }
835 \def\cgr@includegraphics@s@@@[#1][#2]{%
836 \cgr@includegraphics@orig*[#1][#2,scale=\cgr@vecscale]%
837 }
838 % \end{macrocode}
839 %
840 % To play the trick of including the vector graphics part after the \LaTeX{}
841 % part (|vecfirst=false|), we need to know the offset passed to the picture
842 % environment in the \LaTeX{} part. Therefore, the |\picture| macro is
843 % redefined.
844 % \begin{macrocode}
845 \let\cgr@picture@orig=\picture
846 \let\cgr@endpicture@orig=\endpicture
847 \long\def\cgr@picture(#1,#2){%
848 \@ifnextchar({%
849 \cgr@picture@(#1,#2)%
850 }{%
851 \cgr@picture@(#1,#2)(0,0)%
852 }%
853 }
854 \def\cgr@picture@(#1,#2)(#3,#4){%
855 \def\cgr@picture@xoffs{#3}%
856 \def\cgr@picture@yoffs{#4}%
857 \cgr@picture@orig(#1,#2)(#3,#4)%
858 }
859 % \end{macrocode}
860 %
861 % This macro is identical to |\l@addto@macro| from \textsf{koma-script bundle}.
862 % It adds the stuff passed to its second argument to the end of the macro from
863 % its first argument.
864 % \begin{macrocode}
865 \newcommand{\cgr@addto@macro}[2]{%
866 \begingroup\toks@\expandafter{#1#2}%
867 \edef\@tempa{\endgroup\def\noexpand#1{\the\toks@}}%
868 \@tempa%
869 }
870 % \end{macrocode}
871 %
872 % The next macro is similar, but adds the stuff passed to its second argument
873 % to the \emph{beginning} of the macro from its first argument. An optional
874 % argument allows for fine tuning: A comma-separated list containing |expand|
875 % (expands the stuff from the second argument before adding it), |groupfirst|,
876 % and/or |groupsecond| (puts the stuff from the first/second argument in
877 % braces before adding) may be passed.
878 % \begin{macrocode}
879 \newcommand*\cgr@defopts@raddto{\define@key{cgr@raddto}}
880 \newcommand*\cgr@setopts@raddto{\setkeys{cgr@raddto}}
881 \newif\ifcgr@raddto@expand\cgr@raddto@expandfalse
882 \newif\ifcgr@raddto@groupfirst\cgr@raddto@groupfirstfalse
883 \newif\ifcgr@raddto@groupsecond\cgr@raddto@groupsecondfalse
884 \cgr@defopts@raddto{expand}[true]{\@nameuse{cgr@raddto@expand#1}}
885 \cgr@defopts@raddto{groupfirst}[true]{\@nameuse{cgr@raddto@groupfirst#1}}
886 \cgr@defopts@raddto{groupsecond}[true]{\@nameuse{cgr@raddto@groupsecond#1}}
887 \newtoks\cgr@token@a
888 \newtoks\cgr@token@b
889 \newcommand{\cgr@raddto@macro}[3][]{%
890 \begingroup%
891 \cgr@setopts@raddto{#1}%
892 \cgr@token@a\expandafter{#2}%
893 \ifcgr@raddto@expand%
894 \cgr@token@b\expandafter{#3}%
895 \else%
896 \cgr@token@b{#3}%
897 \fi%
898 \ifcgr@raddto@groupfirst%
899 \ifcgr@raddto@groupsecond%
900 \edef\@tempa{\endgroup%
901 \def\noexpand#2{{\the\cgr@token@b}{\the\cgr@token@a}}%
902 }%
903 \else%
904 \edef\@tempa{\endgroup%
905 \def\noexpand#2{\the\cgr@token@b{\the\cgr@token@a}}%
906 }%
907 \fi%
908 \else%
909 \ifcgr@raddto@groupsecond%
910 \edef\@tempa{\endgroup%
911 \def\noexpand#2{{\the\cgr@token@b}\the\cgr@token@a}%
912 }%
913 \else%
914 \edef\@tempa{\endgroup%
915 \def\noexpand#2{\the\cgr@token@b\the\cgr@token@a}%
916 }%
917 \fi%
918 \fi%
919 \@tempa%
920 }
921 % \end{macrocode}
922 %
923 % The way of calculating the scaling factor for |vecwidth| and |vecheight| is
924 % a simplified and adapted version of |\ratio| from the |calc.sty| package.
925 % First, the width or (total) height of the original graphics part is measured.
926 % In order to do this, the graphics are put into a box.
927 % Afterwards, the places before the decimal point are calculated by \TeX{}'s
928 % built-in integer division. Finally, the decimal places are calculated with
929 % an algorithm as division has been taught at school.
930 % \begin{macrocode}
931 \newcount\cgr@tempdigit
932 \newcommand*\cgr@vecscale@wd[3]{%
933 \cgr@vecscale@graphicsbox{#1}{#2}%
934 \cgr@vecscale@calc{\wd\@tempboxa}{#3}%
935 }
936 \newcommand*\cgr@vecscale@ht[3]{%
937 \cgr@vecscale@graphicsbox{#1}{#2}%
938 \@tempdimc=\ht\@tempboxa%
939 \advance\@tempdimc by\dp\@tempboxa%
940 \cgr@vecscale@calc{\@tempdimc}{#3}%
941 }
942 \newcommand*\cgr@vecscale@graphicsbox[2]{%
943 \setbox\@tempboxa\hbox{%
944 \begingroup%
945 \def\setlength{\cgr@setlength@orig}%
946 \def\includegraphics{\cgr@gobble@optone}%
947 \input{#1}%
948 \endgroup%
949 }%
950 }
951 \newcommand*\cgr@vecscale@calc[2]{%
952 \@tempdimb=#1%
953 \@tempcntb=\@tempdimb%
954 \@tempdima=#2%
955 \@tempcnta=\@tempdima%
956 \cgr@tempdigit=\@tempcnta%
957 \divide\cgr@tempdigit by\@tempcntb%
958 \edef\cgr@vecscale{\the\cgr@tempdigit.}%
959 \cgr@next@digit\cgr@next@digit\cgr@next@digit%
960 \cgr@next@digit\cgr@next@digit\cgr@next@digit%
961 }
962 \newcommand*\cgr@next@digit{%
963 \multiply\cgr@tempdigit by\@tempcntb%
964 \advance\@tempcnta by-\cgr@tempdigit%
965 \multiply\@tempcnta by10%
966 \cgr@tempdigit=\@tempcnta%
967 \divide\cgr@tempdigit by\@tempcntb%
968 \edef\cgr@vecscale{\cgr@vecscale\the\cgr@tempdigit}%
969 }
970 % \end{macrocode}
971 %
972 % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
973 %
974 % \Finale
975 %
976 \endinput