11

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.

lockstep
  • 250,273
  • 2
    By the way, both yours and @PeterGrill's examples have useless %'s: there's no need to put them after the control words \noindent or \ignorespaces. It's possible you were expecting the percent there to gobble spaces following the use of the macro, but in fact, that percent is removed (along with the following newline) when the macro itself is defined. Since spaces are ignored after control words anyway, it has no effect at all. On the other hand, you should take note of @Peter's use of % after the opening brace, which does have an effect. – Ryan Reich Dec 04 '11 at 01:27
  • What is the effect of the % after the opening brace? – Aaron Yodaiken Dec 04 '11 at 01:34
  • 1
    The % after the opening brace suppresses the space that will get inserted otherwise. I normall add a % at end of lines in the preamble even if they are not necessary as I learned my lesson in tex capacity exceeded if remove % after use of macro – Peter Grill Dec 04 '11 at 01:45

1 Answers1

14

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

lockstep
  • 250,273