This repository has been archived by the owner on May 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
styles.pkg
376 lines (341 loc) · 11.9 KB
/
styles.pkg
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
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
\LoadPackage{fonts}
\LoadPackage{stacks}
\LoadPackage{counters}
% nastavuje leftskip a rightskip podle parametru aby zarovnání bylo po¾adované
% navíc nastaví okraje na požadované hodnoty
% 1. parametr je øídicí sekvence, která !definuje! jedno slovo z:
% - center
% - left
% - right
% - label (popisek, blok az na posledni radek, ktery je centrovany)
% - block nebo cokoli jineho
% 2. parametr je odsazení zleva
% 3. parametr je odsazení zprava
\def\SetLeftRightSkip#1#2#3{%
\IfLit '#1'='center'%
{% then
\leftskip=#2 plus1fil\rightskip=#3 plus1fil\parfillskip=0pt}%
{% else
\IfLit '#1'='left'%
{%then
\leftskip=#2\rightskip=#3 plus1fil}%
{%else
\IfLit '#1'='right'%
{% then
\leftskip=#2 plus1fil\rightskip=#3\parfillskip=0pt}%
{%else
\IfLit '#1'='label'%
{% then
\leftskip=#2 plus1fil\rightskip=#3 plus-1fil\parfillskip=0pt plus2fil\parindent=0pt}%
{%else - block alignment
\leftskip=#2\rightskip=#3}% jinak zarovnat do bloku
}%
}%
}%
}%
\def\SetAlignment#1{%
\def\\{\break}%
\IfLit '#1'='center'%
{% then
\leftskip=1\leftskip plus1fil\rightskip=1\rightskip plus1fil\parfillskip=0pt\parindent=0pt}%
%\leftskip=1\leftskip plus1fil\rightskip=1\rightskip plus1fil\parfillskip=0pt}%
{% else
\IfLit '#1'='left'%
{%then
\leftskip=1\leftskip\rightskip=1\rightskip plus1fil}%
{%else
\IfLit '#1'='right'%
{% then
\leftskip=1\leftskip plus1fil\rightskip=1\rightskip\parfillskip=0pt}%
{%else
\def\\{\hfil\break}%
\IfLit '#1'='label'%
{% then
\leftskip=1\leftskip plus1fil\rightskip=1\rightskip plus-1fil\parfillskip=0pt plus2fil\parindent=0pt}%
{}%else - block alignment%
}%
}%
}%
}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Styles
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%% parameters of paragraph style:
% - font
% - alignment
% - line spacing
% - top, bottom space (additive, unskip + new)
% - first line, left, right indent
% - allowed to break after the paragraph is finished
% - keep lines together
% - forward text, text behind
% - these two last mechanisms solve: numbering, TOC, references, remembering text
% => preactions, postactions
%% Creates a new style.
%% It's properties can be later changed by using \SetStyleParam, params:
% 1 - name of the style
% 2 - font alias to be used (declared in MkFontTenAlias)
\def\CreateNewStyle#1#2{%
\SetVar{STYLE::#1Exists}{}%
\DeclarePList{STYLE::#1}%
\DeclareStack{STYLE::#1::PreHandlerStack}%
\DeclareStack{STYLE::#1::PostHandlerStack}%
% setting default params and their values
\SetStyleParam{#1}[Font]={#2}%
\SetStyleParam{#1}[Alignment]={left}%
\SetStyleParam{#1}[LineSpacingFactor]={1.0}%
\SetStyleParam{#1}[ExtraTopSpace]={0pt}%
\SetStyleParam{#1}[ExtraBottomSpace]={\parskip}%
\SetStyleParam{#1}[FirstLineIndent]={0pt}%
\SetStyleParam{#1}[LeftIndent]={0pt}%
\SetStyleParam{#1}[RightIndent]={0pt}%
\SetStyleParam{#1}[BreakAllowed]={YES}%
\SetStyleParam{#1}[InVBox]={NO}%
\SetStyleParam{#1}[EndPar]={YES}%
\SetStyleParam{#1}[Prefix]={}%
\SetStyleParam{#1}[Postfix]={}%
\SetStyleParam{#1}[PreActions]={}%
\SetStyleParam{#1}[PostActions]={}%
\SetStyleParam{#1}[SuppresNextParIndent]={NO}%
\SetStyleParam{#1}[SoftTopSpace]={NO}%
\SetStyleParam{#1}[Counter]={}%
\SetStyleParam{#1}[PreHandlerStackName]={STYLE::#1::PreHandlerStack}%
\SetStyleParam{#1}[PostHandlerStackName]={STYLE::#1::PostHandlerStack}%
}%
%% Creates a new style by deriving its properties from an existing one.
%% These can be later changed by using \SetStyleParam, params:
% 1 - name of the style from which to derive
% 2 - name of the new style
% note:
% - content of HandlerStacks is cloned but the macro names are not
\def\DeriveNewStyle#1->#2{{%
\TestStyleExists{#1}%
\SetVar{STYLE::#2Exists}{}%
\DeclarePList{STYLE::#2}%
\DeclareStack{STYLE::#2::PreHandlerStack}%
\DeclareStack{STYLE::#2::PostHandlerStack}%
\def\SetDstStyleParam##1{\CopyStyleParam #1[##1]->{#2}}%
\ClonePList {STYLE::#1}-\SetDstStyleParam->{STYLE::#2}%
\CloneStack {STYLE::#1::PreHandlerStack}->{STYLE::#2::PreHandlerStack}%
\CloneStack {STYLE::#1::PostHandlerStack}->{STYLE::#2::PostHandlerStack}%
\SetStyleParam{#2}[PreHandlerStackName]={STYLE::#2::PreHandlerStack}%
\SetStyleParam{#2}[PostHandlerStackName]={STYLE::#2::PostHandlerStack}}}%
%% tests whether given style exists, if it does not, error message is printed
%% out, params:
% 1 - style in which we are interested
% 2 - error message
\def\TestStyleExists#1{\IfSetVar{STYLE::#1Exists}{}{\FatalErrMsg{Style #1 does not exist, declare it.}}}%
%% typesets given text using given style, params:
% 1 - style to be used
% 2 - text to be typeset
\def\Style#1#2{%
\TestStyleExists{#1}%{Style #1 not found, declare it}%
\GetStyleParam{#1}[PreActions]{% performed locally
\IfVar STYLE::#1Counter=''{}{\hIncrementCounter{\GetStyleParam{#1}[Counter]}}%
\SetFont{\GetStyleParam{#1}[Font]}%
\ex\ifdim\GetVar{STYLE::#1ExtraTopSpace}=0pt\relax\else
\IfVar STYLE::#1SoftTopSpace='YES'{\message{doing softtopspace}\let\next\vskip}{\let\next\vglue}%
\next\GetStyleParam{#1}[ExtraTopSpace]%
\fi
%\IfLit '#1'='Normal'{Nazdar}{}%
% conditionally eat last skip
%\IfVar STYLE::#1RemovePreviousTopSpace='YES'{\removelastskip}{}%
% conditionally insert top space and set bottom space
\baselineskip=1.2em%
\baselineskip=\GetStyleParam{#1}[LineSpacingFactor]\baselineskip%
\parindent=\GetVar{STYLE::#1FirstLineIndent}%
% setting left and right skips
\SetLeftRightSkip
{\GetVar{STYLE::#1Alignment}}%
{\GetVar{STYLE::#1LeftIndent}}%
{\GetVar{STYLE::#1RightIndent}}%
\IfVar STYLE::#1InVBox='YES'%
% then
{\def\StyPreA{\vbox\bgroup}\def\StyPostA{\egroup}}%
% else
{\let\StyPreA=\relax\let\StyPostA=\relax}%
\StyPreA
\def\invokeHandler##1{##1{#2}}%
%
\ForEachStackElem{STYLE::#1::PreHandlerStack}\invokeHandler
\GetVar{STYLE::#1Prefix}%
#2%
\GetVar{STYLE::#1Postfix}%
\ForEachStackElem{STYLE::#1::PostHandlerStack}\invokeHandler
%
\StyPostA
\IfVar STYLE::#1EndPar='YES'{\par}{}} % end of group
\IfVar STYLE::#1BreakAllowed='NO'{\nobreak}{}%
\ex\ifdim\GetVar{STYLE::#1ExtraBottomSpace}=0pt\else
\ex\vskip\GetVar{STYLE::#1ExtraBottomSpace}\fi
\IfVar STYLE::#1SuppresNextParIndent='YES'{\SuppresNextParIndent}{}%
\GetVar{STYLE::#1PostActions}%
}%
%% sets parameter influencing current behaviour of a declared style,
%% using this routine new param may be added to the already existing ones, params:
% 1 - style name
% 2 - style param
% 3 - param's value
\long\def\SetStyleParam#1[#2]=#3{%
\TestStyleExists{#1}%
\AppendToPList{STYLE::#1}{#2}%
\SetVar{STYLE::#1#2}{#3}}%
\long\def\eSetStyleParam#1[#2]=#3{%
\TestStyleExists{#1}%
\AppendToPList{STYLE::#1}{#2}%
\eSetVar{STYLE::#1#2}{#3}}%
\long\def\PostfixStyleParam#1[#2]<#3{%
\TestStyleExists{#1}%
\PostfixVar{STYLE::#1#2}{#3}}%
\long\def\PrefixStyleParam#1[#2]<#3{%
\TestStyleExists{#1}%
\PrefixVar{STYLE::#1#2}{#3}}%
\long\def\SoftSetStyleParam#1[#2]=#3{%
\IfSetVar{STYLE::#1#2}{}{\SetStyleParam#1[#2]={#3}}%
}
\long\def\eSoftSetStyleParam#1[#2]=#3{%
\IfSetVar{STYLE::#1#2}{}{\eSetStyleParam#1[#2]={#3}}%
}
%% copies environment parameter into a new environment under the same name
% 1 - original envi name
% 2 - name of the parameter
% 3 - new envi name
\def\CopyStyleParam#1[#2]->#3{%
%\DPRINT{Copying style params: #1[#2]->#3}%
\TestStyleExists{#1}\TestStyleExists{#3}%
%\AppendToPList{STYLE::#3}{#2}%
\CopyVar {STYLE::#1#2}->{STYLE::#3#2}}%
%% returns value of a style's parameter, params:
% 1 - style name
% 2 - param name
\def\GetStyleParam#1[#2]{%
\TestStyleExists{#1}%
\TestVarExists{STYLE::#1#2}%
\GetVar{STYLE::#1#2}}
%% registers pre-handler by style #1, params:
% 1 - style name
% 2 - handler to be registered - the name is remembered, keep the definition
% visible
\def\AddStylePreHandler#1#2{{%
\TestStyleExists{#1}%
\PushBack{STYLE::#1::PreHandlerStack}{#2}}}%
%\edef\hlpD{\ex\RemoveLeadingGroup\string#2}%
%\ex\hlpC\ex{\hlpD}}}% storing just the textual string not the macro self
%% registers post-handler by style #1, params:
% 1 - style name
% 2 - handler to be registered - the name is remembered, keep the definition
% visible
\def\AddStylePostHandler#1#2{{%
\TestStyleExists{#1}%
\PushBack{STYLE::#1::PostHandlerStack}{#2}}}%
%\ex\hlpC{#2}}}% storing just the textual string not the macro self
\def\ClearStyleHandlers#1{\ClearStylePreHandlers{#1}\ClearStylePostHandlers{#1}}%
\def\ClearStylePreHandlers#1{\ClearStack{STYLE::#1::PreHandlerStack}}%
\def\ClearStylePostHandlers#1{\ClearStack{STYLE::#1::PostHandlerStack}}%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% environments %%%%%%%%%%%%%%%
%% tests whether given environment exists
\def\TestEnviExists#1{\IfSetVar{ENVI::#1Exists}{}{\FatalErrMsg{Environment #1 does not exist, declare it.}}}%
%% sets environment's parameters, params:
% 1 - envi's name
% 2 - param's name
% 3 - param's value
\long\def\SetEnviParam#1[#2]=#3{%
\TestEnviExists{#1}%
\AppendToPList{ENVI::#1}{#2}%
\SetVar{ENVI::#1#2}{#3}
}%
%% sets environment's parameters if it exists, otherwise the parameter is
% ignored, params:
% 1 - envi's name
% 2 - param's name
% 3 - param's value
\long\def\softSetEnviParam#1[#2]=#3{%
\IfSetVar{ENVI::#1Exists}{%
\AppendToPList{ENVI::#1}{#2}%
\SetVar{ENVI::#1#2}{#3}
}{}%
}%
%% copies environment parameter into a new environment under the same name
% 1 - original envi name
% 2 - name of the parameter
% 3 - new envi name
\def\CopyEnviParam#1[#2]->#3{{%
\TestEnviExists{#1}\TestEnviExists{#3}%
%\NewLine appending #2 to ENVI::#3\NewLine
% TODO: create param in PList if necessary
%\AppendToPList{ENVI::#3}{#2}%
\CopyVar {ENVI::#1#2}->{ENVI::#3#2}}}%
%% return's environemnt's parameter value contained, params:
% 1 - envi's name
% 2 - param's name
\def\GetEnviParam#1[#2]{%
\TestEnviExists{#1}%
\TestVarExists{ENVI::#1#2}%
\GetVar{ENVI::#1#2}}%
%% prefixes envi param by given text, params:
% 1 - envi name
% 2 - envi param to be prefixed
% 3 - prefix self
\long\def\PrefixEnviParam#1[#2]<#3{%
\TestEnviExists{#1}%
\PrefixVar{ENVI::#1#2}{#3}}%
%% postfixes envi param by given text, params:
% 1 - envi name
% 2 - envi param to be prefixed
% 3 - postfix self
\long\def\PostfixEnviParam#1[#2]<#3{%
\TestEnviExists{#1}%
\PostfixVar{ENVI::#1#2}{#3}}%
%% returns current envi name
\def\GetCurrEnviName{\GetVar{ENVI::CurrEnvi}}%
%% sets value of a parameter of current envi, params:
% 1 - param name
% 2 - param value
\def\SetCurrEnviParam#1#2{\SetVar{ENVI::\GetCurrEnviName#1}{#2}}%
\def\GetEnviParamInToks#1#2[#3]{%
\TestEnviExists{#2}%
\GetVarInToks{#1}{ENVI::#2#3}}%
%% returns value of a parameter from the current environment, params:
% 1 - param name
\def\GetCurrEnviParam[#1]{%
\GetEnviParam\GetCurrEnviName[#1]}%}
%
%% creates a new environment, params:
% 1 - name of the environment
% 2 - preactions: performed locally
% 3 - postactions: performed locally
\long\def\CreateNewEnvironment#1#2#3{%
\SetVar{ENVI::#1Exists}{}%
\DeclarePList{ENVI::#1}%
\SetEnviParam{#1}[PreActions]={#2}%
\SetEnviParam{#1}[PostActions]={#3}%
\SetEnviParam{#1}[ExtraTopSpace]={0pt}%
\SetEnviParam{#1}[ExtraBottomSpace]={0pt}%
}%
%% creates a new environment by deriving its properties from an existing one, params:
% 1 - name of the environment from which to derive
% 2 - name of the new environment
\def\DeriveNewEnvironment#1->#2{%
\TestEnviExists{#1}%
\SetVar{ENVI::#2Exists}{}%
\DeclarePList{ENVI::#2}%
\def\SetDstEnviParam##1{\CopyEnviParam {#1}[##1]->{#2}}%
\ClonePList ENVI::#1-\SetDstEnviParam->{ENVI::#2}%
%\ForEachPListElem{ENVI::#1}\SetDstEnviParam
}%
%% begins environment: performs pre-actions
\def\Begin#1{%
\TestEnviExists{#1}%
\par %?
\bgroup\lSetVar{ENVI::CurrEnvi}{#1}%
\ifdim\GetCurrEnviParam[ExtraTopSpace]=0cm\else\vskip\GetCurrEnviParam[ExtraTopSpace]\fi
\GetEnviParam{#1}[PreActions]}%
%% end environment: performs post-actions
\def\End#1{%
\TestEnviExists{#1}%
\GetEnviParam{#1}[PostActions]%
\par
\ifdim\GetCurrEnviParam[ExtraBottomSpace]=0cm\else\vskip\GetCurrEnviParam{ExtraBottomSpace}\fi
\egroup
}%
\LoadFile{style_settings.tex}