0

I have a .tex file of about 100 pages which is a handout of my answer key to a course I'm teaching. The file contains exercises with provided solutions in red color. I would like to delete all the texts in red color. Deleting these texts one at a time is a daunting task, how do I delete all the texts at a go?

There is a similar question here Create fill-in-the-blank version of a document with ability to toggle blanks on and off but that one talks about creating "empty spaces" or "fill-ins" within the content of the document. My question is about deleting all texts in red not necessary replacing the texts in red color with "empty spaces" or "fill-ins".

The color packages in the .tex file is:

\usepackage[usenames]{color}

\newcommand{\red}[1]{{\color{red}#1}}

holala
  • 103

1 Answers1

1

Welcome to tex.stackexchange! :)

It's not 100% clear what you mean by "delete" the red text, so here are a few options:

MWE

\documentclass[preview,border=5mm]{standalone}
\usepackage[usenames]{color}
\newcommand{\red}[1]{{\color{red}#1}} % print text red (original)
% \newcommand{\red}[1]{{#1}} % print text black (option 1)
% \newcommand{\red}[1]{{}} % print nothing and leave no space (option 2)
% \newcommand{\red}[1]{\phantom{\vbox{#1}}} % print nothing and leave space (option 3)
\begin{document}
  Hello world

\red{foo}

bar baz \end{document}

Result

result of example

Comment

Now, this assumes that all the solutions in red are separate paragraphs from the rest of the document. If this is not always true, then for those cases, you can remove the \vbox{} part, possibly using 2 different versions of \red{}. Or perhaps someone can suggest a way to test it automatically.

jessexknight
  • 2,732
  • I tried it but there seems to be a conflicting issue BETWEEN \usepackage[usenames]{color} AND \newcommand{\red}[1]{{\color{red}#1}} with the WARNING: " ! LaTeX Error: Command \red already defined. Or name \end... illegal, see p.192 of the manual. See the LaTeX manual or LaTeX Companion for explanation. Type H for immediate help." – holala Mar 02 '21 at 00:48
  • Hmm, It might be that you've uncommented multiple definitions of \red that I gave at the same time. You can only use one at a time. Does that fix the error? – jessexknight Mar 02 '21 at 03:13
  • No. The thing is that whenever I comment off one of the red color packages, some red texts does not show up and it creates an error whenever I run it. Actually, I personally used \usepackage[usenames]{color} for all my red texts. A colleague whom I am working with on the same project decided to use \newcommand{\red}[1]{{\color{red}#1}} for his side of the typesetting. Is there a way I could just combine these two packages into just one since they all seem to serve the same purpose. – holala Mar 02 '21 at 03:54
  • I think there may be some confusion about the word "package" vs "command". When you write \usepackage[usenames]{color} you are loading the package color (with the option usenames), whereas \newcommand{\red}... defines a new command called \red that you can use throughout the document. – jessexknight Mar 02 '21 at 13:20
  • I think what would help most in solving the problem is to create a MWE, which includes only the code necessary to reproduce the problem. Many times as you acr creating the MWE, you might identify the source of the problem! – jessexknight Mar 02 '21 at 13:22
  • I was able to figure it out. – holala Mar 02 '21 at 22:40