[texhax] if condition: is macro body empty?

Philip G. Ratcliffe philip.ratcliffe at uninsubria.it
Thu Feb 12 11:02:59 CET 2009


Sorry, I should've been more carefully.  The following does work properly
(i.e., it's ok even when \buffer remains empty).  Evidently, \newcommand
does something strange (I left it in for the useual protection against
inadvertently overwriting a previous definition), but \def is obviously
cleaner.  The conditional should then also be \ifx and not \if.

\documentclass{article}

\newcommand\buffer{}
\def\buffer{}
\makeatletter
\newcommand{\fillbuffer}[1]{%
	\g at addto@macro{\buffer}{\item #1}%
}
\makeatother

\begin{document}

% create a list of items:
\fillbuffer{First part.}
\fillbuffer{Second part.}
\fillbuffer{Third part.}
\fillbuffer{Fourth part.}

% now print the item list:

This works:
\begin{itemize}
\buffer
\end{itemize}

Unfortunately I need some conditionals like this: 
\ifx\buffer\empty\else
  \begin{itemize}
    \buffer
  \end{itemize}
\fi

\end{document}

Cheers,   Phil



More information about the texhax mailing list