1

If I wanted, say, to nullify all the footnote commands in a document without actually deleting them, I could use the command \renewcommand\footnote[2][]{}. (See, for example, Looking for a Way to Nullify All Footnotes without Actually Removing Them from the Code)

I would like to know if it is possible, and if so, how, may I (analogously) neutralize all the colorizing commands in a document---without deleting them---so that the resulting document contains only grayscale and no other colorings?

I ask the question because, for instance, when one self-publishes a book (on say, Amazon), it is much cheaper to do so in black and white---and I don't know whether a document with color can be uploaded and automatically converted to grayscale---or whether it will be produced in color at a much higher cost.

Hence, consider the MWE:

\documentclass[12pt]{book}
\usepackage{tcolorbox}

\definecolor{darkamber}{RGB}{213,54,0}
\definecolor{forestgreen}{rgb}{.13, .55, .13}
\colorlet{aPurple}{blue!77!red}
\definecolor{RoyalRed}{RGB}{157,16, 45}
\definecolor{scarlet}{RGB}{255, 36, 0}
\definecolor{burntorange}{rgb}{0.8, 0.33, 0.0}
\definecolor{cadmiumgreen}{rgb}{0.0, 0.42, 0.24}

\begin{document}
\thispagestyle{empty}
\Large

\begin{center}
\begin{tcolorbox}[width=.90\textwidth,colback={white},title={\textcolor{white}{\bf \hfill COLOR TO GRAYSCALE \hfill}},colbacktitle=burntorange,coltitle=black] \par \emph{} \\  
\textcolor{scarlet}{\textbf{AAA}} \\
\textcolor{aPurple}{\textbf{BBB}} \\
\textcolor{cadmiumgreen}{\textbf{CCC}} \\
\textcolor{forestgreen!35!black}{\textbf{DDD}} \\
\textcolor{RoyalRed}{\textbf{EEE}} \\
\textcolor{burntorange}{\textbf{FFF}} \\
\textcolor{darkamber}{\textbf{GGG}}
\end{tcolorbox}    
\end{center}
\end{document}

which produces the output:

enter image description here

QUESTION: How may I convert all text and tcolorbox coloring to grayscale (if possible) in ``one fell swoop'' without deleting any of the colorizing code? I compiled the code with pdflatex.

Thank you.

1
  • It can definitely be done. I already do it. BUT I work with a custom document class, so the code is too obscure for here. There are several color-related commands. It is not necessary to go down to the level of primitive commands.
    – user287367
    Commented Jan 24 at 2:03

1 Answer 1

1

Since you ask for an "analogous" way, you might want to use \renewcommand here as well. In certain cases, you can make a copy of a command and then overwrite the original, such as:

\let\olddefinecolor\definecolor
\renewcommand{\definecolor}[3]{\olddefinecolor{#1}{named}{black}}

This will turn all subsequently defined colors black (but of course only those which are defined with \definecolor and not aPurple which you defined via \colorlet).

\documentclass[12pt]{book}
\usepackage{tcolorbox}

\let\olddefinecolor\definecolor
\renewcommand{\definecolor}[3]{\olddefinecolor{#1}{named}{black}}

\definecolor{darkamber}{RGB}{213,54,0}
\definecolor{forestgreen}{rgb}{.13, .55, .13}
\colorlet{aPurple}{blue!77!red}
\definecolor{RoyalRed}{RGB}{157,16, 45}
\definecolor{scarlet}{RGB}{255, 36, 0}
\definecolor{burntorange}{rgb}{0.8, 0.33, 0.0}
\definecolor{cadmiumgreen}{rgb}{0.0, 0.42, 0.24}

\begin{document}
\thispagestyle{empty}
\Large

\begin{center}
\begin{tcolorbox}[width=.90\textwidth,colback={white},title={\textcolor{white}{\bf \hfill COLOR TO GRAYSCALE \hfill}},colbacktitle=burntorange,coltitle=black] \par \emph{} \\  
\textcolor{scarlet}{\textbf{AAA}} \\
\textcolor{aPurple}{\textbf{BBB}} \\
\textcolor{cadmiumgreen}{\textbf{CCC}} \\
\textcolor{forestgreen!35!black}{\textbf{DDD}} \\
\textcolor{RoyalRed}{\textbf{EEE}} \\
\textcolor{burntorange}{\textbf{FFF}} \\
\textcolor{darkamber}{\textbf{GGG}}
\end{tcolorbox}    
\end{center}
\end{document}

enter image description here


But if you want to change the colors to grayscale, a much simpler way is to load the xcolor package with the gray option. This selects grayscale as target color model and hence will convert all defined colors to grayscale. Note that the different colors are quite hard to distinguish then.

Since you use the tcolorbox package that loads the xcolor package, you can add \PassOptionsToPackage{gray}{xcolor} before loading it:

\documentclass[12pt]{book}
\PassOptionsToPackage{gray}{xcolor} % <-
\usepackage{tcolorbox}

\definecolor{darkamber}{RGB}{213,54,0}
\definecolor{forestgreen}{rgb}{.13, .55, .13}
\colorlet{aPurple}{blue!77!red}
\definecolor{RoyalRed}{RGB}{157,16, 45}
\definecolor{scarlet}{RGB}{255, 36, 0}
\definecolor{burntorange}{rgb}{0.8, 0.33, 0.0}
\definecolor{cadmiumgreen}{rgb}{0.0, 0.42, 0.24}

\begin{document}
\thispagestyle{empty}
\Large

\begin{center}
\begin{tcolorbox}[width=.90\textwidth,colback={white},title={\textcolor{white}{\bf \hfill COLOR TO GRAYSCALE \hfill}},colbacktitle=burntorange,coltitle=black] \par \emph{} \\  
\textcolor{scarlet}{\textbf{AAA}} \\
\textcolor{aPurple}{\textbf{BBB}} \\
\textcolor{cadmiumgreen}{\textbf{CCC}} \\
\textcolor{forestgreen!35!black}{\textbf{DDD}} \\
\textcolor{RoyalRed}{\textbf{EEE}} \\
\textcolor{burntorange}{\textbf{FFF}} \\
\textcolor{darkamber}{\textbf{GGG}}
\end{tcolorbox}    
\end{center}
\end{document}

enter image description here

(There is also a monochrome option which should disable colored output and renders all colors as black, but this won't work here since you also use background colors.)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .