4

I'm using the following packages:

\usepackage{algpseudocode}
\usepackage{algorithm}

but I don't understand what package is algpseudocode, since I can't find the documentation. I have followed this page. What's the difference between it and algorithmicx?

Also, how do I make calls inside a function (e.g. a recursion?) without using \text{...} (the font will be different and it does not look like a function). Here is an example:

\begin{algorithm}
\begin{algorithmic}[1]
\Function {foo}{$a$}
...
\State \Return \text{foo($a-1$)}
\EndFunction
\end{algorithmic}
\end{algorithm}

And how do I make a new line (for instance if a \text{...} is too long)?

Finally, how do I define a \TRUE macro (like the algorithmic package)?

Thanks in advance.

  • 4
    algpseudocode is part of algorithmicx package, loads algorithmicx also. Excerpt of algorithmicx's documentation "The main difference is that while the algorithmic package doesn’t allow you to modify predefined structures, or to create new ones,the algorithmicx package gives you full control over the definitions". Related tex.stackexchange.com/q/63450 – texenthusiast Aug 27 '13 at 12:23
  • 1
    may be something like this \newcommand{\TRUE}{\textbf{true}} in preamble as done in algorithmic.sty or may be flag based \algdef provided by algorithmicx for defining macro. – texenthusiast Aug 27 '13 at 12:59
  • 1
    If \TRUE is only a keyword that can appear inside an algorithm, as I suppose, the right definition is \algnewcommand\TRUE{\textkeyword{true}\space} – karlkoeller Aug 27 '13 at 13:43
  • 2
    Thanks to both of you, \algnewcommand\True{\textbf{true}} did the trick :) – Simon Aug 27 '13 at 15:09
  • 1
    @Simon You are right, \textkeyword is defined only if you load algpascal or algc. Anyway, leave \space at the end if something can follow \True. – karlkoeller Aug 27 '13 at 15:21
6

Thanks to the help of texenthusiast and karlkoeller I solved everything.
algpseudocode is part of algorithmicx package (documentation).
For nested function I just did

\begin{algorithm}
\begin{algorithmic}[1]
\Function {foo}{$a$}
...
\State \Return \Call{foo}{$a-1$}
\EndFunction
\end{algorithmic}
\end{algorithm}

To split a long line

\State \parbox[t]{.7\linewidth}{a very very very very very very very very very very very long line}

And for the \True macro I added \algnewcommand\True{\textbf{true}\space} at the beginning of the document.

Here's a fully compilable code:

\documentclass{report}
\usepackage[noend]{algpseudocode}
\usepackage{algorithm}
\algnewcommand\True{\textbf{true}\space}
\algnewcommand\False{\textbf{false}\space}
\begin{document}
\begin{algorithm}
\begin{algorithmic}[1]
\Function {foo}{$a$}
\State \parbox[t]{.7\linewidth}{a very very very very very very very very very very very long line}
\State \Return \Call{foo}{$a-1$}
\EndFunction
\end{algorithmic}
\end{algorithm}
\end{document}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.