# blank lines break xparse or ifthen macro

Leaving blank line break simple macro but % terminating it fixes it. WTH is going on? I know one is suppose to use % BUT I can't have any blank lines in the macro without it complaining. A blank line essentially terminates the macro and TeX complains about a mixing }. Using etoolbox also produces the same problem so it seems it is an issue with xparse.

Is there any way to fix xparses package so I don't have to litter my code with %s?

\documentclass{book}

\usepackage{xparse, ifthen, etoolbox}

\DeclareDocumentCommand\iftb{m m G{\relax}}{\ifthenelse{\boolean{#1}}{#2}{#3}}

%\DeclareDocumentCommand\iftb{m m G{\relax}}{\ifbool{#1}{#2}{#3}}
\newboolean{A}\setboolean{A}{true}
\newboolean{B}\setboolean{B}{true}

\begin{document}

\iftb{A}{%
% <- remove all text on this line breaks macro (keep blank line)
\iftb{B}{%
asdffdsasdff
% <- same here
asdf
}
}

End
\end{document}


## 1 Answer

Macros defined with \DeclareDocumentCommand don't accept \par (or empty lines, which is the same) in their arguments.

You can overcome this behavior by adding + in front of an argument specifier that can possibly contain a \par:

\NewDocumentCommand\iftb{m +m +G{\relax}}{\ifthenelse{\boolean{#1}}{#2}{#3}}


or

\NewDocumentCommand\iftb{m +m +G{\relax}}{\ifbool{#1}{#2}{#3}}


The macros on which \ifthenelse and \ifbool are built already accept \par.

The question why \par is not accepted in macro arguments comes from the fact that this is the default behavior for macros, as Knuth imagined them.

A macro defined with

\def\macro#1{...}


doesn't accept \par in its argument. Knuth thought that this can catch the common error of forgetting the closing brace and wanted to avoid that such a mistake could lead to reading in all the current file looking for the closing brace.

However a macro definition can be prefixed by \long: so

\long\def\macro#1{...}


allows empty lines in the argument of \macro.



• Thanks, can you explain why, by default, \par and empty lines are not accepted? – AbstractDissonance Jul 22 '12 at 22:50
• @AbstractDissonance It is a feature built in to TeX at the most primitive level so that (in a latex context) a typo like \documentclass{article with no closing } stops at the first paragraph not the end of the document. – David Carlisle Jul 22 '12 at 22:57