1

Is there a way to change the color model to monochrome for a section of a document? I would like to make a section mononcrome without affecting the headers. Is this possible? I know about \usepackage[mononcrome]{xcolor} and \passOptionToPackage[mononcrome]{xcolor} but these can only be applied in the preamble, and I think they affect the headers as well?

MWE below

\documentclass{article}
\usepackage{lipsum,fancyhdr,xcolor}

\pagestyle{fancy}
\rhead{}
\chead{\textcolor{red}{\leftmark}}
\lhead{\textcolor{blue}{Keep colors in header}}

\begin{document}

\section{Colors}

\lipsum[1-2]

\section{Monochrome}

\lipsum[3]\textcolor{red}{This should become gray}
\lipsum[4]\textcolor{green}{this too}
\lipsum[5]\textcolor{blue}{and this}

\section{Colors}

\lipsum[5]\textcolor{red}{This should stay red}
\lipsum[66]\textcolor{orange}{same with this}
\lipsum[75]
\end{document}
1
  • 1
    Note that monochrome does not convert colors into grayscale, but instead all colors are turned into black. For grayscale you can use the gray package option - however that does not seem so easy to switch as the monochrome setting as demonstrated in the answer below.
    – Marijn
    Oct 2, 2019 at 20:13

2 Answers 2

3

Here, I looked in the xcolor package and found what was executed by the monochrome option. I then just placed it directly in the document in a group-limited way.

EDITED to make it into the monochrome environment.

\documentclass{article}
\usepackage{lipsum,fancyhdr,xcolor}

\pagestyle{fancy}
\rhead{}
\chead{\textcolor{red}{\leftmark}}
\lhead{\textcolor{blue}{Keep colors in header}}

\makeatletter
\newenvironment{monochrome}
{\begingroup
\colors@false
    \def\set@color{\c@lor@special\m@ne
      {color push \current@color}\aftergroup\reset@color}%
    \def\reset@color{\c@lor@special\m@ne{color pop}}%
    \def\set@page@color{\c@lor@special\m@ne{background \current@color}}
}
{\endgroup}
\makeatother

\begin{document}

\section{Colors}

\lipsum[1-2]

\section{Monochrome}

\begin{monochrome}
\lipsum[3]\textcolor{red}{This should become gray}
\lipsum[4]\textcolor{green}{this too}
\lipsum[5]\textcolor{blue}{and this}
\end{monochrome}

\section{Colors}

\lipsum[5]\textcolor{red}{This should stay red}
\lipsum[66]\textcolor{orange}{same with this}
\lipsum[75]
\end{document}

enter image description here

4
  • Yes, I know that it would seem the monochrome portion has no grayscale, but is merely black. But that still may be useful to the OP. Oct 2, 2019 at 20:44
  • I agree, and the OP also asked for the monochrome option specifically, that's why I commented on his question and not on your answer (which is very nice, +1).
    – Marijn
    Oct 2, 2019 at 20:53
  • Not really suited to write a book on QCD, but who cares? ;-)
    – user194703
    Oct 3, 2019 at 3:40
  • Hi, is it possible to make everything grayscale instead of monochrome? I thought monochrome was grayscale, because of my poor english =( Oct 3, 2019 at 8:56
0

To help with the discussion under Steven B. Segletes's answer, and since I can't comment there, here's how to set grayscale within a group \selectcolormodel{gray}, or as an environment:

\newenvironment{grayscale}
{\begingroup \selectcolormodel{gray}}
{\endgroup}

This might answer the intended question in a straightforward manner.

Any color model could be chosen instead of gray, but it's not obvious why that'd be desired.

You must log in to answer this question.

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