# How can one put a “[” after \item?

The following does not compile because of the "[" after the \item. I presume it is because LaTeX expects a "]" as per the \item[option] syntax. However, I just want to insert the "[" character into the text as the first character of the enumerated item.

\documentclass[oneside,12pt]{article}

\begin{document}

\begin{enumerate}

\item before

\item [ random text

\item after

\end{enumerate}

\end{document}


I would like LaTeX to generate a document:

before

[ random text

after

One way I've come up with is to put a \  in front of the "[", however I'd appreciate thoughts on the least invasive way to do this.

-

## migrated from stackoverflow.comFeb 5 '12 at 1:21

This question came from our site for professional and enthusiast programmers.

What you've done is initializing the displaymath environment. –  Crowley May 24 '10 at 10:33

Just like whenever you want to put a special character (such as a space, or something else) after a command, you can use the {} to suppress the next character.

\item{}[your random text

-
Another option is to insert some other command, such as \relax (which does nothing at all) between \item and the bracket. –  Jouni K. Seppänen Feb 5 '09 at 7:55
@JouniK.Seppänen I don't like the {} tweak, because it looks like that it is an argument of \item, which is not true. So I agree with Jouni that \relax is a good option. –  yo' Feb 5 '12 at 21:50

\item looks ahead for the [ character in its definition using \@ifnextchar [:

\def\item{%
\@inmatherr\item
\@ifnextchar [\@item{\@noitemargtrue \@item[\@itemlabel]}}


This is done to enable an optional argument for \item. In that sense, using anything other than [ before using [ would suffice.

If you never use the optional argument for \item, you could remove it from its definition and use something different like \Item. That way you can use [ without worrying about it:

\documentclass{article}
\makeatletter
% Remove optional argument from \item
\newcommand{\Item}{\@inmatherr\item\@noitemargtrue\@item[\@itemlabel]}
\makeatother
\begin{document}
\begin{enumerate}
\Item before
\Item [ random text
\Item after
\end{enumerate}
\end{document}


The \item renewal removes the conditional "peeking" for a [ in the input stream, setting the default optional argument to be the regular label. As mentioned, if you never use it in any of your lists, this should be no problem.

-
Beware, for this to be safe it's not enough that you never use \item[]. You must also not use any commands or environments that use this internally. latex.ltx uses this for theorems and bibliography items for example, and probably several packages do likewise. –  David Carlisle Feb 5 '12 at 11:18
An alternative would be to create an \Item command that does not have optional arguments, and use that. –  Brian M. Hunt Feb 5 '12 at 13:18
Sorry, but this is bad advice when a simple {} is enough. –  Martin Schröder Feb 5 '12 at 14:53
@DavidCarlisle: Thanks, I forgot about "other" things... in that sense, @ BrianMHunt's suggestion is better. I've updated my answer. –  Werner Feb 5 '12 at 15:29