├── .gitignore ├── LICENSE ├── README.md ├── hyperref.tex ├── mttex.sty ├── test-acmart.tex ├── test-lang.tex ├── test.tex └── uptest.tex /.gitignore: -------------------------------------------------------------------------------- 1 | ## Core latex/pdflatex auxiliary files: 2 | *.aux 3 | *.lof 4 | *.log 5 | *.lot 6 | *.fls 7 | *.out 8 | *.toc 9 | 10 | ## Intermediate documents: 11 | *.dvi 12 | *-converted-to.* 13 | # these rules might exclude image files for figures etc. 14 | # *.ps 15 | # *.eps 16 | # *.pdf 17 | 18 | ## Bibliography auxiliary files (bibtex/biblatex/biber): 19 | *.bbl 20 | *.bcf 21 | *.blg 22 | *-blx.aux 23 | *-blx.bib 24 | *.brf 25 | *.run.xml 26 | 27 | ## Build tool auxiliary files: 28 | *.fdb_latexmk 29 | *.synctex 30 | *.synctex.gz 31 | *.synctex.gz(busy) 32 | *.pdfsync 33 | 34 | ## Auxiliary and intermediate files from other packages: 35 | 36 | # algorithms 37 | *.alg 38 | *.loa 39 | 40 | # achemso 41 | acs-*.bib 42 | 43 | # amsthm 44 | *.thm 45 | 46 | # beamer 47 | *.nav 48 | *.snm 49 | *.vrb 50 | 51 | #(e)ledmac/(e)ledpar 52 | *.end 53 | *.[1-9] 54 | *.[1-9][0-9] 55 | *.[1-9][0-9][0-9] 56 | *.[1-9]R 57 | *.[1-9][0-9]R 58 | *.[1-9][0-9][0-9]R 59 | *.eledsec[1-9] 60 | *.eledsec[1-9]R 61 | *.eledsec[1-9][0-9] 62 | *.eledsec[1-9][0-9]R 63 | *.eledsec[1-9][0-9][0-9] 64 | *.eledsec[1-9][0-9][0-9]R 65 | 66 | # glossaries 67 | *.acn 68 | *.acr 69 | *.glg 70 | *.glo 71 | *.gls 72 | 73 | # gnuplottex 74 | *-gnuplottex-* 75 | 76 | # hyperref 77 | *.brf 78 | 79 | # knitr 80 | *-concordance.tex 81 | *.tikz 82 | *-tikzDictionary 83 | 84 | # listings 85 | *.lol 86 | 87 | # makeidx 88 | *.idx 89 | *.ilg 90 | *.ind 91 | *.ist 92 | 93 | # minitoc 94 | *.maf 95 | *.mtc 96 | *.mtc0 97 | 98 | # minted 99 | _minted* 100 | *.pyg 101 | 102 | # morewrites 103 | *.mw 104 | 105 | # nomencl 106 | *.nlo 107 | 108 | # sagetex 109 | *.sagetex.sage 110 | *.sagetex.py 111 | *.sagetex.scmd 112 | 113 | # sympy 114 | *.sout 115 | *.sympy 116 | sympy-plots-for-*.tex/ 117 | 118 | # todonotes 119 | *.tdo 120 | 121 | # xindy 122 | *.xdy 123 | 124 | # WinEdt 125 | *.bak 126 | *.sav 127 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Unless otherwise specified, files in this project are subject to the 2 | following license. 3 | 4 | Copyright (c) 2015, William J. Bowman 5 | All rights reserved. 6 | 7 | Redistribution and use in source and binary forms, with or without 8 | modification, are permitted provided that the following conditions are 9 | met: 10 | 11 | 1. Redistributions of source code must retain the above copyright 12 | notice, this list of conditions and the following disclaimer. 13 | 14 | 2. Redistributions in binary form must reproduce the above copyright 15 | notice, this list of conditions and the following disclaimer in the 16 | documentation and/or other materials provided with the distribution. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 19 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 20 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 21 | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 22 | HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 23 | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 24 | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 25 | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 26 | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 27 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 28 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 29 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # MTTeX 2 | Welcome to the Meta-Theory LaTeX package. 3 | 4 | This package provides numerous macros and combinators for formatting 5 | meta-theory---particularly multi-language compiler-correctness 6 | meta-theory. I use "combinator" to mean a macro that takes macros as 7 | inputs and defines new macros, or a macro that can be partially applied 8 | to produce a new macro. This README provides sections describing various 9 | aspects of the package. 10 | 11 | Note that this is currently a sort of "kitchen sink" package for me. 12 | The interface is subject to my whims, and eventually I'll reorganize it into a 13 | proper bunch of packages. 14 | 15 | ## Why MTTeX 16 | Partly because it's a La*TeX* package for type-setting *m*eta-*t*heory, and 17 | partly because it's pronounced "Empty TeX". This package started because 18 | the prevailing method for writing papers in my lab was to copy and paste 19 | a file called "defs.tex" and modify it for the new project. I felt the 20 | patterns found in this file could be abstracted, ideally to the point 21 | that "defs.tex" was practically empty. 22 | 23 | ## Table of Contents 24 | 25 | * [Installation](#installation) 26 | * [Required Packages](#required-packages) 27 | * [Options](#options) 28 | * [How to Read](#how-to-read) 29 | * [Automagic Title-case](#automagic-title-case) 30 | * [TODO and Comments](#todo-and-comments) 31 | * [Label References](#label-references) 32 | * [Stack Environments](#stack-environments) 33 | * [Standard Source/Target Macros](#standard-source-target-macros) 34 | * [Meta-Language Macros](#meta-language-macros) 35 | * [Language Symbol Macros](#language-symbol-macros) 36 | * [Language Combinators](#language-combinators) 37 | * [Meta-Theory Combinators](#meta-theory-combinators) 38 | * [Spacing](#spacing) 39 | 40 | ## Installation 41 | You install `mttex` one of two ways: 42 | 1. Per project, as a submodule. This is recommended, as MTTeX is unstable and may change. 43 | From a git repository that could use this project, do 44 | ```bash 45 | > git submodule add https://github.com/wilbowma/mttex 46 | > ln -s mttex/*.sty . 47 | ``` 48 | Then add `\usepackage{mttex}` to your main TeX file. 49 | 2. Per machine, in the local `texmf` for your user. This gives you a single MMTeX installation for all 50 | projects, although you can still override the version using a per project installation. 51 | Assuming `TEXMFHOME=~/texmf`: 52 | ```bash 53 | > mkdir -p ~/texmf/tex/latex 54 | > cd texmf/tex/latex 55 | > git clone https://github.com/wilbowma/mttex 56 | > texhash ~/texmf 57 | ``` 58 | 59 | Eventually, I'll make a CTAN package. 60 | 61 | ## Required Packages 62 | This package includes several packages not available on CTAN, and 63 | requires several that are on CTAN. 64 | 65 | The following packages are required and available on CTAN. Many of these 66 | are included in standard LaTeX installations. 67 | If you want to use different options, require them before requiring `mttex`. 68 | * `pgffor` 69 | * `xcolor` 70 | * `todo` 71 | * `letltxmacro` 72 | * `hyperref` 73 | * `ifthen` 74 | * `latexsym` 75 | * `amsbsy` 76 | * `stmaryrd` (only partially loaded to avoid too many fonts) 77 | * `url` 78 | * `titlecaps` (not loaded when `notitlecaps` specified) 79 | * `mathpartir` 80 | 81 | The following packages are required due to ACM recommendation and 82 | available on CTAN. These are included in standard LaTeX installations. 83 | * `microtype` 84 | * `inputenc` 85 | * `fontenc` 86 | 87 | ## Options 88 | This package defines the following options: 89 | 90 | * `omit` -- This option causes the `\omitthis` macro to discard its 91 | argument, enabling passages to exist in the source that are not 92 | rendered in the output. 93 | * `todo` -- Normally, the `\todo` macro is omitted when the `omit` 94 | option is specified. This option prevents only `\todo` macros from 95 | being omitted. 96 | * `sigplan` -- This option enables ACM/SIGPLAN specific features. Currently does 97 | nothing, since `acmart` handles this now. 98 | * `notitlecaps` -- This option disables automagic title-case in title and section headings. 99 | * `techrpt` -- This option enables features formatting a technical appendix, such as 100 | `\usepackage{fullpage}`. Do not use this option for submissions that are page limited, as it plays 101 | tricks to fit more on one page that are disallowed by many publishers. 102 | * `paper` -- This option disables features for formatting a technical appendix. This 103 | option is on by default. 104 | * `balance` -- This option balances the column on the last page. 105 | * `magicref` -- This option defines `\fullref` and friends, which magically determine which of 106 | `\lemref`, `\thmref`, `\secref`, etc to use. This option requires the `nameref` and `cleveref` 107 | packages. See [Labels and References][] for more info. 108 | * `nocompress` -- Disables PDF compression, making your PDFs larger. Compression 109 | may not work with old versions of `pdflatex`, or non-PDF builds. 110 | 111 | ## How to Read 112 | Each documented macro starts with the name of the macro and an interface 113 | declaring the number of arguments, possibly followed by the default 114 | value for #1. The interface is followed by an explanation of the macro's 115 | purpose and its arguments. 116 | ```latex 117 | \macroname[][default-value] 118 | Has this purpose. 119 | #1 : A description of the first argument. 120 | #2 : And of the second argument. 121 | ``` 122 | 123 | Macros may be undocumented but given with their interface or their 124 | definitions if they merely provide shorthand or match a standard 125 | interface. 126 | 127 | ## Automagic Title-case 128 | This package redefines the following standard macros. These macros match 129 | the interface of their standard counter-parts, with some caveats listed before, but automatically 130 | output the titles in title-case. 131 | ```latex 132 | \title[2][] 133 | \section[2][] 134 | \subsection[2][] 135 | \subsubsection[2][] 136 | ``` 137 | 138 | The original macro are still accessible, though they are @ protected. To 139 | access these, you need to surround their uses with `\makeatletter` and 140 | `\makeatother`. 141 | ```latex 142 | \@title[2][] 143 | \@section[2][] 144 | \@subsection[2][] 145 | \@subsubsection[2][] 146 | ``` 147 | 148 | You can control which words should be left lower-case the macro 149 | `\Addlcwords`. By default, the following words are added: 150 | ```latex 151 | \Addlcwords{for a is but and with of in as the etc on to if} 152 | ``` 153 | 154 | Caveats: 155 | Including math and certain macros inside the title or section name will cause the `titlecaps` package to choke. 156 | To workaround this, use the following pattern: 157 | 158 | ``` 159 | \makeatlatter 160 | \@section{\titlecaps{Title bla bla} $\math$ \titlecaps{More math}} 161 | \makeatother 162 | ``` 163 | 164 | ## TODO and Comments 165 | This package includes the `todo` packages to TODOs. 166 | It also provides the following macro for optionally included comments. 167 | ```latex 168 | \omitthis[1] 169 | Does not render its argument if the omit option is specified. 170 | #1 : A comment to potentially omit. 171 | ``` 172 | ## Label References 173 | This package provides the following macros for referring to sections, 174 | figures, lemmas, and theorems. 175 | ```latex 176 | \secref[1] 177 | Formats a reference to a section. 178 | #1 : The label for the section to reference. 179 | ``` 180 | 181 | ```latex 182 | \figref[1] 183 | Formats a reference to a figure. 184 | #1 : The label for the figure to reference. 185 | ``` 186 | 187 | ```latex 188 | \lemref[1] 189 | Formats a reference to a lemma. 190 | #1 : The label for the lemma to reference. 191 | ``` 192 | 193 | ```latex 194 | \thmref[1] 195 | Formats a reference to a theorem. 196 | #1 : The label for the theorem to reference. 197 | ``` 198 | 199 | If `magicref` is used, it additional defines the following. 200 | ```latex 201 | \nameref[1] 202 | Reprovided from the nameref package. Returns the title given to the referenced object. 203 | #1 : The label to get the title of. 204 | 205 | For example, consider 206 | \begin{lemma}[Foo] \label{lem:foo} \end{lemma} 207 | \begin{lemma} \label{lem:anon} \end{lemma} 208 | 209 | \nameref{lem:foo} produces "Foo". 210 | \nameref{lem:anon} produced "". 211 | \nameref*{lem:foo} produces "Foo", but does not create a hyperlink. 212 | ``` 213 | 214 | ```latex 215 | \fullref[2][ (\nameref*{#1})] 216 | Formats a named reference, such as "Theorem N (Name)", or "Lemma N (Name)". 217 | #1 : The name of the reference. Defaults to the title given to the referenced object. 218 | #2 : The label to reference. 219 | 220 | \fullref{lem:foo} produces "Lemma 1 (Foo)". 221 | \fullref{lem:anon} produces "Lemma 2" 222 | \fullref[Bar]{lem:anon} produces "Lemma 2 (Bar)" 223 | \fullref[]{lem:foo} produces "Lemma 1" 224 | ``` 225 | 226 | ```latex 227 | \fullref*[3][ (\nameref*{#1})] 228 | Like \fullref, but useful when \fullref cannot automatically determine what kind of object is being 229 | referneced. 230 | #1 : The name of the reference. Defaults to the title given to the referenced object. 231 | #2 : A name for the kind of object being referneced. 232 | #3 : The label to reference. 233 | 234 | \fullref*{Lemma}{lem:foo} produces "Lemma 1 (Foo)". 235 | \fullref*{Thing}{lem:foo} produces "Thing 1 (Foo)". 236 | \fullref*[]{Thing}{lem:foo} produces "Thing 1". 237 | ``` 238 | 239 | ## Stack Environments 240 | The stack environments format each line by stacking them atop each 241 | other, similar to the array environment with one column. 242 | 243 | ```latex 244 | \newenvironment{stackCC} 245 | A stack environment that center aligns the column vertically and 246 | horizontially. 247 | ``` 248 | 249 | ```latex 250 | \newenvironment{stackCL} 251 | A stack environment that center aligns the column vertically and left 252 | aligns the column horizontially. 253 | ``` 254 | 255 | ```latex 256 | \newenvironment{stackTL} 257 | A stack environment that top aligns the column vertically and left 258 | aligns the column horizontially. 259 | ``` 260 | 261 | ```latex 262 | \newenvironment{stackTR} 263 | A stack environment that top aligns the column vertically and right 264 | aligns the column horizontially. 265 | ``` 266 | 267 | ```latex 268 | \newenvironment{stackBC} 269 | A stack environment that bottom aligns the column vertically and center 270 | aligns the column horizontially. 271 | ``` 272 | 273 | ```latex 274 | \newenvironment{stackBL} 275 | A stack environment that bottom aligns the column vertically and left 276 | aligns the column horizontially. 277 | ``` 278 | 279 | ### Cases and Subcases 280 | This package provides cases and subcases for use in itemize environments. 281 | This helps format nested proofs. 282 | ```latex 283 | \newcommand{\case}[1][] 284 | \newcommand{\scase}[1][] 285 | \newcommand{\sscase}[1][] 286 | ``` 287 | 288 | ## Standard Source/Target Macros 289 | This package provides a few standard formatting macros for source/target 290 | languages. They assume the source should be in a blue, sans-serif font, 291 | while the target should be in a bold, red, serif font. 292 | ```latex 293 | \newcommand{\scolor}[1]{\textcolor{blue}{#1}} 294 | \newcommand{\tcolor}[1]{\textcolor{red}{#1}} 295 | 296 | \newcommand{\sfonttext}[1]{\textsf{\scolor{#1}}} 297 | \newcommand{\tfonttext}[1]{\textsf{\tcolor{#1}}} 298 | 299 | \newcommand{\sfont}[1]{\mathsf{\scolor{#1}}} 300 | \newcommand{\tfont}[1]{\mathbf{\tcolor{#1}}} 301 | 302 | \newcommand{\sfontsym}[1]{\sfont{#1}} 303 | \newcommand{\tfontsym}[1]{\b{\tfont{#1}}} 304 | 305 | \newcommand{\scal}[1]{\sfontsym{\mathcal{#1}}} 306 | \newcommand{\tcal}[1]{\tfontsym{\mathcal{#1}}} 307 | 308 | \newcommand{\sprime}{\scolor{\prime}} 309 | \newcommand{\tprime}{\tcolor{\prime}} 310 | ``` 311 | 312 | ## Meta-Language Macros 313 | ```latex 314 | \newcommand{\metafont}[1]{\mathrm{#1}} 315 | \newcommand{\dom}[1]{\metafont{dom}(#1)} 316 | \newcommand{\cod}[1]{\metafont{cod}(#1)} 317 | \newcommand{\rng}[1]{\metafont{rng}(#1)} 318 | \newcommand{\FV}{\metafont{fv}} 319 | \newcommand{\FTV}{\metafont{ftv}} 320 | \newcommand{\subst}[3]{{#1}[{#2}/{#3}]} 321 | \newcommand{\defeq}{\stackrel{\metafont{def}}{=}} 322 | \newcommand{\finmap}{\stackrel{\metafont{fin}}{\rightarrow}} 323 | \renewcommand{\iff}{\metafont{iff}} 324 | \newcommand{\lsem}{\left\llbracket} 325 | \newcommand{\rsem}{\right\rrbracket} 326 | \newcommand{\sembrace}[1]{\lsem{#1}\rsem} 327 | \newcommand{\powset}[1]{\mathscr{P}(#1)} 328 | \newcommand{\irred}[1]{\metafont{irred}(#1)} 329 | \renewcommand{\max}[2]{\metafont{max}(#1,#2)} 330 | \newcommand{\free}[2]{\metafont{free}(#1,#2)} 331 | \newcommand{\running}[2]{\metafont{running}({#1},{#2})} 332 | \newcommand{\pair}[2]{( #1, #2 )} 333 | \newcommand{\triple}[3]{( #1, #2, #3 )} 334 | 335 | \newcommand{\satisfy}{\vDash} 336 | 337 | \newcommand{\plus}{+} 338 | \newcommand{\etal}{\textit{et al.}} 339 | \newcommand{\ie}{\emph{i.e.}} 340 | \newcommand{\eg}{\emph{e.g.}} 341 | \newcommand{\etc}{\emph{etc.}} 342 | \newcommand{\bump}{\hspace{3.5pt}} 343 | \newcommand{\fresh}[1]{(\mit{fresh}\:#1)} 344 | \newcommand{\where}[1]{\mrm{where}\:#1} 345 | 346 | \newcommand{\lang}[1]{\mrm{\trm{#1}}} 347 | ``` 348 | 349 | ## Language Symbol Macros 350 | ```latex 351 | \newcommand{\emptyenv}{\cdot} 352 | \newcommand{\emptyctx}{[\cdot]} 353 | \newcommand{\hole}{\emptyctx} 354 | \newcommand{\hw}[1]{\lbrack{#1}\rbrack} 355 | \newcommand{\ectx}{E} 356 | \newcommand{\ctx}{C} 357 | 358 | \newcommand{\hooklongrightarrow}{\lhook\joinrel\longrightarrow} 359 | \newcommand{\redexstep}{\hookrightarrow} 360 | \newcommand{\redexstepinv}{\hookleftarrow} 361 | 362 | \newcommand{\step}{\longmapsto} 363 | \newcommand{\stepin}[1]{\step^{#1}} 364 | \newcommand{\stepstar}{\stepin{*}} 365 | 366 | \newcommand{\red}{\Downarrow} 367 | \newcommand{\diverg}[1]{#1 \Uparrow} 368 | 369 | \newcommand{\termin}[1]{#1\red} 370 | \newcommand{\terminw}[2]{\termin{#1} #2} 371 | 372 | \newcommand{\transarrow}{\leadsto} 373 | \newcommand{\backtransarrow}{\twoheadrightarrow} 374 | 375 | \newcommand{\funarrow}{\rightarrow} 376 | \newcommand{\ctxarrow}{\Rightarrow} 377 | 378 | \newcommand{\bnflabel}[1]{\mbox{\textit{#1}}} 379 | \newcommand{\bnfalt}{{\bf \,\,\mid\,\,}} 380 | \newcommand{\bnfdef}{{\bf ::=}} 381 | \newcommand{\bnfadd}{{\bf +::=}} 382 | \newcommand{\bnfsub}{{\bf -::=}} 383 | ``` 384 | 385 | ## Language Combinators 386 | This package provides various combinators for generating macros that 387 | format multi-language meta-theory. 388 | All macros generated by this package automatically ensure they are in math mode, 389 | using `\inlinemath` (`\im` for short), which uses `\ensuremath`. 390 | The `\inlinemath` macro is meant to be re-defined when one wants to smallify math. 391 | 392 | ### Language Combinator TOC 393 | * [Generating a Language](#generating-a-language) 394 | * [Meta-Variables](#meta-variables) 395 | * [List-of-Meta-Variables Combinators](#list-of-meta-variables-combinators) 396 | * [Formatting Types and Expressions](#formatting-types-and-expressions) 397 | * [Declaring new type and expression combinators](#declaring-new-type-and-expression-combinators) 398 | * [List-of-Types Combinator](#list-of-types-combinator) 399 | * [List-of-Expressions Combinator](#list-of-expressions-combinator) 400 | * [Detailed Type Combinator Documentation](#detailed-type-combinator-documentation) 401 | * [Detailed Expression Combinator Documentation](#detailed-expression-combinator-documentation) 402 | 403 | ### Generating a Language 404 | This package provides a single combinator for generating all the macros 405 | for type-setting meta-variables, types, and expressions. While this is 406 | probably the macro you want to use, you will need to understand the 407 | macros it composes to understand the macros it generates. They are 408 | explained below. 409 | ```latex 410 | \newlanguage[8] 411 | Generates macros for formatting meta-variables, types, and expressions 412 | of a language. 413 | 414 | #1 : A formatting macro for super-scripts, sub-scripts, and primes in 415 | this language, such as \tcolor 416 | #2 : A formatting macro for math text in this language, such as \tfont 417 | #3 : A formatting macro for symbols in this language, such as 418 | \tfontsym 419 | #4 : A language prefix for the macros, such as t 420 | #5 : A list of meta-variables for which to generate macros via 421 | \newmetavars, such as {x, e, v} 422 | #6 : A list of meta-variables for which to generate macros via 423 | \newmetavarsS, such as {ty/\tau,alpha\alpha} 424 | #7 : A list of types for which to generate macros via \newtypes, such 425 | as {fun, forall, exist, pair, bool, unit} 426 | #8 : A list of expressions for which to generate macros via 427 | \newexprs, such as {fun, app, if, true, false, unit} 428 | 429 | Usage: 430 | \newlanguage{\scolor}{\sfont}{\sfontsym}{s} 431 | {x,e,v} 432 | {alpha/\alpha,ty/\sigma} 433 | {fun,bool} 434 | {fun,app,if,true,false} 435 | ``` 436 | 437 | ### Meta-Variables 438 | Writing all the macros to properly format language meta-variables is 439 | obnoxious. So this package provides combinators for meta-variables. 440 | ```latex 441 | \newmetavar[3] 442 | Implements the * LaTeX idiom after currying. It expands in to either 443 | \newmetavarStar{#1}{#2}{#3} or \newmetavarNoStar{#1}{#2}{#3} depending 444 | on whether the character following its 3rd argument is a * or not. 445 | #1 : A formatting macro for the meta-var, such a \tfont 446 | #2 : A formatting macro for the subscripts, superscripts, and primes, 447 | such as \tcolor 448 | #3 : A string prefix for the name of the macro, such as t 449 | 450 | Usage: 451 | \newcommand{\newtmetavar}{\newmetavar{\tfont}{\tcolor}{t}} 452 | \newtmetavar{x} 453 | \newtmetavar*{ty}{\tau} 454 | ``` 455 | 456 | ```latex 457 | \newmetavarStar[5] 458 | Generates some standard macros for formatting a meta-variable. 459 | #1 : A formatting macro for the meta-var, such a \tfont 460 | #2 : A formatting macro for the subscripts, superscripts, and primes, 461 | such as \tcolor 462 | #3 : A string prefix for the name of the macro, such as t 463 | #4 : A string name of the macro, such as ty 464 | #5 : A string to format and display this meta-variable as, such as 465 | \tau 466 | 467 | Usage: 468 | \newmetavarStar{\tfont}{\tcolor}{t}{ty}{\tau} 469 | 470 | This usage generates the following definitions: 471 | 472 | \newcommand{\ttymetavar}[3]{ 473 | \metavar{\tfont{\tau}}{\tcolor{#1}}{\tcolor{#2}}{\tcolor{\prime}}{#3} 474 | } 475 | 476 | \newcommand{\tty}{ \ttymetavar{}{}{} } 477 | \newcommand{\ttyin}[1]{ \ttymetavar{#1}{}{0} } 478 | \newcommand{\ttyto}[1]{ \ttymetavar{}{#1}{0} } 479 | \newcommand{\ttypr}[1][1]{ \ttymetavar{}{}{#1} } 480 | \newcommand{\ttyone}{ \ttymetavar{1}{}{} } 481 | \newcommand{\ttyonepr}[1][1]{ \ttymetavar{1}{}{#1}} 482 | \newcommand{\ttytwo}{ \ttymetavar{2}{}{} } 483 | \newcommand{\ttytwopr}{ \ttymetavar{2}{}{1} } 484 | \newcommand{\ttythree}{ \ttymetavar{3}{}{} } 485 | \newcommand{\ttythreepr}{ \ttymetavar{3}{}{1} } 486 | \newcommand{\ttyi}{ \ttymetavar{i}{}{} } 487 | \newcommand{\ttyipr}[1][1]{ \ttymetavar{i}{}{#1} } 488 | \newcommand{\ttyn}{ \ttymetavar{n}{}{} } 489 | \newcommand{\ttynpr}[1][1]{ \ttymetavar{n}{}{#1} } 490 | 491 | \ttymetavar takes an unformatted sub-script, super-script, and 492 | a natural number n indicating the number of primes. It then formats 493 | the sub-script, the super-script, and n primes and attaches them to 494 | the formatted meta-variable. 495 | ``` 496 | 497 | ```latex 498 | \newmetavarNoStar[4] 499 | Like \netmetavarStar, but assumes the name of the macro is also the 500 | display symbol. 501 | #1 : A formatting macro for the meta-var, such a \tfont 502 | #2 : A formatting macro for the subscripts, superscripts, and primes, 503 | such as \tcolor 504 | #3 : A string prefix for the name of the macro, such as t 505 | #4 : A string name of the macro and symbol to format and display, such 506 | as x 507 | 508 | Usage: 509 | \newmetavarNoStar{\tfont}{\tcolor}{t}{x} 510 | 511 | This usage is equivalent to 512 | \newmetavarStar{\tfont}{\tcolor}{t}{x}{x} 513 | ``` 514 | 515 | ```latex 516 | \metavar[5] 517 | Formats a language meta-var. 518 | #1 : a pre-formatted symbol representing the meta-variable 519 | #2 : a pre-formatted subscript 520 | #3 : a pre-formatted superscript 521 | #4 : a pre-formatted prime symbol 522 | #5 : a natural number, representing the number of primes 523 | 524 | Usage: 525 | \newcommand{\txmetavar}[3]{ 526 | \metavar{\tfont{x}}{\tcolor{#1}}{\tcolor{#2}}{\tprime}{#3} 527 | } 528 | \newcommand{\tx}{\txmetavar{}{}{}} 529 | \newcommand{\txone}{\txmetavar{1}{}{}} 530 | \newcommand{\txonepr}{\txmetavar{1}{}{1}} 531 | ``` 532 | 533 | ```latex 534 | \metavarto[2] 535 | Formats a language meta-var with only a superscript. 536 | #1 : a pre-formatted symbol representing the meta-var 537 | #2 : a pre-formatted superscript 538 | 539 | Usage: 540 | \newcommand{\txF}{\metavarto{\tx}{f}} 541 | ``` 542 | 543 | ```latex 544 | \metavarin[2] 545 | Formats a language meta-var with only a subscript. 546 | #1 : a pre-formatted symbol representing the meta-var 547 | #2 : a pre-formatted subscript 548 | 549 | Usage: 550 | \newcommand{\txone}{\metavarin{\tx}{\tcolor{1}}} 551 | ``` 552 | 553 | ```latex 554 | \metavarpr[3] 555 | Formats a language meta-var with only primes, takes 3 parameters: 556 | #1 : a pre-formatted symbol representing the meta-var 557 | #2 : a pre-formatted prime symbol 558 | #3 : a natural number representing the number of primes 559 | 560 | Usage: 561 | \newcommand{\txpr}{\metavarpr{\tx}{\prime}{1}} 562 | \newcommand{\txdubpr}{\metavarpr{\tx}{\prime}{2}} 563 | ``` 564 | 565 | ### List-of-Meta-Variables Combinators 566 | Generating meta-variables one at a time is annoying, so this package 567 | provides combinators for lists of meta-variables. 568 | 569 | ```latex 570 | \newmetavars[4] 571 | Defines new metavar macros for a list of names, assuming each metavar 572 | will be displayed via the symbol it is named. Essentially, it calls 573 | \newmetavar for each name in its 4th parameter. 574 | #1 : A formatting macro for the meta-var, such a \tfont 575 | #2 : A formatting macro for the subscripts, superscripts, and primes, 576 | such as \tcolor 577 | #3 : A string prefix for the name of the macro, such as t 578 | #4 : A list of names. 579 | 580 | Usage: 581 | \newmetavars{\tfont}{\tcolor}{t}{x,e,v} 582 | \newcommand{\newsmetavars}{\newmetavars{\sfont}{\scolor}{s}} 583 | \newsmetavars{x,e,v} 584 | ``` 585 | 586 | ```latex 587 | \newmetavarsS[4] 588 | Defines new metavar macros for a list of name/symbol pairs. Essentially, 589 | it calls \newmetavar* for each name/symbol pair in its 4th parameter. 590 | #1 : A formatting macro for the meta-var, such a \tfont 591 | #2 : A formatting macro for the subscripts, superscripts, and primes, 592 | such as \tcolor 593 | #3 : A string prefix for the name of the macro, such as t 594 | #4 : A list of name/symbol pairs, separated literally by a /. 595 | 596 | Usage: 597 | \newmetavarsS{\tfont}{\tcolor}{t}{x/x,e/e,v/v,alpha/\b{\alpha}} 598 | \newcommand{\newsmetavarsS}{\newmetavarsS{\sfontsym}{\scolor}{s}} 599 | \newsmetavarsS{\alpha/\alpha, ty/\sigma} 600 | ``` 601 | 602 | ### Formatting Types and Expressions 603 | This package provides combinators for formatting lambda calculus types 604 | and expressions. 605 | 606 | Each combinator starts with a tag and ends with a suffix followed. 607 | The suffix for type combinators is `ty` and the suffix for expression 608 | combinators is `e`. For instance, the function type combinator is 609 | `\funty` and the function expression combinator is `\fune`. 610 | 611 | Each combinator takes a formatting macro for symbols, such as 612 | `\tfontsym`, as its first argument, and a formatting macro for text, 613 | such as `\tfont`, as its second argument. The rest of the arguments 614 | are the sub-types or sub-expressions required for the type or 615 | expression. While the arguments are fairly standard and in an intuitive 616 | order, they are documented in detail below. 617 | 618 | The package provides the following the following types and expressions. 619 | The tag which starts each element of the list indicates the prefix of of 620 | the combinator. 621 | 622 | * fun: function types and function expressions 623 | * app: application expressions 624 | * polyfun: polymorphic function types and polymorphic functions 625 | * papp: polymorphic application expressions 626 | * forall: universal types and abstraction expressions 627 | * inst: instantiation expressions 628 | * exist: existential types 629 | * pi: pi types (dependent function types) 630 | * sigma: sigma types (dependent pair types) 631 | * pack: pack expressions 632 | * unpack: unpack expressions 633 | * mu: isorecursive types 634 | * fold: fold expression 635 | * unfold: unfold expressions 636 | * fix: fix-point expressions 637 | * unit: the unit type, and the unit expression 638 | * void: the void type 639 | * bool: boolean types 640 | * set: the type Set 641 | * prop: the type Prop 642 | * type: the type of types, Type 643 | * true: true expressions 644 | * false: false expressions 645 | * if: if expressions 646 | * pair: pair types and pair expressions 647 | * prj: projection from a pair 648 | * sum: sum types and sum expressions (injections) 649 | * case: case expressions 650 | * dcase: dependent case expressions. 651 | * let: let expressions 652 | * alet: let expressions with type annotations on the bound expression 653 | 654 | ### Declaring New Type and Expression Combinators 655 | Declaring new types and expressions to be used with `\newlanguage` is easy via 656 | the `\newtype` and `\newexpr` combinators, which generate definitions that 657 | `\newlanguage` understands. 658 | 659 | ```latex 660 | \newtype[3] 661 | Generates a type combinator (i.e., a combinator with the suffix `ty`) named \ty 662 | that cooperates with \newlanguage to format the defined type. 663 | Also define `\@ty`, which expects \langfont and \langsymfont to be defined. 664 | Defines \langfont and \langsymfont in the scope of the type definition. 665 | #1 : The type tag, such as `fun`. 666 | #2 : The number of pre-formatted parameters that the type combinator expects in its definition. 667 | #3 : The definition that formats the type. 668 | 669 | Usage: 670 | \newtype{fun}{2}{#1 \langsymfont{\to} #2} 671 | 672 | Defines \funty[4], which expects a font for formatting language symbols as #1, and a font 673 | for formatting language text in #2. 674 | Also define \@funty[2], which expects the arguments used in the definition for formatting this type. 675 | 676 | Useage: 677 | \newtype{bool}{0}{\langfont{bool}} 678 | Define \boolty[2] and \@boolty[0] 679 | ``` 680 | 681 | ```latex 682 | \newexpr[3] 683 | Generates a expr combinator (i.e., a combinator with the suffix `e`) named \e 684 | that cooperates with \newlanguage to format the defined expr. 685 | Also define `\@e`, which expects \langfont and \langsymfont to be defined. 686 | Defines \langfont and \langsymfont in the scope of the type definition. 687 | #1 : The expr tag, such as `true`. 688 | #2 : The number of pre-formatted parameters that the expr combinator expects in its definition. 689 | #3 : The definition that formats the expr. 690 | 691 | Usage: 692 | \newexpr{fun}{3}{\langsymfont{\lambda}\,#1\mathbin{:}#2. #3} 693 | 694 | Defines \fune[5], which expects a font for formatting language symbols as #1, and a font 695 | for formatting language text in #2. 696 | Also define \@fune[3], which expects the arguments used in the definition for formatting this expr. 697 | 698 | Useage: 699 | \newexpr{true}{0}{\langfont{true}} 700 | Define \truee[2] and \@truee[0] 701 | ``` 702 | 703 | ### List-of-Types Combinator 704 | Generating type macros one at a time is annoying, so this package 705 | provides combinators for lists of types. The macros are generated 706 | attaching a prefix and suffix to the tag, followed by ty. For instance, 707 | the macro generate for `fun` when using the prefix `s` and suffix `ty` 708 | is `\sfunty`. 709 | ```latex 710 | \newtypes[5] 711 | Generates type formatting macros given a list of tags. 712 | #1 : A formatting macro for symbols, such as \tfontsym 713 | #2 : A formatting macro for text, such as \tfont 714 | #3 : A prefix for the name of each macro, such as t 715 | #4 : A suffix for the name of each macro, such as ty 716 | #5 : A list of type tags, such as {fun,bool,void,unit} 717 | ``` 718 | 719 | ### List-of-Expressions Combinator 720 | Generating expression macros one at a time is annoying, so this package 721 | provides combinators for lists of expressions. The macros are generated 722 | attaching a prefix and suffice to the tag. For instance, the macro 723 | generate for `fun` when using the prefix `s` and suffix `e` is `\sfune`. 724 | ```latex 725 | \newexprs[5] 726 | Generates type formatting macros given a list of tags. 727 | #1 : A formatting macro for symbols, such as \sfontsym 728 | #2 : A formatting macro for text, such as \sfont 729 | #3 : A prefix for the name of each macro, such as s 730 | #4 : A suffix for the name of each macro, such as e 731 | #5 : A list of type tags, such as {fun,bool,void,unit} 732 | ``` 733 | 734 | #### Detailed Type Combinator Documentation 735 | ```latex 736 | \funty[4] 737 | Formats a function type. 738 | #1 : A formatting macro for symbols, such as \tfontsym 739 | #2 : A formatting macro for text, such as \tfont 740 | #3 : The pre-formatted argument to the function 741 | #4 : The pre-formatted result of the function 742 | ``` 743 | 744 | ```latex 745 | \polyfunty[5] 746 | Formats a polymorphic function type. 747 | #1 : A formatting macro for symbols, such as \tfontsym 748 | #2 : A formatting macro for text, such as \tfont 749 | #3 : The pre-formatted type-variable to bind 750 | #4 : The pre-formatted argument to the function 751 | #5 : The pre-formatted result of the function 752 | ``` 753 | 754 | ```latex 755 | \forallty[4] 756 | Formats a polymorphic type. 757 | #1 : A formatting macro for symbols, such as \tfontsym 758 | #2 : A formatting macro for text, such as \tfont 759 | #3 : The pre-formatted type-variable to bind 760 | #4 : The pre-formatted result in which the type-variable is bound 761 | ``` 762 | 763 | ```latex 764 | \existty[4] 765 | Formats an existential type. 766 | #1 : A formatting macro for symbols, such as \tfontsym 767 | #2 : A formatting macro for text, such as \tfont 768 | #3 : The pre-formatted type-variable to bind 769 | #4 : The pre-formatted result in which the type-variable is bound 770 | ``` 771 | 772 | ```latex 773 | \muty[4] 774 | Formats a recursive type. 775 | #1 : A formatting macro for symbols, such as \tfontsym 776 | #2 : A formatting macro for text, such as \tfont 777 | #3 : The pre-formatted type-variable to bind 778 | #4 : The pre-formatted result in which the type-variable is bound 779 | ``` 780 | 781 | ```latex 782 | \unitty[2] 783 | Formats a unit type. 784 | #1 : A formatting macro for symbols, such as \tfontsym 785 | #2 : A formatting macro for text, such as \tfont 786 | ``` 787 | 788 | ```latex 789 | \pity[4] 790 | Formats a dependent function type. 791 | #1 : A formatting macro for symbols, such as \tfontsym 792 | #2 : The pre-formatted variable to bind 793 | #3 : The pre-formatted argument type 794 | #4 : The pre-formatted result type 795 | ``` 796 | 797 | ```latex 798 | \sigmaty[5] 799 | Formats a dependent pair type. 800 | #1 : A formatting macro for symbols, such as \tfontsym. 801 | #2 : A formatting macro for text, such as \tfont. 802 | #3 : The pre-formatted variable the function binds. 803 | #4 : The pre-formatted type of the variable. 804 | #5 : The pre-formatted body of the function. 805 | ``` 806 | 807 | ```latex 808 | \voidty[2] 809 | Formats a void type. 810 | #1 : A formatting macro for symbols, such as \tfontsym 811 | #2 : A formatting macro for text, such as \tfont 812 | ``` 813 | 814 | ```latex 815 | \boolty[2] 816 | Formats a bool type. 817 | #1 : A formatting macro for symbols, such as \tfontsym 818 | #2 : A formatting macro for text, such as \tfont 819 | ``` 820 | 821 | ```latex 822 | \typety[3][i] 823 | Formats a type of types, or universe (Type) 824 | 825 | #1 : A formatting macros for symbols, such as \tfontsym 826 | #2 : A formatting macros for text, such as \tfont. 827 | #3 : A pre-formatted universe level, which defaults to i. 828 | ``` 829 | 830 | ```latex 831 | \propty[2] 832 | Formats the type Prop, as in CIC's impredicative universe Prop. 833 | 834 | #1 : A formatting macros for symbols, such as \tfontsym 835 | #2 : A formatting macros for text, such as \tfont. 836 | ``` 837 | 838 | ```latex 839 | \setty[2] 840 | Formats the type Set, as in CIC's predicative universe Set. 841 | 842 | #1 : A formatting macros for symbols, such as \tfontsym 843 | #2 : A formatting macros for text, such as \tfont. 844 | ``` 845 | 846 | ```latex 847 | \pairty[4] 848 | Formats a pair type. 849 | #1 : A formatting macro for symbols, such as \tfontsym 850 | #2 : A formatting macro for text, such as \tfont 851 | #3 : The pre-formatted type for the first component of the pair 852 | #4 : The pre-formatted type for the second component of the pair 853 | ``` 854 | 855 | ```latex 856 | \sumty[4] 857 | Formats a sum type. 858 | #1 : A formatting macro for symbols, such as \tfontsym 859 | #2 : A formatting macro for text, such as \tfont 860 | #3 : The pre-formatted type for the first component of the sum 861 | #4 : The pre-formatted type for the second component of the sum 862 | ``` 863 | 864 | #### Detailed Expression Combinator Documentation 865 | ```latex 866 | \fune[5] 867 | Formats a function expression. 868 | #1 : A formatting macro for symbols, such as \tfontsym. 869 | #2 : A formatting macro for text, such as \tfont. 870 | #3 : The pre-formatted variable the function binds. 871 | #4 : The pre-formatted type of the variable. 872 | #5 : The pre-formatted body of the function. 873 | ``` 874 | 875 | ```latex 876 | \polyfune[6] 877 | Formats a polymorphic function expression. 878 | #1 : A formatting macro for symbols, such as \tfontsym. 879 | #2 : A formatting macro for text, such as \tfont. 880 | #3 : The pre-formatted type variable the function binds. 881 | #4 : The pre-formatted variable the function binds. 882 | #5 : The pre-formatted type of the variable. 883 | #6 : The pre-formatted body of the function. 884 | ``` 885 | 886 | ```latex 887 | \abstre[4] 888 | Formats an polymorphic abstraction expression. 889 | #1 : A formatting macro for symbols, such as \tfontsym. 890 | #2 : A formatting macro for text, such as \tfont. 891 | #3 : The pre-formatted type variable the abstraction binds. 892 | #4 : The pre-formatted the body of the abstract. 893 | ``` 894 | 895 | ```latex 896 | \inste[4] 897 | Formats an instantiation expression. 898 | #1 : A formatting macro for symbols, such as \tfontsym. 899 | #2 : A formatting macro for text, such as \tfont. 900 | #3 : The pre-formatted polymorphic abstraction to instantiate. 901 | #4 : The pre-formatted type with which to instantiate the abstraction. 902 | ``` 903 | 904 | ```latex 905 | \appe[4] 906 | Formats an application expression. 907 | #1 : A formatting macro for symbols, such as \tfontsym. 908 | #2 : A formatting macro for text, such as \tfont. 909 | #3 : The pre-formatted function. 910 | #4 : The pre-formatted argument. 911 | ``` 912 | 913 | ```latex 914 | \pappe[5] 915 | Formats a polymorphic function application expression. 916 | #1 : A formatting macro for symbols, such as \tfontsym. 917 | #2 : A formatting macro for text, such as \tfont. 918 | #3 : A pre-formatted polymorphic function expression. 919 | #4 : A pre-formatted type with which to instantiate. 920 | #5 : A pre-formatted argument to the function. 921 | ``` 922 | 923 | ```latex 924 | \ife[5] 925 | Formats an if expression 926 | #1 : A formatting macro for symbols, such as \tfontsym. 927 | #2 : A formatting macro for text, such as \tfont. 928 | #3 : A pre-formatted discriminant expression. 929 | #4 : A pre-formatted consequent expression. 930 | #5 : A pre-formatted alternate expression. 931 | ``` 932 | 933 | ```latex 934 | \packe[5] 935 | Formats a pack expression 936 | #1 : A formatting macro for symbols, such as \tfontsym. 937 | #2 : A formatting macro for text, such as \tfont. 938 | #3 : A pre-formatted type witness. 939 | #4 : A pre-formatted value witness. 940 | #5 : A pre-formatted existential type abstracting the witness type. 941 | ``` 942 | 943 | ```latex 944 | \unpacke[6] 945 | Formats an unpack expression 946 | #1 : A formatting macro for symbols, such as \tfontsym. 947 | #2 : A formatting macro for text, such as \tfont. 948 | #3 : A pre-formatted type variable. 949 | #4 : A pre-formatted expression variable. 950 | #5 : A pre-formatted existential witness expression. 951 | #6 : A pre-formatted expression in which to bind the existential. 952 | ``` 953 | 954 | ```latex 955 | \lete[5] 956 | Formats a let expression 957 | #1 : A formatting macro for symbols, such as \tfontsym. 958 | #2 : A formatting macro for text, such as \tfont. 959 | #3 : A pre-formatted expression variable. 960 | #4 : A pre-formatted expression to bind. 961 | #5 : A pre-formatted body expression for the let. 962 | ``` 963 | 964 | ```latex 965 | \alete[6] 966 | Formats a let expression with an annotation on the bound expression. 967 | #1 : A formatting macro for symbols, such as \tfontsym. 968 | #2 : A formatting macro for text, such as \tfont. 969 | #3 : A pre-formatted expression variable. 970 | #4 : A pre-formatted expression to bind. 971 | #5 : A pre-formatted annotation for bound expression. 972 | #6 : A pre-formatted body expression for the let. 973 | ``` 974 | 975 | ```latex 976 | \folde[4] 977 | Formats a fold expression. 978 | #1 : A formatting macro for symbols, such as \tfontsym. 979 | #2 : A formatting macro for text, such as \tfont. 980 | #3 : A pre-formatted mu type. 981 | #4 : A pre-formatted expression of isorecursive type. 982 | ``` 983 | 984 | ```latex 985 | \unfolde[3] 986 | Formats an unfold expression 987 | #1 : A formatting macro for symbols, such as \tfontsym. 988 | #2 : A formatting macro for text, such as \tfont. 989 | #3 : A pre-formatted expression of isorecursive type. 990 | ``` 991 | 992 | ```latex 993 | \fixe[5] 994 | Formats a recursive function expression. 995 | #1 : A formatting macro for symbols, such as \tfontsym. 996 | #2 : A formatting macro for text, such as \tfont. 997 | #3 : The pre-formatted variable the function binds. 998 | #4 : The pre-formatted type of the variable. 999 | #5 : The pre-formatted body of the function. 1000 | ``` 1001 | 1002 | ```latex 1003 | \unite[2] 1004 | Formats a unit expression. 1005 | #1 : A formatting macro for symbols, such as \tfontsym. 1006 | #2 : A formatting macro for text, such as \tfont. 1007 | ``` 1008 | 1009 | ```latex 1010 | \truee[2] 1011 | Formats a true expression 1012 | #1 : A formatting macro for symbols, such as \tfontsym. 1013 | #2 : A formatting macro for text, such as \tfont. 1014 | ``` 1015 | 1016 | ```latex 1017 | \falsee[2] 1018 | Formats a false expression 1019 | #1 : A formatting macro for symbols, such as \tfontsym. 1020 | #2 : A formatting macro for text, such as \tfont. 1021 | ``` 1022 | 1023 | ```latex 1024 | \paire[4] 1025 | Formats a pair expression. 1026 | #1 : A formatting macro for symbols, such as \tfontsym. 1027 | #2 : A formatting macro for text, such as \tfont. 1028 | #3 : A pre-formatted expression for the first component of the pair. 1029 | #4 : A pre-formatted expression for the second component of the pair. 1030 | ``` 1031 | 1032 | ```latex 1033 | \prje[4] 1034 | Formats a projection expression. 1035 | #1 : A formatting macro for symbols, such as \tfontsym. 1036 | #2 : A formatting macro for text, such as \tfont. 1037 | #3 : An unformatted natural number, either 1 or 2, indicating which 1038 | component of the pair to project. 1039 | #4 : A pre-formatted pair expression to project. 1040 | ``` 1041 | 1042 | ```latex 1043 | \sume[4] 1044 | Formats a sum expression. 1045 | #1 : A formatting macro for symbols, such as \tfontsym. 1046 | #2 : A formatting macro for text, such as \tfont. 1047 | #3 : An unformatted natural number, either 1 or 2, indicating into which 1048 | side of the sum to inject the expression. 1 indicates left, 2 1049 | #4 : A pre-formatted expression to inject into a sum. 1050 | ``` 1051 | 1052 | ```latex 1053 | \casee[7] 1054 | Formats a case expression. 1055 | #1 : A formatting macro for symbols, such as \tfontsym. 1056 | #2 : A formatting macro for text, such as \tfont. 1057 | #3 : A pre-formatted discriminant expression. 1058 | #4 : A pre-formatted variable to bind in the left branch. 1059 | #5 : A pre-formatted expression for the left branch. 1060 | #6 : A pre-formatted variable to bind in the right branch. 1061 | #7 : A pre-formatted expression for the right branch. 1062 | ``` 1063 | 1064 | ```latex 1065 | \dcasee[5] formats a dependent case analysis expression, like that of CIC's. 1066 | #1 : A formatting macro for symbols, such as \tfontsym. 1067 | #2 : A formatting macro for text, such as \tfont. 1068 | #3 : A pre-formatted discriminant expression. 1069 | #4 : A pre-formatted motive 1070 | #5 : A pre-formatted list of branch expressions. 1071 | ``` 1072 | 1073 | ## Meta-Theory Combinators 1074 | This package provides combinators for formatting meta-theory, including 1075 | well-formedness and typing judgments, contextual equivalence, context 1076 | typing, and logical relations. 1077 | 1078 | ### Meta-Theory Combinator TOC 1079 | * [Judgments](#judgments) 1080 | * [Context Typing](#context-typing) 1081 | * [Contextual Equivalence](#contextual-equivalence) 1082 | * [Logical Relations](#logical-relations) 1083 | 1084 | ### Judgments 1085 | ```latex 1086 | \wf[2] 1087 | Formats a well-formedness judgment. 1088 | #1 : Pre-formatted assumptions, such as \tfont{\Delta} 1089 | #2 : The pre-formatted proposition, such as \tfont{\alpha} 1090 | 1091 | Usage: 1092 | \wf{\Delta}{\alpha} 1093 | 1094 | Renders like: 1095 | Δ ⊢ α 1096 | ``` 1097 | 1098 | ```latex 1099 | \judg[3] 1100 | Formats a well-typedness judgment. 1101 | #1 : The assumptions, such as \tfont{\Delta};\tfont{\Gamma} 1102 | #2 : The term, such as \tfont{e} 1103 | #3 : The type, such as \tfont{\tau} 1104 | 1105 | Usage: 1106 | \judg{\Delta;\Gamma}{e}{\tau} 1107 | 1108 | Renders like: 1109 | Δ;Γ ⊢ e : τ 1110 | ``` 1111 | 1112 | ### Context Typing 1113 | ```latex 1114 | \ctxarrowty[3] 1115 | Formats a context typing arrow 1116 | #1 : A formatting macro for symbols, such as \stfontsym 1117 | #2 : The type of the hole 1118 | #3 : The type of the result 1119 | ``` 1120 | 1121 | ```latex 1122 | \ctxty[5] 1123 | Formats a context type, with different typing contexts for the hole and 1124 | result 1125 | #1 : A formatting macro for symbols, such as \stfontsym 1126 | #2 : The typing contexts for the hole 1127 | #3 : The type of the hole 1128 | #4 : The typing contexts for the result 1129 | #5 : The type of the result 1130 | ``` 1131 | 1132 | ```latex 1133 | \ctxtyjudg[6] 1134 | Formats a context typing judgment. 1135 | #1 : A formatting macro for symbols, such as \stfontsym 1136 | #2 : A pre-formatted context 1137 | #3 : The typing contexts for the hole 1138 | #4 : The type of the hole 1139 | #5 : The typing contexts for the result 1140 | #6 : The type of the result 1141 | ``` 1142 | 1143 | ### Contextual Equivalence 1144 | ```latex 1145 | \ciueqvjudg[4] 1146 | Formats a c.i.u. equivalence judgment. 1147 | #1 : Pre-formatted typing contexts, such as 1148 | \tfont{\Delta};\tfont{\Gamma} 1149 | #2 : A pre-formatted expression 1150 | #3 : A pre-formatted c.i.u. equivalent expression 1151 | #4 : A pre-formatted type for the expressions 1152 | ``` 1153 | 1154 | ```latex 1155 | \ctxeqvjudg[4] 1156 | Formats a contextual equivalence judgment. 1157 | #1 : Pre-formatted typing contexts, such as 1158 | \tfont{\Delta};\tfont{\Gamma} 1159 | #2 : A pre-formatted expression 1160 | #3 : A pre-formatted contextually equivalent expression 1161 | #4 : A pre-formatted type for the expressions 1162 | ``` 1163 | 1164 | ### Logical Relations 1165 | ```latex 1166 | \lr[3] 1167 | Formats a logical relation set. 1168 | #1 : A formatting macro, such as \tfont 1169 | #2 : A letter for the relation, such a V or E 1170 | #3 : A pre-formatted index for the relation 1171 | 1172 | Usage: 1173 | \newcommand{\srelV}{\lr{\sfont}{V}} 1174 | \newcommand{\trelV}{\lr{\tfont}{V}} 1175 | ``` 1176 | 1177 | ```latex 1178 | \lrV[2] 1179 | \lrE[2] 1180 | \lrG[2] 1181 | \lrD[2] 1182 | \lrK[2] 1183 | \lrO[2] 1184 | Format logical relation sets. 1185 | #1 : A formatting macro, such as \tfont 1186 | #2 : A pre-formatted index for relation 1187 | 1188 | Usage: 1189 | \newcommand{\srelV}{\lrV{\sfont}} 1190 | \newcommand{\trelV}{\lrV{\tfont}} 1191 | ``` 1192 | 1193 | ```latex 1194 | \mapext[3] 1195 | Extends a key/value map 1196 | #1 : A pre-formatted symbol for the map, such as \tfont{\gamma} 1197 | #2 : A pre-formatted key for the new mapping, such as \tfont{\tx} 1198 | #3 : A pre-formatted symbol for the value of the new mapping such as 1199 | \tfont{\tau} 1200 | 1201 | Usage: 1202 | \newcommand{\btrlrgamma}{\btrfont{\gamma}} 1203 | \newcommand{\btrlrgammaext}{\mapext{\btrlrgamma}} 1204 | ``` 1205 | 1206 | ```latex 1207 | \binmapext[4] 1208 | Extends a map whose value is a pair. 1209 | #1 : A pre-formatted symbol for the map, such as \tfont{\rho} 1210 | #2 : A pre-formatted key for the new mapping, such as \tfont{\alpha} 1211 | #3 : A pre-formatted symbol for the first element of the value such as 1212 | \tfont{\tau} 1213 | #4 : A pre-formatted symbol for the second element of the value 1214 | 1215 | Usage: 1216 | \newcommand{\slrgamma}{\sfont{\gamma}} 1217 | \newcommand{\slrgammaext}{\binmapext{\slrgamma}} 1218 | ``` 1219 | 1220 | ```latex 1221 | \trimapext[5] 1222 | Like \binmapext, but extends a map whose value is a triple. 1223 | #1 : A pre-formatted symbol for the map, such as \tfont{\rho} 1224 | #2 : A pre-formatted key for the new mapping, such as \tfont{\alpha} 1225 | #3 : A pre-formatted symbol for the first element of the value such as 1226 | \tfont{\tau} 1227 | #4 : A pre-formatted symbol for the second element of the value 1228 | #5 : A pre-formatted symbol for the third element of the value 1229 | 1230 | Usage: 1231 | \newcommand{\tlrrho}{\tfont{\rho}} 1232 | \newcommand{\tlrrhoext}{\trimapext{\tlrrho}} 1233 | ``` 1234 | 1235 | ```latex 1236 | \mapat[2] 1237 | Applies a map to a key key. 1238 | #1 : A pre-formatted symbol for the map, as as \tfont{\rho} 1239 | #2 : A pre-formatted symbol for the key 1240 | ``` 1241 | 1242 | ```latex 1243 | \maponeat[2] 1244 | Projects the first element of the value of a map at some key. 1245 | #1 : A pre-formatted symbol for the map, as as \tfont{\rho} 1246 | #2 : A pre-formatted symbol for the key 1247 | ``` 1248 | 1249 | ```latex 1250 | \maptwoat[2] 1251 | Like \maponeat but projects the second element. 1252 | ``` 1253 | 1254 | ```latex 1255 | \maprelat[2] 1256 | Like \maponeat but projects the third element, which is assumed to be a 1257 | relation. 1258 | ``` 1259 | 1260 | ## Spacing 1261 | 1262 | To define meta-language combinators with consistent spacing, you are 1263 | encouraged to liberally use the predefined LaTeX macros `\mathopen`, 1264 | `\mathclose`, `\mathbin`, `\mathpunct` that determine character 1265 | spacing. For example, our language combinator `\forallty` for 1266 | polymorphic quantification ∀α.σ can be defined as follows: 1267 | 1268 | ```latex 1269 | % Formats a polymorphic type. 1270 | % #1 : A formatting macro for symbols, such as \tfontsym 1271 | % #2 : A formatting macro for text, such as \tfont 1272 | % #3 : The pre-formatted type-variable to bind 1273 | % #4 : The pre-formatted result in which the type-variable is bound 1274 | \newcommand{\forallty}[4]{\mathopen{#1{\uplambda}} #3 \mathpunct{#1{.}} #4} 1275 | ``` 1276 | 1277 | In addition, this package defines the macros `\maththinbin` and 1278 | `\maththickbin` to use smaller and larger spacing than plain 1279 | `\mathbin` around their arguments. `\maththinbin` is used around the 1280 | colon of `\fune` (λ(x:σ).e), and `\maththickbin` is used around the 1281 | vertical bar separating the two branches of a `\casee` statement (case 1282 | e of x₁.e₁ | x₂.e₂). 1283 | 1284 | When defining language expression combinators, it is also common to 1285 | use keywords instead of mathematical symbols: `let`, `in`, `if`, 1286 | `then`, `else`, `pack`, `unfold`, etc. This package defines macros 1287 | similar to the math spacing classes above: `\kwopen`, `\kwopen`, 1288 | `\kwbin` and `\kwrel`. Finally, `\kwinfix` can be used for keywords 1289 | used as infix operators (`pack`, `unfold`, etc.). See for example the 1290 | following definitions: 1291 | 1292 | ```latex 1293 | % \packe: pack (σ,e) as ∃α.σ 1294 | % #1 : A formatting macro for symbols, such as \tfontsym. 1295 | % #2 : A formatting macro for text, such as \tfont. 1296 | % #3 : A pre-formatted type witness. 1297 | % #4 : A pre-formatted value witness. 1298 | % #5 : A pre-formatted existential type abstracting the witness type. 1299 | \newcommand{\packe}[5]{% 1300 | \kwopen{#2{pack}}% 1301 | \paire{#1}{#2}{#3}{#4}% 1302 | \kwbin{#2{as}}% 1303 | #5% 1304 | } 1305 | 1306 | % \lete: let x = e in e' 1307 | % #1 : A formatting macro for symbols, such as \tfontsym. 1308 | % #2 : A formatting macro for text, such as \tfont. 1309 | % #3 : A pre-formatted expression variable. 1310 | % #4 : A pre-formatted expression to bind. 1311 | % #5 : A pre-formatted body expression for the let. 1312 | \newcommand{\lete}[5]{% 1313 | \kwopen{#2{let}}% 1314 | #3% 1315 | \mathbin{#1{=}}% 1316 | #4% 1317 | \kwbin{#2{in}}% 1318 | #5% 1319 | } 1320 | 1321 | % \unfolde: unfold e 1322 | % #1 : A formatting macro for symbols, such as \tfontsym. 1323 | % #2 : A formatting macro for text, such as \tfont. 1324 | % #3 : A pre-formatted expression of isorecursive type. 1325 | \newcommand{\unfolde}[3]{\kwinfix{#2{unfold}} #3} 1326 | ``` 1327 | -------------------------------------------------------------------------------- /hyperref.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage[backref]{hyperref} 4 | \usepackage[magicref]{mttex} 5 | 6 | \begin{document} 7 | \tableofcontents 8 | \section{Meow} 9 | \label{sec:meow} 10 | 11 | \fullref{sec:meow} is a cool section. 12 | \end{document} 13 | -------------------------------------------------------------------------------- /mttex.sty: -------------------------------------------------------------------------------- 1 | \ProvidesPackage{mttex} 2 | 3 | %%% -------------------------- Packages ------------------------------- 4 | 5 | \RequirePackage{mathpartir} 6 | % Local packages 7 | 8 | % CTAN packages 9 | \RequirePackage{pgffor} 10 | \RequirePackage{xcolor} 11 | \RequirePackage{letltxmacro} 12 | 13 | \RequirePackage{ifthen} 14 | 15 | \RequirePackage{amsbsy} 16 | \RequirePackage[only,llbracket,rrbracket]{stmaryrd} 17 | 18 | \RequirePackage{url} 19 | 20 | \RequirePackage{hyperref} 21 | 22 | % ACM recommended packages 23 | \RequirePackage{microtype} 24 | \RequirePackage[utf8]{inputenc} 25 | \RequirePackage[T1]{fontenc} 26 | 27 | %%% -------------------------- Options ------------------------------- 28 | 29 | %% omitthis 30 | \newcommand{\omitthis}[1]{#1} 31 | 32 | \newif\ifsecc@omit 33 | \secc@omitfalse 34 | \DeclareOption{omit}{ 35 | \renewcommand{\omitthis}[1]{} 36 | \secc@omittrue 37 | } 38 | 39 | \makeatletter 40 | % todo 41 | \newif\ifsecc@todo 42 | \secc@todofalse 43 | \DeclareOption{todo}{\secc@todotrue} 44 | 45 | %% ACM/SIGPLAN format 46 | \newif\ifsecc@sigplan 47 | \secc@sigplanfalse 48 | 49 | \DeclareOption{sigplan}{\secc@sigplantrue} 50 | \DeclareOption{nosigplan}{\secc@sigplanfalse} 51 | 52 | %% balance the last page? 53 | \newif\ifsecc@balance 54 | \secc@balancefalse 55 | 56 | \DeclareOption{balance}{\secc@balancetrue} 57 | 58 | %% techrpt or paper? 59 | \newif\ifsecc@techrpt 60 | \secc@techrptfalse 61 | 62 | \DeclareOption{techrpt}{\secc@techrpttrue} 63 | \DeclareOption{paper}{\secc@techrptfalse} 64 | 65 | %clever references stuff? 66 | \newif\ifsecc@refstuff 67 | \secc@refstufffalse 68 | 69 | % for backwards compatibility 70 | \DeclareOption{refstuff}{\secc@refstufftrue} 71 | \DeclareOption{magicref}{\secc@refstufftrue} 72 | 73 | %titlecaps usage? 74 | \newif\ifsecc@titlecaps 75 | \secc@titlecapstrue 76 | 77 | \DeclareOption{notitlecaps}{\secc@titlecapsfalse} 78 | 79 | %nocompress ? 80 | \newif\ifsecc@compress 81 | \secc@compresstrue 82 | 83 | \DeclareOption{nocompress}{\secc@compressfalse} 84 | 85 | \ProcessOptions\relax 86 | 87 | \ifsecc@todo 88 | \else 89 | \ifsecc@omit 90 | \PassOptionsToPackage{hide}{todo} 91 | \fi 92 | \fi 93 | \RequirePackage[marginpar]{todo} 94 | 95 | \ifsecc@balance 96 | \RequirePackage{flushend} 97 | \fi 98 | 99 | \ifsecc@techrpt 100 | \RequirePackage{fullpage} 101 | \renewcommand{\baselinestretch}{1.0} 102 | \fi 103 | 104 | \ifsecc@compress 105 | \pdfminorversion=5 106 | \pdfcompresslevel=9 107 | \pdfobjcompresslevel=2 108 | \else 109 | \relax 110 | \fi 111 | \makeatother 112 | 113 | %%% ----------------------- Definitions ----------------------------- 114 | 115 | \makeatletter 116 | \ifsecc@titlecaps 117 | \RequirePackage{titlecaps} 118 | %% Automaigc titlecase 119 | \Addlcwords{for via a is but and with of in as the etc on to if} 120 | 121 | % TODO I'd rather like to hide these internal things, but I guess I'll 122 | % settle for making them @ protected 123 | \LetLtxMacro{\@title}{\title} 124 | \LetLtxMacro{\@section}{\section} 125 | \LetLtxMacro{\@subsection}{\subsection} 126 | \LetLtxMacro{\@subsubsection}{\subsubsection} 127 | 128 | \newcommand{\@titlecrafterStar}[2]{ 129 | #1*{\titlecap{#2}} 130 | } 131 | 132 | \newcommand{\@titlecrafterNoStar}[3]{ 133 | \ifthenelse{\equal{#2}{}} 134 | {#1[#3]{\titlecap{#3}}} 135 | {#1[#2]{\titlecap{#3}}} 136 | } 137 | 138 | \newcommand{\@titleStar}[1]{ 139 | {\@title*{\titlecap{#1}}} 140 | } 141 | 142 | \newcommand{\@titleNoStar}[1]{ 143 | {\@title{\titlecap{#1}}} 144 | } 145 | 146 | \renewcommand{\title}{ \@ifstar \@titleStar \@titleNoStar } 147 | 148 | \newcommand{\@sectionStar}{ 149 | \@titlecrafterStar{\@section} 150 | } 151 | 152 | \newcommand{\@sectionNoStar}[2][]{ 153 | \@titlecrafterNoStar{\@section}{#1}{#2} 154 | } 155 | 156 | \renewcommand{\section}{ 157 | \@ifstar \@sectionStar \@sectionNoStar 158 | } 159 | 160 | \newcommand{\@subsectionStar}{ 161 | \@titlecrafterStar{\@subsection} 162 | } 163 | 164 | \newcommand{\@subsectionNoStar}[2][]{ 165 | \@titlecrafterNoStar{\@subsection}{#1}{#2} 166 | } 167 | 168 | \renewcommand{\subsection}{ 169 | \@ifstar \@subsectionStar \@subsectionNoStar 170 | } 171 | 172 | \newcommand{\@subsubsectionStar}{ 173 | \@titlecrafterStar{\@subsubsection} 174 | } 175 | 176 | \newcommand{\@subsubsectionNoStar}[2][]{ 177 | \@titlecrafterNoStar{\@subsubsection}{#1}{#2} 178 | } 179 | 180 | \renewcommand{\subsubsection}{ 181 | \@ifstar \@subsubsectionStar \@subsubsectionNoStar 182 | } 183 | \fi 184 | \makeatother 185 | 186 | %% Misc commands <<< 187 | %% More automatic "reference stuff" 188 | 189 | \makeatletter 190 | \ifsecc@refstuff 191 | 192 | \usepackage{nameref} 193 | \usepackage{cleveref} 194 | % http://tex.stackexchange.com/questions/121865/nameref-how-to-display-section-name-and-its-number 195 | % , modified to use \Cref instead of \autoref 196 | % \LetLtxMacro{\oldnameref}{\nameref} 197 | % \renewcommand{\nameref}[1]{\hyperref[{#1}]{\oldnameref*{#1}}} 198 | \newcommand{\magicstring}{@} 199 | \newcommand*{\@fullref}[3]{% 200 | \def \@meow{\ifthenelse{\equal{#1}{\magicstring}}{\nameref*{#3}}{#1}}% 201 | \sbox0{\@meow}% 202 | \hyperref[{#3}]{#2% 203 | \ifdim\wd0=0pt% 204 | \else% 205 | ~(\@meow)% 206 | \fi}% 207 | \def\@meow{\undefined}% 208 | } 209 | 210 | \newcommand{\@fullrefNoStar}[2][\magicstring]{\@fullref{#1}{\Cref*{#2}}{#2}} 211 | \newcommand{\@fullrefStar}[3][\magicstring]{\@fullref{#1}{#2\ref*{#3}}{#3}} 212 | \newcommand{\fullref}{\@ifstar\@fullrefStar\@fullrefNoStar} 213 | % here for backwards compatibility 214 | \newcommand{\nameonlyref}{\nameref} 215 | \newcommand{\fullrefnoname}[1]{\@fullrefNoStar[]{#1}} 216 | \newcommand{\shortref}[1]{\@fullrefNoStar{#1}} 217 | \newcommand{\fullrefnamed}{\@fullrefStar} 218 | 219 | \newcommand{\secref}[1]{\!\fullref[]{#1}} 220 | \newcommand{\figref}[1]{\!\fullref[]{#1}} 221 | \newcommand{\lemref}[1]{\!\fullref[]{#1}} 222 | \newcommand{\thmref}[1]{\!\fullref[]{#1}} 223 | \newcommand{\corref}[1]{\!\fullref[]{#1}} 224 | \else 225 | \newcommand{\secref}[1]{\S\ref{#1}} 226 | \newcommand{\figref}[1]{Figure~\ref{#1}} 227 | \newcommand{\lemref}[1]{Lemma~\ref{#1}} 228 | \newcommand{\thmref}[1]{Theorem~\ref{#1}} 229 | \newcommand{\corref}[1]{Corollary~\ref{#1}} 230 | \fi 231 | \makeatother 232 | 233 | % TODO: Document 234 | \newcommand{\judgmath}[1]{\(#1\)} 235 | \newcommand{\judgshape}[2][]{\begin{flushleft}\fbox{\judgmath{#2}~#1}\end{flushleft}} 236 | \newcommand{\inlinemath}[1]{\(#1\)} 237 | \newcommand{\im}{\inlinemath} 238 | \newcommand{\nonbreaking}{\mbox} 239 | \newcommand{\rulename}[1]{[{\scshape #1}]} 240 | 241 | % Text mode 242 | \newenvironment{nop}{\ifvmode\nointerlineskip\fi}{\ignorespacesafterend} 243 | 244 | % Stack formatting 245 | \newenvironment{stackAux}[2]{% 246 | \setlength{\arraycolsep}{0pt} 247 | \begin{array}[#1]{#2}}{ 248 | \end{array}\ignorespacesafterend} 249 | \newenvironment{stackCC}{ 250 | \begin{stackAux}{c}{c}}{\end{stackAux}\ignorespacesafterend} 251 | \newenvironment{stackCL}{ 252 | \begin{stackAux}{c}{l}}{\end{stackAux}\ignorespacesafterend} 253 | \newenvironment{stackTL}{ 254 | \begin{stackAux}{t}{l}}{\end{stackAux}\ignorespacesafterend} 255 | \newenvironment{stackTR}{ 256 | \begin{stackAux}{t}{r}}{\end{stackAux}\ignorespacesafterend} 257 | \newenvironment{stackBC}{ 258 | \begin{stackAux}{b}{c}}{\end{stackAux}\ignorespacesafterend} 259 | \newenvironment{stackBL}{ 260 | \begin{stackAux}{b}{l}}{\end{stackAux}\ignorespacesafterend} 261 | 262 | \newcommand{\case}[1][]{\item[Case] #1} 263 | \newcommand{\scase}[1][]{\item[Sub-Case] #1} 264 | \newcommand{\sscase}[1][]{\item[Sub-Sub-Case] #1} 265 | 266 | %% Meta Language 267 | \newcommand{\metafont}[1]{\mathrm{#1}} 268 | \newcommand{\dom}[1]{\metafont{dom}(#1)} 269 | \newcommand{\cod}[1]{\metafont{cod}(#1)} 270 | \newcommand{\rng}[1]{\metafont{rng}(#1)} 271 | \newcommand{\FV}{\metafont{fv}} 272 | \newcommand{\FTV}{\metafont{ftv}} 273 | \newcommand{\subst}[3]{{#1}[{#2}/{#3}]} 274 | \newcommand{\defeq}{\stackrel{\metafont{def}}{=}} 275 | \newcommand{\finmap}{\stackrel{\metafont{fin}}{\rightarrow}} 276 | \renewcommand{\iff}{\metafont{iff}} 277 | \newcommand{\lsem}{\left\llbracket} 278 | \newcommand{\rsem}{\right\rrbracket} 279 | \newcommand{\sembrace}[1]{\lsem{#1}\rsem} 280 | \newcommand{\powset}[1]{\mathscr{P}(#1)} 281 | \newcommand{\irred}[1]{\metafont{irred}(#1)} 282 | \renewcommand{\max}[2]{\metafont{max}(#1,#2)} 283 | \newcommand{\free}[2]{\metafont{free}(#1,#2)} 284 | \newcommand{\running}[2]{\metafont{running}({#1},{#2})} 285 | \newcommand{\pair}[2]{( #1, #2 )} 286 | \newcommand{\triple}[3]{( #1, #2, #3 )} 287 | 288 | \newcommand{\satisfy}{\vDash} 289 | 290 | \newcommand{\plus}{+} 291 | \newcommand{\etal}{\textit{et al.}} 292 | \newcommand{\ie}{\emph{i.e.}} 293 | \newcommand{\eg}{\emph{e.g.}} 294 | \newcommand{\etc}{\emph{etc.}} 295 | \newcommand{\bump}{\hspace{3.5pt}} 296 | \newcommand{\fresh}[1]{(\mathit{fresh}\:#1)} 297 | \newcommand{\where}[1]{\mathrm{where}\:#1} 298 | 299 | \newcommand{\lang}[1]{\mathrm{\textrm{#1}}} 300 | 301 | %% Standard symbols 302 | 303 | \newcommand{\emptyenv}{\cdot} 304 | \newcommand{\emptyctx}{[\cdot]} 305 | \newcommand{\hole}{\emptyctx} 306 | \newcommand{\hw}[1]{\lbrack{#1}\rbrack} 307 | \newcommand{\ectx}{E} 308 | \newcommand{\ctx}{C} 309 | 310 | \newcommand{\hooklongrightarrow}{\lhook\joinrel\longrightarrow} 311 | \newcommand{\redexstep}{\hookrightarrow} 312 | \newcommand{\redexstepinv}{\hookleftarrow} 313 | 314 | \newcommand{\step}{\longmapsto} 315 | \newcommand{\stepin}[1]{\step^{#1}} 316 | \newcommand{\stepstar}{\stepin{*}} 317 | 318 | \newcommand{\red}{\Downarrow} 319 | \newcommand{\diverg}[1]{#1 \Uparrow} 320 | 321 | \newcommand{\termin}[1]{#1\red} 322 | \newcommand{\terminw}[2]{\termin{#1} #2} 323 | 324 | \newcommand{\transarrow}{\leadsto} 325 | \newcommand{\backtransarrow}{\twoheadrightarrow} 326 | 327 | \newcommand{\funarrow}{\rightarrow} 328 | \newcommand{\ctxarrow}{\Rightarrow} 329 | 330 | % BNF symbols 331 | \newcommand{\bnflabel}[1]{\mbox{\textit{#1}}} 332 | \newcommand{\bnfalt}{\mathrel{\bf \,\mid\,}} 333 | \newcommand{\bnfdef}{\mathrel{\bf ::=}} 334 | \newcommand{\bnfadd}{\mathrel{\bf +::=}} 335 | \newcommand{\bnfsub}{\mathrel{\bf -::=}} 336 | 337 | %% Language Formatting combinators 338 | 339 | % Copy-pasta: http://tex.stackexchange.com/questions/16189/repeat-command-n-times 340 | \makeatletter 341 | \newcommand{\Repeat}[1]{% 342 | \expandafter\@Repeat\expandafter{\the\numexpr #1\relax}% 343 | } 344 | 345 | \def\@Repeat#1{% 346 | \ifnum#1>0 347 | \expandafter\@@Repeat\expandafter{\the\numexpr #1-1\expandafter\relax\expandafter}% 348 | \else 349 | \expandafter\@gobble% 350 | \fi 351 | } 352 | \def\@@Repeat#1#2{% 353 | \@Repeat{#1}{#2}{#2}% 354 | } 355 | 356 | \newcommand{\@super}[3]{ 357 | \ifnum#3=0 358 | {\sbox0{\ensuremath{#1}}% 359 | \ifdim\wd0=0pt 360 | \else% 361 | ^{#1}% 362 | \fi} 363 | \else 364 | ^{\Repeat{#3}{#2}#1}% 365 | \fi 366 | } 367 | 368 | \newcommand{\@sub}[1]{ 369 | \sbox0{\ensuremath{#1}}% 370 | \ifdim\wd0=0pt 371 | \else 372 | _{#1}% 373 | \fi 374 | } 375 | % \metavar formats a language meta-var. 376 | % 377 | % #1 : a pre-formatted symbol representing the meta-variable 378 | % #2 : a pre-formatted subscript 379 | % #3 : a pre-formatted superscript 380 | % #4 : a pre-formatted prime symbol 381 | % #5 : a natural number, representing the number of primes 382 | % 383 | % Usage: 384 | % \newcommand{\txmetavar}[3]{ 385 | % \metavar{\tfont{x}}{\tcolor{#1}}{\tcolor{#2}}{\tprime}{#3} 386 | % } 387 | % \newcommand{\tx}{\txmetavar{}{}{}} 388 | % \newcommand{\txone}{\txmetavar{1}{}{}} 389 | % \newcommand{\txonepr}{\txmetavar{1}{}{1}} 390 | \newcommand{\metavar}[5]{ 391 | #1\@super{#3}{#4}{#5}\@sub{#2}% 392 | } 393 | 394 | \makeatother 395 | 396 | % \metavarto formats a language meta-var with only a superscript. 397 | % 398 | % #1 : a pre-formatted symbol representing the meta-var 399 | % #2 : a pre-formatted superscript 400 | % 401 | % Usage: 402 | % \newcommand{\txF}{\metavarto{\tx}{f}} 403 | \newcommand{\metavarto}[2]{\metavar{#1}{}{#2}{}{0}} 404 | 405 | % \metavarin formats a language meta-var with only a subscript. 406 | % 407 | % #1 : a pre-formatted symbol representing the meta-var 408 | % #2 : a pre-formatted subscript 409 | % 410 | % Usage: 411 | % \newcommand{\txone}{\metavarin{\tx}{\tcolor{1}}} 412 | \newcommand{\metavarin}[2]{\metavar{#1}{#2}{}{}{0}} 413 | 414 | % \metavarpr formats a language meta-var with only primes, takes 3 415 | % parameters: 416 | % 417 | % #1 : a pre-formatted symbol representing the meta-var 418 | % #2 : a pre-formatted prime symbol 419 | % #3 : a natural number representing the number of primes 420 | % 421 | % Usage: 422 | % \newcommand{\txpr}{\metavarpr{\tx}{\prime}{1}} 423 | % \newcommand{\txdubpr}{\metavarpr{\tx}{\prime}{2}} 424 | \newcommand{\metavarpr}[3]{\metavar{#1}{}{}{#2}{#3}} 425 | 426 | \makeatletter 427 | 428 | % \@globalshadowedcommand generates a new global macro. However, when 429 | % the macro is already defined, it warns the user via a compile time 430 | % message that the macro has been shadowed. 431 | % 432 | % #1 : A default value for the optional argument of the new macro 433 | % #2 : The name of the macro to be defined 434 | % #3 : The number of arguments the macro takes 435 | % #4 : The body of the macro to be defined 436 | % 437 | % Usage: 438 | % \@globalshadowedcommand{\ae}{0}{ 439 | % \metavar{\tfont{x}}{}{}{}{0} 440 | % } 441 | \newcommand{\@globalshadowedcommand}[4][]{ 442 | { 443 | \let\def\gdef 444 | \ifcsname#2\endcsname 445 | \message{ 446 | ^^J^^J 447 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^^J 448 | !! mttex Warning: shadowed \@backslashchar#2 when defining metavar macros.^^J 449 | !! If you need this macro, use \@backslashchar LetLtxMacro to save it.^^J 450 | !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!^^J 451 | ^^J 452 | } 453 | \let\newcommand\renewcommand 454 | \fi 455 | \if\relax\detokenize{#1}\relax 456 | \expandafter\newcommand\csname #2\endcsname[#3]{#4} 457 | \else 458 | \expandafter\newcommand\csname #2\endcsname[#3][#1]{#4} 459 | \fi 460 | } 461 | } 462 | 463 | % \newmetavarStar generates some standard macros for formatting a meta-var, 464 | % and takes 5 paraemters: 465 | % 466 | % #1 : A formatting macro for the meta-var, such a \tfont 467 | % #2 : A formatting macro for the subscripts, superscripts, and primes, 468 | % such as \tcolor 469 | % #3 : A string prefix for the name of the macro, such as t 470 | % #4 : A string name of the macro, such as ty 471 | % #5 : A string to format and display this meta-variable as, such as 472 | % \tau 473 | % 474 | % Usage: 475 | % \newmetavarStar{\tfont}{\tcolor}{t}{ty}{\tau} 476 | % 477 | % This usage generates the following definitions: 478 | % 479 | % \newcommand{\ttymetavar}[3]{ 480 | % \metavar{\tfont{\tau}}{\tcolor{#1}}{\tcolor{#2}}{\tcolor{\prime}}{#3} 481 | % } 482 | % 483 | % \newcommand{\tty}{ \ttymetavar{}{}{} } 484 | % \newcommand{\ttyin}[1]{ \ttymetavar{#1}{}{0} } 485 | % \newcommand{\ttyto}[1]{ \ttymetavar{}{#1}{0} } 486 | % \newcommand{\ttypr}[1][1]{ \ttymetavar{}{}{#1} } 487 | % \newcommand{\ttyone}{ \ttymetavar{1}{}{} } 488 | % \newcommand{\ttyonepr}[1][1]{ \ttymetavar{1}{}{#1}} 489 | % \newcommand{\ttytwo}{ \ttymetavar{2}{}{} } 490 | % \newcommand{\ttytwopr}{ \ttymetavar{2}{}{1} } 491 | % \newcommand{\ttytthree}{ \ttymetavar{3}{}{} } 492 | % \newcommand{\ttytthreepr}{ \ttymetavar{3}{}{1} } 493 | % \newcommand{\ttyi}{ \ttymetavar{i}{}{} } 494 | % \newcommand{\ttyipr}[1][1]{ \ttymetavar{i}{}{#1} } 495 | % \newcommand{\ttyn}{ \ttymetavar{n}{}{} } 496 | % \newcommand{\ttynpr}[1][1]{ \ttymetavar{n}{}{#1} } 497 | % 498 | % \ttymetavar takes an unformatted sub-script, super-script, and 499 | % a natural number n indicating the number of primes. It then formats 500 | % the sub-script, the super-script, and n primes and attaches them to 501 | % the formatted meta-variable. 502 | \newcommand{\newmetavarStar}[5]{ 503 | \@globalshadowedcommand{#3#4metavar}{3}{ 504 | \metavar{#1{#5}}{#2{##1}}{#2{##2}}{#2{\prime}}{##3} 505 | } 506 | \@globalshadowedcommand{#3#4}{0}{ 507 | \csname #3#4metavar\endcsname{}{}{0} 508 | } 509 | \@globalshadowedcommand{#3#4in}{1}{ 510 | \csname #3#4metavar\endcsname{##1}{}{0} 511 | } 512 | \@globalshadowedcommand[0]{#3#4to}{2}{ 513 | \csname #3#4metavar\endcsname{}{##2}{##1} 514 | } 515 | \@globalshadowedcommand[1]{#3#4pr}{1}{ 516 | \csname #3#4metavar\endcsname{}{}{##1} 517 | } 518 | \@globalshadowedcommand{#3#4one}{0}{ 519 | \csname #3#4metavar\endcsname{1}{}{0} 520 | } 521 | \@globalshadowedcommand[1]{#3#4onepr}{1}{ 522 | \csname#3#4metavar\endcsname{1}{}{##1} 523 | } 524 | \@globalshadowedcommand{#3#4two}{0}{ 525 | \csname #3#4metavar\endcsname{2}{}{0} 526 | } 527 | \@globalshadowedcommand[1]{#3#4twopr}{1}{ 528 | \csname #3#4metavar\endcsname{2}{}{##1} 529 | } 530 | \@globalshadowedcommand{#3#4three}{0}{ 531 | \csname #3#4metavar\endcsname{3}{}{0} 532 | } 533 | \@globalshadowedcommand[1]{#3#4threepr}{1}{ 534 | \csname #3#4metavar\endcsname{3}{}{##1} 535 | } 536 | \@globalshadowedcommand{#3#4n}{0}{ 537 | \csname #3#4metavar\endcsname{n}{}{0} 538 | } 539 | \@globalshadowedcommand[1]{#3#4npr}{1}{ 540 | \csname #3#4metavar\endcsname{n}{}{##1} 541 | } 542 | \@globalshadowedcommand{#3#4i}{0}{ 543 | \csname #3#4metavar\endcsname{i}{}{0} 544 | } 545 | \@globalshadowedcommand[1]{#3#4ipr}{1}{ 546 | \csname #3#4metavar\endcsname{i}{}{##1} 547 | } 548 | } 549 | 550 | % \newmetavarNoStar is like \netmetavarStar, but assumes the name of 551 | % the macro is also the display symbol. 552 | % It takes 4 paraemters: 553 | % 554 | % #1 : A formatting macro for the meta-var, such a \tfont 555 | % #2 : A formatting macro for the subscripts, superscripts, and primes, 556 | % such as \tcolor 557 | % #3 : A string prefix for the name of the macro, such as t 558 | % #4 : A string name of the macro and symbol to format and display, such 559 | % as x 560 | % 561 | % Usage: 562 | % \newmetavarNoStar{\tfont}{\tcolor}{t}{x} 563 | % 564 | % This usage is equivalent to 565 | % \newmetavarStar{\tfont}{\tcolor}{t}{x}{x} 566 | \newcommand{\newmetavarNoStar}[4]{ 567 | \newmetavarStar{#2}{#3}{#4}{#1}{#1} 568 | } 569 | 570 | \newcommand{\@newmetavarmaybestar}{ 571 | \@ifstar 572 | \newmetavarStar 573 | \newmetavarNoStar 574 | } 575 | 576 | % \newmetavar implement the * LaTeX idiom after currying. It expands in 577 | % to either \newmetavarStar or \newmetavarNoStar depending on whether the 578 | % character following its 3rd argument is a * or not. 579 | % 580 | % Usage: 581 | % \newcommand{\newtmetavar}{\newmetavar{\tfont}{\tcolor}{t}} 582 | % \newtmetavar{x} 583 | % \newtmetavar*{ty}{\tau} 584 | \newcommand{\newmetavar}[4]{ 585 | \@newmetavarmaybestar#4{#1}{#2}{#3} 586 | } 587 | 588 | % \newmetavarS defines new metavar macros for a list of name/symbol 589 | % pairs. Essentially, it calls \newmetavar* for each name/symbol pair 590 | % in its 4th parameter. 591 | % 592 | % #1 : A formatting macro for the meta-var, such a \tfont 593 | % #2 : A formatting macro for the subscripts, superscripts, and primes, 594 | % such as \tcolor 595 | % #3 : A string prefix for the name of the macro, such as t 596 | % #4 : A list of name/symbol pairs, separated literally by a /. 597 | % 598 | % Usage: 599 | % \newmetavarsS{\tfont}{\tcolor}{t}{x/x,e/e,v/v,alpha/\boldsymbol{\alpha}} 600 | % \newcommand{\newsmetavarsS}{\newmetavarsS{\sfontsym}{\scolor}{s}} 601 | % \newsmetavarsS{\alpha/\alpha, ty/\sigma} 602 | \newcommand{\newmetavarsS}[4]{ 603 | \foreach \@n/\@d in {#4} { 604 | \edef \@meow{\noexpand\newmetavarStar{\noexpand#1}{\noexpand#2}{#3}{\@n}{\@d}} 605 | \@meow 606 | } 607 | \def\@meow{\undefined} 608 | \def\@n{\undefined} 609 | \def\@d{\undefined} 610 | } 611 | 612 | % \newmetavar defines new metavar macros for a list of names, assuming 613 | % each metavar will be displayed via the symbol it is named. 614 | % Essentially, it calls \newmetavar for each name in its 4th parameter. 615 | % 616 | % #1 : A formatting macro for the meta-var, such a \tfont 617 | % #2 : A formatting macro for the subscripts, superscripts, and primes, 618 | % such as \tcolor 619 | % #3 : A string prefix for the name of the macro, such as t 620 | % #4 : A list of names. 621 | % 622 | % Usage: 623 | % \newmetavars{\tfont}{\tcolor}{t}{x,e,v} 624 | % \newcommand{\newsmetavars}{\newmetavars{\sfont}{\scolor}{s}} 625 | % \newsmetavars{x,e,v} 626 | \newcommand{\newmetavars}[4]{ 627 | \foreach \@n in {#4} { 628 | \edef \@meow{\noexpand\newmetavarStar{\noexpand#1}{\noexpand#2}{#3}{\@n}{\@n}} 629 | \@meow 630 | } 631 | \def\@meow{\undefined} 632 | \def\@n{\undefined} 633 | } 634 | 635 | % TODO Figure out that currying issue with lists 636 | 637 | %%% Spacing commands 638 | % 639 | % See 640 | % http://tex.stackexchange.com/questions/38982/what-is-the-difference-between-mathbin-vs-mathrel 641 | % for a discussion of the default TeX space-affecting character 642 | % classes, namely 643 | % 644 | % \mathord: Ordinary (eg., /) 645 | % \mathop: Large operator (eg., \sum) 646 | % \mathbin: Binary operation (eg., +) 647 | % \mathrel: Relation (eg., =) 648 | % \mathopen: Opening (eg., () 649 | % \mathclose: Closing (eg., )) 650 | % \mathpunct: Punctuation (eg., ,) 651 | 652 | % For language features, we often use "keywords" instead of 653 | % mathematical symbols: if,then,else,let,in,pack,unpack... 654 | % 655 | % It is customary to space these keywords differently, usually with 656 | % more space around them, as for natural language words. The 657 | % definitions below approximate the role of the character classes 658 | % above for keyword symbols. 659 | 660 | \newcommand{\kwopen}[1]{#1\,} 661 | \newcommand{\kwclose}[1]{,#1} 662 | \newcommand{\kwbin}[1]{\,#1\,} 663 | \newcommand{\kwrel}[1]{\mathrel{#1}} 664 | \newcommand{\kwinfix}[1]{#1\,} 665 | 666 | \newcommand{\maththinbin}[1]{\,#1\,} 667 | \newcommand{\maththickbin}[1]{\:#1\:} 668 | \newcommand{\@thickinfix}[1]{#1\:} 669 | 670 | \newcommand{\@quantifier}[4]{\mathopen{#1{#2}} #3 \mathpunct{#1{#4}}} 671 | 672 | %%% ----------------- Standard language features ---------------------- 673 | 674 | %% --------------- Macros for defining new lang exprs ---------------- 675 | % NB: State passing is easier and more efficient than closures 676 | % Looks like I don't need to clear up the definitions after use. 677 | % TODO: Make more font parameters, ala issue #40 678 | 679 | % \newfeature{suffix}{tag}{args}{def} 680 | \newcommand{\newfeature}[4]{ 681 | \expandafter\newcommand\csname @#2#1\endcsname[#3]{% 682 | #4% 683 | }% 684 | \expandafter\newcommand\csname #2#1\endcsname[2]{% 685 | \def\langsymfont{##1}% 686 | \def\langfont{##2}% 687 | \csname @#2#1\endcsname% 688 | }% 689 | } 690 | 691 | \newcommand{\newtype}{\newfeature{ty}} 692 | \newcommand{\newexpr}{\newfeature{e}} 693 | 694 | %% ----------------------- Standard types ---------------------------- 695 | 696 | % All the following macros itself should only be used through the \newlanguage 697 | % macros. 698 | % All types defined by \newtype{}{n} generate a macro \ty with n 699 | % arguments, where prefixe and formatting is given by the current language. 700 | 701 | % type `fun` formats a function type 702 | % 703 | % #1 : The pre-formatted argument to the function 704 | % #2 : The pre-formatted result of the function 705 | \newtype{fun}{2}{#1 \mathbin{\langsymfont{\to}} #2} 706 | 707 | % \polyfunty formats a polymorphic function type 708 | % 709 | % #1 : The pre-formatted type-variable to bind 710 | % #2 : The pre-formatted argument to the function 711 | % #3 : The pre-formatted result of the function 712 | \newtype{polyfun}{3}{% 713 | \mathopen{\langsymfont{\forall}}% 714 | \mathopen{\langsymfont{[}}% 715 | #1% 716 | \mathclose{\langsymfont{].}}\mathpunct{}% 717 | #2% 718 | \mathbin{\langsymfont{\funarrow}}% 719 | #3% 720 | } 721 | 722 | % type `forall` formats a polymorphic type. 723 | % 724 | % #1 : The pre-formatted type-variable to bind 725 | % #2 : The pre-formatted result in which the type-variable is bound 726 | \newtype{forall}{2}{\@quantifier{\langfontsym}{\forall}{#1}{.} #2} 727 | 728 | % type `exist` formats an existential type. 729 | % 730 | % #1 : The pre-formatted type-variable to bind 731 | % #2 : The pre-formatted result in which the type-variable is bound 732 | \newtype{exist}{2}{\@quantifier{\langsymfont}{\exists}{#1}{.} #2} 733 | 734 | % type `mu` formats a recursive type. 735 | % 736 | % #1 : The pre-formatted type-variable to bind 737 | % #2 : The pre-formatted result in which the type-variable is bound 738 | \newcommand{\@muty}[3]{\@quantifier{\langsymfont}{\mu}{#1}{.} #2} 739 | 740 | % type `pi` formats a dependent function type. 741 | % 742 | % #1 : The pre-formatted variable to bind 743 | % #2 : The pre-formatted argument type 744 | % #3 : The pre-formatted result type 745 | \newtype{pi}{3}{% 746 | \kwopen{\langsymfont{\Pi}}% 747 | {#1} \mathbin{:} {#2}% 748 | \mathclose{.}% 749 | \mathpunct{}#3% 750 | } 751 | 752 | % type `sigma` formats a dependent pair type. 753 | % 754 | % #1 : The pre-formatted variable to bind. 755 | % #2 : The pre-formatted type of the variable. 756 | % #3 : The pre-formatted result type. 757 | \newtype{sigma}{3}{ 758 | \kwopen{\langsymfont{\Sigma}}% 759 | {#1} \mathbin{:} {#2}% 760 | \mathclose{.}% 761 | \mathpunct{}#3% 762 | } 763 | 764 | % type `unit` formats a unit type. 765 | \newtype{unit}{0}{\langsymfont{1}} 766 | 767 | % type `void` formats a void type. 768 | \newtype{void}{1}{\langsymfont{0}} 769 | 770 | % type `bool` formats a bool type. 771 | \newtype{bool}{0}{\langfont{bool}} 772 | 773 | % type `type` formats a type of types Type (i.e., a universe). 774 | % 775 | % #1 : A pre-formatted universe level, which defaults to i. 776 | \newtype{type}{1}{\kwopen{\langfont{Type}}_{#1}} 777 | 778 | %% TODO: Might need a combinator for defining simple keyword's like Prop and Set? 779 | 780 | % type `prop` formats the type Prop, as in CIC's impredicative universe Prop. 781 | \newtype{prop}{0}{\kwopen{\langfont{Prop}}} 782 | 783 | % type `set` formats the type Set, as in CIC's predicative universe Set. 784 | \newtype{set}{0}{\kwopen{\langfont{Set}}} 785 | 786 | % type `star` formats the type * 787 | \newtype{star}{0}{\langsymfont{\star}} 788 | 789 | % type `box` formats the type \square 790 | \newtype{box}{0}{\langsymfont{\square}} 791 | 792 | % type `pair` formats a pair type. 793 | % 794 | % #1 : The pre-formatted type for the first component of the pair 795 | % #2 : The pre-formatted type for the second component of the pair 796 | \newtype{pair}{2}{#1 \mathbin{\langsymfont{\times}} #2} 797 | 798 | % type `sum` formats a sum type. 799 | % 800 | % #1 : The pre-formatted type for the first component of the sum 801 | % #2 : The pre-formatted type for the second component of the sum 802 | \newtype{sum}{2}{#1 \mathbin{\langsymfont{\plus}} #2} 803 | 804 | % type `aexist` formats an existential type, whose type variables require annotations 805 | % 806 | % #1 : The pre-formatted type-variable to bind 807 | % #2 : The pre-formatted type of the type-variable. 808 | % #3 : The pre-formatted result in which the type-variable is bound. 809 | \newtype{aexist}{3}{ 810 | \kwopen{\langsymfont{\exists}}% 811 | {#1} \mathbin{:} {#2}% 812 | \mathclose{.}% 813 | \mathpunct{}#3% 814 | } 815 | 816 | % type `nexist` formats an n-ary existential type 817 | % 818 | % #1 : The pre-formatted list of bindings 819 | \newtype{nexist}{1}{ 820 | \kwopen{\langsymfont{\exists}}% 821 | #1% 822 | } 823 | 824 | % type `npi` formats an n-ary dependent function type. 825 | % 826 | % #1 : The pre-formatted variable declarations 827 | % #2 : The pre-formatted result type 828 | \newtype{npi}{2}{ 829 | \kwopen{\langsymfont{\Pi}}% 830 | #1 831 | \mathclose{.}% 832 | \mathpunct{}#2% 833 | } 834 | 835 | % type `nsigma` formats an n-ary dependent pair type. 836 | % 837 | % #1 : The pre-formatted list of bindings. 838 | \newtype{nsigma}{1}{ 839 | \kwopen{\langsymfont{\Sigma}}{#1}% 840 | } 841 | 842 | %% ----------------------- Standard exprs ---------------------------- 843 | 844 | % expression `fun` formats a function expression. 845 | % 846 | % #1 : The pre-formatted variable the function binds. 847 | % #2 : The pre-formatted type of the variable. 848 | % #3 : The pre-formatted body of the function. 849 | \newexpr{fun}{3}{% 850 | \mathopen{\langsymfont{\lambda (}}% 851 | {#1} \maththinbin{\langsymfont{:}} {#2}% \mathbin{:} spacing would be a bit too large 852 | \mathclose{\langsymfont{).}}% 853 | \mathpunct{}#3% 854 | } 855 | 856 | % expression `polyfun` formats a polymorphic function expression. 857 | % 858 | % #1 : The pre-formatted type variable the function binds. 859 | % #2 : The pre-formatted variable the function binds. 860 | % #3 : The pre-formatted type of the variable. 861 | % #4 : The pre-formatted body of the function. 862 | \newexpr{polyfun}{4}{ 863 | \mathopen{\langsymfont{\lambda}}% 864 | \mathopen{\langsymfont{[}}% 865 | #1% 866 | \mathclose{\langsymfont{]}}% 867 | \mathopen{\langsymfont{(}}% 868 | #2% 869 | \maththinbin{\langsymfont{:}}% 870 | #3% 871 | \mathclose{\langsymfont{).}}\mathpunct{}% 872 | #4% 873 | } 874 | 875 | % expression `abstr` formats an polymorphic abstraction expression. 876 | % 877 | % #1 : The pre-formatted type variable the abstraction binds. 878 | % #2 : The pre-formatted the body of the abstract. 879 | \newexpr{abstr}{2}{\@quantifier{\langsymfont}{\Lambda}{#1}{.} #2} 880 | 881 | % expression `inst` formats an instantiation expression. 882 | % 883 | % #1 : The pre-formatted polymorphic abstraction to instantiate. 884 | % #2 : The pre-formatted type with which to instantiate the abstraction. 885 | \newexpr{inst}{2}{\@thickinfix{#1} \mathopen{\langsymfont{[}} #2 \mathclose{\langsymfont{]}}} 886 | 887 | % expression `app` formats an application expression. 888 | % 889 | % #1 : The pre-formatted function. 890 | % #2 : The pre-formatted argument. 891 | \newexpr{app}{2}{#1\ #2} 892 | 893 | % expression `papp` formats a polymorphic function application expression. 894 | % 895 | % #1 : A pre-formatted polymorphic function expression. 896 | % #2 : A pre-formatted type with which to instantiate. 897 | % #3 : A pre-formatted argument to the function. 898 | \newexpr{papp}{3}{\@thickinfix{\@inste{#1}{#2}} #3} 899 | 900 | % expression `if` formats an if expression 901 | % 902 | % #1 : A pre-formatted discriminant expression. 903 | % #2 : A pre-formatted consequent expression. 904 | % #3 : A pre-formatted alternate expression. 905 | \newexpr{if}{3}{\kwopen{\langfont{if}} #1 \kwbin{\langfont{then}} #2 \kwbin{\langfont{else}} #3} 906 | 907 | % expression `pack` formats a pack expression 908 | % 909 | % #1 : A pre-formatted type witness. 910 | % #2 : A pre-formatted value witness. 911 | % #3 : A pre-formatted existential type abstracting the witness type. 912 | \newexpr{pack}{3}{% 913 | \kwopen{\langfont{pack}}% 914 | \@paire{#1}{#2}% 915 | \kwbin{\langfont{as}}% 916 | #3% 917 | } 918 | 919 | % expression `unpack` formats an unpack expression 920 | % 921 | % #1 : A pre-formatted type variable. 922 | % #2 : A pre-formatted value variable. 923 | % #3 : A pre-formatted existential witness expression. 924 | % #4 : A pre-formatted expression in which to bind the existential. 925 | \newexpr{unpack}{4}{% 926 | \kwopen{\langfont{unpack}}% 927 | \@paire{#1}{#2}% 928 | \mathbin{=}% 929 | #3% 930 | \kwbin{\langfont{in}}% 931 | #4% 932 | } 933 | 934 | % expression `let` formats a let expression 935 | % 936 | % #1 : A pre-formatted expression variable. 937 | % #2 : A pre-formatted expression to bind. 938 | % #3 : A pre-formatted body expression for the let. 939 | \newexpr{let}{3}{% 940 | \kwopen{\langfont{let}}% 941 | #1% 942 | \mathbin{=}% 943 | #2% 944 | \kwbin{\langfont{in}}% 945 | #3} 946 | 947 | % expression `alet` formats a let expression with an annotation on the bound expression. 948 | % 949 | % #1 : A pre-formatted expression variable. 950 | % #2 : A pre-formatted expression to bind. 951 | % #3 : A pre-formatted annotation for bound expression. 952 | % #4 : A pre-formatted body expression for the let. 953 | \newexpr{alet}{4}{% 954 | \kwopen{\langfont{let}}% 955 | #1% 956 | \mathbin{=}% 957 | #2 958 | \mathbin{:} 959 | #3% 960 | \kwbin{\langfont{in}}% 961 | #4} 962 | 963 | % expression `fold` formats a fold expression. 964 | % 965 | % #1 : A pre-formatted mu type. 966 | % #2 : A pre-formatted expression of isorecursive type. 967 | \newexpr{fold}{2}{\kwinfix{\langfont{fold}_{#1}} #2} 968 | 969 | % expression `unfold` formats an unfold expression 970 | % 971 | % #1 : A pre-formatted expression of isorecursive type. 972 | \newexpr{unfold}{1}{\kwinfix{\langfont{unfold}} #1} 973 | 974 | % expression `unit` formats a unit expression. 975 | \newexpr{unit}{0}{\langsymfont{\langle}\langsymfont{\rangle}} 976 | 977 | % expression `fix` formats a recursive function expression. 978 | % 979 | % #1 : The pre-formatted variable the function binds. 980 | % #2 : The pre-formatted type of the variable. 981 | % #3 : The pre-formatted body of the function. 982 | \newexpr{fix}{3}{% 983 | \kwopen{\langfont{fix}}% 984 | {#1} \mathbin{:} {#2}% \mathbin{:} spacing would be a bit too large 985 | \mathclose{.}% 986 | \mathpunct{}#3} 987 | 988 | % expression `true` formats a true expression 989 | \newexpr{true}{0}{\langfont{true}} 990 | 991 | % expression `false` formats a false expression 992 | \newexpr{false}{0}{\langfont{false}} 993 | 994 | % expression `pair` formats a pair expression. 995 | % 996 | % #1 : A pre-formatted expression for the first component of the pair. 997 | % #2 : A pre-formatted expression for the second component of the pair. 998 | \newexpr{pair}{2}{% 999 | \mathopen{\langsymfont{\langle}}% 1000 | #1% 1001 | \mathpunct{\langsymfont{,}}% 1002 | #2% 1003 | \mathclose{\langsymfont{\rangle}}% 1004 | } 1005 | 1006 | % expression `prj` formats a projection expression. 1007 | % 1008 | % #1 : An index, such as 1 or 2, indicating which 1009 | % component of the pair to project. 1010 | % #2 : A pre-formatted pair expression to project. 1011 | \newexpr{prj}{2}{\kwinfix{\langsymfont{\pi}_{#1}} #2} 1012 | 1013 | % expression `sum` formats a sum expression. 1014 | % 1015 | % #1 : An index, such as 1 or 2, indicating into which 1016 | % side of the sum to inject the expression. 1 indicates left, 2 1017 | % indicates right. 1018 | % #2 : A pre-formatted expression to inject into a sum. 1019 | \newexpr{sum}{2}{\kwinfix{\langfont{inj}_{#1}} #2} 1020 | 1021 | % expression `case` formats a case expression. 1022 | % 1023 | % #1 : A pre-formatted discriminant expression. 1024 | % #2 : A pre-formatted variable to bind in the left branch. 1025 | % #3 : A pre-formatted expression for the left branch. 1026 | % #4 : A pre-formatted variable to bind in the right branch. 1027 | % #5 : A pre-formatted expression for the right branch. 1028 | \newexpr{case}{5}{% 1029 | \kwopen{\langfont{case}}% 1030 | #1% 1031 | \kwbin{\langfont{of}}% 1032 | #2 \mathpunct{.} #3% 1033 | \maththickbin{\langsymfont{|}}% 1034 | #4 \mathpunct{.} #5% 1035 | } 1036 | 1037 | % expression `dcase` formats a dependent case analysis expression, like that of CIC's. 1038 | % 1039 | % #1 : A pre-formatted discriminant expression. 1040 | % #2 : A pre-formatted motive. 1041 | % #3 : A pre-formatted list of branch expressions. 1042 | \newexpr{dcase}{3}{% 1043 | \kwopen{\langfont{case}}% 1044 | #1% 1045 | \mathpunct{,}% 1046 | #2% 1047 | \mathpunct{,}% 1048 | \mathopen{(} #3% 1049 | \mathclose{)} 1050 | } 1051 | 1052 | % expression `dpaire` formats a dependent pair expression. 1053 | % 1054 | % #1 : A pre-formatted expression for the first component of the pair. 1055 | % #2 : A pre-formatted expression for the second component of the pair. 1056 | % #3 : A pre-formatted expression for the type annotation. 1057 | \newexpr{dpair}{3}{% 1058 | \mathopen{\langsymfont{\langle}}% 1059 | #1% 1060 | \mathpunct{,}% 1061 | #2% 1062 | \mathclose{\langsymfont{\rangle}} 1063 | \kwbin{\langfont{as}}% 1064 | #3% 1065 | } 1066 | 1067 | % expression `fst` formats a first projection of a pair. 1068 | % 1069 | % #1 : A pre-formatted expression for the pair to project. 1070 | \newexpr{fst}{1}{% 1071 | {\kwopen{\langfont{fst}}#1}% 1072 | } 1073 | 1074 | % expression `snd` formats a second projection of a pair. 1075 | % 1076 | % #1 : A pre-formatted expression for the pair to project. 1077 | \newexpr{snd}{1}{% 1078 | {\kwopen{\langfont{snd}}#1}% 1079 | } 1080 | 1081 | %% expression `nfun` formats an n-ary function. 1082 | % 1083 | % #1 : The pre-formatted variable declarations. 1084 | % #2 : The pre-formatted body of the function. 1085 | \newexpr{nfun}{2}{% 1086 | \kwopen{\langsymfont{\lambda}}% 1087 | #1% 1088 | \mathclose{.}% 1089 | \mathpunct{}#2% 1090 | } 1091 | 1092 | % expression `dnpair` formats a dependent n-ary pair expression. 1093 | % 1094 | % #1 : A pre-formatted list of expressions. 1095 | % #2 : A pre-formatted type annotation. 1096 | \newexpr{dnpair}{2}{% 1097 | \mathopen{\langsymfont{\langle}}% 1098 | #1% 1099 | \mathclose{{\langsymfont{\rangle}}}% 1100 | \kwbin{\langfont{as}}% 1101 | #2% 1102 | } 1103 | 1104 | % expression `packo` is like `pack` but *o*mits the type annotations on the end. 1105 | % 1106 | % #1 : A pre-formatted type witness. 1107 | % #2 : A pre-formatted value witness. 1108 | \newexpr{packo}{2}{% 1109 | \kwopen{\langfont{pack}}% 1110 | \@paire{#1}{#2}% 1111 | } 1112 | 1113 | % expression `npair` formats an n-ary pair expression, also known as a list. 1114 | % 1115 | % #1 : A pre-formatted expression for the n elements of the pair 1116 | % TODO Would be nice to automagically mathpunct all the commas. should be a simple extension with \foreach parsing 1117 | \newexpr{npair}{1}{% 1118 | \mathopen{\langsymfont{\langle}}% 1119 | #1% 1120 | \mathclose{{\langsymfont{\rangle}}}% 1121 | } 1122 | 1123 | % expression `npack` formats an n-ary pack expression 1124 | % 1125 | % #1 : A pre-formatted list of witnesses. 1126 | % #2 : A pre-formatted existential type abstracting the witness type. 1127 | \newexpr{npack}{2}{% 1128 | \kwopen{\langfont{pack}}% 1129 | \@npaire{#1}% 1130 | \kwbin{\langfont{as}}% 1131 | #2% 1132 | } 1133 | 1134 | % expression `npacko` formats an n-ary pack expression, omitting the type annotation. 1135 | % 1136 | % #1 : A pre-formatted list of witnesses. 1137 | \newexpr{npacko}{1}{% 1138 | \kwopen{\langfont{pack}}% 1139 | \@npaire{#1}% 1140 | } 1141 | 1142 | % expression `nunpack` formats an n-ary unpack expression 1143 | % 1144 | % #1 : A pre-formatted list of variables. 1145 | % #2 : A pre-formatted existential witness expression. 1146 | % #3 : A pre-formatted expression in which to bind the existential. 1147 | \newexpr{nunpack}{3}{% 1148 | \kwopen{\langfont{unpack}}% 1149 | \@npaire{#1}% 1150 | \mathbin{=}% 1151 | #2% 1152 | \kwbin{\langfont{in}}% 1153 | #3% 1154 | } 1155 | 1156 | % expression `nfix` formats an n-ary recursive function expression. 1157 | % 1158 | % #1 : The per-formatted name of the recursive function. 1159 | % #2 : The pre-formatted list of variables the function binds. 1160 | % #3 : The pre-formatted type of the recursive function. 1161 | % #4 : The pre-formatted body of the function. 1162 | \newexpr{nfix}{4}{% 1163 | \kwopen{\langfont{fix}}% 1164 | {#1} (#2) \mathbin{:} {#3} 1165 | \mathclose{.}% 1166 | \mathpunct{}#4% 1167 | } 1168 | 1169 | % TODO: Need some error handling. If a macro given to newlanguage and passed here is undefined, you get an error like 1170 | % "argument of \sfontsym has an extra }", which makes no sense. 1171 | 1172 | % \newconstr generates a macro for formatting a language construct. 1173 | % 1174 | % #1 : A formatting macro for symbols, such as \tfontsym 1175 | % #2 : A formatting macro for text, such as \tfont 1176 | % #3 : A construct tag, such as fun 1177 | % #4 : A construct type, either ty or e 1178 | % #5 : The name of the macro to generate 1179 | \newcommand{\newconstr}[5]{ 1180 | \@globalshadowedcommand{#5}{0}{ 1181 | \csname#3#4\endcsname{#1}{#2} 1182 | } 1183 | } 1184 | 1185 | % \@newconstrs generates formatting macros for a list of language 1186 | % constructs 1187 | % 1188 | % #1 : A formatting macro for symbols, such as \tfontsym 1189 | % #2 : A formatting macro for text, such as \tfont 1190 | % #3 : A construct kind, either ty or e 1191 | % #4 : A prefix to use when generating the macro names 1192 | % #5 : A suffix to use when generating the macro names 1193 | % #6 : A list of construct tags, such as {fun,bool,unit,void} 1194 | \newcommand{\@newconstrs}[6]{ 1195 | { 1196 | \foreach \@n in {#6}{ 1197 | \edef\@meow{\noexpand\newconstr{\noexpand#1}{\noexpand#2}{\@n}{#3}{#4\@n#5}} 1198 | \@meow 1199 | } 1200 | \def\@meow{\undefined} 1201 | \def\@n{\undefined} 1202 | } 1203 | } 1204 | 1205 | % \newtypes generates type formatting macros given a list of tags. 1206 | % 1207 | % #1 : A formatting macro for symbols, such as \tfontsym 1208 | % #2 : A formatting macro for text, such as \tfont 1209 | % #3 : A prefix for the name of each macro, such as t 1210 | % #4 : A suffix for the name of each macro, such as ty 1211 | % #5 : A list of type tags, such as {fun,bool,void,unit} 1212 | \newcommand{\newtypes}[2]{\@newconstrs{#1}{#2}{ty}} 1213 | 1214 | % \newexprs generates type formatting macros given a list of tags. 1215 | % 1216 | % #1 : A formatting macro for symbols, such as \sfontsym 1217 | % #2 : A formatting macro for text, such as \sfont 1218 | % #3 : A prefix for the name of each macro, such as s 1219 | % #4 : A suffix for the name of each macro, such as e 1220 | % #5 : A list of type tags, such as {fun,bool,void,unit} 1221 | \newcommand{\newexprs}[2]{\@newconstrs{#1}{#2}{e}} 1222 | \makeatother 1223 | 1224 | % \newlanguage generates macros for formatting meta-variables, types, 1225 | % and expressions of a language. 1226 | % 1227 | % #1 : A formatting macro for super-scripts, sub-scripts, and primes in 1228 | % this language, such as \tcolor 1229 | % #2 : A formatting macro for math text in this language, such as \tfont 1230 | % #3 : A formatting macro for symbols in this language, such as 1231 | % \tfontsym 1232 | % #4 : A language prefix for the macros, such as t 1233 | % #5 : A list of meta-variables for which to generate macros via 1234 | % \newmetavars, such as {x, e, v} 1235 | % #6 : A list of meta-variables for which to generate macros via 1236 | % \newmetavarsS, such as {ty/\tau,alpha\alpha} 1237 | % #7 : A list of types for which to generate macros via \newtypes, such 1238 | % as {fun, forall, exist, pair, bool, unit}. The macros are generated 1239 | % with the language prefix and the suffix ty. 1240 | % #8 : A list of expressions for which to generate macros via 1241 | % \newexprs, such as {fun, app, if, true, false, unit}. The macros 1242 | % are generated with the language prefix and the suffix e. 1243 | \renewcommand{\newlanguage}[8]{ 1244 | \newmetavars{#2}{#1}{#4}{#5} 1245 | \newmetavarsS{#3}{#1}{#4}{#6} 1246 | \newtypes{#3}{#2}{#4}{ty}{#7} 1247 | \newexprs{#3}{#2}{#4}{e}{#8} 1248 | } 1249 | 1250 | %%% Standard meta-theory 1251 | 1252 | % \wf formats a well-formedness judgment. 1253 | % 1254 | % #1 : Pre-formatted assumptions, such as \tfont{\Delta} 1255 | % #2 : The pre-formatted proposition, such as \tfont{\alpha} 1256 | \newcommand{\wf}[2]{#1 \mathrel{\vdash} #2} 1257 | 1258 | % \judg formats a well-typedness judgment. 1259 | % It takes 3 parameters. 1260 | % 1261 | % #1 : The assumptions, such as \tfont{\Delta};\tfont{\Gamma} 1262 | % #2 : The term, such as \tfont{e} 1263 | % #3 : The type, such as \tfont{\tau} 1264 | \newcommand{\judg}[3]{\wf{#1}{#2 \mathrel{:} #3}} 1265 | 1266 | %% Context typing 1267 | 1268 | % \ctxarrowty formats a context typing arrow 1269 | % 1270 | % #1 : A formatting macro for symbols, such as \stfontsym 1271 | % #2 : The type of the hole 1272 | % #3 : The type of the result 1273 | \newcommand{\ctxarrowty}[3]{#2 \mathrel{#1{\ctxarrow}} #3} 1274 | 1275 | % \ctxty formats a context type, with different typing contexts for the 1276 | % hole and result 1277 | % 1278 | % #1 : A formatting macro for symbols, such as \stfontsym 1279 | % #2 : The typing contexts for the hole 1280 | % #3 : The type of the hole 1281 | % #4 : The typing contexts for the result 1282 | % #5 : The type of the result 1283 | \newcommand{\ctxty}[5]{\ctxarrowty{#1}{(\wf{#2}{#3})}{(\wf{#4}{#5})}} 1284 | 1285 | % \ctxtyjudg formats a context typing judgment. 1286 | % 1287 | % #1 : A formatting macro for symbols, such as \stfontsym 1288 | % #2 : A pre-formatted context 1289 | % #3 : The typing contexts for the hole 1290 | % #4 : The type of the hole 1291 | % #5 : The typing contexts for the result 1292 | % #6 : The type of the result 1293 | \newcommand{\ctxtyjudg}[2]{\judg{}{#2}{\ctxty{#1}}} 1294 | 1295 | 1296 | %% Contextual equivalence 1297 | \newcommand{\ctxeqvsym}{\approx^{\mathit{ctx}}} 1298 | \newcommand{\ciueqvsym}{\approx^{\mathit{ciu}}} 1299 | 1300 | % \ciueqvjudg formats a c.i.u. equivalence judgment. 1301 | % 1302 | % #1 : Pre-formatted typing contexts, such as 1303 | % \tfont{\Delta};\tfont{\Gamma} 1304 | % #2 : A pre-formatted expression 1305 | % #3 : A pre-formatted c.i.u. equivalent expression 1306 | % #4 : A pre-formatted type for the expressions 1307 | \newcommand{\ciueqvjudg}[4]{\judg{#1}{#2 \mathrel{\ciueqvsym} #3}{#4}} 1308 | 1309 | % \ctxeqvjudg formats a contextual equivalence judgment. 1310 | % 1311 | % #1 : Pre-formatted typing contexts, such as 1312 | % \tfont{\Delta};\tfont{\Gamma} 1313 | % #2 : A pre-formatted expression 1314 | % #3 : A pre-formatted contextually equivalent expression 1315 | % #4 : A pre-formatted type for the expressions 1316 | \newcommand{\ctxeqvjudg}[4]{\judg{#1}{#2 \mathrel{\ctxeqvsym} #3}{#4}} 1317 | 1318 | %% Logical Relations 1319 | \newcommand{\lratomsym}{\mathrm{Atom}} 1320 | \newcommand{\lratomvalsym}{\mathrm{Atom}^{\mathrm{val}}} 1321 | \newcommand{\lrrelsym}{\mathrm{Rel}} 1322 | 1323 | % \lr formats a logical relation set. 1324 | % 1325 | % #1 : A formatting macro, such as \tfont 1326 | % #2 : A letter for the relation, such a V or E 1327 | % #3 : A pre-formatted index for the relation 1328 | % 1329 | % Usage: 1330 | % \newcommand{\srelV}{\lr{\sfont}{V}} 1331 | % \newcommand{\trelV}{\lr{\tfont}{V}} 1332 | \newcommand{\lr}[3]{#1{\mathcal{#2}}\sembrace{#3}} 1333 | 1334 | % \lrV,\lrE,\lrG,\lrD,\lrK,\lrO format logical relation sets. 1335 | % 1336 | % #1 : A formatting macro, such as \tfont 1337 | % #2 : A pre-formatted index for relation 1338 | % 1339 | % Usage: 1340 | % \newcommand{\srelV}{\lrV{\sfont}} 1341 | % \newcommand{\trelV}{\lrV{\tfont}} 1342 | \newcommand{\lrV}[2]{\lr{#1}{V}{#2}} 1343 | \newcommand{\lrE}[2]{\lr{#1}{E}{#2}} 1344 | \newcommand{\lrG}[2]{\lr{#1}{G}{#2}} 1345 | \newcommand{\lrD}[2]{\lr{#1}{D}{#2}} 1346 | \newcommand{\lrK}[2]{\lr{#1}{K}{#2}} 1347 | \newcommand{\lrO}[2]{\lr{#1}{O}{#2}} 1348 | 1349 | %% The following help define formatting macros relational 1350 | %% interpretations and substitution, normally written as \rho, \delta, 1351 | %% and \gamma 1352 | 1353 | %% TODO Maybe these should use \pair and \triple 1354 | % \mapext extends a key/value map 1355 | % 1356 | % #1 : A pre-formatted symbol for the map, such as \tfont{\gamma} 1357 | % #2 : A pre-formatted key for the new mapping, such as \tfont{\tx} 1358 | % #3 : A pre-formatted symbol for the value of the new mapping such as 1359 | % \tfont{\tau} 1360 | % 1361 | % Usage: 1362 | % \newcommand{\btrlrgamma}{\btrfont{\gamma}} 1363 | % \newcommand{\btrlrgammaext}{\mapext{\btrlrgamma}} 1364 | \newcommand{\mapext}[3]{#1[#2 \mapsto #3 ]} 1365 | 1366 | % \binmapext extends a map whose value is a pair. 1367 | % 1368 | % #1 : A pre-formatted symbol for the map, such as \tfont{\rho} 1369 | % #2 : A pre-formatted key for the new mapping, such as \tfont{\alpha} 1370 | % #3 : A pre-formatted symbol for the first element of the value such as 1371 | % \tfont{\tau} 1372 | % #4 : A pre-formatted symbol for the second element of the value 1373 | % 1374 | % Usage: 1375 | % \newcommand{\slrgamma}{\sfont{\gamma}} 1376 | % \newcommand{\slrgammaext}{\binmapext{\slrgamma}} 1377 | \newcommand{\binmapext}[4]{\mapext{#1}{#2}{(#3,#4)}} 1378 | 1379 | % \trimapext is like \binmapext, but extends a map whose value is a triple. 1380 | % 1381 | % #1 : A pre-formatted symbol for the map, such as \tfont{\rho} 1382 | % #2 : A pre-formatted key for the new mapping, such as \tfont{\alpha} 1383 | % #3 : A pre-formatted symbol for the first element of the value such as 1384 | % \tfont{\tau} 1385 | % #4 : A pre-formatted symbol for the second element of the value 1386 | % #5 : A pre-formatted symbol for the third element of the value 1387 | % 1388 | % Usage: 1389 | % \newcommand{\tlrrho}{\tfont{\rho}} 1390 | % \newcommand{\tlrrhoext}{\trimapext{\tlrrho}} 1391 | \newcommand{\trimapext}[5]{\mapext{#1}{#2}{(#3,#4,#5)}} 1392 | 1393 | %% TODO These should probably accept formatting macros for the 1394 | %% subscript. 1395 | 1396 | % \mapat applies a map to a key key. 1397 | % 1398 | % #1 : A pre-formatted symbol for the map, as as \tfont{\rho} 1399 | % #2 : A pre-formatted symbol for the key 1400 | \newcommand{\mapat}[2]{{#1}({#2})} 1401 | 1402 | % \maponeat projects the first element of the value of a map at some 1403 | % key. 1404 | % 1405 | % #1 : A pre-formatted symbol for the map, as as \tfont{\rho} 1406 | % #2 : A pre-formatted symbol for the key 1407 | \newcommand{\maponeat}[1]{\mapat{{#1}_1}} 1408 | 1409 | % \maptwoat is like \maponeat but projects the second element. 1410 | % The interface is the same 1411 | \newcommand{\maptwoat}[1]{\mapat{{#1}_2}} 1412 | 1413 | % \maprelat is like \maponeat but projects the third element, which is 1414 | % assumed to be a relation. 1415 | \newcommand{\maprelat}[1]{\mapat{{#1}_R}} 1416 | 1417 | %% Standard Source/Target formatting 1418 | \makeatletter 1419 | \newcommand*{\slang}{\@source-language-undefined} 1420 | \newcommand*{\tlang}{\@target-language-undefined} 1421 | \makeatother 1422 | 1423 | \makeatletter 1424 | \newcommand{\mathcolor}[2]{% 1425 | \begingroup 1426 | \colorlet{out}{.}\color{#1}#2\@ifnextchar_{\do@mathcolorsub}{\endgroup}% 1427 | } 1428 | \newcommand{\do@mathcolorsub}[2]{% 1429 | _{{\color{out}#2}}\@ifnextchar^{\do@mathcolorsup}{\endgroup}% 1430 | } 1431 | \newcommand{\do@mathcolorsup}[2]{% 1432 | ^{\color{out}#2}\endgroup 1433 | } 1434 | \makeatother 1435 | 1436 | % ------------- 1437 | % CIC Stuff 1438 | 1439 | % \ind formats an inductive declarations 1440 | % #1 : A pre-formatted name for the inductive. 1441 | % #2 : A pre-formatted meta-expression representing the number of parameters. 1442 | % #3 : A pre-formatted expression for the type of the inductive type. 1443 | % #4 : A pre-formatted local environment expression representing the constructor declarations. 1444 | \newcommand{\ind}[4]{#1\mathbin{:}\mathopen{[}#2\mathclose{]}#3\mathbin{:=}#4} 1445 | 1446 | % branch type computation 1447 | \newcommand{\brty}[2]{\{#1\}^{#2}} 1448 | 1449 | % annotated branch type 1450 | \newcommand{\abrty}[3]{\{#1\mathbin{:}#2\}^{#3}} 1451 | 1452 | % allowable elimination sorts judgment. 1453 | \newcommand{\aesjudg}[2]{[#1\mathpunct{\mid}#2]} 1454 | 1455 | % allowable elimination sorts, annotated, judgment. 1456 | \newcommand{\aesajudg}[3]{[#1\mathbin{:}#2\mathpunct{\mid}#3]} 1457 | 1458 | % recursive position 1459 | \newcommand{\recpos}[2]{RP (#1,#2)} 1460 | 1461 | % terminates judgment 1462 | \newcommand{\terminates}[2]{\wf{#1}{#2\text{ terminates}}} 1463 | 1464 | % guard condition 1465 | % based on Gim{\'{e}}nez 1466 | \newcommand{\guardjudg}[5]{\mathcal{D}_{#4} (#1,#2,#3,#5)} 1467 | 1468 | % ---------- 1469 | 1470 | \newcommand{\scolor}[1]{\mathcolor{blue}{#1}} 1471 | \newcommand{\tcolor}[1]{\mathcolor{red}{#1}} 1472 | 1473 | \newcommand{\sfonttext}[1]{\textsf{\scolor{#1}}} 1474 | \newcommand{\tfonttext}[1]{\textbf{\tcolor{#1}}} 1475 | 1476 | \newcommand{\sfont}[1]{\scolor{\mathsf{#1}}} 1477 | \newcommand{\tfont}[1]{\tcolor{\mathbf{#1}}} 1478 | 1479 | \newcommand{\sfontsym}[1]{\sfont{#1}} 1480 | \newcommand{\tfontsym}[1]{\tfont{\boldsymbol{#1}}} 1481 | 1482 | \newcommand{\scal}[1]{\sfontsym{\mathcal{#1}}} 1483 | \newcommand{\tcal}[1]{\tfontsym{\mathcal{#1}}} 1484 | 1485 | \newcommand{\sprime}{\scolor{\prime}} 1486 | \newcommand{\tprime}{\tcolor{\prime}} 1487 | 1488 | \endinput 1489 | -------------------------------------------------------------------------------- /test-acmart.tex: -------------------------------------------------------------------------------- 1 | \documentclass[format=acmlarge, screen, review, anonymous]{acmart} 2 | 3 | \citestyle{acmauthoryear} 4 | \usepackage[nosigplan]{mttex} 5 | 6 | \author{ttest} 7 | \affiliation{test} 8 | 9 | \title{Testy mc test} 10 | 11 | \begin{document} 12 | \maketitle 13 | 14 | \newlanguage{\scolor}{\sfont}{\sfontsym}{s} 15 | {x,e,v} 16 | {alpha/\alpha,ty/\sigma} 17 | {fun,bool,pi,sigma} 18 | {fun,app,if,true,false,fix,alet,dcase} 19 | 20 | \begin{mathpar} 21 | \sx 22 | 23 | \se 24 | 25 | \sv 26 | 27 | \svtwo 28 | 29 | \salpha 30 | 31 | \stypr[4] 32 | 33 | \sfunty{\styone}{\stytwo} 34 | 35 | \sfune{\sx}{\sty}{\seone} 36 | 37 | \sboolty 38 | \end{mathpar} 39 | 40 | \section{meow} 41 | 42 | \end{document} 43 | -------------------------------------------------------------------------------- /test-lang.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{mttex} 4 | \usepackage{upgreek} 5 | 6 | \newlanguage{\scolor}{\sfont}{\sfontsym}{s} 7 | {x,e,v} 8 | {alpha/\alpha,ty/\sigma} 9 | {fun,bool,pi,sigma} 10 | {fun,app,if,true,false,fix,alet,dcase} 11 | 12 | \newlanguage{\tcolor}{\tfont}{\tfontsym}{t} 13 | {x,e,v} 14 | {alpha/\alpha,ty/\tau} 15 | {fun,bool} 16 | {fun,app,if,true,false} 17 | 18 | \newcommand{\acolor}[1]{\textcolor{orange}{#1}} 19 | \newcommand{\afont}[1]{\mathsf{\acolor{#1}}} 20 | \newcommand{\afontsym}[1]{\afont{\boldsymbol{#1}}} 21 | 22 | \newlanguage{\acolor}{\afont}{\afontsym}{a} 23 | {y,x,e,v} 24 | {ty/A} 25 | {fun,bool,pair,sum} 26 | {fun,app,if,true,false,pair,prj,sum,case} 27 | \begin{document} 28 | 29 | \begin{mathpar} 30 | 31 | \sx 32 | 33 | \se 34 | 35 | \sv 36 | 37 | \svtwo 38 | 39 | \salpha 40 | 41 | \stypr[4] 42 | 43 | \sfunty{\styone}{\stytwo} 44 | 45 | \sfune{\sx}{\sty}{\seone} 46 | 47 | \sboolty 48 | 49 | \tfune{\tx}{\ttyone}{\teone} 50 | 51 | \asume{1}{\aepr} 52 | 53 | \asume{2}{\aepr} 54 | 55 | \acasee{\ae}{\ax}{\aeone}{\ay}{\aetwo} 56 | 57 | \sfixe{\sx}{\sty}{\se} 58 | 59 | \spity{\sx}{\sty}{\stypr} 60 | 61 | \ssigmaty{\sx}{\sty}{\stypr} 62 | 63 | \salete{\sx}{\se}{\sty}{\sepr} 64 | 65 | \sdcasee{\se}{\sein{m}}{\seone,\dots,\sein{n}} 66 | 67 | \end{mathpar} 68 | 69 | \renewcommand{\tlang}{\tfont{\uplambda}^{\tfont{\mu}}} 70 | \makeatletter 71 | \@section[Back-Translation]{\titlecap{Back-translation of} $\tlang$} 72 | \makeatother 73 | \subsection{A very cool title} 74 | \subsection{A very cool title} 75 | \subsection{A cool title} 76 | 77 | 78 | meow 79 | 80 | \end{document} 81 | -------------------------------------------------------------------------------- /test.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage[magicref]{mttex} 4 | 5 | \newcommand{\newtmetavar}{\newmetavar{\tfontsym}{\tcolor}{t}} 6 | \newcommand{\newsmetavar}{\newmetavar{\sfontsym}{\scolor}{s}} 7 | 8 | \newtmetavar{x} 9 | \newtmetavar{e} 10 | \newtmetavar*{alpha}{\tfontsym{\alpha}} 11 | \newtmetavar{v} 12 | \newtmetavar*{ty}{\tfontsym{\tau}} 13 | 14 | \newcommand{\newsmetavars}{\newmetavars{\sfont}{\scolor}{s}} 15 | \newcommand{\newsmetavarsS}{\newmetavarsS{\sfontsym}{\scolor}{s}} 16 | \newsmetavars{x, e, v} 17 | % TODO Star convention is difficult over lists 18 | %\newsmetavars*{x/x, e/e, v/v} 19 | \newsmetavarsS{ty/\sigma, alpha/\alpha} 20 | 21 | \newcommand{\stcolor}{\mathcolor{orange}} 22 | \newcommand{\stfont}[1]{\stcolor{\mathbf{#1}}} 23 | \newcommand{\stfontsym}{\stfont} 24 | 25 | \newcommand{\newstmetavars}{\newmetavars{\stfont}{\stcolor}{st}} 26 | \newcommand{\newstmetavarsS}{\newmetavarsS{\stfontsym}{\stcolor}{st}} 27 | \newstmetavarsS{x/x, v/v, e/e, world/W, alpha/\alpha} 28 | 29 | \newcommand{\trelV}{\lr{\tfontsym}{V}} 30 | \newcommand{\srelE}{\lr{\sfont}{E}} 31 | 32 | \newcommand{\newttypes}{\newtypes{\tfontsym}{\tfont}{t}{ty}} 33 | \newcommand{\newtexprs}{\newexprs{\tfontsym}{\tfont}{te}{}} 34 | \newttypes{fun,polyfun,forall,exist,mu,bool,unit,void,pair} 35 | \newtexprs{let,fun,polyfun,app,papp,abstr,inst,pack,unpack,fold,unfold,if,true,false,unit,pair} 36 | 37 | \newcommand{\tpfunty}{\tpolyfunty} 38 | 39 | \newcommand{\sfune}{\fune{\sfontsym}{\sfont}} 40 | \newcommand{\spolyfune}{\polyfune{\sfontsym}{\sfont}} 41 | \newcommand{\sabstre}{\abstre{\sfontsym}{\sfont}} 42 | \newcommand{\sinste}{\inste{\sfontsym}{\sfont}} 43 | \newcommand{\sappe}{\appe{\sfontsym}{\sfont}} 44 | \newcommand{\spappe}{\pappe{\sfontsym}{\sfont}} 45 | 46 | \newcommand{\sexistty}{\existty{\sfontsym}{\sfont}} 47 | 48 | \newcommand{\sife}{\ife{\sfontsym}{\sfont}} 49 | \newcommand{\spacke}{\packe{\sfontsym}{\sfont}} 50 | \newcommand{\sunpacke}{\unpacke{\sfontsym}{\sfont}} 51 | \newcommand{\slete}{\lete{\sfontsym}{\sfont}} 52 | \newcommand{\sfolde}{\folde{\sfontsym}{\sfont}} 53 | \newcommand{\sunfolde}{\unfolde{\sfontsym}{\sfont}} 54 | \newcommand{\sunite}{\unite{\sfontsym}{\sfont}} 55 | \newcommand{\struee}{\truee{\sfontsym}{\sfont}} 56 | \newcommand{\sfalsee}{\falsee{\sfontsym}{\sfont}} 57 | \newcommand{\spaire}{\paire{\sfontsym}{\sfont}} 58 | 59 | \newcommand{\txdubpr}{\txpr[2]} 60 | 61 | \newcommand{\sttfont}[1]{\mathit{#1}\!\!} 62 | \newmetavarsS{\mathit}{}{stt}{world/W} 63 | 64 | \begin{document} 65 | \tableofcontents 66 | \listoftodos 67 | \begin{mathpar} 68 | \metavar{\tfont{x}}{\tcolor{1}}{}{\tprime}{1} 69 | 70 | \metavar{\tfont{x}}{\tcolor{1}}{}{\tprime}{4} 71 | 72 | \txmetavar{}{}{0} 73 | 74 | \txmetavar{}{}{1} 75 | 76 | \tx 77 | 78 | \tx^1 79 | 80 | \tx^1_1 81 | 82 | 83 | %should cause an error 84 | %\txin{1}_1 85 | 86 | \txpr_1 87 | 88 | \tx'_1 89 | 90 | \tx'^1_1 91 | 92 | % should look worse than 93 | \tx\tfont{'}^1_1 94 | \txmetavar{1}{1}{1} 95 | 96 | \tx_1 97 | 98 | \tx^{+} 99 | 100 | \txpr 101 | 102 | \txdubpr 103 | 104 | \txpr[5] 105 | 106 | \txone 107 | 108 | \txonepr 109 | 110 | \txtwo 111 | 112 | \txtwopr 113 | 114 | \te 115 | 116 | \tvone 117 | 118 | \temetavar{}{}{0} 119 | 120 | \trelV{\tty} 121 | 122 | \srelE{\stypr} 123 | 124 | \lrV{\tfont}{\tty} 125 | 126 | \tfont{\Gamma} 127 | 128 | \tfontsym{\Gamma} 129 | 130 | \tfunty{\ttyone}{\ttytwo} 131 | 132 | \tpfunty{\talpha}{\ttyone}{\ttytwo} 133 | 134 | \tforallty{\talpha}{\tty} 135 | 136 | \texistty{\talpha}{\tty} 137 | 138 | \tmuty{\talpha}{\tty} 139 | 140 | \tunitty 141 | 142 | \tvoidty 143 | 144 | \tboolty 145 | 146 | \tpairty{\ttyone}{\ttytwo} 147 | 148 | \tefun{\tx}{\tty}{\teone} 149 | 150 | \tetrue 151 | 152 | \tefalse 153 | 154 | \sfune{\sx}{\sty}{\seone} 155 | 156 | \spolyfune{\salpha}{\sx}{\sty}{\sepr} 157 | 158 | \sabstre{\salpha}{\sty} 159 | 160 | \sinste{\se}{\sty} 161 | 162 | \sappe{\seone}{\setwo} 163 | 164 | \spappe{\seone}{\stypr}{\setwopr} 165 | 166 | \sife{\sv}{\seone}{\setwo} 167 | 168 | \spacke{\styone}{\se}{\sexistty{\salpha}{\stytwo}} 169 | 170 | \sunpacke{\salpha}{\sx}{\svpr}{\seone} 171 | 172 | \telet{\tx}{\te}{\teone} 173 | 174 | \slete{\sx}{\se}{\seone} 175 | 176 | \sfolde{\tmuty{\salpha}{\styone}}{\sty} 177 | 178 | \sunfolde{\seone} 179 | 180 | \sunite 181 | 182 | \struee 183 | 184 | \sfalsee 185 | 186 | \spaire{\seone}{\svtwopr} 187 | 188 | \stx 189 | 190 | \stalphaonepr 191 | 192 | \stxpr[100] 193 | \stxonepr[5] 194 | 195 | \ctxtyjudg{\tfont}{\tfont{\ectx}}{\tfont{\Gamma}}{\tty}{\tfont{\Gamma}}{\ttypr} 196 | 197 | \ciueqvjudg{\tfont{\Gamma}}{\te}{\tepr}{\tty} 198 | 199 | \ctxeqvjudg{\tfont{\Gamma}}{\te}{\tepr}{\tty} 200 | 201 | \rho 202 | 203 | \mapat{\rho}{\talpha} 204 | 205 | \maponeat{\rho}{\talpha} 206 | 207 | \maptwoat{\rho}{\talpha} 208 | 209 | \maprelat{\rho}{\talpha} 210 | 211 | \mapext{\rho}{\talpha}{\tty} 212 | 213 | \te \bnfdef \tx \bnfalt \tefun \tx \tty \te \bnfalt \teapp \te \tepr 214 | 215 | \sttworldin{1} 216 | W_1 217 | \metavar{\mathit{W}}{1}{}{}{0} 218 | \metavar{\mathit{W}}{\stcolor{1}}{}{}{0} 219 | 220 | \metavar{\stcolor{W}\!}{\stcolor{1}}{}{}{0} 221 | \stcolor{\mathit{W}}_{\stcolor{1}} 222 | \mathit{\stcolor{W}\!}_{\stcolor{1}} 223 | \mathit{W}_{\stcolor{1}} 224 | 225 | \stworldto{1} 226 | \sttworldto{1} 227 | W^1 228 | \mathit{W}^1 229 | 230 | \sttworld\!._2 231 | \metavar{\mathit{W}}{}{}{}{0}._2 232 | \metavar{W}{}{}{}{0}._2 233 | \metavar{\stcolor{W}\!}{}{}{}{0}._2 234 | W._2 235 | 236 | \end{mathpar} 237 | 238 | %{ 239 | % \newcommand{\meow}{meow} 240 | % 241 | %} 242 | %\meow 243 | 244 | \begin{proof} 245 | Meow 246 | \end{proof} 247 | 248 | \begin{proof}[invalid] 249 | Bark 250 | \end{proof} 251 | 252 | \todo{Finish proof} 253 | 254 | \subsubsection{Meow} 255 | Meow 256 | 257 | \section{Meow} 258 | \label{sec:meow} 259 | 260 | \begin{lemma}[Foo] \label{lem:foo} \end{lemma} 261 | \begin{lemma} \label{lem:anon} \end{lemma} 262 | 263 | Should be ``Foo'': \nameref{lem:foo} 264 | 265 | Should be ``'': \nameref{lem:anon} 266 | 267 | Should be ``Foo'' without a hyperlink: \nameref*{lem:foo} 268 | 269 | \fullref{lem:foo} produces ``Lemma 1.1 (Foo)''. 270 | 271 | \fullref{lem:anon} produces ``Lemma 1.2'' 272 | 273 | \fullref[Bar]{lem:anon} produces ``Lemma 1.2 (Bar)'' 274 | 275 | \fullref[]{lem:foo} produces ``Lemma 1.1'' 276 | 277 | \fullref*{Lemma}{lem:foo} produces ``Lemma 1.1 (Foo)''. 278 | 279 | \fullref*{Thing}{lem:foo} produces ``Thing 1.1 (Foo)''. 280 | 281 | \fullref*[]{Thing}{lem:foo} produces ``Thing 1.1''. 282 | 283 | 284 | \end{document} 285 | -------------------------------------------------------------------------------- /uptest.tex: -------------------------------------------------------------------------------- 1 | \documentclass{article} 2 | 3 | \usepackage{upgreek} 4 | \renewcommand{\lambda}{\uplambda} 5 | \renewcommand{\Lambda}{\Uplambda} 6 | \renewcommand{\pi}{\uppi} 7 | \usepackage{mttex} 8 | 9 | \begin{document} 10 | 11 | \newlanguage{\scolor}{\sfont}{\sfontsym}{s} 12 | {e,x,t} 13 | {} 14 | {fun} 15 | {fun} 16 | 17 | \(\sfune{\sx}{\st}{\se}\) 18 | 19 | \end{document} --------------------------------------------------------------------------------