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
/
envis.pkg
135 lines (118 loc) · 4.02 KB
/
envis.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
\LoadPackage{stacks}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 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}%
% case of RadkovyRejstrik
\SetEnviParam{#1}[ExtraTopLines]={1}%
\SetEnviParam{#1}[ExtraBottomLines]={1}%
% whether break is allowed - by default it is
\SetEnviParam{#1}[BreakAllowed]={YES}%
}%
%% 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}%
\IfLit '\GetDocParam[RadkovyRejstrik]'='YES'%
{\IfLit '\GetCurrEnviParam[ExtraTopLines]'='0'{}{\softskiplines{\GetCurrEnviParam[ExtraTopLines]}}}%
{\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
\IfLit '\GetCurrEnviParam[BreakAllowed]'='NO'{\nobreak}{}%
\IfLit '\GetDocParam[RadkovyRejstrik]'='YES'%
{\IfLit '\GetCurrEnviParam[ExtraBottomLines]'='0'{}{\softskiplines{\GetCurrEnviParam[ExtraBottomLines]}}}%
{\ifdim\GetCurrEnviParam[ExtraBottomSpace]=0cm\else\vskip\GetCurrEnviParam[ExtraBottomSpace]\fi}
\egroup
}%
\LoadFile{envi_settings.tex}