2

In some generated code I got that the begin and end tag of a list were given but no item i.e.

\begin{list}{}{}
\end{list}

This leads to the message:

! LaTeX Error: Something's wrong--perhaps a missing \item.

See the LaTeX manual or LaTeX Companion for explanation.
Type  H <return>  for immediate help.
 ...

It is clear that this is due to a missing \item, but as it is generated code there are 2 possibilities:

  • the begin and end tag are not generated in case of no items present (preferred solution, but hard to find all places in the code)
  • adding an option to \begin{list} to make it possible to have no items, does this exist?

Full MWE:

\documentclass{book}

\begin{document}
% working
\begin{list}{}{}
\item the item
\end{list}
% giving error
\begin{list}{}{}

\end{list}

\end{document}
8
  • 2
    Note that the list environment takes two mandatory arguments, the syntax is \begin{list}{<label>}{<commands>} ... \end{list}. This won’t solve the problem, though, since you’ll now get the (correct! ;-) error message Something's wrong--perhaps a missing \item.
    – GuM
    Jul 28, 2018 at 9:59
  • 1
    Please tell us more about the ultimate typographic objective you're looking to achieve. LaTeX's list environment is a very low-level tool; most user-level list-like environments might build on and make use of the list environment, but they usually provide a lot of additional functionality for users. There may be better tools out there for you than the list environment. In short, do tell us what you're trying to achieve.
    – Mico
    Jul 28, 2018 at 10:03
  • @Mico this is generated code by doxygen for general lists (already packed in an own environment setting some lengths).
    – albert
    Jul 28, 2018 at 10:07
  • What should happen, exactly, when an empty list occurs? In particular, should some amount of vertical space be added between the text that comes before and that that follows?
    – GuM
    Jul 28, 2018 at 10:18
  • @GuM for the time being nothing should happen (so more or less ignoring the \begin and \end), but an answer with just a giving some space (or a text like "Empty List" ) would be preferred as it would give a direction for further development.
    – albert
    Jul 28, 2018 at 10:23

1 Answer 1

3

Caveat emptor

You could try this, but please note that it is a really crude hack:

\documentclass{article}
\usepackage{etoolbox}

\makeatletter

\patchcmd\endtrivlist
    {\if@newlist \@noitemerr \global\@newlistfalse \fi}
    {}
    {}{}
\patchcmd\endtrivlist
    {\@endparenv}
    {\if@newlist \@endpefalse \global\@newlistfalse \else \@endparenv \fi}
    {}{}

\makeatother



\begin{document}
Text before
\begin{list}{--}{}
\item the item
    \item another item
    \item \begin{itemize}
            \item a sublist
            \item second subitem
        \end{itemize}
    \item back to outer level
\end{list}
Text after

Text before
\begin{list}{--}{}
\end{list}
Text after\\
another line\\
still another\\
and another

\end{document}

You must log in to answer this question.

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