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
|
\ProvidesPackage {numberedblock} [2007/03/16 v1.01]
%
% by Steven B. Segletes, for the public domain.
%
% numberedblock provides several routines
% intended to print out a block of code with a unique,
% sequentially indexed label. The code block is printed to the left,
% with the block label printed centered vertically on the code block,
% horizontally right-justified. Each line of code is not numbered...
% rather, the block of code gets a single label.
%
% There are three parameters with which the user may freely alter:
% 1) maxblocklabelsize is a length set aside for the code-block labels.
% If it is too small, the label will run off the right margin; too large
% and it limits the width of the code block itself. However, by setting
% this parameter to a negative value, it will force the label to be
% offset into the right margin, which may be a desirable feature.
% 2) blockindent is a length defining the left-side indent to be used
% for the code block to be printed.
% 3) blocklabel is the command that actually formats the block label to
% the desired appearance. Currently, italicized numbers are used within
% non-italicized square brackets to comprise the block label.
%
% There is a command-line version called numblock, which cannot
% handle verbatim input. And there is an environment called numVblock
% which handles cases invloving verbatim input
%
% An example of how to use numberedblock is given below. The
% double-backslash is used for linebreaks in the code. Tildes need to
% be used for hard spaces under two conditions: when the code contains
% multiple sequential spaces; and if a space follows a period (which
% would otherwise invoke end-of-sentence spacing considerations). In
% addition, special LaTeX characters need to be quoted in the
% appropriate manner of LaTeX.
%
% \numblock{Line 1 of code\\Line 2 of code\\Line 3...}
%
% In contrast, the numVblock environment is a verbatim environment:
%
% \begin{numVblock}{
% program test
% implicit none
% integer a, x
% a = 0
% x = 1
% 10 a = a + x
% if (a .eq. 100) stop
% goto 10
% end
% \end{numVblock}
%
% The font used for the code block itself is the ttfamily (typewriter)
% of fixed-width characters. The counter named blocknum is used to
% index the code block sequence.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}
\@ifundefined{verbatim@processline}{\RequirePackage{verbatim}}{}
\usepackage{verbatimbox}
\newsavebox{\@savedverbbox}
\newlength\maxblocklabelsize
\newlength\blockindent
\setlength\maxblocklabelsize{-0.4in}
\setlength\blockindent{0.2in}
\newcommand\blocklabel[1]{[\textit{\arabic{#1}}]}
\newcounter{blocknum}
\setcounter{blocknum}{0}
\newlength\codeblockwidth
\newlength\parindentsave
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\def\numVblock{%
\sbox\@savedverbbox{\usebox{\savedverbbox}}
\verbbox
}
\def\endnumVblock{
\endverbbox
\numblock{\theverbbox[t]}
\global\sbox{\savedverbbox}{\usebox{\@savedverbbox}}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\newcommand\numblock[1]{
\setlength\codeblockwidth{\textwidth}
\addtolength\codeblockwidth{-\maxblocklabelsize}
\addtolength\codeblockwidth{-\blockindent}
\setlength\parindentsave{\parindent}
\parindent 0in
\addtocounter{blocknum}{1}
\vspace{\abovecaptionskip}
\begin{tabular}{@{\hspace{\blockindent}} l @{} r @{}}
{\tt
\begin{tabular*}{\codeblockwidth}{@{} l @{}}
#1
\end{tabular*}%
}
& \makebox[\maxblocklabelsize]{\hfill\blocklabel{blocknum}}\\
\end{tabular}
\vspace{\belowcaptionskip}
\setlength{\parindent}{\parindentsave}
}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\endinput
|