Skip to content

Instantly share code, notes, and snippets.

@gallais
Created May 18, 2026 15:35
Show Gist options
  • Select an option

  • Save gallais/d6ca99c65c9fc82ce47269351fca7570 to your computer and use it in GitHub Desktop.

Select an option

Save gallais/d6ca99c65c9fc82ce47269351fca7570 to your computer and use it in GitHub Desktop.
Using precedence to put parens in the right places
\documentclass[11pt]{article}
\usepackage{etoolbox}
\newcounter{fixity}
\newcommand{\withFixity}[2]{
\ifboolexpe{ test{ \ifnumless{ \value{fixity} }{ #1 } }
}{ \setcounter{fixity}{#1} #2
}{ \setcounter{fixity}{#1} (#2) }
}
\newcommand{\Abs}[2]{\withFixity{1}{\ensuremath{\lambda #1. #2}}}
\newcommand{\App}[2]{\withFixity{2}{\ensuremath{#1 #2}}}
\newcommand{\Var}[1]{\ensuremath{#1}}
\newcommand{\LC}[1]{\setcounter{fixity}{0} #1}
\begin{document}
\LC{\App{\Abs{x}{M}}{\App{\Abs{y}{N}}{P}}}
\LC{\Abs{x}{\App{\App{\Abs{x}{M}}{P}}{N}}}
\end{document}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment