Debian Codegraph @

texmf-dist/doc/support/pst2pdf/pst2pdf-doc.tex

raw
1 \documentclass[11pt,english,
2 BCOR=10mm,DIV=10,% <- changed
3 bibliography=totoc,parskip=half*,<- changed
4 headings=small,% <- changed
5 headinclude=false,% <- changed
6 footinclude=false,oneside,mpinclude=false]{pst-doc}
7 \AfterCalculatingTypearea{%
8 \newgeometry{top=0.5in, bottom=0.3in,left=1.4in,right=0.7in,%
9 marginparwidth=1.3in,marginparsep=0.1in,footskip=0.2in,%
10 headheight=1cm,headsep=0.27cm,reversemarginpar}%
11 \KOMAoptions{headwidth=text,headsepline=:text,footwidth=text}% <- added
12 }
13 \recalctypearea
14 \RedeclareSectionCommand[
15 %runin=false,
16 afterindent=false,
17 beforeskip=\baselineskip,
18 afterskip=.5\baselineskip]{section}
19 \RedeclareSectionCommand[
20 %runin=false,
21 afterindent=false,
22 beforeskip=.75\baselineskip,
23 afterskip=.5\baselineskip]{subsection}
24 \RedeclareSectionCommand[
25 %runin=false,
26 afterindent=false,
27 beforeskip=.5\baselineskip,
28 afterskip=.25\baselineskip]{subsubsection}
29 \listfiles
30 \let\Lfile\LFile
31 \usepackage{biblatex}
32 \addbibresource{\jobname.bib}
33 %\lstset{language=PSTricks,basicstyle=\footnotesize\ttfamily}
34 \def\DVI{\textsc{DVI}}
35 \def\PDF{\textsc{PDF}}
36 \def\gs{\textsc{Ghostscript}}
37 \usepackage{multicol,enumitem,hologo,accsupp,csquotes}
38
39 % Identification
40 \def\myscript{pst2pdf}
41 \def\fileversion{0.20}
42 \def\filedate{2020-08-22}
43
44 % Config hyperref
45 \hypersetup{
46 linktoc = all,
47 pdftitle = {.:: pst2pdf v\fileversion{} [\filedate] --- Running a PSTricks document with (pdf/xe/lua)latex ::.},%
48 pdfauthor = {Herbert Vo\ss, Pablo Gonz\'{a}lez Luengo},%
49 pdfsubject = {Documentation for version \fileversion},%
50 pdfkeywords = {extract, conversion, images, pstricks, standalone files},
51 pdfstartview = {FitH},%
52 bookmarksopenlevel = 2,%
53 }
54
55 % Some font for verbatim examples
56 \newfontfamily\lmmitalic{lmmono10-italic.otf}[
57 Scale = 0.95,%
58 Extension = .otf,%
59 ItalicFont = lmmono10-italic,%
60 SmallCapsFont = lmmonocaps10-oblique,%
61 SlantedFont = lmmonoslant10-regular,
62 ]
63 % The character of visible space is now taken from Latin Modern Mono
64 % to prevent fonts in T1. The original definition for xetex/luatex is
65 % \def\verbvisiblespace{\usefont{OT1}{cmtt}{m}{n}\asciispace}
66 \def\verbvisiblespace{{\fontfamily{lmtt}\selectfont\char"2423}}
67 % Add some colors
68 \definecolor{optcolor}{rgb}{0.281,0.275,0.485}
69 \definecolor{pkgcolor}{rgb}{0,0.5,0.5}
70 \definecolor{araracolor}{rgb}{0, 0.72, 0.28}
71 \definecolor{linkcolor}{rgb}{0.04,0.38,0.04}
72 \definecolor{rulecolor}{rgb}{0.96,0.96,0.96}
73
74 % new macros
75 \makeatletter
76 \def\Lscript#1{\texttt{#1}\index{#1@\texttt{#1}}\index{Script!#1@\texttt{#1}}}
77 \def\Losystem#1{\texttt{#1}\index{#1@\texttt{#1}}\index{Operating system!#1@\texttt{#1}}}
78 \def\Loptcmd#1{\index{Options in command line!#1@\texttt{#1}}}% \index{#1@\texttt{#1}}
79 \def\Limgform#1{\texttt{#1}\index{Image format!#1@\texttt{#1}}}% \index{#1@\texttt{#1}}
80 \def\Loptprg#1{\index{Compiler options!#1@\texttt{#1}}}% \index{#1@\texttt{#1}}
81 \def\Venv#1{\texttt{#1}\index{Environment Verbatim!#1@\texttt{#1}}}
82 \def\Wenv#1{\texttt{#1}\index{Environment Verbatim Write!#1@\texttt{#1}}}
83
84 % Only index a starred version
85 \RenewDocumentCommand{\LFile}{sm}
86 {
87 \IfBooleanTF{#1}%
88 {%
89 \LFile{#2}
90
91 }%
92 {%
93 \texttt{#2}%
94 }%
95 }%
96
97 % \prgopt{sm} : #1 compiler opt, #2 program opt:
98 \NewDocumentCommand{\prgopt}{sm}
99 {
100 \IfBooleanTF{#1}%
101 {%
102 \mbox{\textcolor{gray}{\texttt{-{}#2}}}%
103 \Loptprg{-{}#2}%
104 }%
105 {%
106 \mbox{\textcolor{gray}{\texttt{-{}#2}}}%
107 \index{#2@\texttt{-{}#2}}\index{Program options!#1@\texttt{-{}#2}}%
108 }%
109 }%
110
111 % \DescribeIF{m}, #1 image format
112 \newsavebox{\marginIF}
113 \NewDocumentCommand{\DescribeIF}{ m }
114 {%
115 \begin{lrbox}{\marginIF}%
116 \begin{minipage}[t]{\marginparwidth}%
117 \raggedleft\ttfamily\bfseries%
118 \textcolor{optcolor}{#1}\hfill
119 \end{minipage}%
120 \end{lrbox}%
121 \index{Image format!#1@\texttt{#1}}%
122 \leavevmode%
123 \marginpar{\usebox{\marginIF}}%
124 \ignorespaces%
125 }%
126
127 % \myenv{environ} for margin
128 \NewDocumentCommand{\myenv}{m}
129 {
130 \begin{minipage}[t]{\marginparwidth}%
131 \raggedleft\ttfamily\small%
132 {\textcolor{gray}{\textbackslash begin\{}}{\bfseries\textcolor{pkgcolor}{#1}}\textcolor{gray}{\}}\par%
133 \meta[ac=lightgray,cf=gray]{env content}\par%
134 {\textcolor{gray}{\textbackslash end\{}}{\bfseries\textcolor{pkgcolor}{#1}}\textcolor{gray}{\}}%
135 \end{minipage}%
136 \index{Environment suport by default!#1@\texttt{#1}}
137 }
138 % CleanPST for margin
139 \NewDocumentCommand{\mytag}{m}
140 {%
141 \begin{minipage}[t]{\marginparwidth}%
142 \raggedleft\ttfamily\small%
143 \textcolor{gray}{\%}{\bfseries\textcolor{pkgcolor}{#1}}\par%
144 \meta[ac=lightgray,cf=gray]{code}\par%
145 \textcolor{gray}{\%}{\bfseries\textcolor{pkgcolor}{#1}}%
146 \end{minipage}%
147 \index{Remove PST code!#1@\texttt{#1}}
148 }%
149
150 % \DescribeTE{sm}, #1 tag, #2 env
151 \newsavebox{\marginenvtag}
152 \NewDocumentCommand{\DescribeTE}{sm}{%
153 \begin{lrbox}{\marginenvtag}%
154 \begin{minipage}[t]{\marginparwidth}%
155 \raggedleft
156 \IfBooleanTF{#1}{\mytag{#2}}{\myenv{#2}}
157 \end{minipage}%
158 \end{lrbox}%
159 \leavevmode%
160 \marginpar{\usebox{\marginenvtag}}%
161 \ignorespaces%
162 }%
163 \makeatother
164
165 \ExplSyntaxOn
166 % \cmdopt[short]{long}
167 \NewDocumentCommand{\cmdopt}{om}
168 {
169 \IfNoValueTF{#1}
170 {
171 \textcolor{optcolor}{\texttt{-\/-#2}}
172 }
173 {
174 \textcolor{optcolor}{\texttt{-{}#1}},
175 \textcolor{optcolor}{\texttt{-\/-#2}}
176 }
177 \Loptcmd{-\/-#2}
178 }
179
180 % Custom \meta[...]{...}, \marg[...]{...} and \oarg[...]{...} for color
181 \NewDocumentCommand{\meta}{O{}m}
182 {
183 \myscript_meta_generic:Nnn \myscript_meta:n { #1 } { #2 }
184 }
185 \NewDocumentCommand{\marg}{O{}m}
186 {
187 \myscript_meta_generic:Nnn \myscript_marg:n { #1 } { #2 }
188 }
189 \NewDocumentCommand{\oarg}{O{}m}
190 {
191 \myscript_meta_generic:Nnn \myscript_oarg:n { #1 } { #2 }
192 }
193 % Variables and keys
194 \tl_new:N \l_myscript_meta_font_tl
195
196 \keys_define:nn { myscript/meta }
197 {
198 type .choice:,
199 type / tt .code:n = \tl_set:Nn \l_myscript_meta_font_tl { \ttfamily },
200 type / rm .code:n = \tl_set:Nn \l_myscript_meta_font_tl { \rmfamily },
201 type .initial:n = rm,
202 cf .tl_set:N = \l_myscript_meta_color_tl,
203 cf .initial:n = black,%
204 ac .tl_set:N = \l_myscript_meta_anglecolor_tl,
205 ac .initial:n = lightgray,
206 sbc .tl_set:N = \l_myscript_meta_brackcolor_tl,
207 sbc .initial:n = gray,
208 cbc .tl_set:N = \l_myscript_meta_bracecolor_tl,
209 cbc .initial:n = gray,
210 }
211 % Internal commands
212 \cs_new_protected:Npn \myscript_meta_generic:Nnn #1 #2 #3
213 {
214 \group_begin:
215 \keys_set:nn { myscript/meta } { #2 }
216 \color{ \l_myscript_meta_color_tl }
217 \l_myscript_meta_font_tl
218 #1 { #3 } % #1 is \myscript_meta:n, \myscript_marg:n or \myscript_oarg:n
219 \group_end:
220 }
221 \cs_new_protected:Npn \myscript_meta:n #1
222 {
223 \myscript_meta_angle:n { \textlangle }
224 \myscript_meta_meta:n { #1 }
225 \myscript_meta_angle:n { \textrangle }
226 }
227 \cs_new_protected:Npn \myscript_marg:n #1
228 {
229 \myscript_meta_brace:n { \textbraceleft }
230 \myscript_meta:n { #1 }
231 \myscript_meta_brace:n { \textbraceright }
232 }
233 \cs_new_protected:Npn \myscript_oarg:n #1
234 {
235 \myscript_meta_brack:n { [ }
236 \myscript_meta:n { #1 }
237 \myscript_meta_brack:n { ] }
238 }
239 \cs_new_protected:Npn \myscript_meta_meta:n #1
240 {
241 \textnormal{\textit{#1}}
242 }
243 \cs_new_protected:Npn \myscript_meta_angle:n #1
244 {
245 \group_begin:
246 \fontfamily{lmr}\selectfont
247 \textcolor{\l_myscript_meta_anglecolor_tl}{#1}
248 \group_end:
249 }
250 \cs_new_protected:Npn \myscript_meta_brace:n #1
251 {
252 \group_begin:
253 \color{\l_myscript_meta_bracecolor_tl}
254 #1
255 \group_end:
256 }
257 \cs_new_protected:Npn \myscript_meta_brack:n #1
258 {
259 \textcolor{\l_myscript_meta_brackcolor_tl}{#1}
260 }
261
262 % \DescribeCmd[...]{...}{...}{...}
263 \newsavebox{\optcmdline}
264 \NewDocumentCommand{\DescribeCmd}{ o m m m }
265 {
266 \group_begin:
267 \begin{lrbox}{\optcmdline}%
268 \begin{minipage}[t]{\marginparwidth}%
269 \ttfamily\raggedleft%
270 \IfNoValueTF{#1}
271 {\textcolor{optcolor}{-\/-#2}}
272 {\textcolor{optcolor}{-{#1}}\textcolor{gray}{,} \textcolor{optcolor}{-\/-#2}}%
273 \end{minipage}%
274 \Loptcmd{-\/-#2}
275 \end{lrbox}%
276 \leavevmode%
277 \marginpar{\usebox{\optcmdline}}%
278 \meta[ac=lightgray,cf=gray]{#3}
279 \raggedleft\hfill\textcolor{gray}{\textsf{(default: ~ {#4})}}\ignorespaces\par%
280 %\vspace*{2pt}\par%
281 \group_end:
282 }
283
284 \ExplSyntaxOff
285 % Don't copy numbers in code example for listings
286 \newcommand*{\noaccsupp}[1]{\BeginAccSupp{ActualText={}}#1\EndAccSupp{}}
287
288 % Create a language for documentation
289 \lstdefinelanguage{myscript-doc}{
290 texcsstyle=*,%
291 escapechar=`,%
292 showstringspaces=false,%
293 extendedchars=true, %
294 stringstyle = {\color{red}},%
295 alsoletter={\-,.},%
296 % comments
297 morecomment=[l]{\%},%
298 commentstyle=\lmmitalic\color{lightgray},%
299 % Important words 1
300 keywordstyle=[1]{\color{NavyBlue}},%
301 keywords=[1]{PassOptionsToPackage,AtBeginDocument,documentclass,usepackage,section},%
302 % Important words 2 (macros)
303 keywordstyle=[2]{\color{blue!75}},%
304 keywords=[2]{graphicspath,RequirePackage,renewcommand,includegraphics,coordinate,draw,approx,%
305 PreviewBbAdjust,setlength,parindent,usetikzlibrary,tikzexternalize,psset,tikzset,PrependGraphicsExtensions,%
306 DefineShortVerb,lstMakeShortInline,MakeSpecialShortVerb,UndefineShortVerb,verb,myverb,macro,put,line},%
307 % Important words 3, options in input file
308 keywordstyle=[3]{\color{optcolor!85}},%
309 keywords=[3]{arara,extensions,luatex,env,norun,%
310 clean,pst,tkz,eps,pdf,xetex,latex,luatex,dvips,png,latexmk,svg,srcenv,noprew,imgdir},%
311 % Important words 4, environments and tags
312 keywordstyle=[4]{\color{pkgcolor}},%
313 keywords=[4]{pspicture,endpspicture,description,filecontents,PSTexample,%
314 psgraph, endpsgraph,CleanPST,postscript},%
315 % Important words 5, directory
316 keywordstyle=[5]{\color{OrangeRed}},%
317 keywords=[5]{images},% ,pics
318 % Important words 6, begin, end and other
319 keywordstyle=[6]{\color{gray}},% replace this color
320 keywords=[6]{begin,end,-recorder,doc,active,inactive,tightpage,BEGIN,END,%
321 -shell-escape,osf,--output-format,dvi},%
322 % Important words 7, reserved for arara
323 keywordstyle=[7]{\color{araracolor}},%
324 keywords=[7]{lualatex,halt,xelatex},%
325 % Important words 8, pkg and others load in examples
326 keywordstyle=[8]{\color{SlateBlue}},%
327 keywords=[8]{graphicx,grfext,article,document,preview,libertinus,pst-pdf},%
328 % Important words 9, files used in examples
329 keywordstyle=[10]{\color{OrangeRed}},%
330 keywords=[10]{test.ltx,test-fig-all.pdf,test-fig-1981.tex,test-fig-1981.pdf, test-fig-1,test-fig-2,test-out,test-in.ltx,%
331 test-fig-1981.tex,test-out.tex,file-in.tex,file-out,test.tex,test-fig-all.dvi,test-fig-1.svg,test-fig-all.tex},%
332 }[keywords,tex,comments,strings]% end languaje
333
334 % \begin{examplecode}[opts]...\end{examplecode}
335 \lstnewenvironment{examplecode}[1][]{%
336 \lstset{
337 language=myscript-doc,%
338 stringstyle = {\color{red}},%
339 basicstyle=\ttfamily\small,%
340 numbersep=1em,%
341 numberstyle=\tiny\color{gray}\noaccsupp,%
342 rulecolor=\color{gray!50},%
343 framesep=\fboxsep,%
344 framerule=\fboxrule,%
345 xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,%
346 xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,%
347 % literateee
348 literate=*{\{}{{\bfseries\textcolor{gray}{\{}}}{1}
349 {\}}{{\bfseries\textcolor{gray}{\}}}}{1}
350 {[}{{\textcolor{gray}{[}}}{1}
351 {]}{{\textcolor{gray}{]}}}{1}
352 {\*}{{\bfseries\textcolor{MediumOrchid}{*}}}{1}
353 {:}{{\textcolor{gray}{:}}}{1}
354 {,}{{\textcolor{gray}{,}}}{1}
355 {=}{{\textcolor{gray}{=}}}{1}
356 {/}{{\textcolor{OrangeRed}{/}}}{1}
357 {scale=1}{{\textcolor{gray}{scale=1}}}{7}
358 {\%CleanPST}{{\textcolor{gray}{\%}\textcolor{pkgcolor}{CleanPST}}}{9},%
359 #1,%
360 }% close lstset
361 }%
362 {}% close examplecode
363
364 % \begin{examplecmd}...\end{examplecmd}
365 \lstnewenvironment{examplecmd}{%
366 \lstset{
367 language=myscript-doc,%
368 basicstyle=\ttfamily\small,%
369 frame=single,%
370 alsoletter={\-,.,\-\-},%
371 rulecolor=\color{gray!50},%
372 framesep=\fboxsep,%
373 framerule=\fboxrule,%
374 xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,%
375 xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,%
376 keywordstyle=[20]{\color{gray}},% replace this color
377 keywords=[20]{--margins, -recorder,-shell-escape,-s,-o,-e,-p,-j,--imgdir,%
378 --luatex,--latexmk,--svg,--png,--nopdf,pics,-no-shell-escape,-interaction,nonstopmode},%
379 % Reserved words (cmd line options)
380 deletekeywords=[4]{pst2pdf},%
381 classoffset=7,%
382 keywordstyle=\bfseries\color{ForestGreen},%
383 morekeywords={pst2pdf},%
384 % % Reserved words (cmd line options)
385 classoffset=8,%
386 keywordstyle={\color{ForestGreen}},%
387 morekeywords={gs,pdftoppm,pdftocairo,pdftops,cd,perl,pdfcrop},%
388 % Only for command line options
389 classoffset=5,%
390 keywordstyle=\color{blue},%
391 keywords={user,machine},%
392 literate=*{[}{{\textcolor{darkgray}{[}}}{1}
393 {]}{{\textcolor{darkgray}{]}}}{1}
394 {=}{{\textcolor{gray}{=}}}{1}
395 {@}{{\textcolor{blue}{@}}}{1}
396 {\$}{{\textcolor{blue}{\$}}}{1}
397 {:}{{\textcolor{blue}{:}}}{1}
398 {§}{{\textcolor{red}{\$\space}}}{2}
399 {~}{{\textcolor{blue}{\bfseries\textasciitilde}}}{1}%
400 }% close lstset
401 }%
402 {}% close examplecmd
403
404 % \lstinline[style=inline]|...|
405 \lstdefinestyle{inline}
406 {
407 language=myscript-doc,%
408 basicstyle=\ttfamily\color{gray},%
409 escapechar=`,%
410 upquote=true,%
411 deletekeywords=[8]{preview},%
412 morekeywords =[4]{preview},%
413 literate=*{\%}{{\bfseries\textcolor{gray}{\%}}}{1}
414 {\*}{{\bfseries\textcolor{MediumOrchid}{*}}}{1}
415 }
416
417 % set default style
418 \lstset{style=inline}
419
420 \begin{document}
421
422 \title{\texttt{pst2pdf}}
423 \subtitle{Running a PSTricks document with (pdf/xe/lua)latex;\\ v\fileversion{} --- \filedate\thanks{%
424 This file describes a documentation for version \fileversion, last revised \filedate.}}
425 \author{Herbert Voß \\ Pablo Gonz\'{a}lez L}
426 \date{}
427
428 \maketitle
429
430 \begin{abstract}
431
432 \texttt{pst2pdf} is a \texttt{Perl} \emph{script} which isolates all \texttt{PostScript} or \texttt{PSTricks} related
433 parts of the \TeX{} document, read all \texttt{postscript}, \texttt{pspicture}, \texttt{psgraph}
434 and \texttt{PSTexample} environments and, extract source code in \emph{standalone} files and
435 converting them into image format \texttt{pdf, eps, jpg, svg} or \texttt{png} (default \texttt{pdf}).
436 Create new file with all extracted environments converted to \Lcs{includegraphics} and runs \texttt{(pdf/Xe/lua)latex}.
437 \end{abstract}
438
439 \tableofcontents
440
441 \clearpage
442 \newpage
443
444 \section{Introduction}
445
446 \PST\ as \PS\ related package uses the programming language \PS\ for internal
447 calculations. This is an important advantage, because floating point arithmetic is no
448 problem. Nearly all mathematical calculation can be done when running the \DVI-file
449 with \gs. However, creating a \PDF\ file in a direct way with \Lprog{pdflatex} is
450 not possible. \Lprog{pdflatex} cannot understand the \PS\ related stuff.
451
452 Instead of running \Lprog{pdflatex} one can use the \emph{script} \Lscript{pst2pdf}, it extracts
453 all \PST\ related code into single documents with the same preamble as the original
454 main document.
455
456 The \Lscript{pst2pdf} \emph{script} runs document, extract source code for all \PST\ as \PS\ related parts, clips all whitespace around the
457 image and creates a \Lext{pdf} images of the \PST\ related code.
458
459 In a last run which is the \Lprog{pdflatex} the \PST\ code in the
460 main document is replaced by the created images.
461
462 \section{License}
463
464 This program is free software; you can redistribute it and/or modify
465 it under the terms of the \href{https://www.gnu.org/licenses/gpl-3.0.html}{GNU General Public License} as published by
466 the \href{https://www.fsf.org/}{Free Software Foundation}; either version 3 of the License, or
467 (at your option) any later version.
468
469
470 This program is distributed in the hope that it will be useful, but
471 WITHOUT ANY WARRANTY; without even the implied warranty of
472 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the \href{https://www.gnu.org/licenses/gpl-3.0.html}{GNU General Public License}
473 for more details.
474
475 \section{Requirements for operation}
476
477 For the complete operation of \Lscript{pst2pdf}{} you need to have a modern %
478 \hologo{TeX} distribution such as \hologo{TeX} Live or \hologo{MiKTeX}, the packages \LPack{preview}\cite{preview},
479 \LPack{pst-pdf}\cite{pst-pdf}, \LPack{graphicx}\cite{graphicx} and \LPack{grfext}\cite{grfext}, have
480 a version equal to or greater than \liningnums{5.28} of \Lprog{perl}, a
481 version equal to or greater than \liningnums{9.24} of \Lprog{Ghostscript}, a
482 version equal to or greater than \liningnums{1.40} of \Lscript{pdfcrop}
483 and have a version equal to or greater than \liningnums{0.52} of %
484 \Lprog{poppler-utils}.
485
486 The distribution of \hologo{TeX} Live 2020 for \Losystem{Windows} includes %
487 \Lscript{pst2pdf} and all requirements, \hologo{MiKTeX} users must install the
488 appropriate software for full operation.
489
490 The script auto detects the \Lprog{Ghostscript}, but not \Lprog{poppler-utils}.
491 You should keep this in mind if you are using the script directly and not
492 the version provided in your \hologo{TeX} distribution.
493
494 The script has been tested on \Losystem{Windows} (v10) and %
495 \Losystem{Linux} (fedora 32) using \Lprog{Ghostscript} %
496 \liningnums{v9.52}, \Lprog{poppler-utils} \liningnums{v0.84}, \Lprog{perl} \liningnums{v5.30}
497 and the standard classes offers by \hologo{LaTeX}: \LClass{book},
498 \LClass{report}, \LClass{article} and \LClass{letter}.
499
500 \section{How it works}
501 \label{sec:howtowork}
502
503 It is important to have a general idea of how the \emph{\enquote{extraction and conversion}}
504 process works and the requirements that must be fulfilled so
505 that everything works correctly, for this we must be clear about some
506 concepts related to how to work with the \meta{input file}, the \meta{verbatim content}
507 and the \meta{steps process}.
508
509 \subsection{The input file}
510 \label{sec:inputfile}
511
512 The \meta{input file} must comply with \emph{certain characteristics} in order to
513 be processed, the content at the beginning and at the end of the \meta{input
514 file} is treated in a special way, before \lstinline|\documentclass| and after
515 \lstinline|\end{document}| can go any type of content, internally the script will
516 \emph{\enquote{split}} the \meta{input file} at this points.
517
518 If the \meta{input file} contains files using \Lcs{input}\marg[type=tt]{file} or
519 \Lcs{include}\marg[type=tt]{file} these will not be processed, from the side of
520 the \emph{script} they only represent lines within the file, if you want
521 them to be processed it is better to use the \Lscript{latexpand}\footnote{\url{https://www.ctan.org/pkg/latexpand}}
522 first and then process the file.
523
524 Like \Lcs{input}\marg[type=tt]{file} or \Lcs{include}\marg[type=tt]{file}, blank lines, vertical spaces and tab
525 characters are treated literally, for the \emph{script} the \meta{input file}
526 is just a set of characters, as if it was a simple text file. It is
527 advisable to format the source code \meta{input file} using utilities such
528 as \Lprog{chktex}\footnote{\url{https://www.ctan.org/pkg/chktex}} and
529 \Lscript{latexindent}\footnote{\url{https://www.ctan.org/pkg/latexindent}}, especially if you want to
530 extract the source code of the environments.
531
532 Both \Lcs{thispagestyle}\marg[type=tt]{style} and \Lcs{pagestyle}\marg[type=tt]{style}
533 are treated in a special way by the script, if they do not appear in the
534 preamble then \Lcs{pagestyle}\marg[type=tt]{empty} will be added and if they are present
535 and \marg[type=tt]{style} is different from \marg[type=tt]{empty} this
536 will be replaced by \marg[type=tt]{empty}.
537
538 This is necessary for the image creation process, it does not affect the \meta{output file}, but
539 it does affect the \emph{standalone} files. For the script the process of dividing the \meta{input file} into four
540 parts and then processing them:
541
542 \begin{examplecode}[numbers=left,frame=single]
543 % Part One: Everything before \documentclass
544 \documentclass{article}
545 % Part two: Everything between \documentclass and \begin{document}
546 \begin{document}
547 % Part three: : Everything between \begin{document} and \end{document}
548 \end{document}
549 % Part Four: Everything after \end{document}
550 \end{examplecode}
551
552 If for some reason you have an environment \Lenv{filecontens} before \lstinline|\documentclass| or
553 in the preamble of the \meta{input file} that contains a \emph{sub-document} or \emph{environment}
554 you want to extract, the script will ignore them. Similarly, the content after \lstinline|\end{document}|
555 is ignored in the extraction process.
556
557 \subsection{Verbatim contents}
558 \label{sec:verbatim}
559
560 One of the greatest capabilities of this script is to \emph{\enquote{skip}}
561 the complications that \meta{verbatim content} produces with the extraction
562 of environments using tools outside the \enquote{\hologo{TeX} world}.
563 In order to \emph{\enquote{skip}} the complications, the \meta{verbatim content} is classified into
564 three types:
565
566 \begin{itemize}[nosep]
567 \item Verbatim in line.
568 \item Verbatim standard.
569 \item Verbatim write.
570 \end{itemize}
571
572 \subsubsection{Verbatim in line}
573 \label{sec:verbatim:inline}
574
575 The small pieces of code written using a \emph{\enquote{verbatim macro}}
576 are considered \meta{verbatim in line}, such as \lstinline+\verb|+\meta{code}\lstinline+|+
577 or \lstinline+\verb*|+\meta{code}\lstinline+|+ or \lstinline+\macro+\marg[type=tt]{code} or
578 \lstinline+\macro+\oarg[type=tt]{opts}\marg[type=tt]{code}.
579
580 Most \emph{\enquote{verbatim macro}} provide by packages \LPack{minted}, %
581 \LPack{fancyvrb} and \LPack{listings} have been tested and are fully
582 supported. They are automatically detected the \emph{verbatim macro} (including \texttt{\small\bfseries\textcolor{MediumOrchid}{*}} argument) generates by
583 \Lcs{newmint} and \Lcs{newmintinline} and the following list:
584
585 \vspace*{-10pt}
586 \begin{multicols}{3}
587 \begin{itemize}[font=\sffamily\small,partopsep=5pt,parsep=5pt,nosep,leftmargin=*]
588 \small
589 \item \Lcs{mint}
590 \item \Lcs{spverb}
591 \item \Lcs{qverb}
592 \item \Lcs{fverb}
593 \item \Lcs{verb}
594 \item \Lcs{Verb}
595 \item \Lcs{lstinline}
596 \item \Lcs{pyginline}
597 \item \Lcs{pygment}
598 \item \Lcs{Scontents}
599 \item \Lcs{tcboxverb}
600 \item \Lcs{mintinline}
601 \end{itemize}
602 \end{multicols}
603
604 Some packages define abbreviated versions for \emph{\enquote{verbatim macro}} as %
605 \Lcs{DefineShortVerb}, \Lcs{lstMakeShortInline} and %
606 \Lcs{MakeSpecialShortVerb}, will be detected automatically if are declared
607 explicitly in \meta{input file}.
608
609 The following consideration should be kept in mind for some packages that
610 use abbreviations for verbatim macros, such as \LPack{shortvrb} or %
611 \LPack{doc} for example in which there is no explicit \lstinline+\macro+ in the
612 document by means of which the abbreviated form can be detected, for
613 automatic detection need to find \Lcs{DefineShortVerb} explicitly to process
614 it correctly. The solution is quite simple, just add in \meta{input file}:
615
616 \begin{examplecode}
617 \UndefineShortVerb{\|}
618 \DefineShortVerb{\|}
619 \end{examplecode}
620
621 depending on the package you are using. If your \emph{\enquote{verbatim macro}} is not
622 supported by default or can not detect, use the options described in \ref%
623 {sec:optline}.
624
625 \subsubsection{Verbatim standard}
626 \label{sec:verbatim:std}
627
628 These are the \emph{\enquote{classic}} environments for \emph{\enquote{writing code}} are considered %
629 \meta{verbatim standard}, such as \Venv{verbatim} and \Venv{lstlisting}
630 environments. The following list (including \texttt{\small\bfseries\textcolor{MediumOrchid}{*}} argument)
631 is considered as \meta{verbatim standard} environments:
632
633 \begin{multicols}{4}
634 \begin{itemize}[font=\sffamily\small, noitemsep,leftmargin=*]
635 \small
636 \item \Venv{Example}
637 \item \Venv{CenterExample}
638 \item \Venv{SideBySideExample}
639 \item \Venv{PCenterExample}
640 \item \Venv{PSideBySideExample}
641 \item \Venv{verbatim}
642 \item \Venv{Verbatim}
643 \item \Venv{BVerbatim}
644 \item \Venv{LVerbatim}
645 \item \Venv{SaveVerbatim}
646 \item \Venv{PSTcode}
647 \item \Venv{LTXexample}
648 \item \Venv{tcblisting}
649 \item \Venv{spverbatim}
650 \item \Venv{minted}
651 \item \Venv{listing}
652 \item \Venv{lstlisting}
653 \item \Venv{alltt}
654 \item \Venv{comment}
655 \item \Venv{chklisting}
656 \item \Venv{verbatimtab}
657 \item \Venv{listingcont}
658 \item \Venv{boxedverbatim}
659 \item \Venv{demo}
660 \item \Venv{sourcecode}
661 \item \Venv{xcomment}
662 \item \Venv{pygmented}
663 \item \Venv{pyglist}
664 \item \Venv{program}
665 \item \Venv{programl}
666 \item \Venv{programL}
667 \item \Venv{programs}
668 \item \Venv{programf}
669 \item \Venv{programsc}
670 \item \Venv{programt}
671 \end{itemize}
672 \end{multicols}
673
674 They are automatically detected \meta{verbatim standard} environments
675 (including \texttt{\small\bfseries\textcolor{MediumOrchid}{*}} argument)
676 generates by commands:
677
678 \begin{multicols}{2}
679 \begin{itemize}[font=\sffamily\small,noitemsep,leftmargin=*]
680 \small
681 \item \Lcs{DefineVerbatimEnvironment}
682 \item \Lcs{NewListingEnvironment}
683 \item \Lcs{DeclareTCBListing}
684 \item \Lcs{ProvideTCBListing}
685 \item \Lcs{lstnewenvironment}
686 \item \Lcs{newtabverbatim}
687 \item \Lcs{specialcomment}
688 \item \Lcs{includecomment}
689 \item \Lcs{newtcblisting}
690 \item \Lcs{NewTCBListing}
691 \item \Lcs{newverbatim}
692 \item \Lcs{NewProgram}
693 \item \Lcs{newminted}
694 \end{itemize}
695 \end{multicols}
696
697 If any of the \meta{verbatim standard} environments is not supported by
698 default or can not detected, you can use the options described in \ref%
699 {sec:optline}.
700
701 \subsubsection{Verbatim write}
702 \label{sec:verbatim:write}
703
704 Some environments have the ability to write \emph{\enquote{external files}}
705 or \emph{\enquote{store content}} in memory, these environments are
706 considered \meta{verbatim write}, such as \Wenv{scontents}, \Wenv{filecontents}
707 or \Lenv{VerbatimOut} environments. The following list is considered (including \texttt{\small\bfseries\textcolor{MediumOrchid}{*}} argument) as %
708 \meta{verbatim write} environments:
709
710 \begin{multicols}{4}
711 \begin{itemize}[font=\sffamily\small, noitemsep,leftmargin=*]
712 \ttfamily\small
713 \item \Wenv{scontents}
714 \item \Wenv{filecontents}
715 \item \Wenv{tcboutputlisting}
716 \item \Wenv{tcbexternal}
717 \item \Wenv{tcbwritetmp}
718 \item \Wenv{extcolorbox}
719 \item \Wenv{extikzpicture}
720 \item \Wenv{VerbatimOut}
721 \item \Wenv{verbatimwrite}
722 \item \Wenv{filecontentsdef}
723 \item \Wenv{filecontentshere}
724 \item \Wenv{filecontentsdefmacro}
725 \item \Wenv{filecontentsdefstarred}
726 \item \Wenv{filecontentsgdef}
727 \item \Wenv{filecontentsdefmacro}
728 \item \Wenv{filecontentsgdefmacro}
729 \end{itemize}
730 \end{multicols}
731
732 They are automatically detected \meta{verbatim write}
733 (including \texttt{\small\bfseries\textcolor{MediumOrchid}{*}} argument) environments generates
734 by commands:
735
736 \begin{itemize}[font=\sffamily\small, noitemsep,leftmargin=*]
737 \small
738 \item \Lcs{renewtcbexternalizetcolorbox}
739 \item \Lcs{renewtcbexternalizeenvironment}
740 \item \Lcs{newtcbexternalizeenvironment}
741 \item \Lcs{newtcbexternalizetcolorbox}
742 \item \Lcs{newenvsc}
743 \end{itemize}
744
745 If any of the \meta{verbatim write} environments is not supported by default
746 or can not detected, you can use the options described in \ref{sec:optline}.
747
748 \subsection{Steps process}
749 \label{sec:steps:process}
750
751 For creation of the image formats, extraction of source code of environments and creation of an
752 \meta{output file}, \Lscript{pst2pdf} need a various steps. Let's assume that the %
753 \meta{input file} is \LFile{test.tex}, \meta{output file} is %
754 \LFile{test-pdf.tex}, the working directory are \enquote{\texttt{./}}, the
755 directory for images are \texttt{./images}, the temporary
756 directory is \texttt{/tmp} and we want to generate images in \Limgform{pdf}
757 format and \meta{standalone} files for all environments extracted.
758
759 We will use the following code as \LFile{test.tex}:
760
761 \begin{examplecode}[numbers=left,frame=single]
762 % Some commented lines at begin file
763 \documentclass{article}
764 \usepackage{pstricks}
765 \begin{document}
766 Some text
767 \begin{pspicture}
768 Some code
769 \end{pspicture}
770 Always use \verb|\begin{pspicture}| and \verb|\end{pspicture}| to open
771 and close environment
772 \begin{pspicture}
773 Some code
774 \end{pspicture}
775 Some text
776 \begin{verbatim}
777 \begin{pspicture}
778 Some code
779 \end{pspicture}
780 \end{verbatim}
781 Some text
782 \end{document}
783 Some lines that will be ignored by the script
784 \end{examplecode}
785
786 \subsubsection{Validating Options}
787
788 The first step is read and validated \oarg[type=tt,cf=optcolor,sbc=gray,ac=lightgray]{options} from the command
789 line, verifying that \LFile{test.tex} contains \emph{some} environment to extract,
790 check the directory \texttt{./images} if it doesn't exist create it and create a temporary directory \texttt{/tmp/hG45uVklv9}.
791
792 The entire \LFile{test.tex} file is loaded into memory and \emph{\enquote{split}} to start the extraction process.
793
794 \subsubsection{Comment and ignore}
795 In the second step, once the file \LFile{test.tex} is loaded and divided in memory,
796 proceeds (in general terms) as follows:
797
798 \begin{quotation}
799 Search the words \lstinline|\begin{| and \lstinline|\end{| in verbatim standard, verbatim write, verbatim in line and
800 commented lines, if it finds them, converts to \lstinline|\BEGIN{| and \lstinline|\END{|, then places all code to
801 extract inside the \lstinline|\begin{preview}| \ldots \lstinline|\end{preview}|.
802 \end{quotation}
803
804 At this point \emph{\enquote{all}} the code you want to extract is inside \lstinline|\begin{preview}|\ldots\lstinline|\end{preview}|.
805
806 \subsubsection{Creating standalone files and extracting}
807
808 In the third step, the script generate \meta{standalone} files: \LFile{test-fig-1.tex},
809 \LFile{test-fig-2.tex}, \dots{} and saved in \texttt{./images} then proceed in two ways
810 according to the \oarg[type=tt,cf=optcolor,sbc=gray,ac=lightgray]{options}
811 passed to generate a temporary file with a random number (1981 for example):
812
813 \begin{enumerate}[leftmargin=*]
814 \item If script is call \emph{without} \cmdopt{noprew} options, the following lines
815 will be added at the beginning of the \LFile{test.tex} (in memory):
816
817 \begin{examplecode}
818 \PassOptionsToPackage{inactive}{pst-pdf}%
819 \AtBeginDocument{%
820 \RequirePackage[inactive]{pst-pdf}%
821 \RequirePackage[active,tightpage]{preview}%
822 \renewcommand\PreviewBbAdjust{-60pt -60pt 60pt 60pt}}%
823 % rest of input file
824 \end{examplecode}
825
826 The different parts of the file read in memory are joined and save in a temporary
827 file \LFile{test-fig-1981.tex} in \texttt{./}. This file will contain all the environments
828 for extraction between \lstinline|\begin{preview}|\ldots\lstinline|\end{preview}| along with the rest of the document.
829 If the document contains images, these must be in the formats supported by the \emph{engine} selected to process the \meta{input file}.
830
831 \item If script is call \emph{with} \cmdopt{noprew} options, the \lstinline|\begin{preview}|\ldots\lstinline|\end{preview}|
832 lines are only used as delimiters for extracting the content \emph{without} using the package \LPack{preview}, the following lines
833 will be added at the beginning of the \LFile{test.tex} (in memory):
834
835 \begin{examplecode}
836 \PassOptionsToPackage{inactive}{pst-pdf}%
837 \AtBeginDocument{%
838 \RequirePackage[inactive]{pst-pdf}}%
839 % only environments extracted
840 \end{examplecode}
841
842 Then it is joined with all extracted environments separated by \Lcs{newpage} and saved
843 in a temporary file \LFile{test-fig-1981.tex} in \enquote{\texttt{./}}.
844
845 \end{enumerate}
846
847 If \cmdopt{norun} is passed, the temporary file \LFile{test-fig-1981.tex}
848 is renamed to \LFile{test-fig-all.tex} and moved to \texttt{./images}.
849
850 \subsubsection{Generate image formats}
851
852 In the fourth step, the script generating the file \LFile{test-fig-1981.pdf} with all code extracted and croping, running:
853 \begin{examplecmd}
854 [user@machine ~:]§ `\small\meta[type=tt,cf=ForestGreen,ac=lightgray]{compiler}` -no-shell-escape -interaction=nonstopmode -recorder test-fig-1981.tex
855 [user@machine ~:]§ pdfcrop --margins `\small\textcolor{gray}{0}` test-fig-1981.pdf test-fig-1981.pdf
856 \end{examplecmd}
857
858 Now move \LFile{test-fig-1981.pdf} to \texttt{/tmp/hG45uVklv9} and rename to \LFile{test-fig-all.pdf}, generate image files \LFile{test-fig-1.pdf}
859 and \LFile{test-fig-2.pdf} and copy to \texttt{./images}, if the image files exist, they will be rewritten each time you run the script. The file \LFile{test-fig-1981.tex} is
860 moved to the \texttt{./images} and rename to \LFile{test-fig-all.tex}.
861
862 Note the options passed to \meta[type=tt,cf=ForestGreen,ac=lightgray]{compiler} always use \prgopt*{no-shell-escape}
863 and \prgopt*{recorder}, to generate the \Lext{fls} file which is used to delete temporary files and directories after
864 the process is completed. The \cmdopt{shell} option activates \prgopt*{shell-escape} for compatibility with packages
865 such as \LPack{minted} or others.
866
867 \subsubsection{Create output file}
868
869 In the fifth step, the script creates the output file \LFile{test-pdf.tex} converting all extracted code to
870 \Lcs{includegraphics}, remove all \PST{} packages and content betwen \lstinline|%CleanPST ... %CleanPST|, then
871 adding the following lines at end of preamble:
872
873 \begin{examplecode}[numbers=left]
874 \usepackage{graphicx}
875 \graphicspath{{images/}}
876 \usepackage{grfext}
877 \PrependGraphicsExtensions*{.pdf}
878 \end{examplecode}
879
880 The script will try to detect whether the \LPack{graphicx} package and
881 the \Lcs{graphicspath} command are in the preamble of the \meta[cf=optcolor]{output file}.
882 If it is not possible to find it, it will read the \Lext{log} file generated by the temporary file.
883 Once the detection is complete, the package \LPack{grfext} and \Lcs{PrependGraphicsExtensions*}
884 will be added at the end of the preamble, then proceed to run:
885
886 \begin{examplecmd}
887 [user@machine ~:]§ `\small\meta[type=tt,cf=ForestGreen,ac=lightgray]{compiler}` -recorder -shell-escape test-pdf.tex
888 \end{examplecmd}
889 generating the file \LFile{test-pdf.pdf}.
890
891 \subsubsection{Clean temporary files and dirs}
892
893 In the sixth step, the script read the files \LFile{test-fig-1981.fls}
894 and \LFile{test-out.fls}, extract the information from the
895 temporary files and dirs generated in the process in \enquote{\texttt{./}} and then
896 delete them together with the directory \texttt{/tmp/hG45uVklv9}.
897
898 Finally the output file \texttt{test-pdf.tex} looks like this:
899
900 \begin{examplecode}[numbers=left]
901 % some commented lines at begin document
902 \documentclass{article}
903 \usepackage{graphicx}
904 \graphicspath{{images/}}
905 \usepackage{grfext}
906 \PrependGraphicsExtensions*{.pdf}
907 \begin{document}
908 Some text
909 \includegraphics[scale=1]{test-fig-1}
910 Always use \verb|\begin{pspicture}| and \verb|\end{pspicture}| to open
911 and close environment
912 \includegraphics[scale=1]{test-fig-2}
913 Some text
914 \begin{verbatim}
915 \begin{pspicture}
916 Some code
917 \end{pspicture}
918 \end{verbatim}
919 Some text
920 \end{document}
921 \end{examplecode}
922
923 \section{Default extracted environments}
924 \label{sec:extract:env}
925
926 \nxLprog{pst2pdf} support fourth environments for extraction. Internally
927 the script converts all environments to extract in \Lenv{preview} environments.
928 Is better comment this package in preamble unless the option \cmdopt{noprew} is used.
929
930 \DescribeTE{postscript}
931 Environment provide by \LPack{pst-pdf}\cite{pst-pdf}, \LPack{auto-pst-pdf}\cite{auto-pst-pdf}
932 and \LPack{auto-pst-pdf-lua}\cite{auto-pst-pdf-lua} packages. Since the \LPack{pst-pdf}, \LPack{auto-pst-pdf}
933 and \LPack{auto-pst-pdf-lua} packages internally use the \LPack{preview} package, is better comment this in preamble.
934 Only the \emph{content} of this environment is extracted and \emph{\enquote{not}} the environment itself when using the
935 \cmdopt{srcenv} option. The \Lenv{postscript} environment should always be used, when there is some code before a \Lenv{pspicture}
936 environment or for some code which is not inside of a \Lenv{pspicture} environment.
937
938 \DescribeTE{pspicture}
939 Environment provide by \LPack{pstricks}\cite{girou:02:} package. The plain \hologo{TeX}
940 syntax \lstinline|\pspicture ... \endpspicture| its converted to \hologo{LaTeX} syntax
941 \lstinline|\begin{pspicture} ... \end{pspicture}| if not within the \Lenv{PSTexample} or \Lenv{postscript} environments.
942
943 \DescribeTE{psgraph}
944 Environment provide by \LPack{pst-plot}\cite{pst-plot} package. The plain \hologo{TeX} syntax \lstinline|\psgraph ... \endpsgraph|
945 its converted to \hologo{LaTeX} syntax \lstinline|\begin{psgraph} ... \end{psgraph}| if
946 not within the \Lenv{PSTexample} or \Lenv{postscript} environments.
947
948 \DescribeTE{PSTexample}
949 Environment provide by \LPack{pst-exa}\cite{pst-exa} package. The script automatically detects the
950 \lstinline|\begin{PSTexample}| \lstinline|...\end{PSTexample}|
951 environments and processes them as separately compiled files. The user should have loaded the
952 package with [\Loption{swpl}] or [\Loption{tcb}] option.
953
954 \section{Remove \PST\ code}
955
956 By design, the script remove all \PST{} packages in preamble of \meta{output file}, if you need delete other \PST\ code in preamble use:
957
958 \DescribeTE*{CleanPST}
959 All content betwen \lstinline|%CleanPST ... %CleanPST| are deleted in preamble of the \meta[cf=optcolor]{output file}.
960 This lines can \emph{not} be nested and should be at the beginning of the line and in separate lines.
961
962 \section{Supported image formats}
963 \label{sec:image:format}
964
965 The \Larga{image formats} generated by the \Lscript{pst2pdf} using \Lprog{Ghostscript}
966 and \Lprog{poppler-utils} are the following command lines:
967
968 \DescribeIF{pdf}
969 The image format generated using \Lprog{Ghostscript}. The line executed by the system is:
970
971 \begin{examplecmd}
972 [user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress
973 \end{examplecmd}
974
975 \DescribeIF{eps}
976 The image format generated using \Lprog{pdftoeps}. The line executed by the system is:
977
978 \begin{examplecmd}
979 [user@machine ~:]§ pdftops -q -eps
980 \end{examplecmd}
981
982 \DescribeIF{png}
983 The image format generated using \Lprog{Ghostscript}. The line executed by the system is:
984
985 \begin{examplecmd}
986 [user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=pngalpha -r150
987 \end{examplecmd}
988
989 \DescribeIF{jpg}
990 The image format generated using \Lprog{Ghostscript}. The line executed by the system is:
991 \begin{examplecmd}
992 [user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=jpeg -r150 -dJPEGQ=100 \
993 -dGraphicsAlphaBits=4 -dTextAlphaBits=4
994 \end{examplecmd}
995
996 \DescribeIF{ppm}
997 The image format generated using \Lprog{pdftoppm}. The line executed by the system is:
998
999 \begin{examplecmd}
1000 [user@machine ~:]§ pdftoppm -q -r 150
1001 \end{examplecmd}
1002
1003 \DescribeIF{tiff}
1004 The image format generated using \Lprog{Ghostscript}. The line executed by the system is:
1005
1006 \begin{examplecmd}
1007 [user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=tiff32nc -r150
1008 \end{examplecmd}
1009
1010 \DescribeIF{svg}
1011 The image format generated using \Lprog{pdftocairo}. The line executed by the system is:
1012
1013 \begin{examplecmd}
1014 [user@machine ~:]§ pdftocairo -q -r 150
1015 \end{examplecmd}
1016
1017 \DescribeIF{bmp}
1018 The image format generated using \Lprog{Ghostscript}. The line executed by the system is:
1019
1020 \begin{examplecmd}
1021 [user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=bmp32b -r150
1022 \end{examplecmd}
1023
1024 \section{How to use}
1025
1026 \subsection{Syntax}
1027
1028 The syntax for \myscript\ is simple, if your use the version provided in your \hologo{TeX} distribution:
1029
1030 \begin{examplecmd}
1031 [user@machine ~:]§ pst2pdf `\small\oarg[type=tt,cf=optcolor,sbc=gray,ac=lightgray]{options} \meta[cf=optcolor]{input file}`
1032 \end{examplecmd}
1033 or
1034 \begin{examplecmd}
1035 [user@machine ~:]§ pst2pdf `\small\meta[cf=optcolor]{input file} \oarg[type=tt,cf=optcolor,sbc=gray,ac=lightgray]{options}`
1036 \end{examplecmd}
1037 If the development version is used:
1038 \begin{examplecmd}
1039 [user@machine ~:]§ perl pst2pdf `\small\oarg[type=tt,cf=optcolor,sbc=gray,ac=lightgray]{options} \meta[cf=optcolor]{input file}`
1040 \end{examplecmd}
1041
1042 The extension valid for \meta[cf=optcolor]{input file} are \Lext{tex} or \Lext{ltx},
1043 relative or absolute paths for files and directories is not supported. If used without
1044 \oarg[type=tt,cf=optcolor,sbc=gray,ac=lightgray]{options} the extracted environments are converted to \Limgform{pdf}
1045 image format and saved in the \texttt{./images} directory using \Lprog{latex}\textcolor{optcolor}{\texttt{\bfseries\guillemotright}}\Lprog{dvips}\textcolor{optcolor}{\texttt{\bfseries\guillemotright}}\Lscript{ps2pdf}
1046 and \LPack{preview} package for process \meta[cf=optcolor]{input file} and \Lprog{pdflatex} for compiler \meta[cf=optcolor]{output file}.
1047
1048 \subsection{Command line interface}
1049 \label{sec:optline}
1050
1051 The script provides a \emph{command line interface} with short \textcolor{optcolor}{\bfseries\texttt{-}}
1052 and long \textcolor{optcolor}{\bfseries\texttt{--}} option, they may be given before
1053 the name of the \meta[cf=optcolor]{input file}, the order of specifying the options is not significant.
1054 Options that accept a \meta{value} require either a blank space \verb*| | or \textcolor{optcolor}{\bfseries\texttt{=}}
1055 between the option and the \meta{value}. Some short options can be bundling.
1056
1057 \DescribeCmd[h]{help}{bolean}{off}
1058 Display a command line help and exit.
1059
1060 \DescribeCmd[l]{log}{bolean}{off}
1061 Write a \LFile{pst2pdf.log} file with all process information.
1062
1063 \DescribeCmd[v]{version}{bolean}{off}
1064 Display the current version (\fileversion) and exit.
1065
1066 \DescribeCmd[V]{verbose}{bolean}{off}
1067 Show verbose information of process in terminal.
1068
1069 \DescribeCmd[d]{dpi}{integer}{150}
1070 Dots per inch for images files. Values are positive integers less than or equal to 2500.
1071
1072 \DescribeCmd[t]{tif}{bolean}{off}
1073 Create a \Lext{tif} images files using \Lprog{Ghostscript}.
1074
1075 \DescribeCmd[b]{bmp}{bolean}{off}
1076 Create a \Lext{bmp} images files using \Lprog{Ghostscript}.
1077
1078 \DescribeCmd[j]{jpg}{bolean}{off}
1079 Create a \Lext{jpg} images files using \Lprog{Ghostscript}.
1080
1081 \DescribeCmd[p]{png}{bolean}{off}
1082 Create a \Lext{png} transparent image files using \Lprog{Ghostscript}.
1083
1084 \DescribeCmd[e]{eps}{bolean}{off}
1085 Create a \Lext{eps} image files using \Lprog{pdftops}.
1086
1087 \DescribeCmd[s]{svg}{bolean}{off}
1088 Create a \Lext{svg} image files using \Lprog{pdftocairo}.
1089
1090 \DescribeCmd[P]{ppm}{bolean}{off}
1091 Create a \Lext{ppm} image files using \Lprog{pdftoppm}.
1092
1093 \DescribeCmd[g]{gray}{bolean}{off}
1094 Create a gray scale for all images using \Lprog{Ghostscript}. The line behind this options is:
1095
1096 \begin{examplecmd}
1097 [user@machine ~:]§ gs -q -dNOSAFER -sDEVICE=pdfwrite -dPDFSETTINGS=/prepress \
1098 -sColorConversionStrategy=Gray -dProcessColorModel=/DeviceGray
1099 \end{examplecmd}
1100
1101 \DescribeCmd[f]{force}{bolean}{off}
1102 Try to capture \lstinline|\psset|\marg[type=tt]{code} to extract.
1103 When using the \cmdopt{force} option the script will try to capture \lstinline|\psset|\marg[type=tt]{code} and
1104 leave it inside the \Lenv{preview} environment, any line that is between \lstinline|\psset|\marg[type=tt]{code} and
1105 \lstinline|\begin{pspicture}| will be captured.
1106
1107 \DescribeCmd[np]{noprew}{bolean}{off}
1108 Create images files without \LPack{preview} package. The \lstinline|\begin{preview}|\ldots \lstinline|\end{preview}|
1109 lines are only used as delimiters for extracting the content \emph{without} using the package \LPack{preview}.
1110 Using this option \emph{\enquote{only}} the extracted environments are processed and not the whole \meta[cf=optcolor]{input file}, sometimes
1111 it is better to use it together with \cmdopt{force}. Alternative name \cmdopt{single}.
1112
1113 \DescribeCmd[m]{margins}{integer}{0}
1114 Set margins in bp for \Lscript{pdfcrop}.
1115
1116 \DescribeCmd[r]{runs}{\textnormal{\ttfamily 1\textbar 2\textbar 3}}{1}
1117 Set the number of times the \meta[type=tt,cf=ForestGreen,ac=lightgray]{compiler} will run
1118 on the \meta[cf=optcolor]{input file} for environment extraction.
1119
1120 \DescribeCmd{myverb}{macro name}{myverb}
1121 Set custom verbatim command \lstinline+\myverb+. Just pass the \meta{macro name}{}
1122 \emph{without} \enquote{\textcolor{optcolor}{\texttt{\bfseries\textbackslash}}}.
1123
1124 \DescribeCmd{ignore}{environment name}{empty}
1125 Add a verbatim environment to internal list.
1126
1127 \DescribeCmd{imgdir}{string}{images}
1128 Set the name of directory for save generated files. Only the \meta{name} of directory
1129 must be passed \emph{without} relative or absolute paths.
1130
1131 \DescribeCmd{srcenv}{bolean}{off}
1132 Create separate files with \emph{\enquote{only code}} for all extracted
1133 environments.
1134
1135 \DescribeCmd{shell}{bolean}{off}
1136 Enable \Lcs{write18}\meta{shell command}.
1137
1138 \DescribeCmd[ni]{norun}{bolean}{off}
1139 Execute the script, but do not create image files. This option is designed to
1140 to generate standalone files or used in conjunction with \cmdopt{srcenv} and to
1141 debug the \meta[cf=optcolor]{output file}. Alternative name \cmdopt{noimages}.
1142
1143 \DescribeCmd{nopdf}{bolean}{off}
1144 Don't create a \Lext{pdf} image files.
1145
1146 \DescribeCmd{nocrop}{bolean}{off}
1147 Don't run \Lscript{pdfcrop} in image files.
1148
1149 \DescribeCmd[ns]{nosource}{bolean}{off}
1150 Don't create standalone files.
1151
1152 \DescribeCmd[x]{xetex}{bolean}{off}
1153 Using \Lprog{xelatex} compiler \meta[cf=optcolor]{input file} and \meta[cf=optcolor]{output file}.
1154
1155 \DescribeCmd{luatex}{bolean}{off}
1156 Using \Lprog{dvilualatex}\textcolor{optcolor}{\texttt{\bfseries\guillemotright}}\Lprog{dvips}\textcolor{optcolor}{\texttt{\bfseries\guillemotright}}\Lscript{ps2pdf}
1157 for compiler \meta[cf=optcolor]{input file} and \Lprog{lualatex} for \meta[cf=optcolor]{output file}.
1158
1159 \DescribeCmd{arara}{bolean}{off}
1160 Use \Lprog{arara}\footnote{\url{https://ctan.org/pkg/arara}} tool for compiler \meta[cf=optcolor]{output file}.
1161 This option is designed to full process \meta[cf=optcolor]{output file}, is mutually
1162 exclusive with \cmdopt{latexmk} option.
1163
1164 \DescribeCmd{latexmk}{bolean}{off}
1165 Using \Lscript{latexmk}\footnote{\url{https://www.ctan.org/pkg/latexmk}} for process \meta[cf=optcolor]{output file}.
1166 This option is designed to full process \meta[cf=optcolor]{output file}, is mutually exclusive with \cmdopt{arara}.
1167
1168 \DescribeCmd{zip}{bolean}{off}
1169 Compress the files generated by the script in \texttt{./images} in \Lext{zip} format.
1170 Does not include \meta[cf=optcolor]{output file}.
1171
1172 \DescribeCmd{tar}{bolean}{off}
1173 Compress the files generated by the script in \texttt{./images} in \Lext{tar.gz} format.
1174 Does not include \meta[cf=optcolor]{output file}.
1175
1176 \DescribeCmd{bibtex}{bolean}{off}
1177 Run \Lprog{bibtex} on the \Lext{aux} file (if exists), is mutually
1178 exclusive with \cmdopt{biber} option.
1179
1180 \DescribeCmd{biber}{bolean}{off}
1181 Run \Lprog{biber} on the \Lext{bcf} file (if exists), is mutually
1182 exclusive with \cmdopt{bibtex} option.
1183
1184 \subsection{Example of usage}
1185
1186 An example of usage from command line:
1187
1188 \begin{examplecmd}
1189 [user@machine ~:]§ pst2pdf --luatex -e -p -j --imgdir pics test.ltx
1190 \end{examplecmd}
1191
1192 Create a \texttt{./pics} directory (if it does not exist) with all extracted environments converted to image
1193 formats (\Lext{pdf}, \Lext{eps}, \Lext{png}, \Lext{jpg}) in individual files, an stanalone files (\Lext{ltx}) for all environments extracted,
1194 an output file \LFile{test-pdf.ltx} with all extracted environments converted to \Lcs{includegraphics} and a single file
1195 \LFile{test-fig-all.ltx} with only the extracted environments
1196 using \Lprog{dvilualatex}\textcolor{optcolor}{\texttt{\bfseries\guillemotright}}\Lprog{dvips}\textcolor{optcolor}{\texttt{\bfseries\guillemotright}}\Lscript{ps2pdf}
1197 and \LPack{preview} package for for process \LFile{test.ltx} and
1198 \Lprog{lualatex} for \LFile{test-pdf.ltx}.
1199
1200 \section{Working in another way}
1201
1202 By design, the script generates separate images and files following a predetermined
1203 routine that has already been described in this documentation. Another way to generate
1204 images is as follows:
1205
1206 \begin{enumerate}[font=\small, nosep, noitemsep,leftmargin=*]
1207 \item Execute the script using \cmdopt{norun} to generate \meta{standalone} files, move to \texttt{./images}
1208 and generate \Lext{pdf} files runing:
1209
1210 \begin{examplecmd}
1211 [user@machine~:]§for i in *.tex; do `\meta[type=tt,cf=ForestGreen,ac=lightgray]{compiler} \oarg[type=tt,cf=gray,sbc=optcolor,ac=gray]{options}` $i; done
1212 [user@machine~:]§for i in *.pdf; do pdfcrop `\small\oarg[type=tt,cf=gray,sbc=optcolor,ac=gray]{options}` $i $i; done
1213 \end{examplecmd}
1214
1215 \item Execute the script using \cmdopt{norun}, move to \texttt{./images} \Lext{pdf} file runing:
1216
1217 \begin{examplecmd}
1218 [user@machine~:]§`\meta[type=tt,cf=ForestGreen,ac=lightgray]{compiler} \oarg[type=tt,cf=gray,sbc=optcolor,ac=gray]{options}` test-fig-all.tex
1219 [user@machine~:]§pdfcrop `\oarg[type=tt,cf=gray,sbc=optcolor,ac=gray]{options}` test-fig-all.pdf
1220 \end{examplecmd}
1221
1222 \end{enumerate}
1223
1224 \section{Example files}
1225
1226 The \texttt{pst2pdf} documentation provides three example files \LFile{test1.tex}, \LFile{test2.tex}
1227 and \LFile{test3.tex} plus an image file \LFile{tux.jpg} to test and view the script in action.
1228 Copy these files to a directory you have write access to and execute:
1229
1230 \begin{examplecmd}
1231 [user@machine~:]§pst2pdf `\oarg[type=tt,cf=gray,sbc=optcolor,ac=gray]{options}` test1.tex
1232 \end{examplecmd}
1233
1234 To see how this works.
1235 %\newpage
1236 \clearpage
1237 \nocite{*}
1238 \printbibliography
1239
1240 \printindex
1241
1242 \end{document}