1

When \item is inside a theorem-type environment, but not inside an enumerate or itemize environment, LaTeX does not give an error. Is there a way to make compiling stricter so that one receives an error when this happens?

Here is a minimal working example:

\documentclass{amsart}

\usepackage{enumitem}

\theoremstyle{plain}

\newtheorem{lemma}{Lemma}

\begin{document}

\begin{lemma} Hello

\item abcd \item This compiles without error. \end{lemma}

\end{document}

Here is the version of TeX that I'm using, if it's important:

This is pdfTeX, Version 3.141592653-2.6-1.40.24 (TeX Live 2022) (preloaded format=pdflatex

restricted \write18 enabled.

entering extended mode

Processing: test.tex LaTeX2e <2022-11-01> patch level 1

L3 programming layer <2023-02-22>

1 Answers1

2

If you try hard enough, you can probably do this:

\documentclass{amsart}

\usepackage{enumitem}

\theoremstyle{plain}

\newtheorem{lemma}{Lemma}

\begin{document}

\ExplSyntaxOn \makeatletter \AddToHook{cmd/item/before}{ \str_if_eq:VnT @currenvir {lemma} {\errmessage{oh~no}} } \makeatother \ExplSyntaxOff

\begin{lemma} Hello

\item abcd \item This compiles with error. \end{lemma}

\end{document}

Just a proof of concept, documentation in texdoc lthooks.

You may want to use \str_case or something else (e.g. use TeX's hash table for "constant"-time checking) if you want to check multiple environments etc. but compiling a whitelist (or a blacklist) appears to be unavoidable to me.

user202729
  • 7,143