How can I make a math version of itemize, enumerate, and description environments?

tabular is to array as itemize is to …?

I'd like to have a list like

\documentclass{article}
\begin{document}
\begin{eqlist}
\item E=mc^2
\item e^{i\pi}+1=0
\item \text{ducks} + \text{caffeine}
= \text{\url{http://i.stack.imgur.com/GVksc.gif}}
\end{eqlist}
\end{document}


I'm already using enumitem, but I don't think that package will be of any help. Of course, any solution will work :)

Important variations:

• What about the other list environments – like description and enumerate?

Use Case

The use-case is pretty trivial, actually – to have a list of equations. You could call this 'for fun', but I have in the past actually hacked something together for class notes that allowed me to do something like this (e.g. listing out and naming the properties of algebraic groups). I had thought the idea was limited to that so I never generalized my (terribly messy) solution, but I'm seeing the pattern pop-up more and more in various documents where it actually doesn't look absolutely awful as you'd expect. Conveniently, I don't have any solid examples except this newbie document that popped up on reddit.com/r/LaTeX.

• Since there is no math declaration, you'll have to capture the \items and process them. – Werner Aug 1 '15 at 5:37
• There's no correspondent; use gather or align. Why would you need bullets or similar things? – egreg Aug 1 '15 at 6:24
• do, please, add to the question your reason for wanting to do this. perhaps a multiple choice situation? – barbara beeton Aug 1 '15 at 13:44
• @barbarabeeton See edit (and thanks for your spelling correction :) it was a late night). – Sean Allred Aug 1 '15 at 14:21
• That GIF made my day! <3 – Paulo Cereda Aug 1 '15 at 14:29

