[texhax] if condition: is macro body empty?
Susan Dittmar
SDittmar at eureca.de
Wed Feb 11 19:04:57 CET 2009
Hi folk,
for (pdf)latex I am looking for a way to check whether the body of a macro
is empty or not. At the moment, I use a construct using \equal{}{<macro>},
but I have the impression that during evaluation of this construct some
ugly side effects occur. I am sure there must be a better way.
Here's a short example (the final thing is much more complex, the \buffer
being filled with parts of an \item list or with parts of a tabular):
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
\documentclass{article}
\usepackage{ifthen}
\newcommand{\buffer}{}
\makeatletter
% close to what I need:
\newcommand{\fillbuffer}[1]{%
\ifthenelse{\equal{\buffer}{}}%
{\g at addto@macro{\buffer}{#1}}
{\g at addto@macro{\buffer}{\newline #1}}
}
\makeatother
\begin{document}
Filling the buffer may be called or not, and done here.
\fillbuffer{First part.}
\fillbuffer{Second part.}
Now use the contents of this buffer:
\buffer
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Any ideas please?
Susan
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://tug.org/pipermail/texhax/attachments/20090211/8176cc2f/attachment.bin
More information about the texhax
mailing list