16

I have a document with colored hyperlinks, using the options of the hyperref package. I also have lots of tikz-figures that use various shades of gray and occasionally some colors.

The way my document is right now looks very nice on screen but not so great when I print it on a monochrome printer. I tried using xcolor's \selectcolormodel{gray} but then all the colors are printed as shades of grey. This is ok for figures but not acceptable for the text.

Is there a way to change the color of the text (and only that) to black when printing the document? The figures should stay as they are (colored/shaded).

If this is not possible, is there a way to turn all the figures in grayscale and all the text to black?

Are things like these possible or do I have to maintain 2 diferrent versions of my document (i.e. one for on-screen reading and the other one for printing)?

I am using XeLaTeX if it is of any importance.

some text

text

and a figure with shades of grey

shades

pmav99
  • 6,060
  • Maybe you can use if conditionals like http://www.charlietanksley.net/philtex/maintaining-multiple-versions-of-the-same-file/ but to control the color setup of hyperref. – N.N. Jul 08 '11 at 10:22
  • 4
    If the colored text is coming just from hyperlinks, it's a matter of saying \hypersetup{colorlinks=false}, I believe. – egreg Jul 08 '11 at 10:23
  • @N.N, egreg Thank you. Of course this means that there are going to be 2 different versions of the document. I would prefer to have only one if it is possible. – pmav99 Jul 08 '11 at 10:25
  • 2
    Nice picture. Is it done with TikZ? – N.N. Jul 08 '11 at 10:28
  • 1
    I think you have to go with two versions of the document. Except the PDF format itself support two sets of colors. – Martin Scharrer Jul 08 '11 at 10:55
  • 1
    @N.N, yeah i did it with tikz. I uploaded an uncropped version. – pmav99 Jul 08 '11 at 11:56
  • "Two versions" is quite exaggerated: it suffices to have the line I suggested after the settings to hyperref and commenting or uncommenting it. – egreg Jul 08 '11 at 12:25
  • 1
    @egreg, What I mean is that when I send my document to somebody else, I must send him one for printing and one for screen viewing. It is not something terrible, but i think it is more convenient to have just one pdf. – pmav99 Jul 08 '11 at 12:33
  • @egreg: I meant two PDFs, one for screen view and one for printing. The source code can simply hold a conditional expression, of course. Sorry for the confusion. – Martin Scharrer Jul 08 '11 at 12:36
  • As said, if the PDF format doesn't support it, pdftex can't do nothing about it. Even then, I heavily doubt that it is supported by xcolor, hyperref, etc. You could ask this question on comp.text.tex instead, maybe Heiko Oberdiek (author of hyperref and PDF LaTeX expert) can help you. Maybe you could implement it using colored identical-looking annotations which are placed over the black text but are not printed. However, the PDF viewer must support these and this solution would be difficult and messy. – Martin Scharrer Jul 08 '11 at 12:43
  • 2
    Do your really need colored links? You can switch to a colored border around links to make them stand out (see egreg's first comment). This border is then not printed. – Martin Scharrer Jul 08 '11 at 12:48
  • 3
    @Martin, thank you for your suggestion. No I don't really need them. I just prefer them. I find the colored boxes rather distracting. And if there are lots of references close together sometimes they fall on each other. I think that my question is rather specific though. Even something like It cannot be done + a reference is a perfectly acceptable answer. If nothing comes up, I will ask on comp.text.tex. – pmav99 Jul 09 '11 at 20:03
  • 6
    http://tex.stackexchange.com/questions/4425/is-there-a-way-to-have-coloured-hyperref-hyperlinks-in-the-pdf-but-have-them-pr?rq=1 – pmav99 Jun 21 '14 at 17:01

1 Answers1

8

try

\usepackage[ocgcolorlinks]{hyperref}

Needs a pdf version 1.5 and links can not be broken across lines.

  • 1
    thank you. Unfortunately it is not good enough. Links are still colored, and the links that cannot be broken are very inconvenient too. Causes lots of overfull hboxes. By the way, ocgcolorlinks is an undocumented option? I can't find any reference at hyperref's doc. – pmav99 Jul 08 '11 at 12:05
  • 1
    it needs the pdftex or (for xelatex) the dvipdfm driver –  Jul 08 '11 at 12:42
  • 1
    @pmav99: See e.g. http://www.tug.org/applications/hyperref/ftp/README. "Experimental option ocgcolorlink. The idea are colored links, when viewed, but printed without colors. This [..] uses Optional Content Groups, a feature introduced in PDF 1.5. Main disadvantage: Links cannot be broken across lines. PDF reference 1.7: 4.10.2 "Making Graphical Content Optional": Graphics state operations, such as setting the color, ..., are still applied. Therefore the link text is put in a box and set twice, with and without color." Exactly what I thought. – Martin Scharrer Jul 08 '11 at 12:51
  • @Herbert, could this be adapted to have a \textogcolor{blue}{blargh} command? and/or a \occgcolor{blue} command. – Mariano Suárez-Álvarez Sep 04 '15 at 07:38
  • @MarianoSuárez-Alvarez: I suppose yes, but I never tried it. –  Sep 05 '15 at 07:13