# How to avoid the “perhaps a missing \item.” message in itemize/enumerate

If one has a itemize environment, with no items inside :

\begin{itemize}
\end{itemize}


the compilation will complain "perhaps a missing \item". I would like to modify the environment itemize (or enumerate) such that in case there is no \item, the compilation doest NOT fail, and simply display nothing.

EDIT I think that by trying to extract a MWE from my actual problem, i missed the point. So, i reformulated the question here.

-
Where is the sense in that (if the question is allowed)? –  Thorsten Donig Feb 7 '12 at 20:52
Maybe you are more interested in something like \trivlist\item\relax ... \endtrivlist –  Marco Daniel Feb 7 '12 at 20:54
maybe...if i knew what trivlist is... –  nicolas roy Feb 7 '12 at 20:55

You can deactivate it as follows, though I'm not really sure why anyone would want to do this!

\documentclass{article}
\makeatletter
\let\@noitemerr\relax
\makeatother
\begin{document}
Some text.
\begin{itemize}
\end{itemize}
More text.
\end{document}


If you need to reactivate it later, you need to save the original definition.

\documentclass{article}
\makeatletter
\let\@oldnoitemerr\@noitemerr %Save the command definition
\newcommand\noitemerroroff{\let\@noitemerr\relax}
\newcommand\noitemerroron{\let\@noitemerr\@oldnoitemerr}
\makeatother
\begin{document}
Some text.
\noitemerroroff
\begin{itemize}
\end{itemize}
More text.
%
\noitemerroron
\begin{itemize}
\end{itemize}
\end{document}

-
ok, and how can you reactivate it ? –  nicolas roy Feb 7 '12 at 21:03
I have edited my answer. –  Ian Thompson Feb 7 '12 at 21:08
It's quite funny to read it as no more items moron!. A little bossy for our good old pal LaTeX :P –  percusse Feb 7 '12 at 21:17

what do you actually want to happen?

Given

xxx

aaa\begin{itemize}\end{itemize}bbb

yyy


then do you want to get a middle paragraph of aaabbb as if the empty environment wasn't there? Do you want (just) a paragraph break, do you want a paragraph break and the display spacing that an itemize environment normally gets above and below?, or do you want (the distinctly odd) output that you actually get from LaTeX, but without the error message?

All those things are (probably) possible but some are easier than others.

-
I'm realizing, that extracting a MWE from my original code, i missed the essential point of my problem. So i have to reformulate the question. But yes, i want to get aaabbb. And for this, the solution of user946850 could work... –  nicolas roy Feb 7 '12 at 21:24

These environments are part of the LaTeX kernel, and thus not easily changeable or tweakable without delving into the implementation. (See Ian's answer.) One solution would be to define your own command and use the ifthen package:

\usepackage{ifthen}
\newcommand{\safeitemizecmd}[1]{%
\ifthenelse{\equal{#1}{}}{}{\begin{itemize}#1\end{itemize}}}%
}


Note that this solution expands the parameter #1 twice, just for checking if it's empty. You can avoid this by using \expandonce from the etoolbox package:

\usepackage{ifthen}
\usepackage{etoolbox}
\newcommand{\safeitemizecmd}[1]{%
\ifthenelse{\equal{\expandonce{#1}}{}}{}{\begin{itemize}#1\end{itemize}}}%
}


Then, \safeitemizecmd{\item ...} would typeset an itemized environment, and \safeitemizecmd{} would typeset nothing.

If you want to use an environment, use the command created above:

\newenvironment{safeitemize}{\safeitemizecmd\bgroup}{\egroup}


The \bgroup and \egroup commands are essentially equivalent to braces.

-
I don't think that itemize is part of plain TeX. –  Ian Thompson Feb 7 '12 at 20:59
Not part of, but maybe implemented in? –  krlmlr Feb 7 '12 at 21:00
Not exactly. Plain TeX is a format for TeX. LaTeX is another. See Levels of TeX. –  Ian Thompson Feb 7 '12 at 21:03
What would be the proper way to write it? –  krlmlr Feb 7 '12 at 21:05
I'd say that itemize is part of the LaTeX kernel. –  Ian Thompson Feb 7 '12 at 21:09