summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/latex/pst-exa/pst-exa-doc.tex
blob: f7f3bc89ceb0222cefba5f5554b474d0c088f9e4 (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
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
% arara: latex: {draft: yes}
% arara: latex
% arara: biber
% arara: makeindex
% arara: latex: {draft: yes}
% arara: latex
% arara: dvips
% arara: ps2pdf
% arara: clean: { files:[pst-exa-doc.out, pst-exa-doc.ps, pst-exa-doc.toc,pst-exa-doc.log,pst-exa-doc.ind,pst-exa-doc.aux, pst-exa-doc.bbl, pst-exa-doc.bcf, pst-exa-doc.blg,pst-exa-doc.dvi,pst-exa-doc.idx,pst-exa-doc.ilg,pst-exa-doc.run.xml] }
\documentclass[11pt,english,BCOR=10mm,DIV=12,bibliography=totoc,parskip=false,headings=small,
    headinclude=false,footinclude=false,twoside]{scrartcl}
\usepackage[utf8]{inputenc}
\usepackage[T1]{fontenc}
\usepackage{libertine}
\usepackage[scaled=0.88]{beramono}
\usepackage{babel}
\usepackage{makeidx}\makeindex
\input{\jobname.inc}
\listfiles
\let\Lfile\LFile
\usepackage{pst-node}
\usepackage{biblatex}

\addbibresource{\jobname.bib}

\usepackage{xspace,showexpl}
\usepackage{pst-text,pst-grad}
\usepackage[tcb]{pst-exa}
\let\pstFV\fileversion

%\DeclareFixedFont{\RM}{T1}{ptm}{b}{n}{4cm}
%\renewcommand\bgImage{\pscharpath[fillstyle=gradient,
%  gradbegin=red,gradend=blue,gradangle=-90]{\RM pst-exa}}

\lstset{language=PSTricks,basicstyle=\footnotesize\ttfamily}
\def\DVI{\textsc{DVI}}
\def\PDF{\textsc{PDF}}
\def\gs{\textsc{Ghostscript}}
%
\begin{document}
\title{\texttt{pst-exa}\\
Generate examples for PSTricks environments (with pdflatex);\\  \small v. 0.06}
\author{Herbert Vo\ss  \\ Pablo Gonz\'{a}lez Luengo}
%\docauthor{}
\date{\today}
\maketitle

\tableofcontents

\clearpage

\section{Introduction}

The package \LPack{pst-exa} was created to realize examples with printed
code and output side by side or on top of each other. The package
looks in the image directory for the source code of the examples
and inserts only the image for code environment

However, creating a \PDF\ file in a direct way with \Lprog{pst2pdf} or \Lprog{ltximg} is
possible and the compiles whits \Lprog{pdflatex}. 

\PST\ as \PS\ related package uses the programming language \PS\ for internal
calculations. This is an important advantage, because floating point arithmetic is no
problem. Nearly all mathematical calculation can be done when running the \DVI-file
with \gs. 

\section{Loading the package}

The package \LPack{pst-exa} must be loaded with one of the following options in the preamble of the document:

\begin{verbatim}
\usepackage[swpl]{pst-exa}
\end{verbatim}

automatically load \LPack{showexpl} package. 

\begin{verbatim}
\usepackage[tcb]{pst-exa}
\end{verbatim}

automatically load \LPack{tcolorbox} package.

\section{Environments}
The package \LPack{pst-exa} provides two environments:

\Lenv{PSTcode} to write only code that does not generate 
an image, this is necessary to not interrupt the order in which the images are copied by the script in the process 
of conversion to pdf. 

\Lenv{PSTexample} environment,
to write only code that generates an image, keep in mind that the script that performs the extraction process 
does not distinguish the format given to the lines in this environment (only reads plain text) the idea is to 
concentrate on the image you want to extrare and then in the format of the text.

\section{Programs needed}
You need \nxLprog{pst2pdf} (or \Lprog{ltximg}) whit a latest version of \Lprog{Ghostscript} (9.14), 
\Lprog{perl} (>=5.18), \Lprog{pdf2svg}, \Lprog{pdftoppm} and \Lprog{pdftops}
(from \Lprog{poppler-utils} or \Lprog{xpdf-utils}) for the process file. 

The general syntax for the \emph{script} is simple:

\begin{BDef}
\nxLprog{perl} \nxLprog{pst2pdf} \Larg{file.tex} \Largs{--options}
\end{BDef}

For \TeX Live users:

\begin{BDef}
\nxLprog{pst2pdf} \Larg{file.tex} \Largs{--options}
\end{BDef}

this create file-pdf-exa.pdf and file-fig-exa-1.pdf, file-fig-exa-2.pdf, file-fig-exa-\dots.pdf

\section{Examples with option \texttt{tcb}}

\verb|\begin{pspicture}| o \tcboxverb{\begin{pspicture}[showgrid](4,4)}

\begin{pspicture}[showgrid](4,4)
  \psRing(2,2){0.3}{0.8}
  \psRing*[opacity=0.5](2,2){1}{2}
\psdot(2,2)
\end{pspicture}

%\mint[hola]{algo}$\begin{pspicture} o \begin{pspicture*}$ no problem whit inline verb :)
\section{Test PSTexample}
% numbers=none
\begin{PSTexample}[pos=t,numbers=fancy,title=First example]
\pstVerb{ 1234321 srand }
\begin{pspicture}[showgrid](-2,-2)(2,2)
\psframe*[linecolor=blue,opacity=!Rand](2,2)
\psframe*[linecolor=red,opacity=!Rand](-1,-1)(1,1)
\psframe*[linecolor=green,opacity=!Rand](-2,-2)(0,0)
\end{pspicture}
\end{PSTexample}
\vspace{20pt}
\begin{PSTexample}[hwidth=5cm]
\begin{pspicture}[showgrid](4,4)
  \psRing(2,2){0.3}{0.8}
  \psRing*[opacity=0.5](2,2){1}{2}
\psdot(2,2)
\end{pspicture}
\end{PSTexample}
% ned
\section{Test PSTcode}
\begin{PSTcode}
\pstVerb{ 1234321 srand }
\begin{pspicture}[showgrid](-2,-2)(2,2)
\psframe*[linecolor=blue,opacity=!Rand](2,2)
\psframe*[linecolor=red,opacity=!Rand](-1,-1)(1,1)
\psframe*[linecolor=green,opacity=!Rand](-2,-2)(0,0)
\end{pspicture}
\end{PSTcode}

\begin{PSTcode}
\begin{pspicture}[showgrid](4,4)
  \psRing(2,2){0.3}{0.8}
  \psRing*[opacity=0.5](2,2){1}{2}
\psdot(2,2)
\end{pspicture}
\end{PSTcode}


\section{Examples with option \texttt{swpl}}

\makeatletter
\pstexa@swpltrue
% Star code for swpl option
% Environment for code
\let\PSTcode\relax
\let\endPSTcode\relax
\lstnewenvironment{PSTcode}
  {%
\lstset{
    language=PSTexa,%
    frame=single,%
    numbers=left,%
    numbersep=1em,%
    numberstyle=\tiny\color{black!75}\noaccsupp,%
    rulecolor=\color{black!67},%
    framesep=\fboxsep,%
    framerule=\fboxrule,%
    xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,%
    xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,%
    backgroundcolor=\color[rgb]{1,1,0.8},%
% literateee
literate=*{\{}{{\textcolor{blue}{\{}}}{1}
    {\}}{{\textcolor{blue}{\}}}}{1}
    {[}{{\textcolor{blue}{[}}}{1}
    {]}{{\textcolor{blue}{]}}}{1}
    {(}{{\textcolor{blue}{(}}}{1}
    {)}{{\textcolor{blue}{)}}}{1}
    {\$}{{\textcolor{red}{\$}}}{1}
    {\#}{{\textcolor{red}{\#}}}{1}%,
 }% close lstset
 }%
{}% close PSTcode

% Change position for images
\renewcommand*\SX@resultInput{%
  \ifx\SX@graphicname\@empty
    \begingroup
      \MakePercentComment\makeatother\catcode`\^^M=5\relax
      \SX@@preset\SX@preset
      \if@SX@rangeaccept
       \let\SX@tempa=\SX@input
      \else
       \let\SX@tempa=\input
      \fi
      \SX@tempa{\SX@codefile}\par%
    \endgroup
  \else
    \begin{center}
      \expandafter\includegraphics\expandafter[\SX@graphicparam]{\SX@graphicname}
    \end{center}
  \fi
}% end change postition
% PSTexample definition in swpl
\let\PSTexample\relax
\let\endPSTexample\relax
 \lstnewenvironment{PSTexample}[1][]
 {%
 \lstset{%
    language=PSTexa,%
    frame=single,%
    numbers=left,%
    numbersep=1em,%
    numberstyle=\tiny\color{black!75}\noaccsupp,%
    rulecolor=\color{black!67},%
    framesep=\fboxsep,%
    framerule=\fboxrule,%
    xleftmargin=\dimexpr\fboxsep+\fboxrule\relax,%
    xrightmargin=\dimexpr\fboxsep+\fboxrule\relax,%
    backgroundcolor=\color[rgb]{1,1,0.8},%
% literate for swpl, need inside the explpreset
    explpreset={
% literate
literate=*{\{}{{\textcolor{blue}{\{}}}{1}
    {\}}{{\textcolor{blue}{\}}}}{1}
    {[}{{\textcolor{blue}{[}}}{1}
    {]}{{\textcolor{blue}{]}}}{1}
    {(}{{\textcolor{blue}{(}}}{1}
    {)}{{\textcolor{blue}{)}}}{1}
    {\$}{{\textcolor{red}{\$}}}{1}
    {\#}{{\textcolor{red}{\#}}}{1},%
    codefile=\jobname.swpl,%
    hsep=\columnsep,%
    vsep=15pt,%
    pos=l,%
    wide=false,%
    rframe={},%
    preset=\centering,%
    } % close explpreset
 } % close lstset
  \@temptokena{#1}%
   \begingroup
     \advance\c@ltxexample\@ne \advance\c@lstlisting\@ne
     \expandafter\lstset\expandafter{\SX@explpreset,#1}%
     \edef\x{\endgroup
       \def\noexpand\SX@codefile{\SX@codefile}%
       \def\noexpand\SX@graphicname{\SX@graphicname}%
       \def\noexpand\SX@graphicparam{\SX@graphicparam}}%
   \x
   \xdef\SX@@explpreset{\the\@temptokena,codefile=\SX@codefile,
     graphic={[\SX@graphicparam]{\SX@graphicname}}}%
   \setbox\@tempboxa=\hbox\bgroup% Warum noetig?
   \lst@BeginWriteFile{\SX@codefile}%
% Change position for images
 }
 {%
   \lst@EndWriteFile\egroup
   \SX@put@code@result
  }% close environment
% end swpl code
\makeatother

% numbers=none
\begin{PSTexample}[pos=t,numbers=none]
\pstVerb{ 1234321 srand }
\begin{pspicture}[showgrid](-2,-2)(2,2)
\psframe*[linecolor=blue,opacity=!Rand](2,2)
\psframe*[linecolor=red,opacity=!Rand](-1,-1)(1,1)
\psframe*[linecolor=green,opacity=!Rand](-2,-2)(0,0)
\end{pspicture}
\end{PSTexample}
% numbers true default
\begin{PSTexample}[width=5cm]
\begin{pspicture}[showgrid](4,4)
  \psRing(2,2){0.3}{0.8}
  \psRing*[opacity=0.5](2,2){1}{2}
\psdot(2,2)
\end{pspicture}
\end{PSTexample}
% ned

\begin{PSTcode}
\pstVerb{ 1234321 srand }
\begin{pspicture}[showgrid](-2,-2)(2,2)
\psframe*[linecolor=blue,opacity=!Rand](2,2)
\psframe*[linecolor=red,opacity=!Rand](-1,-1)(1,1)
\psframe*[linecolor=green,opacity=!Rand](-2,-2)(0,0)
\end{pspicture}
\end{PSTcode}

\begin{PSTcode}
\begin{pspicture}[showgrid](4,4)
  \psRing(2,2){0.3}{0.8}
  \psRing*[opacity=0.5](2,2){1}{2}
\psdot(2,2)
\end{pspicture}
\end{PSTcode}

\begin{pspicture}[showgrid](4,4)
  \psRing(2,2){0.3}{0.8}
  \psRing*[opacity=0.5](2,2){1}{2}
\psdot(2,2)
\end{pspicture}




\definecolor{mygreen}{rgb}{0,0.6,0}
\definecolor{mygray}{rgb}{0.5,0.5,0.5}

\lstset{ %
  basicstyle=\ttfamily\small,
  commentstyle=\color{mygreen},
  extendedchars=true,
  frame={},
  keepspaces=true,
  keywordstyle=\color{blue},
  numbers=left,
  numbersep=5pt,
  numberstyle=\tiny\color{mygray}
}
%\lstinputlisting[language=TeX]{pst-exa.sty}
%\newpage
%
\clearpage
\nocite{*}
\printbibliography

\printindex
\end{document}