Take the 2-minute tour ×
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.

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

\hfil\a\quad\b\hfil

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
1  
\hfil \a\quad \b\unskip \hfil can handle the "empty \b" case. –  Ulrike Fischer Jul 3 at 13:07

2 Answers 2

up vote 9 down vote accepted

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

\a
\ifx\a\empty
\else
  \ifx\b\empty
  \else
    \quad
  \fi
\fi
\b
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:

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


\begin{document}
\lipsum[1]

\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

\end{document}
share|improve this answer

Your Answer

 
discard

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.