Tuesday, February 12, 2008

Latex: lstlistings pseudo language

For my thesis I need to display a lot of algorithm to document the actions taken by peers talking a specific protocol. Since the thesis should present a theoretical view of the protocol itself and the algorithms, I do not want to display them in a specific language. I do want to use a pseudo language. Also I want the keyword of the language to be highlighted to ease the reading.

Here's the definition of my pseudo language to be used with lstlistings latex package:

\lstdefinelanguage{pseudo}{
morekeywords={if, else, for, in, remove, from, case, do, forever, to, False, True},
sensitive=true,%
morecomment=[l]\#,%
morestring=[b]',%
}
\lstset{language=pseudo}
\lstset{commentstyle=\textit}
\lstset{literate=
{<=} {$\le$}{2} {!=} {$\neq$}{2} {=} {$\leftarrow$}{2} {==} {=}{2} {&&} {$\cap$}{2} {||} {$\cup$}{2} }

This is an example of what your listing will look like:

1 comment:

Ivan said...

ql, I like it! thanks!