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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

In my overkill solution to Enclose an entry in an enumerate list in parentheses there is spurious space at the beginning of some (not all) uses of \SpecialItem. I have narrowed it down to the MWE below where the macro \SpecialItem is defined with two optional first parameters, the first of which defaults to \DrawLines:

\NewDocumentCommand{\SpecialItem}{O{\DrawLines} o}{...code...}

In the \SpecialItem macro defined here, the first optional parameter is not used (the macro \DrawLines is not even defined). So, using:

\SpecialItem  ...text...

is just fine. But if I specify the first optional parameter:

\SpecialItem[\DrawLines]  ...text...

I get spurious space introduced following the \item's label as in the third list item:

enter image description here


  • If \tikzmark is not used, or defined to be {}, then there is no spurious space. I don't think this problem is related to \tikzmark as I have used that numerous time and not noticed this problem earlier.
  • Moving the \tikzmark to be before the \item also does not produce this spurious space. But, I need it to be after the label as I want a reference to the start of this \item, and not to the end of the previous \item.
  • In this answer to strange interaction between mdframed and item, egreg mentions that

    Redefining \item can be dangerous and have impredictable results

    Even though in the actual usage I am redefining \item, in this MWE \item is not redefined, just called via another macro. Hence, I do not think that the problem is related to this.



\newcommand{\tikzmark}[1]{\tikz[overlay,remember picture] \node (#1) {};}
%\renewcommand{\tikzmark}[1]{}%  Using this does not produce spurious space

\NewDocumentCommand{\SpecialItem}{O{\DrawLines} o}{%
    % #1 is not really used in this MWE, but is used in actual application

\item item
\SpecialItem SpecialItem without optional param
\SpecialItem[\DrawLines] SpecialItem with optional param
\item item
share|improve this question
up vote 6 down vote accepted

The usual \item command doesn't start horizontal mode, so a space after the closing ] of its optional argument is ignored.

The problem with your macro is that \item is followed by \tikzmark which calls \tikz which in turn starts horizontal mode. Now the space after ] in

\SpecialItem[\DrawLines] SpecialItem with optional param

is not ignored any more.


Add \ignorespaces:

\NewDocumentCommand{\SpecialItem}{O{\DrawLines} o}{%
    % #1 is not really used in this MWE, but is used in actual application
share|improve this answer

Your Answer


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.