0

I've defined a macro using xparse to have one or two arguments, and to use different commands depending on the number of arguments given. It's been working very well until I had to put one of the macros inside parenthesis, then there's a space added before the closing parenthesis.

MWE:

\documentclass{article}
\usepackage[utf8]{inputenc}
\usepackage{xparse}

\title{xparse MWE}

\NewDocumentCommand\Da{m+g}{%
    \IfNoValueTF{#2}
        {#1 Dalton}
        {#1 Dalton to #2 Dalton}
}

\begin{document}
\section*{No parenthesis}
Number: \Da{10000} and range: \Da{20000}{30000}
\section*{Parenthesis with xparse}
Number: (\Da{10000}) and range: (\Da{20000}{30000})
\section*{Parenthesis without xparse - the expected result}[![enter image description here][1]][1]
Number: (10000 Dalton) and range: (20000 Dalton to 30000 Dalton)
\end{document}

Output:

Result

  • 1
    You have a stray space: you need % after Dalton}. Probably that makes the question a dupe of the general 'when to use %' one. – Joseph Wright Mar 19 '19 at 13:34
  • https://tex.stackexchange.com/questions/7453/what-is-the-use-of-percent-signs-at-the-end-of-lines – Joseph Wright Mar 19 '19 at 13:35
  • Right, I was not aware of the need for % signs inside macro definitions. Thank you very much for the answer and the link with the info! – Rui Apóstolo Mar 19 '19 at 14:10

0 Answers0