Skip to content

Algorithms and pseudocode

Wrap the pseudocode in an algorithm environment with a \caption to get "Algorithm 1"; inside it, Scissor LaTeX reads algorithmic's upper-case commands (\STATE, \FOR) only in conference layouts, so for other documents put the steps in a verbatim block.

The algorithm environment

The algorithm package provides a numbered environment for pseudocode, like a figure: a \caption gives it a number ("Algorithm 1"), and a \label after the caption lets you refer to it with \ref. In Scissor LaTeX the algorithm stays where you write it and its caption is set below it.

What goes inside depends on the package you use for the steps, and that is where support differs:

PackageCommandsIn Scissor LaTeX
algorithmalgorithm environment, \caption, \labelWorks: numbered "Algorithm N", caption below.
algorithmic\STATE, \IF, \FOR, \WHILE, \RETURN ... (upper case)Partly: read only in documents with a conference layout; elsewhere they are unknown commands.
algpseudocode (algorithmicx)\State, \If, \For, \EndFor, \Return ...Not supported: skipped with a message, and the steps run together in one line.
algorithm2e\KwIn, \For{..}{..}, \eIf ...Not supported: skipped with a message.

Pseudocode that works everywhere

The most reliable way to show pseudocode in any Scissor LaTeX document is a verbatim block inside algorithm. You keep the number and caption, and the lines keep their indentation.

An algorithm with verbatim steps

LaTeXPreamble: \usepackage{algorithm}Open in editor (opens in a new tab)
\begin{algorithm}
\caption{Sum of a list}
\label{alg:sum}
\begin{verbatim}
s := 0
for each a in xs:
    s := s + a
return s
\end{verbatim}
\end{algorithm}
Algorithm~\ref{alg:sum} adds the numbers of a list.
Rendered by Scissor LaTeX: An algorithm with verbatim steps

For pseudocode with formulas, an lstlisting works the same way, or write the steps as ordinary text outside the algorithm environment, as a numbered list.

Steps as a numbered list, with math

\textbf{Input:} numbers $a_1, \dots, a_n$.
\begin{enumerate}
  \item Set $s \gets 0$.
  \item For $i = 1, \dots, n$: set $s \gets s + a_i$.
  \item Return $s$.
\end{enumerate}
Rendered by Scissor LaTeX: Steps as a numbered list, with math

algorithmic in conference layouts

The conference look-alike layouts (arXiv, IEEE, NeurIPS, ICML and the others) read the upper-case commands of the algorithmic package: keywords such as for, do, end for and return are set in bold, and each command starts a new line. Line numbers are not drawn, and the lines are centred. The Problems tab names the layout in use.

algorithmic in an arXiv-style document

\documentclass{article}
\usepackage{arxiv}
\usepackage{algorithm,algorithmic}
\begin{document}
\begin{algorithm}
\caption{Sum of a list}
\begin{algorithmic}
\STATE $s \gets 0$
\FOR{$i = 1$ to $n$}
  \STATE $s \gets s + a_i$
\ENDFOR
\RETURN $s$
\end{algorithmic}
\end{algorithm}
\end{document}
Rendered by Scissor LaTeX: algorithmic in an arXiv-style document

Problems tab: Layout in the style of the arXiv preprint style (final mode). Not official. To compile elsewhere, add arxiv.sty from github.com/kourgeorge/arxiv-style.

algpseudocode is not supported

algpseudocode, the most common package in recent papers, uses mixed-case commands such as \State and \EndFor. Scissor LaTeX does not know them: their names are skipped, the formulas and words are kept, and everything runs together in one line. The Problems tab lists the skipped commands.

algpseudocode: the steps run together

LaTeXPreamble: \usepackage{algorithm,algpseudocode}Open in editor (opens in a new tab)
\begin{algorithm}
\caption{Sum of a list}
\begin{algorithmic}[1]
\State $s \gets 0$
\For{$i = 1$ to $n$}
  \State $s \gets s + a_i$
\EndFor
\State \Return $s$
\end{algorithmic}
\end{algorithm}

Problems tab: Skipped 4 unknown commands: \State, \For, \EndFor, \Return

If you need the document to work both here and in a TeX installation, write the steps in verbatim as shown above; it compiles everywhere.

What differs from a TeX installation

The package page is algorithm, algorithmic and algpseudocode. The manuals are on CTAN: algorithms, algorithmicx and algorithm2e.

See also algorithm packages, Code listings and Conference layouts.

Questions and answers

How do I write an algorithm in LaTeX?

Use the algorithm environment with a \caption, and put the steps inside. In Scissor LaTeX the steps work best in a verbatim block, or with algorithmic's \STATE commands in a conference layout.

Why do my \State lines run together?

\State comes from algpseudocode, which Scissor LaTeX does not support. The command names are skipped, so the steps join into one line. Use verbatim for the steps instead.

Can I refer to an algorithm by number?

Yes. Put \label{alg:name} after the \caption and write Algorithm~\ref{alg:name}.

Every example on this page is typeset by Scissor LaTeX when the site is built. Last updated 2026-11-06.