3

I have an inlinetodo macro/command that is defined depending on a toggle:

\nottoggle{disableAnnotations}{
    \NewDocumentCommand \inlinetodo {m}{\pdfmarkupcomment[color=yellow]{[TODO: #1]}{}}
}{
    \NewDocumentCommand \inlinetodo {m}{}
}

As you see, the command does not make anything if disableAnnotations is enabled. But that is not entirely true. If I have

This is the first line.
\inlinetodo{Explain the issue here!}
Last line here.

Then there will be a larger space between "…first line." and "Last line…".

How can I avoid the space, so that the result will be equal to

This is the first line.
Last line here.

if annotations are disabled?

Flow
  • 1,013
  • 2
    That's the usual missing % at the line endings, which will avoid them acting as space. Try with \inlinetodo{Explain the issue here!}%. See https://tex.stackexchange.com/questions/7453/what-is-the-use-of-percent-signs-at-the-end-of-lines-why-is-my-macro-creat for more information – samcarter_is_at_topanswers.xyz Apr 13 '23 at 15:43
  • @samcarter_is_at_topanswers.xyz Silly me! I did not take inline todo as meaning what it says. I have tried a similar command with \ignorespaces but it gobbles one one side. I will delete my prior comment. – rallg Apr 13 '23 at 16:33
  • @rallg No worries, given that the question neither has a mwe nor shows the output, it is a bit hard to picture :) – samcarter_is_at_topanswers.xyz Apr 13 '23 at 16:39
  • I think this question does ask the same, but the only answer provided is \@bsphack\@esphack, whereas Ulrike's answer here lists several options, from which I went with a particular one that I refined to \ifhmode \unskip{} \fi. And from what I can tell \@bsphack\@esphack has some issues if it appears right after another \@bsphack\@esphack sequence. – Flow Apr 14 '23 at 09:43

1 Answers1

8

It depends what you want exactly:

\documentclass{article}

\begin{document}

This is the first line. Last line here.

\medskip \NewDocumentCommand \inlinetodo {m}{}

This is the first line. \inlinetodo{Explain the issue here!} Last line here.

This is the first line. \inlinetodo{Explain the issue here!}Last line here.

This is the first line.\inlinetodo{Explain the issue here!} Last line here.

\medskip \RenewDocumentCommand \inlinetodo {m}{\ignorespaces}

This is the first line. \inlinetodo{Explain the issue here!} Last line here.

This is the first line. \inlinetodo{Explain the issue here!}Last line here.

This is the first line.\inlinetodo{Explain the issue here!} Last line here.

\medskip \RenewDocumentCommand \inlinetodo {m}{\unskip}

This is the first line. \inlinetodo{Explain the issue here!} Last line here.

This is the first line. \inlinetodo{Explain the issue here!}Last line here.

This is the first line.\inlinetodo{Explain the issue here!} Last line here.

\medskip \makeatletter \RenewDocumentCommand \inlinetodo {m}{@bsphack@esphack} \makeatother

This is the first line. \inlinetodo{Explain the issue here!} Last line here.

This is the first line. \inlinetodo{Explain the issue here!}Last line here.

This is the first line.\inlinetodo{Explain the issue here!} Last line here.

\end{document}

enter image description here

Ulrike Fischer
  • 327,261
  • 1
    Thanks, I went with \NewDocumentCommand \inlinetodo {m}{\ifhmode \unskip{} \fi}. – Flow Apr 13 '23 at 19:15
  • Since this question will probably be closed as a duplicate, it would be good to add this answer to the original question, since such a comparison is still missing there. – dexteritas Apr 14 '23 at 10:44