Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I want to check if a variable is empty or not in a custom command. This works well, as long as it contains "normal text" but as soon as there is an itemize environment, I get an error message:

\documentclass[11pt, a4paper]{scrartcl}

\usepackage[ngerman]{babel}
\usepackage{ifthen, paralist}

\begin{document}

\begin{compactitem}
\item Item 1
\item Item 2
\end{compactitem}

\newcommand{\equalsNothing}[1]{
\ifthenelse{\equal{#1}{}}{true}{false}
}

\equalsNothing{}
\equalsNothing{1}

\equalsNothing{ 
\begin{compactitem}
\item Item 1
\item Item 2
\end{compactitem}
}

\end{document}

How can I change the \equalsNothing-command, so that it correctly works also with that itemize-content?

share|improve this question

1 Answer 1

up vote 5 down vote accepted

The arguments of \equal are fully expanded and this of course causes problems with fragile commands, such as \begin.

Say

\newcommand{\equalsNothing}[1]{%
  \ifthenelse{\equal{\unexpanded{#1}}{}}{true}{false}%
}

In this way you look exactly whether there's something in the argument of \equalsNothing.

Don't forget to mask unwanted spaces with %. I'd also recommend to use xifthen instead of ifthen. For example, xifthen provides the test \isempty that doesn't expand its argument:

\newcommand{\equalsNothing}[1]{%
  \ifthenelse{\isempty{#1}}{true}{false}%
}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.