<<

The pst- package∗

Rolf Niepraschk† Hubert Gäßlein

2020/10/10

1 Introduction

The package pst-pdf simplifies the use of graphics from PSTricks and other Post- Script code in PDF documents. As in building a bibliography with BibTEX ad- ditional external programmes are being invoked. In this case they are used to create a PDF file (\PDFcontainer) that will contain all this graphics material. In the final document this contents will be inserted instead of the original PostScript code.

2 Usage 2.1 Package options active Activates the extraction mode (DVI output). An explicit declaration usu- ally is not necessary (default in LATEX mode). inactive No special actions; only the packages and graphicx are loaded (default in VTEX). Can be used to just convert the document with LATEX into a DVI file while avoiding the automatic extraction mode. pstricks The package pstricks is loaded (default). nopstricks The package pstricks does not get loaded. Once it is detected that pstricks was loaded however in some other way, the pspicture environment is treated as if the option “pstricks” was given. draft From the \PDFcontainer file included graphics is displayed as frame in pdfLATEX mode. final From the \PDFcontainer file included graphics is correctly displayed in pdfLATEX mode (default). tightpage The graphics’ dimensions in the \PDFcontainer file match exactly those of the corresponding TEX boxes (default). notightpage The dimensions of the TEX box corresponding to its graphics is not always correct, since a PostScript statement can draw outside its box. The option “notightpage” makes the graphics in the \PDFcontainer file to be at

∗This document corresponds to pst-pdf v1.2f, dated 2020/10/10. Thanks to Peter Dyballa for the translation. †[email protected]

1 least the size of the whole page. To be able to make use of the graphics’ in a later pdfLATEX run, the \PDFcontainer file needs to be finished in a way that each graphics gets reduced in size to its visible part. For this an external programme like pdfcrop1 can be useful. Its use can save declaring the option “trim” (see also section 2.4). displaymath In PDF mode the mathematical environments displaymath, eqnar- ray, and $$ get also extracted and included as graphics. This way additional PSTricks extensions can easily be added to the contents of these environ- ments. (Question: how do AMSLATEX environments behave?) hotheri All other options are passed to pstricks package.

2.2 Program calls The following table shows the course necessary to create a PDF document contain- ing PostScript graphics2. As comparison the analogous course for a bibliography is shown.

PostScript graphics bibliography pdflatex document. pdflatex document.tex auxiliary calls document.tex dvips -o document-pics.ps document.dvi ps2pdf document-pics.ps bibtex document.aux pdflatex document.tex pdflatex document.tex

While creating the output only code from inside a pspicture or postscript en- vironment is considered. PostScript graphics files, which are passed as parameter of an \includegraphics statement, too are included into the \PDFcontainer file. This file’s name is by default h\jobname i-pics.pdf. It can be changed by re-defining the macro \PDFcontainer.

2.3 User commands pspicture \begin{pspicture}[hkeysi](hx0,x1 i)(hy0,y1 i) ... \end{pspicture} The pspicture environment is not available when the option “nopstricks” was given. It is to be used the same way as if in PSTricks. In pdfLATEX mode this environment’s contents is only displayed when the \PDFcontainer file was created before. postscript \begin{postscript}[hkeysi] ... \end{postscript} The postscript environment can contain any code except floats. In pdfLATEX mode its contents is take too off the \PDFcontainer file. Other as in the pspicture environment the necessary space is not always preserved when the \PDFcontainer file does not exist yet. \includegraphics \includegraphics[hkeysi]{hfilenamei}

1CTAN: support/pdfcrop/ 2The TEX distribution “teTEX” contains a UNIX shell script ps4pdf which executes all the necessary steps. See: CTAN: macros/latex/contrib/ps4pdf/

2 To be used as in graphics/graphicx defined. In pdfLATEX mode it is now additionally feasable to pass the name of an EPS file. Its visible contents too is taken from the \PDFcontainer file. \includegraphicx \includegraphicx[hkeysi](hpfxaddi)[hovpbgdi]{hfilenamei} To be used like defined in packagepsfragx. \savepicture \savepicture{hnamei} The last output graphics (result of the pspicture or postscript environments or the \includegraphics statement with an PostScript file as argument) is being saved in a file under the name as given by the parameter. \usepicture \usepicture[hkeysi]{hnamei} The graphic previously stored with \savepicture is outputted. The optional parameter corresponds to \includegraphics. pst-pdf-defs \begin{pst-pdf-defs} ... \end{pst-pdf-defs} For defining macros or environments, which contain character & (others?) in the output, these defintions have to be wrapped with environment pst-pdf-defs.

2.4 Command options The behaviour of the \includegraphics and \usepicture statements and the postscript environment can be modified with any of the following parameters (key value syntax):

frame=htrue|falsei As with the \fbox statement a frame is drawn around the graphics. Any change of size due to rotation is taken into account. Drawing happens in pdfLATEX mode; before, in creating the \PDFcontainer file, it is ignored. Default: false. innerframe=htrue|falsei As in “frame”, but the frame is drawn around the gra- phics, not its box. ignore=htrue|falsei If set to “true” no graphics are outputted. With macro \savepicture{hnamei} the graphics can be used later in a different place via \usepicture. Default: false. showname=htrue|falsei A caption of minimal font size records the used file’s name. Default: false. namefont=hfont commandsi Controls the font used when “showname=true” is set. Default: \ttfamily\tiny

All parameters can be set globally as in \setkeys{Gin}{hkey=valuei}.

3 Implementation

1 h∗packagei 3.1 Package options

2 \newcommand*\ppf@TeX@mode{-1} 3 \newcommand*\ppf@draft{false}

