[Tex/LaTex] No spacing between words in the pseudocode package

pseudocodespacing

I am using the pseudocode package for an algorithm. (Here is the documentation: Pseudo Code Package Documentation)

There is no spacing between normal text inside the pseudocode block. I have to manually insert \ after every word for spacing.

\documentclass{report}  
\usepackage{pseudocode}
\begin{document}
    This is a text area. Another text\\

\begin{pseudocode}{Celsius To Fahrenheit}{c}
f \GETS {9c/5} + 32\\
\RETURN{f}\\
\\

\BEGIN
 basic\ algo\ for\ nothing\\
 secondary\ algo
\END
\\\\

This\ is\ experimental\ text 
\\\\


\end{pseudocode}

Outside Pseudocode

\begin{pseudocode}{Name}{Parameter 1, 2 ,3}

\IF True
\THEN 
\BEGIN
    something\ to\ do\\
    or\ ther\ thing\ to\ do
\END
\ELSEIF otherwise
\THEN
\BEGIN
    Do\ other\ things\\
    Don't\ do\ something\ else
\END
\\

\FOR i \GETS 0 \TO 10
\DO something\ processing
\\

\WHILE not\ true \DO don't\ do\ it
\\\\

\REPEAT something 
\UNTIL exception
\\\\

\PROCEDURE{Procedure name}{proc\ params}
    something
\ENDPROCEDURE

\DO \BEGIN
1.something\\
2.anything\\
3.nothing\\
4.many\ things\\
5.everything
\END
\\

\REPEAT repeat something
\UNTIL some condition is met


\end{pseudocode}

\end{document}

But, according to the documentation it should automatically insert space between words in text. Please help, is there anyway to activate spacing? or any other having these problem? I really liked the output of this package.

Thanks!

Best Answer

The manual also says

Note that the contents of statements are typeset in math mode. Therefore, non-math mode text must be enclosed in an \mbox{}.

By using \mbox or \text (requires amsmath) for the text parts, it works. The manual is a bit wrong in the first examples actually, here is a code excerpt from pseudocode.tex, used to create the manual:

To form compound statements from simple statements, the {\em begin-end} 
construct is used as follows:
\begin{verbatim}
 \BEGIN
    some statement\\
    another statement\\
    yet another statement
 \END
\end{verbatim}
This generates the following:

\medskip
\begin{pseudocode}[display]{}{}
\BEGIN
\mbox{some statement}\\
\mbox{another statement}\\
\mbox{yet another statement}
\END
\end{pseudocode}

The first code will not create the output shown right after, as that uses \mbox, whereas the code example does not. Below is an example for your original code, where I've used both \text and \mbox. Stick to just one of them though. Consider also the \COMMENT macro that LaRiFaRi mentioned in a comment.

enter image description here

\documentclass{article}
\usepackage{pseudocode,amsmath}
\begin{document}
\begin{pseudocode}{Name}{Parameter 1, 2 ,3}
\COMMENT{This is experimental text} \\

\IF \mbox{using \texttt{mbox}}
\THEN 
\BEGIN
    \mbox{something to do}\\
    \mbox{or other thing to do}
\END
\ELSEIF \text{using \texttt{text}}
\THEN
\BEGIN
    \text{Do  other things}\\
    \text{Don't do something else}
\END
\end{pseudocode}
\end{document}
Related Question