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:
Notes:
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 thatRedefining
\item
can be dangerous and have impredictable resultsEven 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.
Code:
\documentclass{article}
\usepackage{xparse}
\usepackage{tikz}
\usepackage{showframe}
\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
\IfNoValueTF{#2}{%
\item\tikzmark{MarkStart}%
}{%
\item[#2]\tikzmark{MarkStart}%
}%
}%
\begin{document}
\begin{enumerate}
\item item
\SpecialItem SpecialItem without optional param
\SpecialItem[\DrawLines] SpecialItem with optional param
\item item
\end{enumerate}
\end{document}