Macros – How to Avoid Whitespace After a Macro Which Takes Arguments

macrosspacing

I have a macro that (simplified) is defined like this:

\newcommand{\mymacro}[1]{
     %use #1
     \par\noindent%
}

I'd like to be able to use it like

\mymacro{Arg 1}
Beginning of paragraph

However, my output PDF file has a bit of horizontal space before the B when I do this.

To get rid of it, I must call it like

\mymacro{Arg 1}Beginning of paragraph

which is not ideal.

If I change \mymacro to not take any arguments, the space goes away too—but I need to be able to take arguments.

Best Answer

Use \par\noindent\ignorespaces in the macro's definition.

\documentclass{article}

\newcommand{\mymacro}[1]{%
  use #1%
  \par\noindent\ignorespaces
}

\usepackage{lipsum}

\begin{document}

\mymacro{Arg 1}
Beginning of paragraph: \lipsum[1]

\end{document}

enter image description here

Related Question