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

(This may be a duplicate, but I could not find an answer among the pile of similar questions...)

Suppose we have the following command:

% <month> <year> <month> <year>
\newcommand{\timeperiod}[4] {%
#1 #2 -- #3 #4%

As long as all arguments are provided, everything works fine. But were one to omit e.g. the second month argument (#3), an extra space would appear between the dash and the ending year:

June 2000 – July 2001
June 2000 –  2001

How could I suppress that extra space? Or better yet, how could I make LaTeX ignore any spacing between empty command arguments?

share|improve this question
up vote 10 down vote accepted

Let's see what happens:




(where I use to make spaces more visible). With


you get


Indeed consecutive spaces are reduced to one only when TeX is reading input and converting it to tokens; the definition text has already been tokenized, so those two spaces remain. You can avoid the double space by saying

  #1 #2 -- #3\unskip\space#4%

If #3 is empty, the \unskip will remove the space between -- and the (empty) argument. If #3 is not empty, \unskip will do nothing.

share|improve this answer
+1 Perfect! This does exactly what I want. I also appreciate the explanation... – thkala Jun 25 '12 at 8:46


\newcommand\timeperiod[4] {#1 #2 -- \ifx\relax#3\relax\else#3~\fi#4}

share|improve this answer
+1 This does work, although it is a bit complex... – thkala Jun 25 '12 at 8:45

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.