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
|
This directory contains files that allow to generate two style
files: 'programs.sty' and 'keywords.sty'.
The 'demo' subdirectory contains an example of what can be done with
these two styles ('demo.tex' can be compiled either with LaTeX or with
LaTeX2.09 -- see the corresponding directory under macros/latex209/contrib).
The two files in this archive may be used independently or in
conjunction, according to your wish.
The file 'programs.sty' is intended to allow a parameterized way of
typesetting programs with TeX/LaTeX commands inside.
The file 'keywords.sty' allows use and define sets of keywords that
will be typeset with different fonts, according to the wish of the
user.
The purpose of these two files, when used in conjunction, is to allow
a user to write only one program and to print it differently,
according to the document where it must be put (ex: keywords in
english/french, keywords underlined, boldfaced, programs
indented, no indented, numbered, unnumbered, etc). Of course, the
algorithm will be written only once.
Below I give a short description of the files and the way to generate
them.
------------
programs.sty
------------
I have written a style file for typesetting programs.
Its particularities are:
- TABS are replaced by simple SPACES as in the 'astyped.sty' style
- and you can use emphasized fonts, math formulae, etc.
- programs may be numbered or unnumbered
- line numbers may appear in the left side or right side margin,
or in both sides, or inside the text body (on the left of the text)
- line numbers may be refered to with \label / \ref
- the first line of a numbered program is by default 1, but it is
possible to change this first value in two manners:
o by specifying a particular first number
o by indicating that the next program will start at the line
number that follows the last line of the last previous
program typed
- programs may be globally indented, but a particular occurrence may
have a different indentation
By default, 7 environments are provided, according to the font size:
program normal size
programs small size
programf footnote size
programsc scriptsize
programt tiny size
programl large size
programL Large size
For each environment, there exist to file inclusion commands that work
in a manner similar to the \verbatimfile and \verbatimlisting commands
of the 'verbatimfiles.sty' file:
\fprogram? inclusion of unnumbered program
\lprogram? inclusion of numbered program
where '?' stands for nothing, or for one string in "s", "f", "sc",
"t", "l" and "L", according to the font size desired.
It is possible to define new environments. For instance
\NewProgram{FOO}{LARGE}
will define the environment FOO with font size set to LARGE, and to
file inclusion commands: \fFOO and \lFOO.
Extract the package file from its '.dtx' file as follows:
latex programs.ins
And get the documented source by:
latex programs.drv
latex programs.drv
latex programs.drv
makeindex -s programs.ist programs.idx
latex programs.drv
------------
keywords.sty
------------
As a companion to the style programs.sty, here follows a style called
keywords.sty whose main purpose is to provide a parameterized way to
typeset keywords. This style may be used in conjunction with the
programs.sty file, but this is not necessary.
What you can do is, for instance, to type a program where keywords
will appear boldfaced. It suffices to issue the \ProgKeywords command
(global scope), and then to type the text, for instance:
\BEGIN
\FOR I := 1 \TO 10 \DO
....
\ENDDO
\END
In this example, the keywords are commands defined in the second part
of the keywords.sty file. If the environment is such that spaces are
obeyed (like in the verbatim environment or by using the programs.sty
file), then keywords can be typed as is; otherwise (i.e. in normal
text) they must be typed followed by a "\" character
(e.g.: \BEGIN\ ...).
Assume now, that you want that the program above is typed with
keywords written with an emphazised font and underlined, and that
words appear in French instead of English.
Then take the same program, but just change the "\ProgKeywords"
command that precedes it to "\UFAlgoKeywords" (for: Underlined French
AlgoKeywords).
I have sorted keywords in lexicographic order.
If you need to change or add a definition go anywhere among the
keywords and type (e.g. definition of the keyword FOO):
#1{\FOO}{this is an example}[bla bla]%
Then if you chose commands where the 'F' does not appear in the
beginning of the name, any occurrence of "\FOO" is replaced by the
sentence "this is an example"; otherwise, the sentence "bla bla" will
be used.
If your wish is that the same expansion is performed for all the
commands, the omit tht fourth parameter:
#1{\FOO}{this is an example}
The commands provided are:
-------------------------------------------------------------------------
English keywords French keywords
-------------------------------------------------------------------------
\tt BOLDFACE DISPLAY \ProgKeywords \FProgKeywords
\tt NORMAL DISPLAY \ttKeywords \FttKeywords
\em DISPLAY \AlgoKeywords \FAlgoKeywords
underlined \em DISPLAY \UAlgoKeywords \UFAlgoKeywords
normal (\rm) DISPLAY \NormalKeywords \FNormalKeywords
-------------------------------------------------------------------------
As I am French, I have used English and French languages; however you
can use any couple of languages you want. I recall that if parameter 4
in keyword definition is omitted, then only the first language is
used.
The file terminates by a command that selects the default mode (in the
current case this is \UFAlgoKeywords).
Extract the package file from its '.dtx' file as follows:
latex keywords.ins
And get the documented source by:
latex keywords.drv
latex keywords.drv
latex keywords.drv
makeindex -s keywords.ist keywords.idx
latex keywords.drv
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Miguel ALABAU
LaBRI, Universite BORDEAUX I
351, cours de la Liberation 33405 TALENCE Cedex (FRANCE)
e-mail: Miguel.Alabau@labri.u-bordeaux.fr
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|