1

I would like to create a command \comment{} which would not compile anything inside of { }.

Why would I not use % or \begin{comment} bla bla \end{comment} from the \usepackage{comment}? Because I want to put some text inside brackets and comment it.

The reason I want to do this is because I have a lot of text in red using \textcolor{red}{bla bla} and I would like to redefine \textcolor{red} so that I can delete everything in red from my document (note that I have a lot of parts in red...).

In a nutshell, my current code

x=x+1 \\
\textcolor{red}{
    I don't want to see this
}

produces this

enter image description here

Instead I would like it to produce this

enter image description here

without having to comment manually every part with \textcolor{red}. I would instead like to redefine this command so that it would comment the text in red.

Note: I want the red text not to be compiled and not to appear invisible, creating blank spaces.

Babado
  • 217
  • Have a look at the todonotes pacakge. That can do waht you want, plus a lot more. – Peter Grill Oct 19 '21 at 16:23
  • 1
    if that's your only use of colour then \renewcommand\textcolor[2]{\ignorespaces} otherwise you need to include a test for red – David Carlisle Oct 19 '21 at 16:30
  • 1
    Search and replace all \textcolor{red} by \comment. Then you only need \newcommand \comment[1]{\textcolor{red}{#1}} to show the comments in red or \newcommand \comment[1]{\ignorespaces}} to hide the comments. – Fran Oct 19 '21 at 16:49
  • Do you want the invisible part to still take up space in the resulting pdf? Or should it not happen at all? – Teepeemm Oct 19 '21 at 18:21
  • @Teepeemm, it shouldn't happen. – Babado Oct 20 '21 at 07:52

1 Answers1

1

Using the command \suppress from Selectively suppress generation of typeset output to redefine \textcolor

Original document x

Redefining \textcolor

x

\documentclass[12pt,a4paper]{article}

\usepackage{xcolor} \usepackage{ifthen}

\let\oldtextcolor\textcolor \renewcommand{\textcolor}[2]{% <<<<<<<<<<<<<<<<<<<<<< \ifthenelse{\equal{red}{#1}} {\suppress#2\endsuppress} {\oldtextcolor{#1}{#2}}% }

%% From https://tex.stackexchange.com/a/97360/161015 \makeatletter
\font\dummyft@=dummy \relax \def\suppress{% \begingroup\par \parskip\z@ \offinterlineskip \baselineskip=\z@skip \lineskip=\z@skip \lineskiplimit=\maxdimen \dummyft@ \count@\sixt@@n \loop\ifnum\count@ >\z@ \advance\count@\m@ne \textfont\count@\dummyft@ \scriptfont\count@\dummyft@ \scriptscriptfont\count@\dummyft@ \repeat \let\selectfont\relax \let\mathversion@gobble \let\getanddefine@fonts@gobbletwo \tracinglostchars\z@ \frenchspacing \hbadness@M} \def\endsuppress{\par\endgroup} \makeatother

\begin{document}

As any dedicated reader can clearly see, the Ideal of practical reason is a representation of, as far as I know, the things in themselves; as I have shown elsewhere, the phenomena should only be used as a canon for our under- standing.

x=x+1

\noindent \textcolor{red}{I don't want to see this \ I don't want to see this \ I don't want to see this.}

Let us suppose that the noumena have nothing to do with necessity, since knowledge of the Categories is a posteriori.

{\color{red} But I want to see this.}

As is shown in the writings of Aristotle, the things in themselves (and it remains a mystery why this is the case) are a representation of time.

\textcolor{green}{And also to see this.}

Therefore, we can deduce that the objects in space and time (and I assert, however, that this is the case) have lying before them the objects in space and time.

\end{document}

From the quoted link

However rules, radical bars, fraction bars and some other things (mostly math) can escape.

Simon Dispa
  • 39,141
  • Interesting solution, but then the text that is not visible creates "blank space" in the document. Not sure if this is desired. – Peter Grill Oct 19 '21 at 20:04
  • @Peter Grill I know, but literally reproduced the OP posted output :). I updated the answer for a more useful solution. – Simon Dispa Oct 19 '21 at 22:32
  • @SimonDispa thank you for your answer. Maybe I wasn't clear enough when I first posted the question, but I don't want the red text to be compiled. Putting the text invisible and creating blank spaces is not ideal for me. – Babado Oct 20 '21 at 07:58
  • @Babado How or where do you see blank spaces? The red text is not typeset. In the figure there are not blank lines. – Simon Dispa Oct 20 '21 at 15:09
  • For example, if I have $\textcolor{red}{\colorbox{black}{I don't want to see this}}$, I don't see the text but I see the black background. – Babado Oct 21 '21 at 05:44