I want to create a custom enumerate environment specifically for algorithms:
The First \item should have the label Input:
The second \item should have the label Output:
From then on, have the standard (\arabic*) counter.
This is, what it should look like:
I got the counter offset to work, but I can't figure out how to check the counter for the two first items.
How can I do that?
I already tried all kinds of combinations of algo
, algoi
, thealgo
, \thealgo
and \value{...}
etc., all if which result in the following:
MWE:
\documentclass[a4paper,12pt]{article}
\usepackage{amsmath}
\usepackage{ifthen}
\usepackage[shortlabels]{enumitem}
\newcommand{\step}{
\ifthenelse{ \equal{\value{algoi}}{-2} }
{ \item[Input: ]}
{ \ifthenelse { \equal{\value{algoi}}{-1} }
{\item[Output: ]}
{\item }
}
}
\newenvironment{algo}{\begin{enumerate}[label=(\arabic*), start = -1]}{\end{enumerate}}
\begin{document}
\begin{algo}
\step This is the input.
\step This is the output.
\step This is step 1.
\step This is step 2.
\end{algo}
\end{document}
This code will throw the error message You can't use `\relax' after \the. \step
twice for each \step
.