# Make an item in itemize disappear if a condition is not met

Here is the MWE:

\documentclass{article}
\newcommand{\VarOne}{1500}
\begin{document}
I want this list to have item Two if VarOne is more than 1000. If it is not, this will be a two item list. By the way, I could not    get this to print VarOne with a backslash!
\begin{itemize}
\item One
\item Two only if VarOne is more than 1000.
\item Three
\end{itemize}
\end{document}


How do I achieve this?

• \ifnum\VarOne>1000\relax\item Two only if VarOne is more than 1000.\fi. More latex like variations exist too. – Ulrike Fischer Nov 25 '14 at 15:24
• to get \VarOne to print with a backslash, treat it as verbatim: \verb+\VarOne+. this will work in "open" text, though not in "moving" text such as a footnote. – barbara beeton Nov 25 '14 at 15:32

Ulrike Fischer gave a hint about low-level \ifnum query, this version uses the \ifnumgreater macro from the etoolbox package (and provides a comparison).

In my point of view, \VarOne should not be used as a macro but as a counter, as long only integer values are concerned.

\documentclass{article}
\newcommand{\VarOne}{1500}

\usepackage{etoolbox}%
\begin{document}
I want this list to have item Two if VarOne is more than 1000. If it is not, this will be a two item list. By the way, I could not    get this to print $$\backslash$$VarOne with a backslash!
\begin{itemize}
\item One
\ifnumgreater{\VarOne}{1000}{\item Two only if VarOne is more than 1000.}{}
\item Three
\end{itemize}

\renewcommand{\VarOne}{100}%
Once again -- without the 2nd argument
\begin{itemize}
\item One
\ifnumgreater{\VarOne}{1000}{\item Two only if VarOne is more than 1000.}{}
\item Three
\end{itemize}

\end{document}


Here is a mildly-automated version of your request using some magic from Order items in enumerate environment automatically:

\documentclass{article}
\usepackage{environ,etoolbox,multido}

% Taken from https://tex.stackexchange.com/a/128318/5764
\makeatletter
\newcounter{varoneitem}\newcounter{listcount}[varoneitem]
\let\olditem\item% Store regular \item macro
\NewEnviron{varoneitem}[1][0]{%
\stepcounter{varoneitem}% New orderenum environment (also resets listcount)
\g@addto@macro{\BODY}{\item\relax\item}% Used to delimit the items; last item identified by \item\relax\item
\def\item##1\item{% Redefine \item to capture contents
\def\itemarg{##1}%
\expandafter\ifx\itemarg\relax\else% Last item not reached
\stepcounter{listcount}% Next item being processed
\csgdef{varoneitem@\thevaroneitem @\thelistcount}{##1}% Store item in control sequence
\expandafter\item% Recursively continue processing items
\fi
}
\BODY% Process environment (save items)
\begin{itemize}
\multido{\i=1+1}{\value{listcount}}{%
\ifnum\i=#1\relax
\ifnum\VarOneCondition\relax
\olditem \csname varoneitem@\thevaroneitem @\i\endcsname
\fi
\else
\olditem \csname varoneitem@\thevaroneitem @\i\endcsname
\fi
}
\end{itemize}
}
\makeatother

\newcommand{\VarOne}{1500}
\newcommand{\VarOneCondition}{\VarOne>1000}

\begin{document}

I want this list to have item Two if \verb|\VarOne| is more than 1\,000. If it is not, this will be a two item list.
By the way, I could not get this to print \verb|\VarOne| with a backslash!

\begin{varoneitem}[2]
\item One
\item Two only if \texttt{\string\VarOne} is more than 1\,000.
\item Three
\end{varoneitem}

\renewcommand{\VarOne}{900}
\begin{varoneitem}[2]
\item One
\item Two only if \texttt{\string\VarOne} is more than 1\,000.
\item Three
\end{varoneitem}

\end{document}


The idea is to process the list twice. During the first iteration, all \items are collected and stored in macros. During the second iteration, items are output conditionally based on \VarOneCondition.

Since the process "captures" each \item in a macro, verbatim content should be passed differently. I've shown that in the example above as well.

The newly-created varoneitem environment takes an optional argument that identifies the number of the item to be suppressed conditionally. Other improvements are also possible, but I'm not sure what your end use-case is.