For annotating documents, I've defined a command like so:
\DeclareDocumentCommand \commment { o m } {%
\stepcounter{commentcounter}
\ifhidecomments
\else \IfNoValueTF{#1}{%
\textsf{\textcolor{Red}{\footnotesize[Comment:\;#2]}}%
}{%
\textsf{\textcolor{lightgray}{\footnotesize[Comment:\;#2]}}%
}%
\fi
}
In the text you can embed a comment by doing \comment{blah blah blah}
and it will render like [Comment: blah blah blah]
in the text, but in red. If you want the comment to render but in gray instead (to keep it around but indicate it's been addressed), you can do \comment[]{blah blah blah}
, i.e. pass an empty optional argument.
Now, what I want is to be able to hide all comments without a trace with a single command (as opposed to manually removing them). I have an if-else statement in my DocumentCommand that doesn't render the comment if \hidecommentstrue
is specified in the document. When I used that command, indeed all the comments are hidden. Unfortunately, it can mess with the spacing between words. For instance, if I have word1 \comment{blah} word1
and I do \hidecommentstrue
, there's extra space between word1
and word2
that is not there if I actually remove the \comment
.
Is there something I can add to my command that would fix this? Or is there no way around removing the comments manually?
Here is a minimum working example:
\documentclass{article}
\usepackage{lipsum}
\usepackage[dvipsnames]{xcolor}
\usepackage{totcount}
\newif\ifhidecomments
\newtotcounter{commentcounter}
\setcounter{commentcounter}{0}
\DeclareDocumentCommand \comment { o m } {%
\stepcounter{commentcounter}
\ifhidecomments
\else \IfNoValueTF{#1}{%
\textsf{\textcolor{Red}{\footnotesize[Comment:\;#2]}}%
}{%
\textsf{\textcolor{lightgray}{\footnotesize[Comment:\;#2]}}%
}%
\fi
}
% \hidecommentstrue
\begin{document}
\lipsum[1]
\comment{this is a comment}
\lipsum[1]
\end{document}