2 Answers
2

No package needed except fontenc for setting things like < properly. Parameters \lindent, \rthk, and \rindent control the space to the left of the rule, the rule thickness, and the space to the right of the rule, respectively.

After several failed attempts to allow special characters, I decided that for pseudo code, you might be able to survive without the use of special characters. The macro I introduce is \block{pre\\code}{indented\\code}{post\\code}.

EDITED to \ignorespaces and \unskip, so that % are not needed everywhere.

\documentclass{article}
\usepackage[T1]{fontenc}
\def\lindent{.5ex}
\def\rindent{2ex}
\def\rthk{1.5pt}
\newcommand\block[3]{\unskip%
\noindent\parbox[b]{\textwidth}{\strut\ignorespaces#1\strut}\\
\setbox0=\hbox{\parbox[b]{\textwidth}{\strut\ignorespaces#2\strut}}%
\hspace*{\lindent}\rule[-.5\dp\strutbox]{\rthk}{\ht0}\hspace{\rindent}\box0\\%
\parbox[b]{\textwidth}{\strut\ignorespaces#3\strut}%
\ignorespaces}
\begin{document}
\block{
function toto:\\
setup
}{
\block{
for i = 0 , i < 10, i++
}{
\block{
if i is a prime number
}{
print prime number\\
then do something else
}{
end if
}\\
some intermediate stuff\\
\block{
if i is a superprime number
}{
print superprime number\\
then really do something amazing
}{
end if
}
}{
end for
}
}{
finish up\\
end function
}
\end{document}

We're looking for long answers that provide some explanation and context. Don't just give a one-line answer; explain why your answer is right, ideally with citations. Answers that don't include explanations may be removed.