Debian Codegraph @

texmf-dist/doc/otherformats/lollipop/manual/struct.tex

raw
1 % struct.tex copyright 1992 Victor Eijkhout
2 % copyright 2014--2016 Vafa Khalighi
3 %
4 %
5 % This program is free software: you can redistribute it and/or modify
6 % it under the terms of the GNU General Public License as published by
7 % the Free Software Foundation, either version 3 of the License, or
8 % (at your option) any later version.
9 %
10 % This program is distributed in the hope that it will be useful,
11 % but WITHOUT ANY WARRANTY; without even the implied warranty of
12 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 % GNU General Public License for more details.
14 %
15 % You should have received a copy of the GNU General Public License
16 % along with this program. If not, see <http://www.gnu.org/licenses/>.
17 %
18 %
19 \Chapter The structure of Lollipop
20
21 Lollipop provides tools for realizing the style or layout of a
22 document. Some of these tools are macros ready to be used by the end
23 user; they concern for instance selection of fonts.
24 Others, the `generic constructs', are for the style designer so that
25 she can use them to program the macros for the user.
26
27 \Section[sec:doc-start-stop] Lollipop Files
28
29 Any Lollipop document has to have a \cs{Start} and \cs{Stop} command.
30 Before the \cs{Start} there can be style definition commands, but no
31 text. For a number of reasons it is advisable to put as much of the
32 style definition before the \cs{Start} command as possible. You can
33 do that easily by loading the style as an input file, or by first
34 dumping it as a format (see section~\ref[sec:style-dump]).
35
36 \ImpNote
37 Before the \cs{Start} command, \cs{everypar} contains an error
38 message. The start command installs the default value for
39 \cs{everypar}.
40 \ImpNoteStop
41
42 Both the start and the stop file load the \file{.aux} auxiliary file.
43 None of this should concern you, really. Expert users who want to
44 have certain actions performed at the start of the document may want
45 to use \refcs{StartCommand} to specify what they wish done. See
46 section~\ref[sec:adapt-distance] for an example.
47
48 \Section Generic Constructs
49
50 \label[generic:construct]\label[option:macro]
51 There are five `generic constructs': headings, lists, text blocks, page
52 grids, and external items. For each construct type there is a defining
53 command, for instance \cs{DefineHeading}
54 which is followed a list of `options', terminated by the word `Stop'.
55
56 Options (possibly with values) have to be separated by a
57 space or a line end; the keyword \opt{Stop} has to be followed by a
58 space or a line end.
59 Options may have zero, one or two values; if there are values, then
60 the first one is separated from the option by a colon, the second is
61 separated from the first by an equals sign.
62
63 \Ver>\DefineFoo:Bar optiona optionb optionc:value
64 optiond:valuea=valueb optione
65 optionf Stop<Rev
66
67 As a result of this definition, a command
68 \cs{Bar} is created. If the \con{Foo} construct was a \con{List} or
69 \con{TextBlock}, an additional command \cs{BarStop} is created.
70
71 This command can then be used in the ordinary way, for instance
72 after \ver>\DefineHeading:Foo> you can type
73 \Ver>\Foo The title<Rev and after \ver>\DefineList:Foo> you can type
74 \Ver>\Foo
75 \item One item
76 \item And another
77 \FooStop<Rev
78
79 \ImpNote
80 Actually, this `Stop' business can be customized for other languages.
81 The file \file{tools} has the following lines:
82 \Ver>
83 \def\stop@command@suffix{Stop}
84 \def\stop@command{\@command\stop@command@suffix}<Rev
85 \ImpNoteStop
86
87 \Section Options
88
89 Options are mostly used to specify how a construct will look. Some
90 options, for instance \opt{title}, indicate material that will appear
91 on the page. Other options are interpreted as commands, for instance
92 \opt{IndentAfter:yes} in the definition of a heading indicates that
93 the first paragrah after such a heading will indent.
94
95 In addition to keywords that only exist as options, commands can
96 be used as options. Also, single characters are accepted as options.
97 For instance a definition of a subsection heading can contain:
98
99 \Ver>\DefineHeading:SubSection
100 [...]
101 SectionCounter . SubSectionCounter
102 [...] Stop<Rev
103 (Here and later the \n{[...]} will denote arbitrary omitted text.)
104 This definition contains the commands \cs{SectionCounter} and
105 \cs{SubSectionCounter} and the \n{.} character.
106
107 If a number of options appears together in a number of constructs it
108 is convenient to have an abbreviation for them. This can be done with the command
109 \refcs{OptionsMacro} as follows. The options that appear together are
110 given a common name
111 \Ver>\OptionsMacro:baz=optiona optionb:value optionc
112 Stop<Rev
113 (be sure to leave
114 no spaces around the equals sign) and this name is then used as
115 \Ver> macro:baz<Rev
116 in the option list wherever the options are needed.
117
118 This is for
119 instance a good way of specifying identical white space around all
120 sorts of constructs without duplicating the typing each time.
121 However, it is only for your convenience: it doesn't save any \TeX\
122 resources or processing time.
123
124 \Section[sec:error-msg] Popular error messages. Not!
125
126 Lollipop is a macro package on top of an existing program, \TeX.
127 Therefore it is inevitable that you will get \TeX\ error messages
128 every once in a while. Some of these may confuse you.
129
130 Here are a few of the errors that I~keep making.
131
132 \SubSection Missing \cs{endcsname} inserted
133
134 If you forget the second parameter in a \cs{Distance} or
135 \cs{SetCounter} command, writing for instance
136 \Ver>\Distance:TheWidth<Rev
137 instead of \Ver>\Distance:TheWidth=15pt<Rev
138 \TeX\ will scan
139 forward, and it can easily bump into something that is highly
140 unexpected given the context. If this is a \cs{def} or \cs{Define...}
141 command, a `missing \cs{endcsname}' results. If a blank line follows
142 the incomplete declaration, the following section applies.
143
144 \SubSection Paragraph ended before something was complete
145
146 \TeX\ has found a blank line (or a~\cs{par} command) where this was
147 not expected. See for instance the previous section.
148
149 \SubSection Missing number
150
151 You have used something that you thought was the name of a control
152 sequence, but it wasn't. Example:
153 \Ver>\Distance:parskip=parundent<Rev
154 Since \cs{parundent} is undefined, \Lollipop\ thought you were
155 writing something like
156 \Ver>\Distance:parskip=5pt<Rev
157
158 And yes, the message refers to `number' even though what is missing
159 is a distance.
160
161 \ImpNote
162 \iSection Defining Generic Constructs
163
164 The \cs{Define...} commands are not defined explicitly, instead they
165 are generated by a call such as
166 \Ver> \@GenericConstruct{Heading}<Rev
167 Full definition:
168 \Ver>\def\@GenericConstruct#1{<Rev
169 to be used as \ver>\@GenericConstruct{Foo}>;
170 \Ver> \append@to@list{@gencons}{\\#1;}<Rev
171 book keeping of existing generic constructs;
172 \Ver> \csarg\newtoks{#1@defaults}
173 \csn #1@defaults\ecs{}<Rev
174 default commands to be executed whenever
175 an instance of this construct
176 is defined;
177 \Ver> \csarg\def{add@#1@default}##1%
178 {\append@to@list{#1@defaults}{##1}}<Rev
179 the command \cs{add@Foo@default}
180 to add defaults for this construct;
181 \Ver> \Install@Noops{#1}<Rev
182 possibility to generate error msgs for the use of an option that is
183 not allowed for this type of construct;
184 \Ver> \csarg\def{Define#1}:##1 {<Rev
185 instances of this construct will be defined
186 by a statement like \ver>\DefineFoo:Bar>;
187 \Ver> \def\@name{##1}\def\@class{#1}
188 \Tmessage[def]{Defining a #1: ##1}<Rev
189 \ver>DefineFoo:Bar> leads to \cs{@name} begin \n{Bar},
190 \cs{@class} being \n{Foo};
191 \Ver> \the\generic@defaults
192 \csarg\the{#1@defaults}<Rev
193 unpack token lists of generic and specific default actions;
194 \Ver> \Get@Items}<Rev
195 start recursive processing of list of options. This ends the
196 definition of \cs{DefineFoo}; the definition of
197 \cs{@GenericConstruct} ends with
198 \Ver> \csarg\def{@#1Option}##1%
199 {\csarg\def{#1@##1}####1####2}<Rev
200 which defines the \cs{@FooOption} macro; see~\ref[imp:option].
201 \Ver> }<Rev
202
203 \iSection Items Processing
204
205 Processing the list of items is recursive; at the end some concluding
206 actions have to be taken, mostly the actual definition of the
207 construct.
208
209 First we have to filter out empty arguments, which can be caused by
210 the use of option macros (\ref[option:macro], \ref[imp:option:macro]).
211
212 \Ver>\def\Get@Items#1 {\if\EmptyList{#1}\let\get@next@item\Get@Items
213 \else\def\get@next@item{\@Get@Items#1 }\fi
214 \get@next@item}<Rev
215
216 Next, check if the argument is \opt{Stop} (defined by
217 \ver>\NewDummy{Stop}>, \ref[imp:new:dummy]), in which case you
218 have reached the end of a generic definition, and can start performing
219 the final rites. Otherwise, dissect this option item
220 and go on with the rest
221 of the options.
222 \Ver>
223 \def\@Get@Items#1 {\let\get@next@item=\Get@Items
224 \csarg\ifx{#1}\Stop
225 \the\generic@stop@defaults
226 \let\get@next@item=\relax
227 \else \Item@or@Macro#1::. \fi \get@next@item}<Rev
228
229 The \n{::.} concluding \cs{Item@or@Macro} accomodates one,
230 possibly empty, argument.
231
232 \iSection Options\label[imp:option]\label[imp:option:macro]
233
234 Options can either be specific, defined as
235 \Ver>\@FooOption{Bar}{ [...] }<Rev
236 in which case the option \opt{Bar} can only be used inside
237 a call to \cs{DefineFoo},
238 or they can be generic, defined as
239 \Ver>\@GenericOption{Bar}{ [...] }<Rev
240 For both definitions, the definition text can use up to two parameters.
241 Parameters are given to the options as
242 \Ver> optiona:par1 optionb:par1=par2<Rev
243
244 Specific options are defined by the line
245 \Ver>
246 \csarg\def{@#1Option}##1%
247 {\csarg\def{#1@##1}####1####2}<Rev
248 in \cs{@DefineGenericConstruct}; a call
249 \Ver>\@FooOption{Bar}{ ... }<Rev
250 expands to
251 \Ver>\def\Foo@Bar#1#2{ ... }<Rev
252 Generic options are defined by the
253 following command:
254 \Ver>\def\@GenericOption#1{
255 \append@to@list{@GenericOptions}{\\#1;}
256 \csarg\def{Option@#1}##1##2}<Rev
257 A call
258 \Ver>\@GenericOption{Bar}{ ... }<Rev
259 expands to
260 \Ver>\def\Option@Bar#1#2{ ... }<Rev
261
262 \ImpNoteStop
263
264 \endinput