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.

It's in the title -- I am looking for a macro to insert spaces. I would like to call \mycmd{032911} to get 03 29 11.

share|improve this question
add comment

1 Answer

up vote 13 down vote accepted
\def\mycmd#1{\dostartmycmd#1\dostopmycmd}

\def\dostartmycmd#1#2#3#4#5#6\dostopmycmd
    {#1#2\space
     #3#4\space
     #5#6}
share|improve this answer
    
What is the role of \dostopmycmd here? In my (admittedly limited) testing I get the same results with and without it. Would you care to explain this more? –  cefstat Mar 29 '11 at 7:38
3  
@cefstat: The end-marker makes TeX read everything up to it. If the user gives more than six digits all of them would be read as part of #6. Without the end-marker all further content would not be read, which doesn't matter in your case, but might cause wrong results in other cases, e.g. when you also want to change the font for the numbers. –  Martin Scharrer Mar 29 '11 at 12:31
1  
+1. In this specific case, as long no access to the single digits is required, it could also be written as \def\dostartmycmd#1#2#3#4#5\dostopmycmd {#1#2\space #3#4\space #5}, which might be slightly more efficient. –  Martin Scharrer Mar 29 '11 at 12:31
    
@Martin Scharrer: Thanks for the explanation! –  cefstat Mar 29 '11 at 12:40
add comment

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.