TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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
share|improve this question

migrated from stackoverflow.com Nov 8 '11 at 13:07

This question came from our site for professional and enthusiast programmers.

up vote 4 down vote accepted

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.

share|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}
share|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
@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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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