Aligned, hanging indents in non-monospaced code

There are various ways to accomplish this:

  1. You can use \phantom{<arg>} to leave as much space as taken up by <arg>. So in this case you would do:

    \phantom{swap a b x = }of tuple a b y z. let x' = tuple b a z y

    \phantom{swap a b x = of tuple a b y z. }in x'

    \phantom{} will take up as much horizontal and vertical space as its parameter. There is also a \vphantom{} which takes up as much vertical space as its parameter but zero horizontal space, and a corresponding \hphantom{} that takes up as much horizontal space as its parameter but zero vertical space.

  2. As @egreg commented, you can also use the tabbing environment as shown below.

  3. As @cmhughes commented you could also use tabular.


Each of these yield similar results:

enter image description here

Notes:

  • Although the tab spaces are hard coded below, they could easily be computed using \widthof{} available with the calc package. Or better still, see solution provided by egreg which shows how to use tabbing properly.
  • Since a MWE was not provided, I guessed at the definitions.

Code:

\documentclass{article}
\usepackage{amsmath}

\newcommand{\Case}{\mathsf{case}}%
\newcommand{\Let}{\mathsf{let}}%
\newcommand{\Swap}{\mathsf{swap}}%
\newcommand{\Tuple}{\mathsf{Tuple}}%
\begin{document}
\noindent
$\Swap : \forall\alpha,\beta.\;\Tuple\;\alpha\;\beta\to\Tuple\;\beta\;\alpha$

\noindent
$\Swap : \alpha,\beta x = \Case\; x$

\noindent
$\phantom{\Swap : \alpha,\beta x ={}}of \;\Tuple\; \alpha \beta y z. \;\Let\; x' = \Tuple\; \beta \alpha z y$

\noindent
$\phantom{\Swap : \alpha,\beta x = of \;\Tuple\; \alpha \beta y z.}\in x'$

\begin{tabbing}
\hspace{0em}\=\hspace{6.5em}\=\hspace{6.8em}\=\kill
%
\>$\Swap : \forall\alpha,\beta.\;\Tuple\;\alpha\;\beta\to\Tuple\;\beta\;\alpha$\\

\>$\Swap : \alpha,\beta x ={}$\>$\Case\; x$\\

\>\>$of \;\Tuple\; \alpha \beta y z. \;\Let\; x' = \Tuple\; \beta \alpha z y$\\

\>\>\>$\in x'$
\end{tabbing}

\noindent
\begin{tabular}{l@{}l@{}l@{}}
\multicolumn{3}{l}{$\Swap : \forall\alpha,\beta.\;\Tuple\;\alpha\;\beta\to\Tuple\;\beta\;\alpha$}\\
$\Swap : \alpha,\beta x ={}$&$\Case\; x$\\
&$of \;\Tuple\; \alpha \beta y z. \;$&$\Let\; x' = \Tuple\; \beta \alpha z y$\\
&&$\in x'$
\end{tabular}
\end{document}

With tabbing one can set dynamically the tab stops:

\begin{tabbing}
$\mathsf{swap} : \forall\alpha,\beta.\;\mathsf{Tuple}\;\alpha\;\beta\to\mathsf{Tuple}\;\beta\;\alpha$\\
$\mathsf{swap}\;\alpha\;\beta\;x={}$%
  \=$\mathsf{case}\;x$\\
  \>$\mathsf{of}\;\mathsf{Tuple}\;\alpha\;\beta\;x\;z.\;$%
    \=$\mathsf{let}\;x'=\mathsf{Tuple}\;\beta\;\alpha\;z\;y$\\
  \>\>$\mathsf{in}\;x'$
\end{tabbing}

With \= one sets a tab stop valid from that line onwards, with \> we go to the next tab stop.

enter image description here

It's also possible to cancel tab stops previously set by using again \=.