How do you write pseudocode in the style below? I tried using the verbatim environment but I can't seem to get the variables italicized and symbols like \in to work. I also tried using the algorithmic and algorithm2e packages but they seem much more restrictive than the style used in this book.
Asked
Active
Viewed 185 times
2
-
Have you checked the docs, e.g for algorithm2e? You can set the style of every keyword, function,... individually. – ttnick Jan 07 '21 at 16:47
-
I will keep looking in the docs. I guess I'm mainly posting just in case I'm overthinking something really simple. The psuedocode in the text basically reads like regular English so I was hoping there was some straightforward way to go about this. – nvi Jan 07 '21 at 17:02
1 Answers
1
Maybe you don't need an extra algorithms package and the tabbing environment (standard LaTeX) suffices.
\documentclass{article}
\newcommand\tab{\hspace{1.5em}}
\begin{document}
{\ttfamily
\begin{tabbing}
\tab\=\tab\=\tab\=\tab\=\tab\=\tab\=\kill
Initially, all $m\in M$ and $w\in W$ are free\\
While there is a man $m$ who is free and hasn't proposed to every woman\\
\>Choose such a man $m$\\
\>Let $w$ be the highest-ranked woman in $m$'s preference list\\
\>\>to whom $m$ has not yet proposed\\
\>If $w$ is free then\\
\>\>$(m,w)$ become engaged\\
\>Else $w$ is currently engaged to $m'$\\
\>\>If $w$ prefers $m'$ to $m$ then\\
\>\>\>$m$ remains free\\
\>\>Else $w$ prefers $m$ to $m'$\\
\>\>\>$(m,w)$ become engaged\\
\>\>\>$m'$ becomes free\\
\>\>Endif\\
\>Endif\\
Endwhile\\
Return the set $S$ of engaged pairs
\end{tabbing}%
}
\end{document}
gernot
- 49,614

