summaryrefslogtreecommitdiff
path: root/usergrps/uktug/baskervi/6_3/fancyvrb.rc
blob: 248ffc7e13ef729ede80f814184e9d0e800c7313 (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
% Define verbatim and example environments:
%  verbatim  - indented like quote environment
%  Verbatim  - indented like quote environment, \small font.
%  nVerbatim - Like "Verbatim", but numbered.
%  example   - code and output, side by side
%  example*  - one above other
%  example** - one above other, with frames
%  Example   - Rendered as PS, like original, side by side
%  Example*  - Rendered as PS, one above other
%  Example** - Rendered as PS, one above other, with frames
%  Escape - Rendered as PS, with *no* verbatim text
%  GridPSExample   - PSTricks (gridded) picture, like original, side by side
%  PSExample   - PSTricks picture, like original, side by side
% The example environments have the following steps in common:
% 1. Save example verbatim to numbered example file
% 2. Input file verbatim  or EPS file
% 3. Input again
% All of them save their text as files in the \EXdir directory
% (this needs a trailing / as part of the definition)
%
\RequirePackage{ifthen}
\RequirePackage{graphicx}
\RequirePackage{calc}
%
% variable features
%
\def\EXdir{}
\def\EXprefix{}
\def\EXclass{article}
%
\@ifundefined{fullwidth}{\let\fullwidth\textwidth}{}
\@ifundefined{thechapter}{\newcounter{chapter}}{}
%
\newcounter{eps@counter}[section]
\renewcommand\theeps@counter{%
 \arabic{chapter}-\arabic{section}-\arabic{eps@counter}}
\newcounter{side@count}
%\newwrite\exepsfile
%\immediate\openout\exepsfile \EXdir\jobname.expslist\relax

\def\EPSinput#1{%
\IfFileExists{\EXdir\EXprefix#1.eps}%
 {\includegraphics{\EXdir\EXprefix#1.eps}}%
 {\underline{\EXdir\EXprefix#1}}%
}

\def\SideBySideEx#1{%
\trivlist\item[]%
  \leavevmode
   \global\advance\c@side@count by 1
   \label{\thechapter.\theside@count}%
   \ifthenelse{\isodd{\pageref{\thechapter.\theside@count}}}{%
   \makebox[\fullwidth][l]{\@@Display{#1}\hspace{5mm}
    \BVerbatimInput[fontsize=\small]{\EXdir\EXprefix\theeps@counter}}%
      }{%
   \makebox[\fullwidth][r]{\@@Display{#1}\hspace{5mm}
     \BVerbatimInput[fontsize=\small]{\EXdir\EXprefix\theeps@counter}}%
    }%
  \endtrivlist
}
\newsavebox{\@display}
\def\@@Display#1{%
 \savebox{\@display}{%
\begin{minipage}[b]{.5\fullwidth}#1\end{minipage}%
}
 \raisebox{\depth}{\usebox{\@display}}%
}

\newcommand{\BeginExample}{%
  \multiply\topsep by 2
  \global\advance\c@eps@counter\@ne
  \edef\@tempa{%
    \write\@auxout{\string
      \newlabel{ex-\theeps@counter}{{\theeps@counter}{\noexpand\the\c@page}}}}
  \@tempa
  \nobreak
  \VerbatimEnvironment
  \catcode`\<=12
  \begin{VerbatimOut}{\EXdir\EXprefix\theeps@counter.tex}%
}
\newcommand{\EndExample}{%
  \end{VerbatimOut}%
}

\def\EndRuleExample{\vskip 7pt \hrule height 1.5pt\relax}

\newif\ifgrid
\gridfalse

\def\PSExample(#1,#2)(#3,#4){%
    \def\PictureSize{(#1,#2)(#3,#4)}%
    \def\Write@Ex##1{}\BeginExample
   }
\def\endPSExample{%
  \EndExample
  \SideBySideEx{%
    %\ifgrid\vskip 8pt \else\relax\fi
    \expandafter\pspicture\PictureSize
    \ifgrid\usergrid\else\relax\fi
    \input{\EXdir\theeps@counter}%
    \endpspicture
    %\ifgrid\vskip 8pt \fi
 }%
}

\newenvironment{GridPSExample}{\gridtrue\PSExample}{\endPSExample}

\def\PSTInlineExample(#1,#2){%
    \def\PictureSize{(-.2,-.5)(#1,#2)}%
    \def\Write@Ex##1{}\BeginExample
   }
\def\endPSTInlineExample{%
  \EndExample
  \expandafter\pspicture\PictureSize
  \usergrid
  \input{\EXdir\theeps@counter}%
  \endpspicture
 \hspace{16pt}%
 \BVerbatimInput[gobble=0,fontsize=\small]{\EXdir\theeps@counter}%
}
% side by side
\newenvironment{example}{\def\Write@Ex##1{}\BeginExample} %
  {\EndExample\SideBySideEx{\input{\EXdir\theeps@counter}}}

% one above the other
\newenvironment{example*}%
  {\def\Write@Ex##1{}\BeginExample}%
  {%
    \EndExample
    \VerbatimInput[gobble=0,fontsize=\small]{\EXdir\theeps@counter}%
      \begin{center}
        \leavevmode\input{\EXdir\theeps@counter}\par
      \end{center}
}
% one above the other
\newenvironment{numexample*}%
  {\def\Write@Ex##1{}\BeginExample}%
  {%
    \EndExample
    \VerbatimInput[gobble=0,numbers=left,
        fontsize=\small]{\EXdir\theeps@counter}%
      \begin{center}
        \leavevmode\input{\EXdir\theeps@counter}\par
      \end{center}
}

% with a frame, one above the other
\newenvironment{example**}%
{\def\Write@Ex##1{}\BeginExample}%
{%
\EndExample
\VerbatimInput[gobble=0,fontsize=\small,
      frame=topline,framerule=1.5pt]{\EXdir\theeps@counter}%
\begin{center}
\input{\EXdir\theeps@counter}
        \EndRuleExample
\end{center}
}

% now the ones which write stuff for an EPS file
% for side by side examples, the text width of the separate file
% needs to be half the normal width.
\def\EX@extra{}
\def\HalfWidth{%
 \def\EX@extra{%
 \string\makeatletter
 \string\@tempdima\string\textwidth
 \string\textwidth.5\string\@tempdima
 \string\addtolength{\string\textwidth}{-6mm}
 \string\makeatother}
}
\def\Setup@Escape{%
 \edef\FancyVerbStopString{\string\end{document}}%
 \edef\FancyVerbStartString{\string\begin{document}}%
}
% side by side
\newenvironment{Example}{%
 \HalfWidth
 \BeginExample} %
 {\EndExample
\Setup@Escape
\SideBySideEx{\EPSinput{\theeps@counter}}}

% first verbatimcode, then actual example
\newenvironment{Example*}{\BeginExample}%
  {\EndExample
  \Setup@Escape
  \begin{center}\leavevmode
    \VerbatimInput[gobble=0,fontsize=\small]{\EXdir\EXprefix\theeps@counter}%
 \EPSinput{\theeps@counter}%
 \end{center}%
}

% one above the other, framed
\newenvironment{Example**}%
{\BeginExample}%
{%
\EndExample
\Setup@Escape
    \VerbatimInput[gobble=0,fontsize=\small,
      frame=topline,framerule=1.5pt]{\EXdir\EXprefix\theeps@counter}%
\EPSinput{\theeps@counter}
\EndRuleExample
}

% no verbatim text at all, just to run the thing separately
\newenvironment{Escape}%
{\BeginExample}%
{%
\EndExample
\Setup@Escape
\EPSinput{\theeps@counter}%
}

\def\CurrentPackages{}

\def\FVE@VerbatimOut{\Write@Ex{\string\end{document}}%
\immediate\closeout\FV@OutFile\endgroup\@esphack}

\def\Write@Ex#1{%
      \begingroup
       \let\protect\@unexpandable@protect
       \edef\reserved@a{\immediate\write\FV@OutFile{#1}}
       \reserved@a
      \endgroup
}

\def\FVB@VerbatimOut#1{%
  \@bsphack
  \begingroup
    \FV@UseKeyValues
    \FV@DefineWhiteSpace
    \def\FV@Space{\space}%
    \FV@DefineTabOut
    \def\FV@ProcessLine{\immediate\write\FV@OutFile}%
    \immediate\openout\FV@OutFile #1\relax
    \Write@Ex{\string\documentclass{\EXclass}}%
    \Write@Ex{\string\nonstopmode}%
    \Write@Ex{\string\usepackage{\CurrentPackages}}%
    \Write@Ex{\string\pagestyle{empty}}%
    \Write@Ex{\EX@extra}%
    \Write@Ex{\string\begin{document}}%
    \let\FV@FontScanPrep\relax
    \FV@Scan}
%
% compatibility with Michel, with moreverb, and verbatim package
%
\def\SixPt{\fontsize{6}{7\p@}\selectfont}
%
% input files verbatim, numbered and unnumbered
%
\def\verbfile#1{\VerbatimInput[fontsize=\small]{#1}}
\let\verbatiminput\verbfile
\def\listinginput#1#2{\VerbatimInput[fontsize=\small,firstnumber=#1,numbers=left]{#2}}
%
% verbatim in various sizes
\DefineVerbatimEnvironment{sssverbatim}{LVerbatim}{fontsize=\SixPt}
\DefineVerbatimEnvironment{ssverbatim}{LVerbatim}{fontsize=\scriptsize}
\DefineVerbatimEnvironment{fverbatim}{LVerbatim}{fontsize=\footnotesize}
\DefineVerbatimEnvironment{sverbatim}{LVerbatim}{fontsize=\small}
\DefineVerbatimEnvironment{Verbatim}{LVerbatim}{fontsize=\normalsize}
\DefineVerbatimEnvironment{verbatim}{LVerbatim}{fontsize=\normalsize}
% numbered
\DefineVerbatimEnvironment{nVerbatim}{LVerbatim}{fontsize=\small,numbers=left}
\endinput