0

I'll go straight to the MWE:

\documentclass{article}
\newcommand\mymacro{\MakeUppercase{this is my macro}}
\begin{document}
Foo \mymacro bar.
\end{document}

In my understanding, this should produce Foo THIS IS MY MACRO bar., but instead I get Foo THIS IS MY MACRObar., using both xelatex and pdflatex.

What is wrong with the macro above?

  • 1
    Why is that wrong? Spaces after macros are gobbled. –  Sep 14 '18 at 23:06
  • 1
    TeX ignores spaces after control sequences (commands), so if you type \mymacro bar or \mymacro bar TeX will print THIS IS MY MACRObar. This is because if it didn't ignore spaces, it wouldn't know that what \mymacrobar is. If you want spaces after control sequences you can use \mymacro\ bar or \mymacro{} bar or use xspace as Bernard suggested... – Phelype Oleinik Sep 14 '18 at 23:13

1 Answers1

2

Use \xspace:

\documentclass{article}
\usepackage{xspace} 
\newcommand\mymacro{\MakeUppercase{this is my macro}\xspace}


\begin{document}

Foo \mymacro bar.

\end{document}

enter image description here

Bernard
  • 271,350