4

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.

3
  • 2
    Where is the sense in that (if the question is allowed)? Feb 7, 2012 at 20:52
  • Maybe you are more interested in something like \trivlist\item\relax ... \endtrivlist Feb 7, 2012 at 20:54
  • maybe...if i knew what `trivlist` is... Feb 7, 2012 at 20:55

3 Answers 3

5

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}
3
  • ok, and how can you reactivate it ? Feb 7, 2012 at 21:03
  • I have edited my answer. Feb 7, 2012 at 21:08
  • 2
    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, 2012 at 21:17
1

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.

1
  • 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... Feb 7, 2012 at 21:24
1

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.

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .