[Tex/LaTex] Which package to use for writing algorithms

algorithmscodelistingspseudocode

I am looking for a package that will allow me to write pseudocode
of algorithms. The pseudocode may include mathematical symbols, like
\forall, \in and subscripts. But I would like also to "talk" about
variables contained in the pseudocode in my text, so be able to say "In figure …
variable foobar corresponds .." and make the word foobar have the same appearance
as in the pseudocode example.

I found that with the listings package
I can add mathematical symbols by using: \begin{lstlisting}[mathescape]. The problem
with this package is that I don't know how to make just one word have the
same appearance as the words appearing inside \begin{lstlisting} ... \end{lstlisting}.

Any ideas how to do this?
Or perhaps of another package that will help solve the above
mentioned problem?

Best Answer

The lstlisting environment is part of the “listings” package.

Additionally to providing an environment for listings (\begin{lstlisting}) and a command to import code from files (\lstinputlisting), it also provides a command to highlight code inline: \lstinline.

Be aware, that \lstinline has some limitations though (and does not obay all options from lstset)