# How can I align this equation well?

I try formulate some lambda expression in lambda calculus. It is similar to a code, but I have to use align environment because it contains math symbols. I wonder how I can formulate its structures better? The current one has a lot of unneeded spaces in between, although it captures some of what I want it to look like.

\begin{align*}
\text{cell} = & \text{rec} (& \lambda b.&\lambda c.  &\lambda m.&  \\
&             & \text{if} &(\text{get?}&(m),      &  \\
&             &           & \text{seq} &(\text{send}&(\text{contents}(m), c), & \text{ready}(b(c))), \\
&             &           & \text{if}  &(\text{set?}&(m), & \\
&             &           &            & \text{ready}&(b(\text{contents}(m))), & \\
\end{align*} Here is what I want • Hi, may be You have image of what You wonna have as a result, it would be very nice Oct 17 at 20:28
• Thanks. Question updated.
– Ben
Oct 17 at 20:40
• Try replacing {align*} with {alignat*}{3} (I suppose you made the right calculation and have three alignment points). Oct 17 at 20:48
• Is it the last image an algorithm? Oct 17 at 20:54
• a lambda expression, using math symbol @Sebastiano
– Ben
Oct 17 at 20:54

\documentclass{article}
\usepackage{mathtools, amssymb}

\begin{document}

\begin{alignat*}{4}
\text{cell} ={} & \text{rec} ( & & \lambda\mathrlap{ b.\lambda c. \lambda m.} \\
& & & \text{if} &( & \mathrlap{\text{get?}(m),} \\
& & & & & \text{seq} &( & \text{send}(\text{contents}(m), c), \\
& & & & & & & \text{ready}(b(c))), \\
& & & & & \text{if}\:( & & \text{set?}(m),\\
& & & & & & & \text{ready}(b(\text{contents}(m))), \\
& & & & & & & \text{ready}(b(c)))))
\end{alignat*}

\end{document} It is a bit hard coding but easiest and enough fast (is it what You need?): \documentclass{article}
\usepackage{amsfonts}
\usepackage{amsmath}
\usepackage{amssymb}

\begin{document}
\begin{align*}
\text{cell} =  \text{rec} (&\lambda b.\lambda c.\lambda m.\\
&\text{if} (\text{get?}(m), \\
\end{align*}
\end{document}

• Thanks Looks good. Why does mine fail?
– Ben
Oct 17 at 21:16
• Sorry I don't understand Your question, You mean why Your code do not produse the same result as mine? or what? Oct 17 at 21:27

Probabily your code can be more fine if it is used lambdax package here on this link, https://ctan.org/pkg/lambdax

To work with this package you should download the lambdax.sty and keyparse.sty from your TeX distribuition (on MikTeX the answer is yes.)

Reading the explanation there is written This package provides Lambda expressions. that it is your objective.

Here there is a small example taken from https://github.com/rogard/lambdax/blob/main/testfiles/lambdax-001.lvt

\documentclass{article}
\usepackage{lambdax}
\begin{document}
\ExplSyntaxOn
\START
\box_new:N \l_tmp_box
\hbox_set:Nn \l_tmp_box{\LambdaX{(#1)}{x}}
\box_use:N \l_tmp_box
%\END
\ExplSyntaxOff
\end{document}