latex: xspace not suppressing space in combination with textit [closed]
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 11 years ago.
Improve this questionI put xspace at the end of most of my macros, e.g.
\newcommand*{\foobar}{foobar\index{foobar}\xspace}
but I just discovered that if the macro is placed inside textit
开发者_开发知识库, it does not work as expected, e.g.
Test 1: \foobar. Test 2: \textit{\foobar}.
produces
Test 1: foobar. Test 2: foobar .
with an extra space before the .
character. Of course I could make a duplicate non-xspace macro for these case, but can I fix this more properly in some way?
I found the answer "hidden" in /usr/share/texmf/doc/latex/tools/xspace.pdf:
Sometimes \xspace may make the wrong decision, and add a space when it is not required. There may be different reasons for this behavior but it can always be handled by following the macro with {}, as this has the effect of suppressing the space.
So
Test 3: \textit{\foobar{}}.
produces
Test 3: foobar.
精彩评论