[Tex/LaTex] Optional argument to \item

enumitemlistsoptional arguments

I am typesetting an ordered list where the entries may appear out of order, but should be assumed in order otherwise. I don't want to have to jump through \setcounter hoops to do this. That is, I want something like

\begin{enumerate}
  \item First
  \item Second
  \item[8] Eighth!
  \item Ninth!
  \item[4] Fourth
\end{enumerate}

to give the following Good output, instead of the Bad output:

Good and Bad outputs, as given by MWE below

A minimum working example follows.

\documentclass{article}
\usepackage{enumitem} % preferably something compatible with this guy
\begin{document}

Good:

\begin{enumerate}
  \item[1.] First
  \item[2.] Second
  \item[8.] Eighth!
  \item[9.] Ninth!
  \item[4.] Fourth
\end{enumerate}

Bad:

\begin{enumerate}
  \item First
  \item Second
  \item[8] Eighth!
  \item Ninth!
  \item[4] Fourth
\end{enumerate}

\end{document}

It should be noted that I don't want to have to specify the period afterwards, in case my list using a different numbering, e.g. Roman. Compatibility with enumitem is preferred, but not required.

What is the correct way of going about this?

Best Answer

You don't want to abuse the optional argument to \item; better defining a \nextitem command:

\documentclass{article}

\makeatletter
\newcommand\nextitem[1]{%
  \setcounter{\@enumctr}{#1}%
  \addtocounter{\@enumctr}{-1}%
}
\makeatother

\begin{document}
\begin{enumerate}
\item First
\item Second
\nextitem{8}
\item Eighth!
\item Ninth!
\nextitem{4}
\item Fourth
\end{enumerate}
\end{document}

enter image description here

Related Question