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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I just tried to write some commands which used its argument to check whether they were empty (isempty{...} from package ifthen) or not. The problem was that the text to check contained a linebreak, and that screwed up the whole system and caused it to produce very strange error messages.

Is there a way to work around this and make it safe to pass text containing linebreaks as parameter to a command or environment?

share|improve this question
up vote 6 down vote accepted

The etextools package provides an expandable \ifempty{<text>}{<true>}{<false>} macro which works with newlines.

If you don't need the test to be expandable you can also use the following code:

       % empty
       % not empty
share|improve this answer
Why do you work with begingroup ... endgroup ? – Marco Daniel May 9 '11 at 15:49
@Macro: to make \temp local – Leo Liu May 9 '11 at 15:56
@Macro: As Leo already said, it is to make the assignment to \temp local, which is generally a good design decision. – Martin Scharrer May 9 '11 at 16:00
@Leo: I can't understand the background. \def works only inside \mymacro. During the writing of this comment I think the attention is to use \temp once more inside \mymacro. EDIT: Thanks Martin – Marco Daniel May 9 '11 at 16:03
@Macro: If you use several such macros uses \temp nestly, it is necessary. – Leo Liu May 10 '11 at 18:20

The \isempty test expands its argument; you may try


or resort to a different test like


In both cases #1 stands for the argument you want to test.

share|improve this answer

Your Answer


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.