TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. Join them; it only takes a minute:

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

The algorithmicx package defines two commands \Require and \Ensure for providing initial conditions. However, I'd like some custom commands such as \Assume, \Define, \Input, etc. At present, I merely rename the above two commands to something I want, like:


However, this is not really a good solution because

  1. it clutters the algorithm code and what I see in LaTeX is not what is output, which can be confusing if I forget to read the preamble.
  2. it's not useful when the number of custom definitions needed is more than the predefined ones.

How do I define a custom command equivalent to the above two in the algorithmicx package (I'm using algpseudocode)? The examples in the documentation seem to cover blocks like for ... end, etc., and not individual statements.

share|improve this question
up vote 14 down vote accepted

In the documentation you can find \algnewcommand. In relation \Require is defined as


So you can do:


Here is a complete example:

\INPUT foo
\Require $x\ge5$
\Ensure $x\le-5$
\State $x\gets x-1$

enter image description here

share|improve this answer
Ah, thanks :) I tried defining \algorithmicinput with \algnewcommand like you have, but my mistake was to follow it up with \newcommand without \item, which only messed up the layout. Now I realize what I should've done. – Lorem Ipsum Oct 3 '11 at 17:34
Why do we need two level of definition, what is the dfference when we simply write :\algnewcommand\INPUT{\item[{\textbf{INPUT:}}]} – DurgaDatta Nov 15 '13 at 5:24
@DurgaDatta: The advantages is the lower error rate. With \algorithmicinput you simple define the string to print. The command \INPUT also contains relevant definition -- in this simple case only \item. So the user can simply redefine \algorithmicinput. – Marco Daniel Nov 15 '13 at 10:32

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.