[Tex/LaTex] algorithmicrequire undefined when using algorithmicx

algorithmicxalgorithms

I was using algorithmic and algorithm to write algorithm:

\usepackage[noend]{algorithmic}
\usepackage{algorithm}
\renewcommand{\algorithmicrequire}{\textbf{Input: }}
\renewcommand{\algorithmicensure}{\textbf{Output: }}

and now I need to use algorithmicx instead of algorithmic, in order to use \algstore{myalg}. Since my algorithm is too long to fit in one page.

\usepackage{algorithm}
\usepackage{algorithmicx}
\algnewcommand\algorithmicinput{\textbf{Input:}}
\algnewcommand\algorithmicoutput{\textbf{Output:}}

After I compiled the Tex file, I got the following error:

! Undefined control sequence.
l.219 \REQUIRE

SO how to resolve the issue?

thanks

Best Answer

Consider using \Require instead of \REQUIRE. LaTeX is case-sensitive. Here's a small example with \Require which I made for my next LaTeX book, as a demo showing several features.

\documentclass{article}
\usepackage{dsfont}
\usepackage{algorithm}
\usepackage{algorithmicx}
\usepackage{algpseudocode}
\usepackage{mathtools}
\newcommand{\minbox}[2]{%
  \mathmakebox[\ifdim#1<\width\width\else#1\fi]{#2}}
\newcommand{\Let}[2]{\State $ \minbox{1em}{#1} \gets #2 $}
\algnewcommand{\Local}{\State\textbf{local variables: }}
\begin{document}
\begin{algorithm}
  \caption{Mandelbrot set}
  \label{alg:mandelbrot}
  \begin{algorithmic}[1]
    \Require{$c_x, c_y, \Sigma_{\max} \in \mathds{R},
      \quad i \in \mathds{N}, \quad i_{\max} > 0,
      \quad \Sigma_{\max} > 0$}
    \Function{mandelbrot}{$c_x, c_y, i_{\max},
              \Sigma_{\max}$}
      \Local{$x, y, x^\prime, y^\prime, i, \Sigma$}
      \Let{x, y, i, \Sigma}{0}
        \Comment{initial zero value for all}
      \While{$\Sigma \leq \Sigma_{\max}$
             and $i < i_{\max}$}
        \Let{x^\prime}{x^2 - y^2 + c_x}
        \Let{y^\prime}{2xy + c_y}
        \Let{m}{x^\prime}
        \Let{y}{y^\prime}
        \Let{\Sigma}{x^2 + y^2}
      \EndWhile
      \If{$i < i_{\max}$}
        \State \Return{$i$}
      \EndIf
      \State\Return{0}
    \EndFunction
  \end{algorithmic}
\end{algorithm}
\end{document}

Algorithm

For completeness, in the LaTeX-Community forum the question was posted in this thread: "How to continue displaying an algorithm if it is too long".