Here is a solution (it doesn't use, but I hope it will be compatible with enumitem)

Note: I don't understand what the OP want to do with display math

Limitation: blank lines not supported (this code will not work)

\begin{mathitem}
\item E=mc^2

\item e^{i\pi}+1=0
\item \text{ducks} + \text{caffeine}
= \text{\url{http://i.stack.imgur.com/GVksc.gif}}
\end{mathitem}


Complete code

\documentclass{article}
\usepackage{xpatch}

\usepackage{amsmath,url}
\usepackage{enumitem}

\makeatletter
\newcommand{\mtmathitem}{%
\xpatchcmd{\item}{\@inmatherr\item}{\relax\ifmmode$\fi}{}{\errmessage{Patching of \noexpand\item failed}} \xapptocmd{\@item}{$}{}{\errmessage{appending to \noexpand\@item failed}}}
\makeatother

\newenvironment{mathitem}[1][]{%
\itemize[#1]\mtmathitem}{$\endlist} %$

\newenvironment{mathenum}[1][]{%
\enumerate[#1]\mtmathitem}{$\endlist} %$

\newenvironment{mathdesc}[1][]{%
\description[#1]\mtmathitem}{$\endlist} %$

\begin{document}

\begin{mathitem}
\item E=mc^2
\item e^{i\pi}+1=0
\item \text{ducks} + \text{caffeine}
= \text{\url{http://i.stack.imgur.com/GVksc.gif}}
\end{mathitem}

\begin{mathenum}
\item E=mc^2
\item e^{i\pi}+1=0
\item \text{ducks} + \text{caffeine}
= \text{\url{http://i.stack.imgur.com/GVksc.gif}}
\end{mathenum}

\begin{mathenum}[label=\emph{\alph*})]
\item E=mc^2
\item e^{i\pi}+1=0
\item \text{ducks} + \text{caffeine}
= \text{\url{http://i.stack.imgur.com/GVksc.gif}}
\end{mathenum}

\begin{mathdesc}
\item[some] E=mc^2
\item[thing] e^{i\pi}+1=0
\item[else] \text{ducks} + \text{caffeine}
= \text{\url{http://i.stack.imgur.com/GVksc.gif}}
\end{mathdesc}

\end{document}


• (+1). Does it work with the amsmath environments? I mean could we have, say, an align environment, with the bullet aligned with the first line of the environment, while keeping equation tags on the right side? – Bernard Aug 1 '15 at 9:11
• @Bernard I didn't try. As I noted in the answer I don't understand what the OP want do with displaymath. – touhami Aug 1 '15 at 9:19
• The displaymath isn't rightly my idea – I was originally content to just center (\hfil content\hfil) the content. The document I wrote this question for (see edit) does use display-style mathematics, though. Whether I agree with the layout isn't really of consequence at the end of the day. It's not 'optimal', but it's also not terrible – the best thing to do would be do re-imagine how the information is presented, but that's not feasible in this situation. (Of course I imagine it would be unproblematic to insert a \displaystyle, but this doesn't help the centering.) – Sean Allred Aug 1 '15 at 14:25

(Answer modified to (i) add a "MathDescription" environment and (ii) demonstrate compatibility with the enumitem package.)

Here's a LuaLaTeX-based solution. It defines three new environments called MathItemize, MathEnumerate, and MathDescription. The environments work just like the "ordinary" itemize, enumerate, and description environments, except that all material (other than the descriptive labels in the MathDescription environment) is typeset in math mode instead of text mode.

If need be, \displaystyle can be inserted after \item in order to render an item's contents in displaymath mode. Use

\item \displaystyle \hfill <formula> \hfill


to center-set the display-math material.

The code appears to work very well with the enumitem package. To wit, the example below below loads the enumitem package and changes some of the default settings of the itemize and enumerate environments.

As the OP's write-up and comments do not seem to indicate a need for nested lists, the code works only for non-nested lists.

% !TEX TS-program = lualatex
\documentclass{article}
\usepackage{amsmath}      % for "\text" macro
\usepackage{url,hyperref}

%% Check compatibility with "enumitem" package...
\usepackage{enumitem}
\setlist{itemsep=1ex}
\setlist[itemize]{label=$\star$}
\setlist[enumerate]{label=\roman*), leftmargin=*, widest = iii}

\usepackage{luacode,luatexbase}
%% Lua-side code: Three Boolean variables, two new
%% functions, & calls to assign the new functions to
%% the "process_input_buffer" callback
\begin{luacode}
env_type_1 = false
env_type_2 = false
first_list_item = true

if (env_type_1 == true) then
if (first_list_item == true) then
line = string.gsub( line, "\\item", "\\item $" ) first_list_item = false else line = string.gsub( line, "\\item", "$ \\item $" ) end end return (line) end function change_item_properties_desc ( line ) if (env_type_2 == true) then if (first_list_item == true) then line = string.gsub( line, "(\\item.-%[.-%])", "%0$" )
first_list_item = false
else
line = string.gsub( line, "(\\item.-%[.-%])", "$%0$" )
end
end
return (line)
end

"MathModeItemizeEnumerate" )
change_item_properties_desc,
"MathModeDescription" )
\end{luacode}

%% TeX-side code -- Three new environments:
%% MathItemize, MathEnumerate, MathDescription
\newenvironment{MathItemize}%
{\directlua{ env_type_1 = true }
\begin{itemize} }%
{$\end{itemize} \directlua{ env_type_1 = false first_list_item = true}} \newenvironment{MathEnumerate}% {\directlua{ env_type_1 = true } \begin{enumerate}}% {$\end{enumerate}
\directlua{ env_type_1 = false
first_list_item = true}}
\newenvironment{MathDescription}%
{\directlua{ env_type_2 = true }
\begin{description}}%
{$\end{description} \directlua{ env_type_2 = false first_list_item = true}} \begin{document} \noindent A \verb+MathItemize+ list \begin{MathItemize} \item E=mc^2 \item e^{i\pi}+1=0 \item \text{ducks} + \text{caffeine} = \text{\url{http://i.stack.imgur.com/GVksc.gif}} \end{MathItemize} \bigskip\noindent An ordinary'' \verb+itemize+ list \begin{itemize} \item Hello world. \item Goodbye world. \end{itemize} \bigskip\noindent A \verb+MathEnumerate+ list \begin{MathEnumerate} \item a^2+b^2=c^2 \item \displaystyle \hfill \sum_{k=1}^\infty \frac{1}{k^2} = \frac{\pi^2}{6} \hfill \item 1+1=2 \end{MathEnumerate} \bigskip\noindent A \verb+MathDescription+ list \begin{MathDescription} \item [Einstein] \hfill E=mc^2 \hfill \item[Euler] e^{i\pi}+1=0 \item [Pythagoras] a^2+b^2=c^2 \end{MathDescription} \bigskip\noindent Finally, an ordinary'' \verb+enumerate+ list \begin{enumerate}[widest=ii] \item abcdef, and \item uvwxyz. \end{enumerate} \end{document}  Quick and dirty: \documentclass{article} \makeatletter \newif\if@mathitemize \newif\if@closemathitem \let\orig@item=\item \renewcommand{\item}{\if@closemathitem$\fi\orig@item\if@mathitemize\@closemathitemtrue$\fi} \newenvironment{mathitemize}{\@mathitemizetrue\itemize\@closemathitemfalse}{$\enditemize}
\makeatother

\begin{document}

\begin{itemize}
\item test
\item test2
\end{itemize}

\begin{mathitemize}
\item E=mc^2
\end{mathitemize}

\end{document}


• Do you need ifthen here? – user31729 Aug 1 '15 at 8:17
• Actually no.. Thanks. I'll change the post accordingly. – Philipp Imhof Aug 1 '15 at 8:19
• this does not work for more than one item – touhami Aug 1 '15 at 8:41
• I was about to make the same remark as @touhami; moreover, \@mathitemizefalse at the end of the environment is redundant (a group is about to end). – GuM Aug 1 '15 at 8:45
• My bad. I'll post an updated version in a short moment. Thanks for the remarks. – Philipp Imhof Aug 1 '15 at 8:59