# Passing text containing linebreaks as command or environment parameter?

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?

-

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:

\newcommand{\mymacro}[1]{%
\begingroup
\def\temp{#1}%
\ifx\temp\empty
\endgroup
% empty
\else
\endgroup
% not empty
\fi
}

-
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

\ifthenelse{\isempty{\unexpanded{#1}}}{<true>}{<false>}


or resort to a different test like

\ifx\relax\detokenize{#1}\relax
<true>%
\else
<false>%
\fi


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

-