Coming back to this question after a few weeks, I was ultimately able to do what I wanted using the State
and Statex
commands of the algorithmicx
package, both of which allow you to just write a line of whatever text you want.
Statex
supresses line numbering if it's being used, so if you want lines in your algorithm that are sort of like headings and don't entail a step in the algorithm, then you can place bold text on a Statex
line and it works nicely. I realize that's not typical of pseudo-code, but what I was trying to make was fairly plain-english pseudo-code to outline a high-level algorithm.
Probably the user who asked this question is not interested in my answer anymore. But I was in the same quest didn't find any good-looking algorithm package (for my taste).
Since I'm a fan of the Listings package I followed Ruben's suggestion and created my own environment. Features:
- higlights my own specific keywords (but a predefined language can be used to that end)
- When defined a caption, it appears as "Algorithm x.y: the caption" where x is the number of the chapter and y is the number of the algorithm (but this is easily changed if chapter-level is not required)
Here follows the code to go in the preamble!
\usepackage{color}
\usepackage{listings}
\usepackage{caption}
\newcounter{nalg}[chapter] % defines algorithm counter for chapter-level
\renewcommand{\thenalg}{\thechapter .\arabic{nalg}} %defines appearance of the algorithm counter
\DeclareCaptionLabelFormat{algocaption}{Algorithm \thenalg} % defines a new caption label as Algorithm x.y
\lstnewenvironment{algorithm}[1][] %defines the algorithm listing environment
{
\refstepcounter{nalg} %increments algorithm number
\captionsetup{labelformat=algocaption,labelsep=colon} %defines the caption setup for: it ises label format as the declared caption label above and makes label and caption text to be separated by a ':'
\lstset{ %this is the stype
mathescape=true,
frame=tB,
numbers=left,
numberstyle=\tiny,
basicstyle=\scriptsize,
keywordstyle=\color{black}\bfseries\em,
keywords={,input, output, return, datatype, function, in, if, else, foreach, while, begin, end, } %add the keywords you want, or load a language as Rubens explains in his comment above.
numbers=left,
xleftmargin=.04\textwidth,
#1 % this is to add specific settings to an usage of this environment (for instnce, the caption and referable label)
}
}
{}
Now you can use as simple as follows:
\begin{algorithm}[caption={Integer division.}, label={alg1}]
input: int N, int D
output: int
begin
res $\gets$ 0
while N $\geq$ D
N $\gets$ N - D
res $\gets$ res + 1
end
return res
end
\end{algorithm}

Hope you enjoy as much as I did :P
Best Answer
Pseudocode has a different purpose compared to the actual programs. It should convey ideas, not implementation, and as such should be as close to the natural language as possible. Therefore I think it's not good to introduce programming language-specific syntax in the algorithm listing.
I suggest one of these options:
algorithmicx
and select a human-readable name for the operation:\State $x \gets \Call{ShiftLeft}{x, 3}$
;listings
package and typeset the actual C++ program with comments.