3 4 \newif\if@ppf@PST@used\@ppf@PST@usedtrue 5 \newif\if@ppf@tightpage \@ppf@tightpagetrue 6 \DeclareOption{active}{\OptionNotUsed} 7 \DeclareOption{inactive}{\def\ppf@TeX@mode{9}} 8 \DeclareOption{ignore}{\def\ppf@TeX@mode{999}} 9 \DeclareOption{pstricks}{\@ppf@PST@usedtrue} 10 \DeclareOption{nopstricks}{\@ppf@PST@usedfalse} 11 \DeclareOption{displaymath}{% 12 \PassOptionsToPackage\CurrentOption{preview}} 13 \DeclareOption{draft}{\def\ppf@draft{true}} 14 \DeclareOption{final}{\def\ppf@draft{false}% 15 \PassOptionsToPackage\CurrentOption{graphicx}}

16 \DeclareOption{notightpage}{\@ppf@tightpagefalse}% 17 \DeclareOption{tightpage}{\@ppf@tightpagetrue}% 18 \DeclareOption*{% 19 \PassOptionsToPackage\CurrentOption{pstricks}} 20 \ProcessOptions\relax 21 \ifnum\ppf@TeX@mode=999\relax\expandafter\endinput\fi 3.2 Compiler tests

It is tested which TEX compiler in which mode of operation is actually used (see ‘graphics.cfg’ in teTEX/TEX Live). Accordingly the environments pspicture and postscript gain each a different range of functions. This test is only executed when the options active or inactive were not given. 22 \RequirePackage{ifpdf,ifxetex,ifvtex} 23 \ifnum\ppf@TeX@mode=-1\relax 24 \ifpdf ⇒ pdfTEX or LuaTEX are running in PDF mode 25 \def\ppf@TeX@mode{1}% 26 \RequirePackage{luatex85}% 27 \else 28 \ifvtex ⇒ VTEX 29 \def\ppf@TeX@mode{9}% 30 \else 31 \ifxetex ⇒ XeTEX 32 \def\ppf@TeX@mode{9}% 33 \else ⇒ DVI mode 34 \def\ppf@TeX@mode{0}% 35 \fi 36 \fi 37 \fi 38 \fi

39 \newcommand*\PDFcontainer{} 40 \edef\PDFcontainer{\jobname-pics.pdf} 41 \newcounter{pspicture} 42 \newcommand*\ppf@other@extensions[1]{} 43 \newcommand*\usepicture[2][]{}

4 44 \newcommand*\savepicture[1]{}

pst-pdf-defs 45 \newenvironment*{pst-pdf-defs}{% 46 \endgroup 47 % ??? \@currenvline 48 }{% 49 \begingroup 50 \def\@currenvir{pst-pdf-defs}% 51 }

52 \RequirePackage{graphicx}[2017/06/01]% 53 \let\ppf@Ginclude@graphics\Ginclude@graphics 54 \let\ppf@Gin@extensions\Gin@extensions 55 \let\ppf@Gin@ii\Gin@ii

56 \newif\if@ppf@@graphic 57 \newif\ifGin@frame\Gin@framefalse 58 \newif\ifGin@innerframe\Gin@innerframefalse 59 \newif\ifGin@showname\Gin@shownamefalse 60 \newif\ifGin@ignore\Gin@ignorefalse \ifpr@outer in fact is defined in package preview. We have to do it here too since otherwise TEX could “stumble and fall” while parsing the \ifcase structure. 61 \newif\ifpr@outer

\ppf@is@pdfTeX@graphic Parameter #1 is the name of a graphics file with or without extension, parameter #2 contains the valid extensions in PDF mode, parameter #3 contains the valid extensions in DVI mode. If it works to process the graphics in PDF mode, then the statements in #4 are executed, otherwise those in #5. 62 \newcommand*\ppf@is@pdfTeX@graphic[5]{% 63 \@ppf@pdftex@graphicfalse% 64 \begingroup 65 \edef\pdfTeXext{,#2,}% 66 \edef\pdfTeXext{\detokenize\expandafter{\pdfTeXext}}% Instead of loading the found graphics, only a test on file name extension. 67 \def\Gin@setfile##1##2##3{% 68 \edef\@tempa{,##2,}% 69 \@expandtwoargs\in@{\detokenize\expandafter{\@tempa}}{\pdfTeXext}% 70 \ifin@\global\@ppf@pdftex@graphictrue\fi}% File types for both modes need to be determined to prevent a wrong error message “File ‘#1’ not found”. 71 \edef\Gin@extensions{#2,#3}% Trial invocation. Output is completely inhibited. 72 \pr@outerfalse\ppf@Ginclude@graphics{#1}% 73 \endgroup 74 \if@ppf@pdftex@graphic#4\else#5\fi 75 }

76 \ifcase\ppf@TeX@mode\relax

