% 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}