James
James

Reputation:

LaTeX \newcommand \par issue

When I assign a new command and call it at the beginning of a \par the space between the variable text and next word is missing.

\newcommand{\testcmd}{This is a test}

\par \testcmd foobar.

Will be rendered as:

This is a testfoobar.

\par foo \testcmd bar.

Renders fine as: foo This is a test bar.

Anyone come across this before and have a solution?

Thanks

Upvotes: 2

Views: 4210

Answers (2)

bastijn
bastijn

Reputation: 5953

Actually a much simpler answer would be to:

\newcommand{\testcmd}{This is a test}

\par \testcmd \ foobar.

Notice the extra "\ " before foobar (slash and space). No extra package needed. It is the same as the most common method for things like:

Mr.\ Smith
etc.\ and
Proc.\ Amer.\ Math.\ Soc.

Upvotes: 1

Laurynas Biveinis
Laurynas Biveinis

Reputation: 10848

I do not know the exact thing which is going on here but there are several ways to get that space back:

  1. \newcommand{\testcmd}{This is a test } % <- space before closing brace
  2. par \testcmd{} foobar % <- note {}
  3. The most verbose but the most robust way too:

    \usepackage{xspace}

    \newcommand{\testcmd}{This is a test\xspace}

Upvotes: 4

Related Questions