I am writing a text which references a whole bunch of Brazilian norms. All of these norms are prefixed with "NBR". I therefore created the following command
\newcommand*{\NBR}[1]{NBR #1\cite{NBR#1}}
This way, I can, anywhere in the text, simply type \NBR{6118} and it comes out in a standard (instead of accidentally alternating between NBR6118, NBR 6118, NBR-6118, etc). This also puts a citation next to the name, which I tend to find useful, since the text is usually of the form "According to Table 8.1 of NBR 6118...". This way, this saves me from referencing things by hand.
There are instances, however, where I'd rather not have this citation. For example, I may have "Though the equations may differ, international norms and NBR 6118 share similar concepts...", where the citation adds nothing.
I therefore thought of creating an asterisked version of command (\NBR*) which places the name but not the citation. After trying the naive path
\newcommand*{\NBR*}[1]{NBR #1}
and getting an error, I found that one must use different methods. The xparse package seemed promising, so I defined the following:
\NewDocumentCommand \NBR {s m}
{
\IfBooleanTF{#1}
{NBR #2}
{NBR #2\cite{NBR#2}}
}
which seems to do the trick. \NBR{6118} gives me the text with the citation, while \NBR* omits the cite. However, I noticed the end-result is different, with what seems to be additional spaces before and after the command in the \NewDocumentCommand version. The citation's automatic move after punctuation is also inhibited in the \NewDocumentCommand.
This is easily seen below:
With \newcommand

With \NewDocumentCommand

Is there a way of correcting this?
\newcommand{\NBR*}from the link shown, but I just couldn't figure out how to get the formatting right. But those comments (%) solved it. Many thanks! – Wasabi Aug 11 '14 at 20:14