summaryrefslogtreecommitdiff
path: root/graphics/pstricks/base/latex/pstricks-pdf.sty
blob: 9923109fbbabe990340b475c4ae36d5945e30989 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
% $Id: pstricks-pdf.sty 23 2020-09-18 06:29:04Z herbert $
%%
%% This is file `pstricks-pdf.sty'.
%%
%% IMPORTANT NOTICE:
%%
%% pstricks-pdf.sty Copyright (C) 2020 Herbert Voss <hvoss@tug.org>
%%
%% This package may be distributed under the terms of the LaTeX Project
%% Public License, as described in lppl.txt in the base LaTeX distribution.
%% Either version 1.0 or, at your option, any later version.
%%
%%
%% This code is more or less exactly the same as for auto-pst-pdf from
%% Will Robertson
%%

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{pstricks-pdf}[2020/06/11 v0.02 creating pdf output (hv)]
\RequirePackage{ifpdf,xkeyval,ifplatform}

\newif\if@app@off@
\newif\if@app@crop@
\newcounter{app@runs}
\def\app@suffix{autopp}
\edef\app@jobname{\jobname-\app@suffix}
\edef\app@pics{\jobname-pics.pdf}
\DeclareOptionX{off}[]{\@app@off@true}
\define@choicekey{pstricks-pdf.sty}{crop}[\@tempa\@tempb]{on,off}{%
  \ifcase\@tempb\relax
    \@app@crop@true
  \or
    \@app@crop@false
  \fi}
\DeclareOptionX{on}[]{\@app@off@false}
\DeclareOptionX{ext}{\def\app@ext{#1}}
\DeclareOptionX{latex}{%
  \def\app@latex@opts{%
    \ifwindows
      -disable-write18
    \else
      -no-shell-escape
    \fi
    -jobname="\app@jobname"
    -interaction=batchmode
    #1}}
\DeclareOptionX{dvips}{\def\app@dvips@opts{#1}}
\DeclareOptionX{pspdf}{\def\app@pspdf@opts{#1}}
\DeclareOptionX{pdfcrop}{\def\app@pdfcrop@opts{#1}}

\DeclareOptionX{cleanup}{%
  \let\app@rm@files\@empty
  \@for\@ii:=#1\do{%
    \edef\app@rm@files{\app@rm@files,\app@jobname.\@ii}}}

\DeclareOptionX{runs}{%
  \setcounter{app@runs}{#1}% support calc
  \ifnum\c@app@runs > \z@
  \else
    \app@PackageWarning{The number of runs must be at least one.}%
    \c@app@runs\@ne
  \fi}

\DeclareOptionX*{\PassOptionsToPackage{\CurrentOption}{pst-pdf}\PassOptionsToPackage{\CurrentOption}{pstricks}}

\ExecuteOptionsX{%
    ext=tex,
    crop=on,
    latex={},
    dvips={-Ppdf},
    pdfcrop={},
    cleanup={log,aux,dvi,ps,pdf},
    runs=1,
    pspdf={-dALLOWPSTRANSPARENCY},
}
\ifwindows
  \ExecuteOptionsX{pspdf={}}
\else
  \ExecuteOptionsX{pspdf={-dAutoRotatePages=/None}}
\fi
\ProcessOptionsX
\def\app@exe{\immediate\write18}
\def\app@nl{^^J\space\space\space\space}
\newcommand\app@PackageError[2]{%
  \PackageError{pstricks-pdf}{\app@nl #1^^J}{#2}}
\newcommand\app@PackageWarning[1]{%
  \PackageWarning{pstricks-pdf}{\app@nl #1^^JThis warning occured}}
\newcommand\app@PackageInfo[1]{\PackageInfo{pstricks-pdf}{#1}}
\newcommand\OnlyIfFileExists[2]{\IfFileExists{#1}{#2}{}}
\newcommand\NotIfFileExists[2]{\IfFileExists{#1}{}{#2}}
\def\app@convert#1#2#3{%
  \OnlyIfFileExists{#2}{%
    \app@exe{\csname app@cmd@#1\endcsname{#2}{#3}}%
    \NotIfFileExists{#3}{\app@PackageWarning{Creation of #3 failed.}}}}
\def\app@compile{%
  \app@cleanup
  \app@remove@container
  \loop\ifnum\c@app@runs > \@ne
     \app@convert{extralatex}{\jobname.\app@ext}{\app@jobname.dvi}%
     \advance\c@app@runs\m@ne
  \repeat
  \app@convert{latex}{\jobname.\app@ext}{\app@jobname.dvi}%
  \app@convert{dvips}{\app@jobname.dvi}{\app@jobname.ps}%
  \if@app@crop@
    \app@convert{pstopdf}{\app@jobname.ps}{\app@jobname.pdf}%
    \app@convert{pdfcrop}{\app@jobname.pdf}{\app@pics}%
  \else
    \app@convert{pstopdf}{\app@jobname.ps}{\app@pics}%
  \fi
  \IfFileExists{\app@pics}
    {\app@cleanup}
    {\app@PackageWarning{Could not create \app@pics.
      Auxiliary files not deleted.}}}
\edef\app@rm{\ifwindows del \else rm -- \fi}
\newcommand\app@try@rm[1]{%
  \@for\@tempa:=#1\do{%
    \OnlyIfFileExists{\@tempa}{\app@exe{\app@rm "\@tempa"}}}}
\def\app@remove@container{\app@try@rm{\app@pics}}
\def\app@cleanup{\app@try@rm{\app@rm@files}}
\def\app@cmd@latex#1#2{latex \app@latex@opts\space
  "\unexpanded{\let\APPmakepictures\empty\input} #1"}
\def\app@cmd@extralatex#1#2{latex \app@latex@opts\space
  "\unexpanded{\let\APPmakepictures\undefined\input} #1"}
\def\app@cmd@dvips#1#2{dvips \app@dvips@opts\space -o "#2" "#1"}
\def\app@cmd@pstopdf#1#2{ps2pdf \app@pspdf@opts\space "#1" "#2"}
\def\app@cmd@pdfcrop#1#2{pdfcrop \app@pdfcrop@opts\space "#1" "#2"}
\ifpdf
  \if@app@off@\else
    \ifshellescape
      \app@exe{echo "  "}
      \app@exe{echo "-------------------------------------------------"}
      \app@exe{echo "pstricks-pdf: Auxiliary LaTeX compilation"}
      \app@exe{echo "-------------------------------------------------"}
      \app@compile
      \app@exe{echo "-------------------------------------------------"}
      \app@exe{echo "pstricks-pdf: End auxiliary LaTeX compilation"}
      \app@exe{echo "-------------------------------------------------"}
    \else
      \app@PackageError{%
        "shell escape" (or "write18") is not enabled:\app@nl
        pstricks-pdf will not work!}
       {You need to run LaTeX with the equivalent of
        "pdflatex -shell-escape"\app@nl
        Or turn off pstricks-pdf.}%
    \fi
  \fi
  \if@app@crop@
    \PassOptionsToPackage{notightpage}{pst-pdf}
  \fi
\else
  \ifx\APPmakepictures\@undefined
    \PassOptionsToPackage{inactive}{pst-pdf}
  \else
    \if@app@crop@
      \PassOptionsToPackage{notightpage}{pst-pdf}
    \fi
  \fi
\fi
\RequirePackage{pst-pdf}
\let\app@ig\includegraphics

\ifpdf\else\RequirePackage{pstricks}\fi

%%
%% End of file `pstricks-pdf.sty'.