# How do I make conditions based on list options?

Specifically, I need to write a command which changes its behavior if the option wide is turned on... So I need some kind of condition

if wide is on then do this, else do that.


Can somebody point out how to do such condition in TeX ?

Pseudocode:

\documentclass{article}
\usepackage{enumitem}

\begin{document}
\begin{itemize}[wide]
\item
\if@wide \do "print{this list is wide} and change \rightmargin to 3cm"
\else \do "print{this list is not wide} and change \rightmargin to 2cm"
\fi
\end{itemize}
\end{document}

• The wide option doesn't activate a different branch of code, it just changes some internal parameters of enumitem. It's easy to make the code detect if the option was used, but I think you won't get anything useful here. What exactly do you want to achieve with that? – Phelype Oleinik Jun 28 at 19:19
• @PhelypeOleinik I need to change some lengths and variables based on if this option is on. – Lust_For_Love Jun 28 at 19:21

You can hook into the definition of the wide option and make your conditional true. The value of the conditional is reset after the environment.

Note also that the wide option takes an argument. If you pass none, then \parindent is used (i.e., \begin{itemize}[wide] is the same as \begin{itemize}[wide=\parindent]).

However you should not try to change enumitem's internal parameters (they are internal for a reason) in the document. You should stick to the key-value interface it provides.

Anyhow, here it is:

\documentclass{article}
\usepackage{enumitem}
\usepackage{etoolbox}

\makeatletter
\newif\ifwide
\patchcmd\enitkv@enumitem@wide
{\enit@align@left}% <- Search
{\widetrue\enit@align@left}% <- Replace
{}{\FailedToPatch}
\makeatother

\begin{document}
\begin{itemize}[wide]
\item
\ifwide \texttt{wide} was used
\else \texttt{wide} was NOT used
\fi
\end{itemize}
\begin{itemize}
\item
\ifwide \texttt{wide} was used
\else \texttt{wide} was NOT used
\fi
\end{itemize}
\end{document}


Here is a way you could use list styles, contained in macro settings.

\documentclass{article}
\usepackage{enumitem,lipsum}

\newenvironment{styledlist}[1][]
{\expandafter\itemize\expandafter[#1]}{\enditemize}

\def\widelist{wide,itemindent=15pt,label=*,leftmargin=-1cm,rightmargin=-1cm}
\def\narrowlist{itemindent=15pt,label=++,leftmargin=1cm,rightmargin=1cm}

\begin{document}
\begin{styledlist}[\widelist]
\item \lipsum[4]
\end{styledlist}

\begin{styledlist}[\narrowlist]
\item \lipsum[4]
\end{styledlist}
\end{document}


• No, I meant... I need this condition for my other macro command. I don't want to complicate my question with those so I wrote it like that... I just need a switch which would have different behaviour based on if option is wide on or not. I need to change some variables and lengths specifically... – Lust_For_Love Jun 28 at 19:23
• @Lust_For_Love See my edit, if that helps. – Steven B. Segletes Jun 28 at 19:26