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.

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.

share|improve this question
    
Welcome to TeX.SE. –  Peter Grill Dec 4 '11 at 1:00
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 4 '11 at 1:27
    
What is the effect of the % after the opening brace? –  Aaron Yodaiken Dec 4 '11 at 1: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 4 '11 at 1:45

1 Answer 1

up vote 10 down vote accepted

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

share|improve this answer

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.