TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

share|improve this question
\hfil \a\quad \b\unskip \hfil can handle the "empty \b" case. – Ulrike Fischer Jul 3 '14 at 13:07
up vote 11 down vote accepted

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

share|improve this answer

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



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

\hfil\a\ifnum\gluestretchorder\lastskip>0\else\quad\fi\b\unskip \hfil

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

\hfil\a\ifnum\gluestretchorder\lastskip>0\else\quad\fi\b\unskip \hfil

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

\hfil\a\ifnum\gluestretchorder\lastskip>0\else\quad\fi\b\unskip \hfil

\hfil balbalbablabl\hfil

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.