Debian Codegraph @

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

raw
1 % \iffalse meta-comment
2 %
3 % Copyright (C) 2007, 2017-2022 by Rolf Niepraschk
4 % ---------------------------------------------------------------------------
5 % This work may be distributed and/or modified under the
6 % conditions of the LaTeX Project Public License, either version 1.3
7 % of this license or (at your option) any later version.
8 % The latest version of this license is in
9 % http://www.latex-project.org/lppl.txt
10 % and version 1.3 or later is part of all distributions of LaTeX
11 % version 2005/12/01 or later.
12 %
13 % This work has the LPPL maintenance status `maintained'.
14 %
15 % The Current Maintainer of this work is Rolf Niepraschk.
16 %
17 % This work consists of the files blowup.dtx and blowup.ins
18 % and the derived filebase blowup.sty.
19 %
20 % \fi
21 %
22 % \iffalse
23 %<*driver>
24 \ProvidesFile{blowup.dtx}
25 %</driver>
26 %<package>\NeedsTeXFormat{LaTeX2e}[2020/10/01]
27 %<package>\ProvidesPackage{blowup}[2023/07/15 2.2.0 Page scaling (RN)]
28 %
29 %<*driver>
30 \documentclass{ltxdoc}
31 \usepackage{blowup,array,longtable,ragged2e}
32 \let\RaggedRight=\raggedright
33 \newcommand{\m}[1]{\mbox{$\langle$\it #1\/$\rangle$}}
34 \renewcommand{\arg}[1]{{\ttfamily\string{}\m{#1}{\ttfamily\string}}}
35 \EnableCrossrefs
36 \CodelineIndex
37 \RecordChanges
38 \begin{document}
39 \DocInput{blowup.dtx}
40 \PrintChanges
41 \PrintIndex
42 \end{document}
43 %</driver>
44 % \fi
45 %
46 % \CheckSum{546}
47 %
48 % \CharacterTable
49 % {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
50 % 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
51 % Digits \0\1\2\3\4\5\6\7\8\9
52 % Exclamation \! Double quote \" Hash (number) \#
53 % Dollar \$ Percent \% Ampersand \&
54 % Acute accent \' Left paren \( Right paren \)
55 % Asterisk \* Plus \+ Comma \,
56 % Minus \- Point \. Solidus \/
57 % Colon \: Semicolon \; Less than \<
58 % Equals \= Greater than \> Question mark \?
59 % Commercial at \@ Left bracket \[ Backslash \\
60 % Right bracket \] Circumflex \^ Underscore \_
61 % Grave accent \` Left brace \{ Vertical bar \|
62 % Right brace \} Tilde \~}
63 %
64 %
65 % \changes{0.1a}{2007/08/14}{Initial version. (RN)}
66 % \changes{2.0.0}{2022/09/19}{Major parts rewritten. (RN)}
67 %
68 % \DoNotIndex{\newcommand,\newenvironment,\z@,\vskip,\hskip,\vss,\hss,\value,
69 % \the,\ifx,\if,\fi,ifdim,\ifodd,\else,\providecommand,\newif,\newlength,\noexpand,
70 % \let,\def,\gdef,\edef,\xdef,\kern,\string,\box,\copy,\csname,\endcsname,
71 % \begingroup,\endgroup,\expandafter,\relax,\@tempboxa,\@tempdima,\@tempdimb,
72 % \@empty,\@firstoftwo,\@ifundefined,\@nil,\@secondoftwo,\@tempswafalse,
73 % \@tempswatrue,\if@tempswa,\@for,\do,\ht,\wd,\dp,\g@addto@macro,\hbox,\vbox,
74 % \hb@xt@,\vb@xt@,\global,\l@addto@macro,\moveright,\BL@tempa,\BL@tempb}
75 %
76 % \providecommand*{\url}{\texttt}
77 % \GetFileInfo{blowup.sty}
78 % \title{The \textsf{blowup} package}
79 % \author{Rolf Niepraschk}
80 % \date{Version~\fileversion~(\filedate)}
81 %
82 % \maketitle
83 %
84 % \section{Introduction}
85 %
86 % This package only defines the user-level macro \cmd{\blowUp}, which can be
87 % used to scale all pages of a document up or down. It is similar to the \TeX\
88 % primitive \cmd{\mag}, but more accurate and user-friendly. \cmd{\blowUp} can
89 % be useful for creating posters from a normal sized document and for many other
90 % types of fine-tuning of a finished document (e.g., minor scaling changes and
91 % position of the pages).
92 %
93 % \section{Usage}
94 % The only user macro is \cmd{\blowUp}\arg{key=value}. Call it before
95 % |\begin{document}| to scale all pages of the document: \par \medskip\noindent
96 %
97 % \setlength\extrarowheight{.2ex}
98 % \newcolumntype{P}[1]{>{\RaggedRight\hspace{0pt}}p{#1}}
99 % \begin{longtable}{@{}lP{.75\linewidth}@{}}
100 % \multicolumn{1}{@{}l}{\textbf{key}} &
101 % \multicolumn{1}{l@{}}{\textbf{value}} \tabularnewline \hline
102 % target & The final paper size: \tabularnewline
103 % & |letter|, |legal|, |executive| or a paper size from the
104 % ISO/DIN paper series A, B, C, D
105 % (e.\,g., |a8|, |c7|,..., |b1|, |a0|) or a pair of dimensions
106 % in curly brackets (e.\,g., |target={925mm,1225mm}|) or the
107 % letter `x' followed by a scaling factor
108 % (e.\,g., |target=x1.414213|). \tabularnewline[.75ex]
109 % origin & Scaled size of the source document: \tabularnewline
110 % & |letter|, |legal|, |executive| or a paper size from the
111 % ISO/DIN paper series A, B, C, D
112 % (e.\,g., |a8|, |c7|,..., |b1|, |a0|) or a pair of dimensions
113 % in curly brackets (e.\,g., |origin={925mm,1225mm}|) or the
114 % letter `x' followed by a scaling factor
115 % (e.\,g., |origin=x1.414213|). \tabularnewline[.75ex]
116 % h-mirroring & horizontally mirroring of the final pages \tabularnewline
117 % & |true| (the same as no value) or |false| (default: |false|).
118 % \tabularnewline[.75ex]
119 % v-mirroring & vertically mirroring of the final pages \tabularnewline
120 % & |true| (the same as no value) or |false| (default: |false|).
121 % \tabularnewline[.75ex]
122 % landscape & Exchanges paperwidth and paperheight: \tabularnewline
123 % & |true| (the same as no value) or |false| (default: |false|).
124 % \tabularnewline[.75ex]
125 % noscale & No scaling of the original paper size: \tabularnewline
126 % & |true| (the same as no value) or |false| (default: |false|).
127 % \tabularnewline[.75ex]
128 % pos & Position of the page on the paper: \tabularnewline
129 % & |left| or |right|, |inside| or |outside|, |top| or |bottom|
130 % (only the first letter is significant; default is
131 % centering), or
132 % a pair of dimensions in curly brackets which means the offset
133 % from the lower left or lower outside corner of the final paper.
134 % Only meaningful for |noscale=true| and up-scaled paper
135 % size. \tabularnewline[.75ex]
136 % onepage & Suppresses the second page and all following pages:
137 % \tabularnewline
138 % & |true| (the same as no value) or |false| (default: |false|).
139 % \tabularnewline
140 % & Useful for creating a one-page document like a poster.
141 % \end{longtable}
142 % \vspace{0\baselineskip}
143 % See also the example documents |blowup-ex?.tex|.
144 %
145 % \StopEventually{}
146 %
147 % \section{Implementation}
148 %
149 % \iffalse
150 %<*package>
151 % \fi
152 %
153 % Load some packages for utility macros.
154 % \begin{macrocode}
155 \RequirePackage{keyval,graphics}
156 \@ifpackageloaded{typearea}{}{%
157 \newcommand*\BL@save@dimen[1]{%
158 \@ifundefined{BL@#1}{%
159 \expandafter\newlength\csname BL@#1\endcsname}{}%
160 \csname BL@#1\endcsname\csname #1\endcsname
161 \g@addto@macro\BL@restore@dimens{%
162 \csname #1\endcsname\csname BL@#1\endcsname}%
163 }%
164 % \end{macrocode}
165 % \begin{macro}{\BL@restore@dimens}
166 % Some dimensions changed by \textsf{typearea} must be saved and restored.
167 % \begin{macrocode}
168 \newcommand*\BL@restore@dimens{}%
169 % \end{macrocode}
170 % \end{macro}
171 % \begin{macrocode}
172 \BL@save@dimen{paperwidth}%
173 \BL@save@dimen{paperheight}%
174 \BL@save@dimen{textwidth}%
175 \BL@save@dimen{textheight}%
176 \BL@save@dimen{evensidemargin}%
177 \BL@save@dimen{oddsidemargin}%
178 \BL@save@dimen{topmargin}%
179 \BL@save@dimen{headheight}%
180 \BL@save@dimen{headsep}%
181 \BL@save@dimen{topskip}%
182 \BL@save@dimen{footskip}%
183 \BL@save@dimen{baselineskip}%
184 \let\l@addto@macro=\relax
185 \RequirePackage[pagesize=false]{typearea}%
186 \expandafter\let\csname [email protected]\endcsname=\relax
187 \BL@restore@dimens
188 \let\BL@save@dimen=\relax
189 \let\BL@restore@dimens=\relax
190 }
191 % \end{macrocode}
192 %
193 % \begin{macro}{\vb@xt@}
194 % Similar to \cmd{\hb@xt@}
195 % \begin{macrocode}
196 \providecommand*\vb@xt@{\vbox to}
197 % \end{macrocode}
198 % \end{macro}
199 % \begin{macro}{\tPaperWidth}
200 % \begin{macro}{\tPaperHeight}
201 % The size of the scaled final pages.
202 % \begin{macrocode}
203 \newlength\tPaperWidth
204 \newlength\tPaperHeight
205 % \end{macrocode}
206 % \end{macro}
207 % \end{macro}
208 % \begin{macro}{\oPaperWidth}
209 % \begin{macro}{\oPaperHeight}
210 % The size of the original pages.
211 % \begin{macrocode}
212 \newlength\oPaperWidth \oPaperWidth=\z@
213 \newlength\oPaperHeight \oPaperHeight=\z@
214 % \end{macrocode}
215 % \end{macro}
216 % \end{macro}
217 %
218 % \begin{macro}{\BL@resize}
219 % Resizes the shipout box.
220 % \begin{macrocode}
221 \newcommand*\BL@resize[1]{#1}
222 % \end{macrocode}
223 % \end{macro}
224 % \begin{macro}{\BL@scalePage}
225 % The whole scaling process of the the shipout box to the dimension of the
226 % new paper size.
227 % \changes{2.1.0}{2022/09/22}{New options `h-mirroring' and `v-mirroring' (RN)}
228 % \changes{2.2.0}{2023/07/15}{Using \LaTeX's \cmd{\ShipoutBox} (RN)}
229 % \begin{macrocode}
230 \newcommand*\BL@scalePage{%
231 % \end{macrocode}
232 % Normalize the shipout box
233 % \begin{macrocode}
234 \setbox\ShipoutBox=\vbox{%
235 \vskip1in\moveright1in\box\ShipoutBox}%
236 \setbox\ShipoutBox=\hb@xt@\paperwidth{%
237 \box\ShipoutBox\hss}%
238 \setbox\ShipoutBox=\vb@xt@\paperheight{%
239 \box\ShipoutBox\vss}%
240 \ifBL@noscale\else
241 \ifdim\oPaperWidth>\z@
242 \setbox\ShipoutBox=\hbox{\resizebox{\oPaperWidth}{\oPaperHeight}%
243 {\box\ShipoutBox}}%
244 \else
245 \def\BL@resize##1{\resizebox{\tPaperWidth}{!}{##1}}%
246 \setbox\@tempboxa=\hbox{\BL@resize{\copy\ShipoutBox}}%
247 \ifdim\ht\@tempboxa>\tPaperHeight
248 \def\BL@resize##1{\resizebox{!}{\tPaperHeight}{##1}}%
249 \fi
250 \fi
251 \fi
252 \setbox\@tempboxa=\vb@xt@\tPaperHeight{%
253 \kern\z@\BL@t
254 \hb@xt@\tPaperWidth{\BL@l\BL@resize{\box\ShipoutBox}\BL@r}%
255 \BL@b\kern\z@
256 }%
257 \ifBL@mirroring
258 \setbox\@tempboxa=\hbox{\scalebox{\BL@h}[\BL@v]{\box\@tempboxa}}%
259 \fi
260 % \end{macrocode}
261 % Denormalize the shipout box
262 % \begin{macrocode}
263 \setbox\ShipoutBox=\vbox{%
264 \vskip-1in\moveright-1in\box\@tempboxa}%
265 }
266 % \end{macrocode}
267 % \end{macro}
268 %
269 % \begin{macrocode}
270 \newcommand\BL@tempa{}
271 \newcommand\BL@tempb{}
272 \newcommand*\BL@strip@comma{}
273 \def\BL@strip@comma#1,{#1}
274 % \end{macrocode}
275 %
276 % \begin{macro}{\BL@is@dimen@pair}
277 % The parameter two will be executed if the first parameter is
278 % a comma-separated pair of two dimensions. If not the parameter three
279 % will be executed.
280 % \begin{macrocode}
281 \newcommand*\BL@is@dimen@pair[1]{%
282 \expandafter\BL@@is@dimen@pair#1,\@nil
283 }
284 \newcommand*\BL@@is@dimen@pair{}
285 \def\BL@@is@dimen@pair#1,#2\@nil{%
286 \edef\BL@tempa{#1}\edef\BL@tempb{#2}%
287 \@tempswafalse
288 \ifx\BL@tempb\@empty\else
289 \edef\BL@tempb{\expandafter\BL@strip@comma\BL@tempb}%
290 \ifdimen{\BL@tempa}{%
291 \ifdimen{\BL@tempb}{\@tempswatrue}{}%
292 }{}%
293 \fi
294 \if@tempswa
295 \expandafter\@firstoftwo
296 \else
297 \expandafter\@secondoftwo
298 \fi
299 }
300 % \end{macrocode}
301 % \end{macro}
302 %
303 % \begin{macrocode}
304 \newcommand*\BL@strip@x{}
305 \def\BL@strip@x#1x{#1}
306 % \end{macrocode}
307 %
308 % \begin{macro}{\BL@is@factor}
309 % The parameter two will be executed if the first parameter is the
310 % small letter x (`times') immediately followed by a number. If not
311 % the parameter three will be executed.
312 % \begin{macrocode}
313 \newcommand*\BL@is@factor[1]{%
314 \expandafter\BL@@is@factor#1x\@nil
315 }
316 \newcommand*\BL@@is@factor{}
317 \def\BL@@is@factor#1x#2\@nil{%
318 \edef\BL@tempa{#2}%
319 \@tempswafalse
320 \ifx\BL@tempa\@empty\else
321 \edef\BL@tempa{\expandafter\BL@strip@x\BL@tempa}%
322 \ifdimen{\BL@tempa pt}{\@tempswatrue}{}%
323 \fi
324 \if@tempswa
325 \expandafter\@firstoftwo
326 \else
327 \expandafter\@secondoftwo
328 \fi
329 }
330 % \end{macrocode}
331 % \end{macro}
332 %
333 %
334 % \begin{macro}{\BL@getDimens}
335 % Sets the two dimen registers (|#2| and |#3|) according to parameter |#1|.
336 % \begin{macrocode}
337 \newcommand*\BL@getDimens[3]{%
338 \BL@is@dimen@pair{#1}{%
339 \global#2=\BL@tempa\relax
340 \global#3=\BL@tempb\relax
341 }{%
342 \BL@is@factor{#1}{%
343 \global#2=\BL@tempa\paperwidth
344 \global#3=\BL@tempa\paperheight
345 }{%
346 \begingroup
347 \KOMAoptions{paper=portrait,paper=#1}%
348 \global#2=\paperwidth
349 \global#3=\paperheight
350 \endgroup
351 }%
352 }%
353 }
354 % \end{macrocode}
355 % \end{macro}
356 % The key-value definitions for \cmd{\blowUp}:
357 % \begin{macrocode}
358 \define@key{BL@}{origin}{%
359 \BL@getDimens{#1}{\oPaperWidth}{\oPaperHeight}%
360 }
361 % \end{macrocode}
362 %
363 % \begin{macrocode}
364 \define@key{BL@}{target}{%
365 \BL@getDimens{#1}{\tPaperWidth}{\tPaperHeight}%
366 }
367 % \end{macrocode}
368 %
369 % \begin{macrocode}
370 \newif\ifBL@noscale \BL@noscalefalse
371 \newif\ifBL@mirroring \BL@mirroringfalse
372 % \end{macrocode}
373 %
374 % \begin{macrocode}
375 \define@key{BL@}{noscale}[true]{%
376 \global\csname BL@noscale#1\endcsname
377 }
378 \define@key{BL@}{h-mirroring}[true]{%
379 \global\csname BL@mirroring#1\endcsname
380 \gdef\BL@h{-1}%
381 }
382 \define@key{BL@}{v-mirroring}[true]{%
383 \global\csname BL@mirroring#1\endcsname
384 \gdef\BL@v{-1}%
385 }
386 % \end{macrocode}
387 %
388 % \begin{macrocode}
389 \newcommand*\BL@l{}
390 \newcommand*\BL@r{}
391 \newcommand*\BL@i{}
392 \newcommand*\BL@o{}
393 \newcommand*\BL@t{}
394 \newcommand*\BL@b{}
395 \newcommand*\BL@h{1}
396 \newcommand*\BL@v{1}
397 % \end{macrocode}
398 %
399 %
400 % \begin{macro}{\BL@setPos}
401 % Modify the macros \cmd{\BL@l}, \cmd{\BL@r} (\cmd{\BL@i}, \cmd{\BL@o}),
402 % \cmd{\BL@t}, and \cmd{\BL@b} for positioning the page on the paper.
403 % \begin{macrocode}
404 \newcommand\BL@setPos[1]{%
405 \def\BL@l{\hss}\def\BL@r{\hss}%
406 \def\BL@o{\hss}\def\BL@i{\hss}%
407 \def\BL@t{\vss}\def\BL@b{\vss}%
408 \BL@is@dimen@pair{#1}{%
409 \edef\BL@b{\vskip\BL@tempb}%
410 \if@twoside
411 \edef\BL@l{\noexpand\ifodd\value{page}%
412 \hskip\BL@tempa\noexpand\else\hss\noexpand\fi}%
413 \edef\BL@r{\noexpand\ifodd\value{page}%
414 \hss\noexpand\else\hskip\BL@tempa\noexpand\fi}%
415 \else
416 \edef\BL@l{\hskip\BL@tempa}%
417 \if
418 }{%
419 \@for\BL@tempa:=#1\do{%
420 \edef\BL@tempb{\expandafter\@car\BL@tempa\@nil}%
421 \expandafter\let\csname BL@\BL@tempb \endcsname\relax
422 }%
423 \if@twoside
424 \ifx\BL@i\relax
425 \def\BL@r{\ifodd\value{page}\hss\else\relax\fi}%
426 \def\BL@l{\ifodd\value{page}\relax\else\hss\fi}%
427 \fi
428 \ifx\BL@o\relax
429 \def\BL@l{\ifodd\value{page}\hss\else\relax\fi}%
430 \def\BL@r{\ifodd\value{page}\relax\else\hss\fi}%
431 \fi
432 \else
433 \let\BL@l=\BL@o
434 \let\BL@r=\BL@i
435 \fi
436 }%
437 }
438 % \end{macrocode}
439 % \end{macro}
440 %
441 % \begin{macrocode}
442 \define@key{BL@}{pos}{%
443 \BL@setPos{#1}%
444 }
445 % \end{macrocode}
446 %
447 % \begin{macrocode}
448 \newif\ifBL@landscape \BL@landscapefalse
449 % \end{macrocode}
450 %
451 % \begin{macrocode}
452 \define@key{BL@}{landscape}[true]{%
453 \csname BL@landscape#1\endcsname
454 }
455 % \end{macrocode}
456 %
457 % \begin{macrocode}
458 \newcommand*\BL@setup{}
459 % \end{macrocode}
460 %
461 % \begin{macrocode}
462 \define@key{BL@}{onepage}[true]{%
463 \csname if#1\endcsname
464 \def\BL@setup{\gdef\shipout{\deadcycles\z@\setbox\@tempboxa=}}%
465 \fi
466 }
467 % \end{macrocode}
468 %
469 % \begin{macro}{\blowUp}
470 % The only user-level macro.
471 % \changes{2.2.0}{2023/07/15}{Using \LaTeX's shipout hook instead of package `atbegshi'}
472 % \begin{macrocode}
473 \newcommand*\blowUp[1]{%
474 \global\tPaperWidth=\paperwidth
475 \global\tPaperHeight=\paperheight
476 \setkeys{BL@}{#1}%
477 \ifBL@landscape
478 \@tempdima=\tPaperWidth
479 \global\tPaperWidth=\tPaperHeight
480 \global\tPaperHeight=\@tempdima
481 \fi
482 \AtBeginDocument{%
483 \AtBeginDvi{\BL@pagesize@code{\tPaperWidth}{\tPaperHeight}}%
484 \AddToHook{shipout}{\BL@setup\BL@scalePage}%
485 }%
486 \gdef\blowUp##1{%
487 \PackageWarning{blowup}{Only the first call of `\string\blowUp'
488 \MessageBreak is effective}}%
489 }
490 % \end{macrocode}
491 % \end{macro}
492 %
493 % \begin{macrocode}
494 \@onlypreamble\blowUp
495 % \end{macrocode}
496 %
497 % \begin{macro}{\BL@pagesize@code}
498 % Page size information (depending on the \TeX\ compiler or driver).
499 % \begin{macrocode}
500 \newcommand*\BL@pagesize@code[2]{}
501 % \end{macrocode}
502 % \end{macro}
503 %
504 % \begin{macrocode}
505 \RequirePackage{iftex}
506 % \end{macrocode}
507 %
508 % \begin{macrocode}
509 \ifluatex
510 \PackageInfo{blowup}{Generating code for LuaTeX}%
511 \@ifundefined{pagewidth}{%
512 \def\BL@pagesize@code#1#2{\global\pdfpagewidth=#1 %
513 \global\pdfpageheight=#2}%
514 }{%
515 \def\BL@pagesize@code#1#2{\global\pagewidth=#1 %
516 \global\pageheight=#2}%
517 }
518 \else
519 \ifxetex
520 \PackageInfo{blowup}{Generating code for XeTeX}%
521 \def\BL@pagesize@code#1#2{\global\pdfpagewidth=#1 %
522 \global\pdfpageheight=#2}%
523 \else
524 \ifvtex
525 \PackageInfo{blowup}{Generating code for VTeX}%
526 \def\BL@pagesize@code#1#2{\global\mediawidth=#1 %
527 \global\mediaheight=#2}%
528 \else
529 \ifpdf
530 \PackageInfo{blowup}{Generating code for pdfTeX}%
531 \def\BL@pagesize@code#1#2{\global\pdfpagewidth=#1 %
532 \global\pdfpageheight=#2}%
533 \else
534 \PackageInfo{blowup}{Generating code for dvips}%
535 \def\BL@pagesize@code#1#2{%
536 \@tempdima=#1 \@tempdimb=#2 %
537 \special{papersize=\the\@tempdima,\the\@tempdimb}%
538 }%
539 \fi
540 \fi
541 \fi
542 \fi
543 % \end{macrocode}
544 %
545 % \iffalse
546 %</package>
547 % \fi
548 %
549 % \Finale
550 \endinput