# Infinitely shrinkable glue except if surrounded by text?

Say \a and \b are two macros that expand to some text and either one may be \empty but not both. I want to put \a and \b in a line, centered and separated by a \quad.

Problem: if one of \a or \b are \empty, then the \quad prevents the text from being properly centered. Ideally I would need some glue between \a and \b that would shrink to zero if it came in direct contact with infinitely stretchable glue.

-
\hfil \a\quad \b\unskip \hfil can handle the "empty \b" case. –  Ulrike Fischer Jul 3 '14 at 13:07

The definitions \a and \b can be tested, whether they are \empty:

\a
\ifx\a\empty
\else
\ifx\b\empty
\else
\fi
\fi
\b
-

You can remove the \quad before an empty \b with \unskip. You can test for an empty \a by checking the \gluestretchorder of \lastskip:

\documentclass[parskip=half-]{scrartcl}
\usepackage{lipsum}

\begin{document}
\lipsum[1]

\def\a{balbalbablabl} \def\b{balbalbablabl}