-
Notifications
You must be signed in to change notification settings - Fork 0
/
containers.tex
190 lines (167 loc) · 6.01 KB
/
containers.tex
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
% Containers
% ==================================================
% for typesetting MMT theories, views, constants; and BNF grammars
% ==================================================
% Source: <https://tex.stackexchange.com/a/63233/38074>
% Author: egreg <https://tex.stackexchange.com/users/4427/egreg>
% License: CC BY-SA 3.0 <https://creativecommons.org/licenses/by-sa/3.0/>
\ExplSyntaxOn
\DeclareExpandableDocumentCommand{\IfNoValueOrEmptyTF}{mmm}
{
\IfNoValueTF{#1}{#2}
{
\tl_if_empty:nTF {#1} {#2} {#3}
}
}
\ExplSyntaxOff
% name of theory, meta theory, parameters (for parametric theories)
\NewDocumentCommand\theory{moo}{%
\keyword{theory}\;#1\IfValueT{#2}{\colon #2}%
\IfNoValueOrEmptyTF{#3}{}{\ \{#3\}}
}
% name of diagram, optional meta theory
\NewDocumentCommand\diagram{mo}{%
\keyword{diagram}\;#1\IfValueT{#2}{\colon #2}%
}
\NewDocumentCommand\morph{mmmO{mor}}{%
\operatorname{\mathbf{#4}}\;#1\colon #2 \to #3%
}
\NewDocumentCommand\view{mmm}{\morph{#1}{#2}{#3}[view]}
\NewDocumentCommand\incl{s m o}{%
\keyword{include}\;#2\IfValueT{#3}{%
\,\IfBooleanTF{#1}{[=#3]}{= #3}
}%
}
% `\const{c}{A}` typesets `c: A`
% `\const{c}{A}[t]` typesets `c: A
% `\const*{c}{A}[t]` typesets `c: A [= t]`
\NewDocumentCommand\cst{s m m o}{%
#2\colon #3\IfValueT{#4}{%
\,\IfBooleanTF{#1}{[=#4]}{= #4}
}%
}
\let\const\cst% deprecated alias, please switch to \cst
\NewDocumentCommand\paraincl{m m}{%
\keyword{include}\;#1\ #2%
}
% note: \structure would clash with a Beamer macro
\NewDocumentCommand\structureDecl{s m m o}{%
\keyword{structure}\;#2\colon#3\IfValueT{#4}{%
\,\IfBooleanTF{#1}{[=#4]}{= #4}
}%
}
% arguments: bracket definiens?, theory name, definiens, parameters (for includes of parametric theories)
\NewDocumentCommand\includeDecl{smoo}{%
\incl{#2}\IfValueT{#4}{\ #4}\IfNoValueOrEmptyTF{#3}{}{%
\,\IfBooleanTF{#1}{[=#3]}{= #3}%
}%
}
\newcommand{\realizeDecl}[1]{\keyword{realize}{\;#1}}
\NewDocumentEnvironment{eqns}{O{=}+b}{%
\providecommand{\nl}[1][.2cm]{\\[##1]}%
\providecommand{\txt}[1]{\multicolumn{2}{l}{\text{\rm##1}}}%
\providecommand{\eqcont}{\\\multicolumn{1}{l@{\;\hphantom{#1}\;}}{}&\quad}%
% \def to force overwriting \eqdef from some other packages
\def\eqdef{\\\multicolumn{1}{l}{}&\hspace{-0.5em}=}%
\providecommand{\eqskip}{\\[0.5cm]}%
\[\begin{array}{l@{\;#1\;}l@{\quad}l}%
#2%
\end{array}\]%
}{}
\NewDocumentEnvironment{eqnstyped}{+b}{%
% to give definitions without typing in eqnstyped
\providecommand{\eqeq}[1]{\multicolumn{1}{l@{\;=\;}}{##1}}%
\begin{eqns}[\colon]%
#1%
\end{eqns}%
}{}
\NewDocumentEnvironment{mmttheory}{m+b}{%
\begin{align*}%
&\theory{#1} = \{\\%
&\quad\begin{array}{l@{\colon}l}#2\end{array}\\%
&\}%
\end{align*}%
}{}
\NewDocumentEnvironment{lfsig}{mO{}+b}{%
\[#1 = #2\left\{\begin{array}{l@{\colon}l}#3\end{array}\right\}\]
}{}
% args: mor name, domain, codomain, keyword, decl separator, body
\NewDocumentEnvironment{mmtmor}{mmmO{mor}O{=}+b}{%
\begin{align*}%
&\morph{#1}{#2}{#3}[#4] = \{\\%
&\quad\begin{array}{l@{\;#5\;}l}#6\end{array}\\%
&\}%
\end{align*}%
}{}
% args: view name, domain, codomain, body
\NewDocumentEnvironment{mmtmortyped}{mmmO{mor}+b}{%
\begin{mmtmor}{#1}{#2}{#3}[#4][\colon]%
#5%
\end{mmtmor}%
}{}
\NewExpandableDocumentCommand\mmtinclude{m}{\multicolumn{2}{l}{\includeDecl{#1}}\\}
\NewExpandableDocumentCommand\mmtcomment{m}{\multicolumn{2}{l}{{\color{gray}\text{/* #1 */}}}\\}
\NewDocumentEnvironment{lfsigmor}{m+b}{%
\[#1 = \left\{\begin{array}{l@{=}l}#2\end{array}\right\}\]%
}{}
% star means that expected types are also given
\NewDocumentEnvironment{lfsigmor*}{m+b}{%
\[#1 = \left\{\begin{array}{l@{\colon}l@{=}l}#2\end{array}\right\}\]%
}{}
\makeatletter
% unused, deprecated, use \mmtcont and \mmtdef
\NewDocumentCommand\mmtdecl{mo}{%
\setsepchar{\\}%
\readlist*\mylines{#1}%
% see https://chat.stackexchange.com/transcript/message/57658768#57658768
\gdef\bdy{}%
\foreachitem\myline\in\mylines{\g@addto@macro\bdy{&\myline\\}}%
\begin{aligned}[t]\bdy\end{aligned}%
\IfValueT{#2}{%
\\\multicolumn{1}{l@{=}}{}
}%
}
\makeatother
% continue right-hand side expression of current line of mmttheory on next line
% by default, the new line gets indented by \quad, you can override the space by the optional argument (e.g. `\mmtcond[\;]`)
% if starred, no indentation is applied
\NewDocumentCommand\mmtcont{sO{\quad}}{%
\\\multicolumn{1}{l}{}&\IfBooleanTF{#1}{}{#2}%
}
% begin a definiens right-hand side expression on next line of mmttheory
\NewDocumentCommand\mmtdef{}{\\\multicolumn{1}{l@{=}}{}&}
\NewDocumentCommand\mmtskip{}{\\[0.4em]}
%Example:
%\begin{mmttheory}
% A & \prop \to \prop \to\mmtcont
% \type\\
% B & \prop \to \prop \to \type\mmtdef
% \lam{p q}\mmtcont
% A\ p\ q
%\end{mmttheory}
% Grammars, from https://github.com/UniFormal/implicit/blob/aaba021c3238eae022c5dc620a0f9a7f75fac68e/macros/basics.sty
% CFGs
\newcommand{\tb}{\hspace*{.5cm}}
\newenvironment{grammar}{\[\begin{array}{l@{\tb\bbc\tb}l@{\tb}l}}{\end{array}\]}
% use like:
% \begin{grammar}
% D & & \text{theory declarations}\grammarcont
% \bnfalt \includeDecl{T} & \quad\text{includes}\grammarcont
% \bnfalt c\colon A & \quad\text{constants}\\
% t & a \bnfalt b & \text{something else}
% \end{grammar}
\NewDocumentCommand\grammarcont{}{\\\multicolumn{1}{l}{}&}
%Added by Navid Roux:
\newenvironment{packedgrammar}{\[\begin{array}{l@{\hspace*{.2cm}\bbc\hspace*{.2cm}}l@{\hspace*{.2cm}}l}}{\end{array}\]}
\newcommand{\bnf}[1]{#1}
\newcommand{\bbc}{\bnf{::=}}
\newcommand{\bnfalt}{\ensuremath{\;\bnf{|}\;}}
\providecommand{\alt}{\ensuremath{\;\bnf{|}\;}} % already used by beamer
\newcommand{\opt}[1]{\bnf{[}#1\bnf{]}}
\newcommand{\bnfbracket}[1]{\bnf{(}#1\bnf{)}}
\newcommand{\rep}[1]{#1^{\bnf{\ast}}}
\newcommand{\bnfchoice}[1]{\bnf{[}#1\bnf{]}}
\newcommand{\bnfnegchoice}[1]{\bnf{[\caret}#1\bnf{]}}
% Added by Navid Roux:
\newcommand{\grammarEmptyRow}{\multicolumn{1}{c}{}\\}
% Grammars End