I would like to add a new command to an existing environment. The \renewenvironment command does not help a lot since I need to copy and paste the entire environment definition.

For an example I would like to make a \FORALL_P for the algorithmic environment such that instead of producing

forall ... do 

as original \FORALL, it produces

forall ... do in parallel

You can say

\newcommand{\algorithmicdoinparallel}{\textbf{do in parallel}}
  \newcommand{\FORALLP}[2][default]{\ALC@it\algorithmicforall\ #2\ %

The definition of \FORALLP is modeled on that of \FORALL; you can't call it \FORALL_P, however.

| improve this answer | |
  • Thanks, I tried to do this but failed, \makeatletter does the magic... – iKid Nov 8 '11 at 14:06

The etoolbox package offers you some commands that could be useful, for example:


Perhaps if you give us some mor information about your actual intent, we could provide more helpful information.

Now that new information has been provided in the question, I would suggest to use the algorithmicx package to define the new block; while the algorithmic package doesn’t allow you to easily modify predefined structures, or to create new ones, the algorithmicx package gives you full control over the definitions. Using algcompatible, you can have full compatibility with the syntax of the algorithmic package; a little example of the definition of the new block:


  {\textbf{for all }#1 \textbf{do in parallel}}%
  {\textbf{end for}}


\caption{A test algorithm}
\FORALL {$v \in V(G)$}
\STATE $l(v) \leftarrow \infty$
\FORALLP{$v \in V(G)$}
\STATE $l(v) \leftarrow \infty$


enter image description here

To have the \RETURN command as defined by algorithmic, you need to add the following definition:

\algloopdefx{RETURN}[1][]{\textbf{return} #1}
| improve this answer | |
  • thanks, I will look into etoolbox. I also added more info to my original post. – iKid Nov 8 '11 at 13:18
  • @iKid: please see my updated answer. – Gonzalo Medina Nov 8 '11 at 13:39
  • I failed to use the algorithmicx as they do not support \return ? – iKid Nov 8 '11 at 13:53
  • @iKid: I've added the corresponding definition. – Gonzalo Medina Nov 8 '11 at 14:00
  • 1
    @iKid: no problem. In fact, I thought that there was full compatibility (as algorithmicx advertises), but apparently it's not so "full". – Gonzalo Medina Nov 8 '11 at 14:06

In your specific case, using commands of the etoolbox package to change the look of the \FORALL statement might not work because you're trying to change the subsequent statement, viz. "do..."

The algorithmic package allows for a fair bit of customization of various algorithm-like statements. For example, you could issue the command

\renewcommand{\algorithmicdo}{\textbf{do in parallel}}

However, this will change the output of the "do" statement in all instances, which may not be to your liking.

| improve this answer | |

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.