Skip to content

Instantly share code, notes, and snippets.

@lambdabetaeta
Last active June 24, 2024 11:00
Show Gist options
  • Save lambdabetaeta/37893248e39b7272be4c9d6956ec24d2 to your computer and use it in GitHub Desktop.
Save lambdabetaeta/37893248e39b7272be4c9d6956ec24d2 to your computer and use it in GitHub Desktop.
LaTeX macros for Call-by-Push-Value
%% LaTeX macros for Call-by-Push-Value
%% Alex Kavvos, 2021-2024
\ProvidesPackage{cbpv}[2023/01/11 cbpv-macros]
%% We require Jon Sterling's delimiters package for nice parentheses.
\RequirePackage{jmsdelim}
%% THE FOLLOWING MACROS REQUIRE THE USE OF **xparse**
%% I HIGHLY RECOMMEND YOU LEARN HOW TO USE IT
%% IT IS ONE OF THE FEW PACKAGES THAT MAKE LaTeX MORE BEARABLE
\RequirePackage{xparse}
%% We also need this to make pretty colours
\RequirePackage{xcolor}
%% This package requires lambda-macros for most of the lambda calculus
\RequirePackage{lambda-macros}
\definecolor{IdiotPurple}{RGB}{102, 51, 102}
\definecolor{FernGreen}{HTML}{467D5E}
\definecolor{ThroneBlue}{RGB}{51, 51, 102}
\definecolor{PermaRed}{RGB}{255, 102, 102}
\definecolor{DogwoodRose}{RGB}{204, 51, 102}
\definecolor{MaizeCrayola}{RGB}{255, 204, 102}
\definecolor{CommandPurple}{RGB}{135, 23, 77}
\definecolor{RegalBlue}{RGB}{3,69,117}
\definecolor{Marooon}{HTML}{573F0E}
\definecolor{Petrol}{HTML}{006D63}
\definecolor{ACMMatch1}{HTML}{006AC4}
\definecolor{ACMMatch2}{HTML}{694A00}
\definecolor{ACMMatch3}{HTML}{006768}
\NewDocumentCommand{\SuperscriptS}{mmm}{
\IfBooleanTF{#1}{\DelimPrn{#2}^{#3}}{#2^#3}
}
\NewDocumentCommand{\VTerm}{m}{{\color{ACMMatch1}{#1}}}
\NewDocumentCommand{\CTerm}{m}{{\color{ACMMatch2}{#1}}}
\NewDocumentCommand{\TmT}{m}{{\color{MaizeCrayola}{#1}}}
\NewDocumentCommand{\MTerm}{m}{{\color{ACMMatch3}{#1}}}
\RenewDocumentCommand{\Tm}{m}{\CTerm{#1}}
%%%%%%%%%%%%%%%%%%%% TYPES %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NewDocumentCommand{\CType}{m}{\DelimMin{1} \underline{#1}}
\NewDocumentCommand{\CAnd}{}{\mathbin{\binampersand}}
\NewDocumentCommand{\ReturnerT}{sm}{%
F\IfBooleanTF{#1}{\DelimPrn{#2}}{#2}
}
\NewDocumentCommand{\ThunkT}{sm}{%
U\IfBooleanTF{#1}{\DelimPrn{#2}}{#2}
}
%%%%%%%%%%%%%%%%%%%% TERMS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NewDocumentCommand{\Return}{sm}{%
\textsf{return}\;\IfBooleanTF{#1}{\DelimPrn{\VTerm{#2}}}{\VTerm{#2}}
}
% old fashioned, Moggi let-style bind
% \NewDocumentCommand{\Bind}{smmm}{%
% \textsf{bind}\
% #2
% \leftarrow
% \IfBooleanTF{#1}{\DelimPrn{#3}}{#3}\
% \textsf{in}\
% #4
% }
\NewDocumentCommand{\CTo}{smmm}{%
\IfBooleanTF{#1}{\DelimPrn{#2}}{#2} \textsf{ to } #3.\, #4
}
\NewDocumentCommand{\Thunk}{sm}{%
\textsf{thunk}\;\IfBooleanTF{#1}{\DelimPrn{\CTerm{#2}}}{\CTerm{#2}}
}
\NewDocumentCommand{\Force}{sm}{%
\textsf{force}\;\IfBooleanTF{#1}{\DelimPrn{\VTerm{#2}}}{\VTerm{#2}}
}
% value product
\NewDocumentCommand{\VTuple}{mm}{\DelimPrn{#1, #2}}
\NewDocumentCommand{\Split}{mmmm}{\textsf{split}\DelimPrn{\VTerm{#1}; #2, #3.\, #4}}
% computation product
\NewDocumentCommand{\CTuple}{mm}{\DelimGl{#1, #2}}
%%%%%%%%%%%%% ADDITIONAL TYPES AND TERMS %%%%%%%%%%%%%%%%%%%%%%%%%%%
% booleans
\NewDocumentCommand{\CIf}{mmm}{
\textsf{if } \VTerm{#1} \textsf{ then } #2 \textsf{ else } #3
}
\NewDocumentCommand{\Arb}{}{\textsf{arb}}
% natural numbers
\NewDocumentCommand{\CIfz}{mmmm}{\textsf{ifz}(\VTerm{#1}; #2; #3.\, #4)}
% application
\NewDocumentCommand{\CApp}{smm}{\IfBooleanTF{#1}{\DelimPrn{#2}}{#2}\DelimPrn{\VTerm{#3}}}
% finite choice type
\NewDocumentCommand{\FinT}{m}{\underline{\mathbf{#1}}}
\NewDocumentCommand{\Fin}{m}{\widehat{#1}}
\NewDocumentCommand{\CFinCase}{mm}{\textsf{case}\DelimPrn{\VTerm{#1}; #2}}
\NewDocumentCommand{\CFam}{mm}{\DelimMin{1} \DelimPrn{#1}_{#2}}
% indexed sums
% use \Inj[i] from lambda-macros for the introduction form
%\NewDocumentCommand{\IdxSumT}{mmm}{\DelimMin{1} \DelimPrn{#1 < #2} \times #3}
\NewDocumentCommand{\CCase}{mm}{\textsf{case}\DelimPrn{\VTerm{#1}; #2}}
\NewDocumentCommand{\CCaseG}{mmmm}{
\textsf{case}\DelimPrn{\VTerm{#1}; \DelimMin{1} \DelimPrn{#2.\, #3}_{#4}}
}
% algebraic effects
\NewDocumentCommand{\COp}{oO{\textunderscore}g}{%
\textsf{op}\IfValueT{#3}{\DelimPrn{\IfValueT{#1}{\VTerm{#1} ;}#2.\, #3}}
}
% value lists
\NewDocumentCommand{\ListT}{m}{
\textsf{list}\;#1
}
%%%%%%%%%%%%%%%%%%%%%%% TYPING JUDGMENTS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\NewDocumentCommand{\IsCTerm}{O{\Gamma}mm}{%
#1 \DelimMin{1} \vdash^\text{c} \CTerm{#2} : #3
}
\NewDocumentCommand{\IsVTerm}{O{\Gamma}mm}{%
#1 \DelimMin{1} \vdash^\text{v} \VTerm{#2} : #3
}
% the Amp versions are used in aligns, arrays, etc.
\NewDocumentCommand{\IsCTermEq}{O{\Gamma}mmm}{#1 \DelimMin{2} \vdash^\text{c} \CTerm{#2} = \CTerm{#3} : #4}
\NewDocumentCommand{\IsCTermEqAmp}{O{\Gamma}mmm}{\CTerm{#2} &= \CTerm{#3} : #4}
\NewDocumentCommand{\IsVTermEq}{O{\Gamma}mmm}{#1 \DelimMin{2} \vdash^\text{v} \VTerm{#2} = \VTerm{#3} : #4}
\NewDocumentCommand{\IsVTermEqAmp}{O{\Gamma}mmm}{\VTerm{#2} &= \VTerm{#3} : #4}
%%%% SUBSTITUTION
\NewDocumentCommand{\CSubst}{smmm}{%
\IfBooleanTF{#1}{\DelimBrk{\CTerm{#2}}}{\CTerm{#2}}\Meta{[\VTerm{#3}/\VTerm{#4}]}
}
\NewDocumentCommand{\VSubst}{smmm}{%
\IfBooleanTF{#1}{\DelimBrk{\VTerm{#2}}}{\VTerm{#2}}\Meta{[\VTerm{#3}/\VTerm{#4}]}
}
\NewDocumentCommand{\SubstTwo}{smmmmm}{%
\IfBooleanTF{#1}{\parens{#2}}{#2}\Meta{[\VTerm{#3}, \VTerm{#4}/\VTerm{#5}, \VTerm{#6}]}
}
\NewDocumentCommand{\IsTerminal}{m}{\CTerm{#1}\ \textsf{terminal}}
\NewDocumentCommand{\Terminal}{o}{\mathcal{T}_{#1}}
\NewDocumentCommand{\Terminals}{O{}}{\textsf{Tmn}\IfValueT{#1}{\DelimPrn{#1}}}
%%% VARIOUS SETS
\NewDocumentCommand{\Val}{g}{\mathsf{Val}\IfValueT{#1}{\DelimPrn{#1}}}
\NewDocumentCommand{\Comp}{g}{\mathsf{Comp}\IfValueT{#1}{\DelimPrn{#1}}}
\NewDocumentCommand{\FOType}{}{\textsf{FO}}
% \NewDocumentCommand{\FOVal}{o}{
% \textsf{FOVal}_{\IfNoValueTF{#1}{}{#1}}
% }
\NewDocumentCommand{\Term}{O{\CType{C}}}{
\textsf{Term}\DelimPrn{#1}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment