Set math mode as default for each item in list

\documentclass{article}
\begin{document}
\begin{enumerate}
\item $x + y = z$
\item $e^{i\pi} + 1 = 0$
\end{enumerate}
\end{document}


I have a long list in which 95% of the entries are to be written in math mode. I'd rather not have to wrap each entry with $...$ again and again. Is there any way to set the default mode to math mode just for the list entries?

• May be for that tasks package is better suited. In any case, it would be great to have in tasks also what you propose of math mode by default. – Manuel May 1 '16 at 20:38
• – clemens May 1 '16 at 21:50
• @Manuel this is now implemented in v0.11 of tasks (available on CTAN): \begin{tasks}[item-format=\ensuremath] – clemens May 4 '16 at 8:35
• @clemens You could add an answer to this question. – Manuel May 4 '16 at 9:05
• @Manuel done :) – clemens May 4 '16 at 9:10

Here's a enumitem way and a patch that starts $$ after item and ends $$ before \item or at the end of the environment, checking with \ifmmode whether we are in math mode or not.

Note: \item[...] is not catched here! -- Since the patch is inside the environment group, all other \item definitions in other environments are not changed.

It's possible to jump out of math mode with \item $Non math content, but perhaps a \item \text{Non math stuff} would be better then! The automatic math mode works with any math content, that expects the math mode, i.e. a \begin{pmatrix}...\end{pmatrix} would also be possible. \documentclass{article} \usepackage{enumitem} \newlist{mathlist}{enumerate}{1} \setlist[mathlist,1]{label={\arabic*.}} \usepackage{xpatch} \AtBeginEnvironment{mathlist}{% \xpretocmd{\item}{\ifmmode\)\fi}{}{} \xapptocmd{\item}{\ifmmode\else$$\fi}{}{} } \AtEndEnvironment{mathlist}{% \ifmmode$$\fi% Close math mode } \begin{document} \begin{mathlist} \item x + y = z \item e^{i\pi} + 1 = 0 \item E=mc^2 \item \)Non math - mode % Jumping out of math-mode \end{mathlist} \begin{enumerate} \item Foo % It's regular and not in math mode! \end{enumerate} \end{document}  • It's you again with your xpatch wizardry! Thanks for an answer. – Synergist May 1 '16 at 21:52 • @Synergist: Patching is easier here than redefinition of \item -- but I should provide another (better) version to catch \item[...] as well. – user31729 May 1 '16 at 21:54 You can create a command like \mathitem that you would use in place of \item when you want that the current item contains only math: \newcommand\mathitem[1]{\item$#1$}  Your lists will look like this: \begin{itemize} \mathitem{1+1=2} \mathitem{e^{i\pi}+1=0} \end{itemize}  • This is my best option so far. It's still slightly inconvenient as my editor autocompletes \item when I hit Enter while in the list environment. I'm probably spending more time nitpicking than I would ever save, but it'd be nice to have to have a wrapper around the environment that sets math mode as the default for each entry rather than doing as you said. Still, thanks for your suggestion. – Synergist May 1 '16 at 20:45 • You simply replace typing a pair of dollars with typing a pair of braces… – Bernard May 1 '16 at 20:48 • I'd like to be able to do \begin{mathItemize} { \item 1, \tem 2, ... } \end{mathItemize} rather than having to do \begin{itemize} { \mathitem 1, \mathitem 2, ...} \end{itemize}, or, even worse, having to do\begin{itemize} {\item$1$, \item$2$, ... } \end{itemize}. Does that make sense? – Synergist May 1 '16 at 21:03 Here's a LuaLaTeX-based solution, which works with both enumerate and itemize environments. It does not actually modify the enumerate and itemize environments, it doesn't modify the \item macro, and it doesn't require the use of a new macro called, say, \mathitem. How does the solution work, then? It takes a preprocessor approach: It sets up a Lua function which, by being assigned to the process_input_buffer callback, acts as a preprocessor, scans each line of input, and -- if (and only if!) it's inside an enumerate or itemize environment -- adds $ symbols as needed at the start and end of the scope of each \item. All this happens before TeX starts its normal work. Put differently, from the point of view of TeX's "eyes" (let alone "mouth" and "stomach"), it's as if all the required $ symbols had been entered by hand all along. What if you have one or more \items whose content should not be treated as needing to be in math mode? For such \items, you could write either \item$ An item without math.  $ or, if the amsmath package is loaded, \item \text{An item without math.}  Which assumptions does this approach make regarding the formatting of the contents of the tex file? The only restrictive assumption is: The directives \begin{enumerate}, \begin{itemize}, \end{enumerate}, \end{itemize}, and \item must occur on separate lines. Hopefully, this assumption isn't all that restrictive. If you need to suspend the operation of the Lua function at some point in the document, just insert the instruction \addmathOff. Conversely, to restart the Lua function later on in the document, insert the instruction \addmathOn. % !TEX TS-program = lualatex \documentclass{article} \usepackage{amsmath} % for "bmatrix" environment and "\text" macro %% Lua-side code \usepackage{luacode} \begin{luacode} in_list_env = false at_first_item = false function add_dollar_symbols ( buff ) if string.find ( buff, "\\begin{enumerate}" ) or string.find ( buff, "\\begin{itemize}" ) then in_list_env = true at_first_item = true elseif string.find ( buff , "\\end{enumerate}" ) or string.find ( buff , "\\end{itemize}" ) then in_list_env = false buff = "$"..buff
elseif in_list_env == true then
if at_first_item == true then
at_first_item = false
• @Zoxume - I've modified the code to provide an \item that features a bmatrix environment. – Mico May 2 '16 at 16:46

With version 0.11 of tasks it is possible to say item-format=\ensuremath:

\documentclass{article}
\begin{document}

This is some text.
\task x + y = z
\task e^{i\pi} + 1 = 0
This is some text.