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
|
% $Id: pst-exa.sty 239 2010-01-01 17:23:13Z herbert $
%% BEGIN pst-exa.tex
%%
%% Code and image side by side or on top of
%% each other with PSTricks.
%%
%% COPYRIGHT 2010 by Herbert Voss, hvoss tug.org.
%%
%% This program can be redistributed and/or modified under the terms
%% of the LaTeX Project Public License Distributed from CTAN
%% archives in directory macros/latex/base/lppl.txt.
%%
%
\NeedsTeXFormat{LaTeX2e}
\RequirePackage{graphicx}
\RequirePackage{listings}
\RequirePackage{pst-xkey}
\def\fileversion{0.01}
\def\filedate{2010/01/01}
%
\ProvidesPackage{pst-exa}[\filedate\ v\fileversion\ PSTricks example code (hv)]
\lstset{basicstyle=\ttfamily\footnotesize,numbers=left,numbersep=0.5pt,
xleftmargin=1em,
numberstyle=\tiny,breaklines,
language=PSTricks}
\pst@addfams{pst-exa}
\define@key[psset]{pst-exa}{pos}[l]{%
\ifx#1l\def\psk@exa@pos{0}
\else
\ifx#1r\def\psk@exa@pos{1}
\else
\ifx#1b\def\psk@exa@pos{2}
\else \def\psk@exa@pos{3}
\fi\fi\fi}
\psset[pst-exa]{pos=l}
\define@key[psset]{pst-exa}{halign}[c]{\def\psk@exa@halign{#1}}
\psset[pst-exa]{halign=c}
\define@key[psset]{pst-exa}{valign}[c]{\def\psk@exa@valign{#1}}
\psset[pst-exa]{valign=c}
\define@key[psset]{pst-exa}{frame}[{}]{\def\psk@exa@frame{#1}}
\psset[pst-exa]{frame=}
\newlength\pst@exa@width
\define@key[psset]{pst-exa}{width}[0.5\linewidth]{\pssetlength\pst@exa@width{#1}}
\psset[pst-exa]{width=0.5\linewidth}
\newlength\pst@exa@sep
\define@key[psset]{pst-exa}{sep}[1em]{\pssetlength\pst@exa@sep{#1}}
\psset[pst-exa]{sep=1em}
%
\def\PSTfilename@i#1.#2.#3\@nil{\xdef\PSTfilename{#1.#2.tex}}%
%
\providecommand\IncludeGraphics[2][]{}
\renewcommand\IncludeGraphics[2][]{%
\expandafter\PSTfilename@i#2\@nil%
\includegraphics[#1]{#2}}
%
\newenvironment{PSTexample}[1][]
{\par\noindent\psset{#1}%
\begin{lrbox}{\pst@hbox}}
{\end{lrbox}%
\ifcase\psk@exa@pos
\minipage{\pst@exa@width}%
\ifdim\wd\pst@hbox<\linewidth\usebox\pst@hbox%
\else\resizebox{\linewidth}{!}{\usebox\pst@hbox}\fi
\endminipage\kern\pst@exa@sep%
\pst@dimm=\linewidth%
\advance\pst@dimm by -\pst@exa@width%
\advance\pst@dimm by -\pst@exa@sep%
\minipage{\pst@dimm}%
\lstinputlisting[includerangemarker=false,firstnumber=1,
linerange=\\begin\{document\}-\\end\{document\}]{\PSTfilename}
\endminipage%
\or
\pst@dimm=\linewidth%
\advance\pst@dimm by -\pst@exa@width
\advance\pst@dimm by -\pst@exa@sep
\minipage{\pst@dimm}%
\lstinputlisting[includerangemarker=false,firstnumber=1,
linerange=\\begin\{document\}-\\end\{document\}]{\PSTfilename}
\endminipage\kern\pst@exa@sep%
\minipage{\pst@exa@width}%
\ifdim\wd\pst@hbox<\linewidth\usebox\pst@hbox%
\else\resizebox{\linewidth}{!}{\usebox\pst@hbox}\fi
\endminipage
\or
\lstinputlisting[includerangemarker=false,firstnumber=1,
linerange=\\begin\{document\}-\\end\{document\}]{\PSTfilename}
\par\vskip\pst@exa@sep%
\usebox\pst@hbox\par
\or
\usebox\pst@hbox\par
\vskip\pst@exa@sep%
\lstinputlisting[includerangemarker=false,firstnumber=1,
linerange=\\begin\{document\}-\\end\{document\}]{\PSTfilename}\par
\fi}
%
\endinput
|