# How to use procedure in latex algorithm?

    %%%% ijcai21.tex

\typeout{IJCAI--21 Instructions for Authors}

% These are the instructions for authors for IJCAI-21.

\documentclass{article}
\pdfpagewidth=8.5in
\pdfpageheight=11in
% The file ijcai21.sty is NOT the same than previous years'
\usepackage{ijcai21}

% Use the postscript times font!
\usepackage{times}
\usepackage{soul}
\usepackage{url}
\usepackage[utf8]{inputenc}
\usepackage[small]{caption}
\usepackage{graphicx}
\usepackage{amsmath}
\usepackage{amsthm}
\usepackage{booktabs}
\usepackage{algorithm}
\usepackage{algorithmic}
\urlstyle{same}

\newtheorem{example}{Example}
\newtheorem{theorem}{Theorem}

\pdfinfo{
/TemplateVersion (IJCAI.2021.0)
}

\title{IJCAI--21 Formatting Instructions}

% Single author syntax
\author{
}

\begin{document}

\maketitle

\begin{algorithm}[tb]
\caption{Example algorithm}
\label{alg:algorithm}
\textbf{Parameter}: Optional list of parameters\\
\begin{algorithmic}[1] %[1] enables line numbers
\STATE Let $t=0$.
\WHILE{condition}
\STATE Do some action.
\IF {conditional}
\ELSE
\ENDIF
\ENDWHILE
\STATE \textbf{return} solution
\end{algorithmic}
\end{algorithm}

\end{document}


All I want to use the procedure contains input and the three statements.

• Welcome to TeX.SX! Can you explain what's going wrong or what you want to achieve? When I download ijcai21.sty from here and compile your file, everything works as expected. Dec 29 '20 at 23:47
• @gernot it is not working, i want to start my code with a procedure Dec 30 '20 at 9:52

If you want/have to use the algorithmic package, you have to define the procedure statement yourself. Put the following code into your preamble.

\usepackage{algorithmic}
\newcommand\algorithmicprocedure{\textbf{procedure}}
\newcommand{\algorithmicendprocedure}{\algorithmicend\ \algorithmicprocedure}
\makeatletter
\newcommand\PROCEDURE[3][default]{%
\ALC@it
\algorithmicprocedure\ \textsc{#2}(#3)%
\ALC@com{#1}%
\begin{ALC@prc}%
}
\newcommand\ENDPROCEDURE{%
\end{ALC@prc}%
\ifthenelse{\boolean{ALC@noend}}{}{%
\ALC@it\algorithmicendprocedure
}%
}
\newenvironment{ALC@prc}{\begin{ALC@g}}{\end{ALC@g}}
\makeatother


Use it as follows:

\PROCEDURE[optional comment]{proc name}{arguments}
...
\ENDPROCEDURE


If you use the algpseudocode package (which is based on the algorithmicx package), procedures are predefined.

Package "algorithmic"

\documentclass{article}
\usepackage{algorithmic}
\newcommand\algorithmicprocedure{\textbf{procedure}}
\newcommand{\algorithmicendprocedure}{\algorithmicend\ \algorithmicprocedure}
\makeatletter
\newcommand\PROCEDURE[3][default]{%
\ALC@it
\algorithmicprocedure\ \textsc{#2}(#3)%
\ALC@com{#1}%
\begin{ALC@prc}%
}
\newcommand\ENDPROCEDURE{%
\end{ALC@prc}%
\ifthenelse{\boolean{ALC@noend}}{}{%
\ALC@it\algorithmicendprocedure
}%
}
\newenvironment{ALC@prc}{\begin{ALC@g}}{\end{ALC@g}}
\makeatother
\begin{document}
\begin{flushleft}
\textbf{Parameter}: Optional list of parameters\\
\begin{algorithmic}[1] %[1] enables line numbers
\PROCEDURE[some comment]{MyProc}{$a,b\colon \mathrm{int}$}
\STATE Let $t=0$.
\WHILE{condition}
\STATE Do some action.
\IF {conditional}
\ELSE
\ENDIF
\ENDWHILE
\STATE \textbf{return} solution
\ENDPROCEDURE
\end{algorithmic}
\end{flushleft}
\end{document}


Package "algpseudocode"

\documentclass{article}
\usepackage{algpseudocode}
\begin{document}
\begin{flushleft}
\textbf{Parameter}: Optional list of parameters\\
\begin{algorithmic}[1] %[1] enables line numbers
\Procedure{MyProc}{$a,b\colon \mathrm{int}$}\Comment{some comment}
\State Let $t=0$.
\While{condition}
\State Do some action.
\If{conditional}