forked from NUT-RogerPrice/ConfigExamples
-
Notifications
You must be signed in to change notification settings - Fork 4
/
lineprinter.sty
172 lines (140 loc) · 5.9 KB
/
lineprinter.sty
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
% lineprinter.sty
% This LaTeX2e package file provides a crude line printer with
% numbered lines. Any line may be given a name which may be referred
% to with the \ref command.
% Copyright 2000 Roger Price
% This program is free software; you can redistribute it and/or
% modify it under the terms of the GNU General Public License
% as published by the Free Software Foundation; either version 2
% of the License, or (at your option) any later version.
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place - Suite 330,
% Boston, MA 02111-1307, USA.
% Roger Price rprice@cs.uml.edu
% For details of the techniques used in this package specification,
% see the LaTeX2e Companion, appendix A.
% The LinePrinter environment displays its contents as if they were a
% computer printout. The markup of each line requires use of the Chunk
% command provided by this package and the verb command provided by
% LaTeX.
% The Chunk command has an optional argument which is a label for the
% line. This allows use of the ref command to reference a named line.
% \begin{LinePrinter}
% \Chunk & \verb_\begin{document}_ \\
% \Chunk & \verb_%%%%%%%%% Abstract %%%%%%%%%_ \\
% \Chunk & \verb_\begin{Abstract}_ \\
% \Chunk[line:Bla] & \verb_Bla bla bla ..._ \\
% \Chunk & \verb_\end{Abstract}_ \\
% \end{LinePrinter}= \\
% Your text appears at line \ref{line:Bla}.
% The last line is typeset as: Your text appears at line 234.
% Note that every line to be printed, including the last line, is
% terminated with a double backslash ``\\''.
% The LinePrinter environment has an optional parameter which
% reduces the width of the printer. You may specify
% \begin{LinePrinter}[\Medium]
% or even
% \begin{LinePrinter}[\Narrow]
% Don't forget to place a backslash ``\'' before the option name,
% or you will get a mysterious error mesage from LaTeX:
% !Missing number, treated as zero.
%%%%%%%%%%%%%%%%%%%%%%%% Changes for version 1.1 %%%%%%%%%%%%%%%%%%%
% *
%%%%%%%%%%%%%%%%%%%%%%%% Identification part %%%%%%%%%%%%%%%%%%%%%%%
\NeedsTeXFormat{LaTeX2e}[1996/12/01]
\ProvidesPackage{lineprinter}%
[2000/07/30 V1.0 Line printer]
%%%%%%%%%%%%%%%%%%%%%%%% Initial code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%% Declaration of options %%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%% Execution of options %%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%%%%%% Class and package loading %%%%%%%%%%%%%%%%%
\RequirePackage{ifthen}
%%%%%%%%%%%%%%%%%%%%%%%% Main code %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%%%%%%%%%%%%%%%%%%%% Define new commands and environments %%%%%%%%%%
%
% Simulated line printer
%
% The printer is a table with two columns. It comes in three
% models Narrow, Medium and Wide.
% Column 1 provides line numbers generated by command \Chunk.
% Column 2 is the printed material.
% This printer is noisy - it goes chunk, chunk, chunk,...
% Example \begin{LinePrinter}{\Narrow}
% \Chunk & \verb_ o o_ \\
% \Chunk & \verb_ ^ _ \\
% \Chunk & \verb_ ---_ \\
% \end{LinePrinter}
% By default, the printer is \Wide, almost the width of the text,
% but \Medium and \Narrow printers are available.
% See the LaTeX 2e User's Guide, section C.8.4, p.194.
\newcounter{LinePrinterNumber} % All printed lines are numbered
\setcounter{LinePrinterNumber}{0}
% US Letter paper is 215.9x279.4mm ISO A4 paper is 210x297mm.
\newlength{\Narrow} % Width of narrow lineprinter
\setlength{\Narrow}{\textwidth}
\addtolength{\Narrow}{-78mm}
\newlength{\Medium} % Width of medium lineprinter
\setlength{\Medium}{\textwidth}
\addtolength{\Medium}{-48mm}
\newlength{\Wide} % Width of wide lineprinter
\setlength{\Wide}{\textwidth}
\addtolength{\Wide}{-18mm}
% The Chunk command uses the counter LinePrinterNumber to number
% all lines consecutively through the document.
% Since the counter LinePrinterNumber is not a referencing counter,
% the value is transferred to the enumiv counter which is pirated
% because it is referencing.
% The optional argument, when specified, is a label attached to
% the line. E.g \Chunk[x] allows use of \ref{x}.
\newcommand{\Chunk}[1][]{%
\ifthenelse{\equal{#1}{}}{}%
{\setcounter{enumiv}{\theLinePrinterNumber}%
\renewcommand\theenumiv{\@arabic\c@enumiv}%
\renewcommand\p@enumiv{}% Display only the line number
\refstepcounter{enumiv}% Provides text for \ref
\label{#1}}%
\stepcounter{LinePrinterNumber}% Number lines in document
\theLinePrinterNumber}
% Clunk is a simple version of Chunk suitable for use when hyperref present
\newcommand{\Clunk}[1][]{%
\refstepcounter{LinePrinterNumber}% Provides text for \ref
\theLinePrinterNumber% Number for every line
\ifthenelse{\equal{#1}{}}%
{}%
{\label{#1}}}% No empty labels
\newenvironment{LinePrinter}[1][\Wide]
{\begin{center}
\small
\begin{tabular}{r|p{#1}|}
\cline{2-2}}
{\cline{2-2}
\end{tabular}
\normalsize
\end{center}}
%
% Simulated label printer
%
% This printer is like the line printer, but the width is no more
% than needed to print the label. This printer is useful when
% working in the seminar style to produce slides. There is
% no option.
\newenvironment{LabelPrinter}
{\begin{center}
\small
\begin{tabular}{r|l|}
\cline{2-2}}
{\cline{2-2}
\end{tabular}
\normalsize
\end{center}}
%
% A paper fold, used to separate groups of lines
%
\newcommand{\PaperFold}{\cline{2-2}}
%%%%%%%%%%%%%%%%%%%%%%%% Issue commands and text %%%%%%%%%%%%%%%%%%%
% End of file