5 3.3 Extraction mode (DVI output) The pspicture environment retains any definition from pstricks.tex. Only the code from the environments pspicture and postscript as well as \includegraphics with PostScript files leads to records into the DVI file. The remainder of the document’s code is ignored for output. After conversion of the DVI file via Post- Script (“dvips”) into PDF (\PDFcontainer file) each graphics takes exactly one page in the \PDFcontainer file. The TEX compiler with DVI output and the package option “active” both force this mode. 77 \PackageInfo{pst-pdf}{% 78 MODE: \ppf@TeX@mode\space (dvi -- extraction mode)}% 79 \nofiles 80 \let\makeindex\@empty \let\makeglossary\@empty \let\printindex\@empty 81 \renewcommand*\makeindex[1][]{}% 82 \renewcommand*\makeglossary[1][]{}% 83 \renewcommand*\printindex[1][]{}% 84 \AtBeginDocument{\overfullrule=\z@}% 85 \if@ppf@PST@used\RequirePackage{pstricks}\fi 86 \RequirePackage[active,dvips,tightpage]{preview}[2005/01/29]% 87 \newcommand*\ppf@PreviewBbAdjust{}% 88 \newcommand*\ppf@RestoreBbAdjust{% 89 \let\PreviewBbAdjust\ppf@PreviewBbAdjust}% The pdfLATEX mode compliant graphics file formats are needed too. (Argument copied from ‘pdftex.def’ – 2020/10/05). 90 \def\ppf@other@extensions{% 91 .pdf,.png,.jpg,.mps,.jpeg,.jbig2,.jb2,% 92 .PDF,.PNG,.JPG,.JPEG,.JBIG2,.JB2% 93 } In PDF mode no rules must be defined for its compliant (PNG, JPEG, PDF) graphics file formats (because of for example ‘dvips’ extensions). The universal EPS rule is used to at least find these files. 94 \AtBeginDocument{% 95 \@ifpackageloaded{keyval}{% 96 \def\KV@errx#1{\PackageInfo{keyval}{#1}}% 97 }{}% 98 \@ifpackageloaded{xkeyval}{% 99 \def\XKV@err#1{\PackageInfo{xkeyval}{#1}}% 100 }{}% In this mode undefined keys should not be an error. 101 \@for\@tempa:=\ppf@other@extensions\do{% 102 \expandafter\let\csname Gin@rule@\@tempa\endcsname\relax}% 103 \DeclareGraphicsRule{*}{eps}{*}{}}% No function in this mode. 104 \define@key{Gin}{innerframe}[true]{}% 105 \define@key{Gin}{frame}[true]{}% 106 \define@key{Gin}{ignore}[true]{}% 107 \define@key{Gin}{showname}[true]{}% 108 \define@key{Gin}{namefont}{}% 109 \@ifundefined{Gin@page}{\define@key{Gin}{page}{}}{}%

110 \if@ppf@tightpage\else

6 111 \def\PreviewBbAdjust{% 112 -600pt -600pt 600pt 600pt}% 113 \AtEndDocument{% 114 \PackageWarningNoLine{pst-pdf}{Picture container needs cropping.}}% 115 \fi postscript The postscript environment utilises the trim option in the same manner as does \includegraphics (any specification without dimension is interpreted as if given in bp). 116 \newenvironment{postscript}[1][]% 117 {% 118 \global\let\ppf@PreviewBbAdjust\PreviewBbAdjust 119 \if@ppf@tightpage 120 \begingroup 121 \setkeys{Gin}{#1}% 122 \xdef\PreviewBbAdjust{% 123 -\Gin@vllx bp -\Gin@vlly bp \Gin@vurx bp \Gin@vury bp}% 124 \endgroup 125 \fi 126 \ignorespaces 127 }% 128 {\aftergroup\ppf@RestoreBbAdjust}%

129 \PreviewEnvironment{postscript}% 130 \AtBeginDocument{% 131 \@ifundefined{PSTricksLoaded}{}% 132 {%

pspicture Announce preview original definition. 133 \PreviewEnvironment{pspicture}%

psmatrix Announce preview original definition. 134 \@ifundefined{psmatrix}{}% 135 {% 136 \PreviewEnvironment{psmatrix}% 137 \newcommand*\ppf@set@mode{}% 138 \newcommand*\ppf@test@mmode{% 139 \ifmmode 140 \ifinner 141 \let\ppf@set@mode=$% 142 \else 143 \def\ppf@set@mode{$$}% 144 \fi 145 \else 146 \let\ppf@set@mode=\@empty 147 \fi 148 }% 149 \let\ppf@psmatrix=\psmatrix 150 \expandafter\let\expandafter\ppf@pr@psmatrix% 151 \expandafter=\csname pr@\string\psmatrix\endcsname 152 \let\ppf@endpsmatrix=\endpsmatrix 153 \def\psmatrix{\ppf@test@mmode\ppf@psmatrix}% 154 \expandafter\def\csname pr@\string\psmatrix\endcsname{% 155 \ppf@set@mode\ppf@pr@psmatrix}%

7 156 \def\endpsmatrix{\ppf@endpsmatrix\ppf@set@mode}% 157 }%

Announce internal macro \pst@object to enable the use of some PSTricks code outside of pspicture environments. At the moment invocations of the following kind are feasible:

\pst@object {hmi}h* i[hoi]{hoi}{hoi}(hoi)(hoi)(hoi) (m = necessary, * = optional, o = optional)

More than three optional arguments at the call’s end, as in \psline possible, do not work yet. 158 \PreviewMacro[{{}*[]% 159 ?\bgroup{#{#1}{{#1}}}{}% 160 ?\bgroup{#{#1}{{#1}}}{}% 161 ?({#{(#1)}{({#1})}}{}% 162 ?({#{(#1)}{({#1})}}{}% 163 ?({#{(#1)}{({#1})}}{}% 164 }]{\pst@object}}% Prevent multiple test-wise setting of table contents by “tabularx”. 165 \@ifundefined{tabularx}{}{% 166 \newcolumntype{X}{c}% 167 \expandafter\let\expandafter\tabularx\csname tabular*\endcsname 168 \expandafter\let\expandafter\endtabularx\csname endtabular*\endcsname 169 }% Support of \includegraphicx from the package psfragx. 170 \@ifundefined{pfx@includegraphicx}{}{% 171 \PreviewMacro[{{}{}}]{\pfx@includegraphicx}}% 172 }%

\Gscale@@box Disable scaling. 173 \def\Gscale@@box#1#2#3{% 174 \toks@{\mbox}% 175 }%

\Ginclude@graphics All graphics content of well known format (for instance EPS files) is treated in a regular way, which in this mode denotes that it is subject to preview functions. Other graphics content (for instance PDF files) is ignored. 176 \def\Ginclude@graphics#1{% 177 \ifpr@outer Generally pdfTEX supported graphics formats are intended to be preferred (in- clusion in final pdfTEX run). If it’s a PostScript type graphics, then the original definition is in function again and registration for the preview package is necessary in order to convert this PostScript type graphics into PDF. 178 \ppf@is@pdfTeX@graphic{#1}{\ppf@other@extensions}{\Gin@extensions}% Dummy box to prevent a division by zero while scaling or rotating. Otherwise ignored. 179 {\rule{10pt}{10pt}}% 180 {\ppf@Ginclude@graphics{#1}}% 181 \else

8 Inside a PostScript environment (pspicture etc.) \includegraphics has to behave as in its original definition (only DVIPS supported graphics formats are allowed). 182 \ppf@Ginclude@graphics{#1}% 183 \fi 184 }%

185 \PreviewMacro[{{}}]{\ppf@Ginclude@graphics}% 186 \let\pdfliteral\@gobble% 187 \or

3.4 pdfLATEX mode (PDF output) When the \PDFcontainer file (default: h\jobname i-pics.pdf) exists, the con- tents of the environments pspicture and postscript is ignored. Instead the corre- sponding graphics from the \PDFcontainer file is used. 188 \PackageInfo{pst-pdf}{MODE: \ppf@TeX@mode\space (pdfTeX mode)}% Prevent pdfTEX’s message Non-PDF special ignored!. 189 \if@ppf@PST@used 190 \let\ppf@temp\AtBeginDvi\let\AtBeginDvi\@gobble 191 \def\c@lor@to@ps#1 #2\@@{}% 192 \RequirePackage{pstricks}\let\AtBeginDvi\ppf@temp 193 \fi

194 \@temptokena{% 195 \let\Gin@PS@file@header\@gobble\let\Gin@PS@literal@header\@gobble 196 \let\Gin@PS@raw\@gobble\let\Gin@PS@restored\@gobble 197 \@ifundefined{PSTricksLoaded}{}{% Necessary if PSTricks < 2.0. 198 \PSTricksOff% 199 \def\c@lor@to@ps#1 #2\@@{}% 200 }% 201 }% PostScript output is now inhibited and later once again. 202 \the\@temptokena% 203 \expandafter\AtBeginDocument\expandafter 204 {\the\@temptokena\@temptokena{}}% 205 \@ifundefined{PSTricksLoaded}{}{% To parse the arguments of PSTricks’ \pst@object we load preview in active mode, but restore the default definitions of \output and \shipout. \pr@startbox and \pr@endbox serve here only to disable \pst@object and to load the corresponding graphics from the \PDFcontainer file. At present a maximum of three optional parameters in round braces (parenthesis) at the end of \pst@object is supported, which is sufficient, but not always enough. 206 \newtoks\ppf@output 207 \ppf@output\expandafter{\the\output}% 208 \let\ppf@nofiles=\nofiles \let\nofiles=\relax 209 \let\ppf@shipout=\shipout 210 \RequirePackage[active]{preview}[2005/01/29]% 211 \let\shipout=\ppf@shipout \let\ppf@shipout=\relax 212 \let\nofiles=\ppf@nofiles \let\ppf@nofiles=\relax 213 \output\expandafter{\the\ppf@output} \ppf@output{}%

9 \pr@startbox, \pr@endbox: simpler over original definitions. 214 \long\def\pr@startbox#1#2{% 215 \ifpr@outer 216 \toks@{#2}% 217 \edef\pr@cleanup{\the\toks@}% 218 \setbox\@tempboxa\vbox\bgroup 219 \everydisplay{}% 220 \pr@outerfalse% 221 \expandafter\@firstofone 222 \else 223 \expandafter\@gobble 224 \fi{#1}}% 225 \def\pr@endbox{% 226 \egroup 227 \setbox\@tempboxa\box\voidb@x 228 \ppf@@getpicture 229 \pr@cleanup}% (See also the identical definition in DVI mode.) 230 \AtBeginDocument{% 231 \@ifundefined{pst@object}{}% 232 {% 233 \PreviewMacro[{{}*[]% 234 ?\bgroup{#{#1}{{#1}}}{}% 235 ?\bgroup{#{#1}{{#1}}}{}% 236 ?({#{(#1)}{({#1})}}{}% 237 ?({#{(#1)}{({#1})}}{}% 238 ?({#{(#1)}{({#1})}}{}% 239 }]{\pst@object}}% 240 }% 241 }% Too the supported file name extensions from DVI mode are needed. (Argument copied from ‘dvips.def’ – 2017/06/20). 242 \def\ppf@other@extensions{.eps,.ps,.eps.gz,.ps.gz,.eps.Z,.mps}% Dummy definition for in DVI mode supported file formats. 243 \DeclareGraphicsRule{*}{eps}{*}{}%

244 \define@key{Gin}{innerframe}[true]{% 245 \lowercase{\Gin@boolkey{#1}}{innerframe}}% 246 \define@key{Gin}{frame}[true]{% 247 \lowercase{\Gin@boolkey{#1}}{frame}}% 248 \define@key{Gin}{ignore}[true]{% 249 \lowercase{\Gin@boolkey{#1}}{ignore}}% 250 \define@key{Gin}{frame@@}{% (For internal use only!) 251 \edef\@tempa{\toks@{\noexpand\frame{\the\toks@}}}% 252 \ifcase#1\relax 253 \ifGin@innerframe\else\let\@tempa\relax\fi 254 \or 255 \ifGin@frame\else\let\@tempa\relax\fi 256 \fi 257 \@tempa% 258 }%

10 259 \define@key{Gin}{showname}[true]{% 260 \lowercase{\Gin@boolkey{#1}}{showname}}% 261 \define@key{Gin}{namefont}{% 262 \begingroup 263 \@temptokena\expandafter{\ppf@namefont#1}% 264 \edef\x{\endgroup\def\noexpand\ppf@namefont{\the\@temptokena}}% 265 \x% 266 }% 267 \newcommand*\ppf@filename{}% 268 \newcommand*\ppf@namefont{\tiny\ttfamily}% 269 \newcommand*\ppf@Gin@keys{}% 270 \let\ppf@Gin@setfile\Gin@setfile

\Gin@setfile Save real file name and, if applicable, page number for later use. 271 \def\Gin@setfile#1#2#3{\ppf@Gin@setfile{#1}{#2}{#3}% 272 \xdef\ppf@filename{% 273 #3\ifx\Gin@page\@empty\else(\Gin@page)\fi}}%

\Gin@ii Examine the options “frame”, “ignore”, etc. as soon as other special cases. 274 \def\Gin@ii[#1]#2{% 275 \begingroup The value of \ifGin@innerframe has to be known before the inner frame is drawn. The values for \ifGin@showname and \ppf@namefont need to be available after rendering the graphics too. Thus beforehand and protected inside a group examine the options. 276 \@temptokena{#1}\def\ppf@tempb{#2}% Finds empty file name when calling \usepicture. 277 \ifx\ppf@tempb\@empty\else 278 \ppf@is@pdfTeX@graphic{#2}{\Gin@extensions}{\ppf@other@extensions}% Graphics out of \PDFcontainer are complete – scaled, rotated, etc. Don’t apply these things again and therefore ignore the optional parameters. 279 {% 280 \setkeys{Gin}{#1}% 281 \ifx\ppf@tempb\PDFcontainer 282 \@temptokena{page=\Gin@page}% 283 \fi 284 }% 285 {% 286 \refstepcounter{pspicture}% 287 \@temptokena{page=\the\c@pspicture}\def\ppf@tempb{\PDFcontainer}% 288 }% 289 \fi 290 \ifGin@ignore\else “frame@@=0” = inner frame, “frame@@=1” = outer frame. 291 \edef\@tempa{\noexpand\ppf@Gin@ii[frame@@=0,\the\@temptokena,% 292 frame@@=1]{\ppf@tempb}}% 293 \@tempa% 294 \ifGin@showname 295 \ppf@namefont% 296 \raisebox{-\ht\strutbox}[0pt][0pt]{\llap{\ppf@filename}}% 297 \gdef\ppf@filename{}%

11 298 \fi 299 \fi 300 \endgroup 301 }%

302 \IfFileExists{\PDFcontainer}% 303 {%

\ppf@container@max The number of pages as contained in \PDFcontainer file. 304 \pdfximage{\PDFcontainer}% 305 \edef\ppf@container@max{\the\pdflastximagepages}%

306 \AtEndDocument{% 307 \ifnum\c@pspicture>\z@ A warning only makes sense when a graphics is needed at all. 308 \ifnum\c@pspicture=\ppf@container@max\else 309 \PackageWarningNoLine{pst-pdf}{% 310 ‘\PDFcontainer’ contains \ppf@container@max\space pages 311 \MessageBreak but \the\c@pspicture\space pages are requested: 312 \MessageBreak File ‘\PDFcontainer’ is no more valid! 313 \MessageBreak Recreate it 314 }% 315 \fi 316 \fi 317 }% 318 }% 319 {% 320 \def\ppf@container@max{0}% 321 \AtEndDocument{% 322 \ifnum\c@pspicture>\z@ 323 \filename@parse{\PDFcontainer}% 324 \PackageWarningNoLine{pst-pdf}{% 325 File ‘\PDFcontainer’ not found. \MessageBreak 326 Use the following commands to create it: \MessageBreak 327 ------328 \MessageBreak 329 latex \jobname.tex\MessageBreak 330 dvips -o \[email protected] \jobname.dvi\MessageBreak 331 ps2pdf \[email protected]\MessageBreak 332 ------333 }% 334 \fi 335 }% 336 }%

\ppf@isnum If parameter #1 is numeric, the instructions in #2, otherwise those in #3 are exe- cuted (see bibtopic.sty). 337 \newcommand\ppf@isnum[1]{% 338 \if!\ifnum9<1#1!\else_\fi\expandafter\@firstoftwo 339 \else\expandafter\@secondoftwo\fi}%

psmatrix Both environments ignore their contents and load instead the corresponding graph- pspicture ics out of the \PDFcontainer file. The value of the herein used pspicture counter’s value can be used in \label/\ref.

12 postscript 340 \newcommand*\ppf@set@mode{}% 341 \newcommand*\ppf@test@mmode{% 342 \ifmmode 343 \ifinner 344 \let\ppf@set@mode=$% 345 \else 346 \def\ppf@set@mode{$$}% 347 \fi 348 \else 349 \let\ppf@set@mode=\@empty 350 \fi 351 }

352 \RequirePackage{environ}% 353 \newenvironment{postscript}[1][]{% 354 \def\@tempa{postscript}% 355 \ifx\@tempa\@currenvir 356 \def\ppf@Gin@keys{#1}% 357 \else 358 \def\ppf@Gin@keys{}% 359 \fi 360 \ppf@@getpicture% 361 \Collect@Body\@gobble}{}% 362 \AtBeginDocument{% 363 \@ifundefined{PSTricksLoaded}{}{% 364 \def\pst@@@picture[#1](#2,#3)(#4,#5){\postscript}% 365 \def\endpspicture{\endpostscript\endgroup}% 366 \@ifundefined{psmatrix}{}{% 367 \let\psmatrix=\postscript 368 \let\endpsmatrix=\endpostscript}% 369 }% 370 \@ifundefined{pfx@includegraphicx}{}{% The useless redefinition of \includegraphics in pdfTEX mode (package psfragx) is leading to double insertion of the result. We go back to the original meaning. 371 \let\includegraphics=\pfx@includegraphics 372 \def\pfx@includegraphicx#1#2{\ppf@@getpicture}% 373 }% 374 }%

\savepicture Saves the recent graphics’ number in a macro named \ppf@@@#1. 375 \def\savepicture#1{% 376 \expandafter\xdef\csname ppf@@@#1\endcsname{\the\pdflastximage}}%

\usepicture Inserts graphics with symbolic name #2. This name has to be declared beforehand in \savepicture{hnamei}. Instead of a name a number can be used too, which directly addresses a graphics in the \PDFcontainer file. The optional parameter #1 corresponds to the one in \includegraphics. 377 \renewcommand*\usepicture[2][]{% 378 \@ifundefined{ppf@@@#2}% 379 {% 380 \ppf@isnum{#2}% 381 {\ppf@getpicture{#1}{#2}}%

13 382 {\@latex@error{picture ‘#2’ undefined}\@ehc}% 383 }% 384 {% 385 \begingroup 386 \def\Ginclude@graphics##1{% 387 \xdef\ppf@filename{#2}% 388 \setbox\z@\hbox{\pdfrefximage\@nameuse{ppf@@@#2}}% 389 \Gin@nat@height\ht\z@ \Gin@nat@width\wd\z@ 390 \def\Gin@llx{0}\let\Gin@lly\Gin@llx 391 \Gin@defaultbp\Gin@urx{\Gin@nat@width}% 392 \Gin@defaultbp\Gin@ury{\Gin@nat@height}% 393 \Gin@bboxtrue\Gin@viewport@code% 394 \Gin@nat@height\Gin@ury bp% 395 \advance\Gin@nat@height-\Gin@lly bp% 396 \Gin@nat@width\Gin@urx bp% 397 \advance\Gin@nat@width-\Gin@llx bp% 398 \Gin@req@sizes% 399 \ht\z@\Gin@req@height \wd\z@\Gin@req@width 400 \leavevmode\box\z@}% 401 \define@key{Gin}{type}{}% 402 \includegraphics[scale=1,#1]{}% 403 \endgroup 404 }}%

\ppf@getpicture Inserts the page (graphics) with number #2 from the \PDFcontainer file. Param- eter #1: any option as in \includegraphics. 405 \newcommand*\ppf@getpicture[2]{% 406 \@tempcnta=#2\relax% 407 \ifnum\@tempcnta>\ppf@container@max 408 \PackageWarningNoLine{pst-pdf}{% 409 pspicture No. \the\@tempcnta\space undefined}% 410 \else 411 \includegraphics[draft=\ppf@draft,#1,page=\the\@tempcnta]% 412 {\PDFcontainer}% 413 \fi 414 \gdef\ppf@Gin@keys{}}%

\ppf@@getpicture Inserts next page (graphics) from the \PDFcontainer file. 415 \newcommand*\ppf@@getpicture{% 416 \ifpr@outer 417 \refstepcounter{pspicture}% 418 \expandafter\ppf@getpicture\expandafter{\ppf@Gin@keys}% 419 {\the\c@pspicture}% 420 \fi}%

pst-pdf-defs Environment without grouping. The character & has the catcode “other”. Useful for user-defined macro definitions with e. g. psmatrix inside. 421 \renewenvironment*{pst-pdf-defs}% 422 {% 423 \endgroup 424 % ??? \@currenvline 425 \chardef\ppf@temp=\catcode‘\&% 426 \@makeother\&% 427 }{%

14 428 \catcode‘\&=\ppf@temp 429 \begingroup 430 \def\@currenvir{pst-pdf-defs}% 431 }

432 \else

3.5 Inactive Mode Only the packages pstricks and graphicx are loaded – no further exertion of in- fluence. The package option “inactive” as soon as the VTEXcompiler force this mode. 433 \PackageInfo{pst-pdf}{MODE: \ppf@TeX@mode\space (inactive mode)}% 434 \newenvironment{postscript}[1][]{\ignorespaces}{}% 435 \let\ppf@is@pdfTeX@graphic\relax 436 \fi

437 \InputIfFileExists{pst-pdf.cfg}{% 438 \PackageInfo{pst-pdf}{Local config file pst-pdf.cfg used}}{}% 439 h/packagei

Change History

v1.0a v1.0g General: Initial version...... 1 \usepicture: Now \usepspicture v1.0b does accept a numerical General: Some code and parameter. (RN) ...... 13 documentation cleaning. (RN) . 1 General: Definition of v1.0c \PDFcontainer now with \edef. (RN) ...... 4 General: New options “pstricks”, v1.0h “nopstricks”, “draft” and “final”. (RN) ...... 3 psmatrix: Based no more on the comment environment from the v1.0d verbatim package. (RN) . . . . 12 General: Redefinition of v1.0i \includegraphics in modes 0 \ppf@is@pdfTeX@graphic: No und 1. Now using of eps more errors for given files graphics directly in pdfLAT X is E without extensions. (RN) . . . . 5 possible. (RN) ...... 1 v1.0j v1.0e General: Check AtBeginDocument postscript: “trim” option added. for package ‘pstricks’ even if (RN) ...... 7 “nopstricks” is given. (RN) . . . 1 v1.0f For \includegraphics \savepicture: New macro \usepicture and postscript \savepspicture. (RN) . . . . . 13 the new options “frame”, \usepicture: New macro “framesep”, “framerule”, \usepspicture. Useful for “linewidth”, and “ignore” putting a PSTricks graphic in a added. (RN) ...... 1 box or something else. (RN) . 13 v1.0k General: Config file loading added. \Gin@setfile: Show also the (RN) ...... 15 pagenumber if exists. (RN) . . 11

15 \Ginclude@graphics: Prevent Special support for “tabularx”. division by zero. (RN) ...... 8 (RN) ...... 8 v1.0l Supress handling of pdfLATEX General: Options “framesep”, graphic formats in DVI mode. “framerule”, “linewidth” (RN) ...... 6 removed, “fname” and v1.1d “innerframe” added. (RN) . . . . 1 postscript: Support for PSTricks v1.0m environment “psmatrix”. (RN) 13 General: New package option v1.1e “notightpage” added. (RN) . . . 1 General: New option “displaymath” v1.0n (see preview package). General: Changed marcro names (HjG/RN) ...... 3 (\savepicture and v1.1f \usepicture). (RN) ...... 1 General: Package option “ignore” Some code cleaning. (RN) . . . . 1 reimplemented. Now the v1.0o compilation of the dtx file in General: New code for LATEX mode is possible. (RN) . 3 “notightpage”. (RN) ...... 6 v1.1g Option “fname” renamed to postscript: “psmatrix” “showname”. (RN) ...... 1 environment (preserve math v1.0p mode). (RN/HjG) ...... 13 General: Some code and pspicture: pspicture environment documentation cleaning. (RN) . 1 must still parse its arguments. v1.0q (RN/HjG) ...... 12 \usepicture: Now \usepspicture v1.1h works for all kind of graphics. \Ginclude@graphics: Check if (RN) ...... 13 inside of a PS-related v1.0r environment (correct graphic \ppf@is@pdfTeX@graphic: inclusion). (RN) ...... 8 Changed v1.1i \ppf@is@known@graphic to \Ginclude@graphics: Correction \ppf@is@pdfTeX@graphic. of the inside check. (RN/HjG) . 8 Now pdfTEX graphics are General: \ifpr@outer must be prefered. (RN) ...... 5 predefined. (HjG/RN) ...... 5 v1.0s Package option “final” also for \Gin@ii: Rewritten. (RN) . . . . . 11 “graphicx”. (RN) ...... 4 General: Scaling e.g. of PostScript v1.1k pictures now only in extraction General: New environment mode. Some code cleaning. pst-pdf-defs: Support for (RN) ...... 1 PSTricks environment v1.1a “psmatrix” inside user General: Support for the internal definitions. (RN,HjG) ...... 1 PSTricks macro \pst@object. v1.1l (HjG/RN) ...... 8 General: Support for the package v1.1b “psfragx”. (RN) ...... 8 General: Ignore the call of v1.1m \nofiles inside of preview. General: Merge english and (RN) ...... 9 german version of the Some code and documentation documentation. (RN) ...... 1 cleaning. (RN) ...... 1 v1.1n v1.1c General: \nofiles added General: New package option (suggestion of Torsten “tightpage” added. (RN) . . . . . 1 Bronger)...... 6

16 v1.1o v1.1v \Gscale@@box: Disable scaling. \Gin@ii: Key settings only for pdf (RN) ...... 8 graphics. (RN) ...... 11 v1.1p General: Local redefinition of General: \let\output\@gobble \pdfoutput to be a counter. before loading of “preview” (RN) ...... 6 added. (RN) ...... 9 v1.2a \nofiles makes \makeindex General: Engine tests changed and \makeglossary to \relax. (RN) ...... 4 \@empty is better because of v1.2b later \renewcommand’s...... 6 General: Loading packages ‘if*’ at v1.1q wrong place (RN) ...... 4 General: Problem with “tabularx” v1.2c and “threeparttabel” solved. General: “postscript” environment (RN) ...... 8 no more allowed before \begin{document} (changed v1.1r example file)...... 1 General: Fixed values for v1.2d \PreviewBbAdjust because General: \c@lor@to@ps must not \paperwidth is not allways be undefined before loading defined (suggested by Will ‘PSTricks’ ...... 9 Robertson)...... 6 Version parameter for ‘graphicx’ v1.1s and rename \GPT@page to General: Dummy definition of the \Gin@page at several places . . . 5 page key in DVI mode...... 6 v1.2e v1.1t \ppf@is@pdfTeX@graphic: General: Remove the line Parameter #2 is detokenized “\let\output\@gobble” when expanded to \pdfTeXext . 5 because of bad side effects. General: gobble optional argument (RN) ...... 9 for \makeindex, postscript: Using environ the \makeglossary and environment postscript is now \printindex ...... 6 simple and more robust. (RN) 13 v1.2f v1.1u General: No more loading of file General: \pdfoutput must be set ‘dvisps.def’ (RN) ...... 10 when loading “pdftex.def” in No more loading of file DVI mode. (RN) ...... 6 ‘pdftex.def’ (RN) ...... 6

17 Index

Numbers written in italic refer to the page where the corresponding entry is de- scribed; numbers underlined refer to the code line of the definition; numbers in roman refer to the code lines where the entry is used.

Symbols pspicture 2, 133, 340 I \& ...... 425, 426, 428 pst-pdf-defs ... \if@ppf@pdftex@graphic \@currenvir 50, 355, 430 ...... 3, 45, 421 ...... 56, 74 \@currenvline . . 47, 424 \everydisplay . . . . . 219 \if@ppf@PST@used .. \@ehc ...... 382 ...... 4, 85, 189 \@expandtwoargs . . . 69 F \if@ppf@tightpage . \@firstofone ...... 221 \filename@base 330, 331 ...... 5, 110, 119 \@ifpackageloaded 95, 98 \filename@parse . . . 323 \ifGin@frame . . . 57, 255 \@latex@error . . . . . 382 \frame ...... 251 \ifGin@ignore . . 60, 290 \@makeother ...... 426 \ifGin@innerframe . \@ppf@PST@usedfalse 10 G ...... 58, 253 \@ppf@PST@usedtrue 4, 9 \Gin@bboxtrue . . . . . 393 \ifGin@showname 59, 294 \@ppf@pdftex@graphicfalse \Gin@boolkey ...... \ifin@ ...... 70 ...... 63 . 245, 247, 249, 260 \ifinner . . . . . 140, 343 \@ppf@pdftex@graphictrue \Gin@defaultbp 391, 392 \ifmmode . . . . . 139, 342 ...... 70 \Gin@extensions ... \ifpdf ...... 24 \@ppf@tightpagefalse 16 . . 54, 71, 178, 278 \ifpr@outer ...... \@ppf@tightpagetrue \Gin@framefalse . . . 57 . 61, 177, 215, 416 ...... 5, 17 \Gin@ignorefalse . . 60 \ifvtex ...... 28 \Gin@ii ...... 55, 274 \ifxetex ...... 31 A \Gin@innerframefalse 58 \in@ ...... 69 \AtBeginDvi . . . 190, 192 \Gin@llx . . . . . 390, 397 \includegraphics .. \Gin@lly . . . . . 390, 395 .. 2, 371, 402, 411 C \Gin@nat@height ... \includegraphicx ... 3 \c@lor@to@ps . . 191, 199 . 389, 392, 394, 395 \c@pspicture 287, 307, \Gin@nat@width .... J 308, 311, 322, 419 . 389, 391, 396, 397 \jobname . . 40, 329, 330 \catcode . . . . . 425, 428 \Gin@page . . . . 273, 282 \Collect@Body . . . . . 361 \Gin@PS@file@header 195 K \CurrentOption 12, 15, 19 \Gin@PS@literal@header \KV@errx ...... 96 ...... 195 D \Gin@PS@raw ...... 196 L \DeclareGraphicsRule \Gin@PS@restored . . 196 \leavevmode ...... 400 ...... 103, 243 \Gin@req@height . . . 399 \long ...... 214 \define@key 104–109, \Gin@req@sizes . . . . 398 244, 246, 248, \Gin@req@width . . . . 399 M 250, 259, 261, 401 \Gin@setfile 67, 270, 271 \makeglossary . . . 80, 82 \detokenize . . . . . 66, 69 \Gin@shownamefalse . 59 \makeindex . . . . . 80, 81 \Gin@urx . . . . . 391, 396 \mbox ...... 174 E \Gin@ury . . . . . 392, 394 \endpostscript 365, 368 \Gin@viewport@code . 393 N \endpsmatrix ...... \Gin@vllx ...... 123 \newcolumntype . . . . 166 . . . . 152, 156, 368 \Gin@vlly ...... 123 \nofiles . . 79, 208, 212 \endpspicture . . . . . 365 \Gin@vurx ...... 123 \endtabularx ...... 168 \Gin@vury ...... 123 O environments: \Ginclude@graphics . \OptionNotUsed . . . . . 6 postscript 2, 116, 340 . . . . . 53, 176, 386 \output ...... 207, 213 psmatrix . . 134, 340 \Gscale@@box ...... 173 \overfullrule . . . . . 84

18 P 72, 180, 182, 185 \PreviewEnvironment \PassOptionsToPackage \ppf@is@pdfTeX@graphic . . . . 129, 133, 136 ...... 12, 15, 19 . 62, 178, 278, 435 \PreviewMacro ..... \PDFcontainer ..... \ppf@isnum . . . 337, 380 . 158, 171, 185, 233 39, 40, 281, 287, \ppf@namefont ..... \printindex . . . . . 80, 83 302, 304, 310, . 263, 264, 268, 295 \psmatrix . . . . 149, 312, 323, 325, 412 \ppf@nofiles . . 208, 212 151, 153, 154, 367 \pdflastximage . . . . 376 \ppf@other@extensions psmatrix (environ- \pdflastximagepages 305 ...... 42, 90, ment) . . . 134, 340 \pdfliteral ...... 186 101, 178, 242, 278 pspicture (environ- \pdfrefximage . . . . . 388 \ppf@output 206, 207, 213 ment) . 2, 133, 340 \pdfTeXext . . 65, 66, 69 \ppf@pr@psmatrix .. pst-pdf-defs (environ- \pdfximage ...... 304 ...... 150, 155 ment) . . 3, 45, 421 . . . . 364 \pfx@includegraphics \ppf@PreviewBbAdjust \pst@@@picture ...... 371 ...... 87, 89, 118 \pst@object . . . 164, 239 \pfx@includegraphicx \PSTricksOff ...... 198 \ppf@psmatrix . 149, 153 ...... 171, 372 \ppf@RestoreBbAdjust \postscript . . . 364, 367 R ...... 88, 128 postscript (environ- \raisebox ...... 296 \ppf@set@mode ..... ment) . 2, 116, 340 \refstepcounter 286, 417 . 137, 141, 143, \ppf@@getpicture .. \rule ...... 179 146, 155, 156, . 228, 360, 372, 415 340, 344, 346, 349 \ppf@container@max . S \ppf@shipout . . 209, 211 ...... 304, \savepicture . 3, 44, 375 \ppf@temp ...... 308, 310, 320, 407 \setkeys . . . . . 121, 280 . 190, 192, 425, 428 \ppf@draft 3, 13, 14, 411 \shipout . . . . . 209, 211 . . . 276, \ppf@endpsmatrix .. \ppf@tempb \string ...... 151, 154 277, 281, 287, 292 ...... 152, 156 \strutbox ...... 296 \ppf@filename . 267, \ppf@test@mmode ... 272, 296, 297, 387 . . . . 138, 153, 341 T \ppf@getpicture ... \ppf@TeX@mode ..... \tabularx ...... 167 . . . . 381, 405, 418 . . . 2, 7, 8, 21, \ppf@Gin@extensions 54 23, 25, 29, 32, U \ppf@Gin@ii . . . . 55, 291 34, 76, 78, 188, 433 \usepicture .. 3, 43, 377 \ppf@Gin@keys . 269, \pr@cleanup . . . 217, 229 356, 358, 414, 418 \pr@endbox ...... 225 V \ppf@Gin@setfile .. \pr@outerfalse . 72, 220 \voidb@x ...... 227 ...... 270, 271 \pr@startbox ...... 214 \ppf@Ginclude@graphics \PreviewBbAdjust .. X ...... 53, . 89, 111, 118, 122 \XKV@err ...... 99

19