1

Is there a possibility to set a key into my header which defines the desired output of my document? I can imagine three modes:

  1. Print (black and white)
  2. Print (colored)
  3. PDF for display view

With ifthen it should be easy to define different commands for those modes or to insert blank pages and so on. Here are some examples for the use:

  • Blank pages for print
  • Color on/off
  • Color definition in RGB (PDF) or CMYK (print)
  • ignoring hyperrefs
  • printing todos
  • and so on...

This switch could be something like the draft mode in scrreprt. Or maybe a single mark like \setcustomswitch{mode=printColored %,printBW,PDF} (command invented by me).

  • For hyper links, hyperref offers ocgcolorlinks. – user11232 Jul 2 '13 at 23:39
2

The things you list can for the most part be achieved using options to the packages that supply the functionality you want to modify. For example pass option gray or cmyk to the xcolor package to switch the color space. Likewise, hyperref has options to modify the behavior of hyperlinks in the document.

Make a package for each of the desired states of your document, i.e., mydoc-print.sty and mydoc-online.sty and switch between the two.

A more interesting way to generate a document that displays in color but prints in black and white is to use the ocg-p package and define commands that generate black and white in the printed optional contents group and colored output in the visible optional contents group.

Edit:

Here is an example with conditionals to change the output of the document. I still think you would be better off collecting the settings and stylings in a custom package for each of the intended outputs

\documentclass{article}

\newif\ifcolor
\newif\ifonline

\onlinetrue % toggle true/false to change between cmyk/rgb
\colortrue  % change to grayscale

\usepackage{xcolor}
\ifcolor
    \ifonline
        \selectcolormodel{rgb}%
    \else
        \selectcolormodel{cmyk}%
    \fi
\else
    \selectcolormodel{gray}%
\fi

\begin{document}

\textcolor{red}{Test}

\end{document}
  • First suggestion: I am using several functions like those mentioned, but I don't like to search around in all packages and to have %comment for printing all over the place. Second suggestion: I don't like custom packages as they make everything less portable. Third suggestion: I'll have a look on ocg-p tomorrow. Isn*t there any possibility to set a mark which can be read by ifthen. For example I'm checking for xetex or not and switching my preamble for each case. Would be really handy. – LaRiFaRi Jul 2 '13 at 19:59
  • ocg-p is an interesting package. But not what I want. It would make a lot of efforts to layer all parts in my document and the viewer needs the possibility for that. Their should be a possibility to clearly separate print and web version. – LaRiFaRi Jul 3 '13 at 6:47
  • Your edit shows exactly what I wanted. I'm going to try both, conditional and custom package. But very interesting input this \newif\ifcolor command. Thanks. I suggest the ifthen package is needed for your MWE? – LaRiFaRi Jul 3 '13 at 13:22
  • 1
    \newif is a TeX primitive and does not rely on the ifthen package. The ifthen package has the \newboolean command which you can use if you prefer. – Martin Heller Jul 3 '13 at 16:43
1

As proposed by @Martin Heller, there is a good solution. Here are some examples for the use of those conditionals. Maybe, they serve somebody else, too.

Defining the bools:

At top of the header.txt

\newif\ifcolor %bool for toggling color mode to b/w mode
\newif\ifprint %bool fot toggling web mode to print mode

\colortrue
%\colorfalse
%\printtrue
\printfalse

Defining commands such as logos (real black for printing instead of grey scale):

\newcommand{\Logo}{\ifcolor ... \else ... \fi}

General use of colors with xcolor:

\usepackage{xcolor}
\definecolor{aBlueSample}{cmyk}{1.00, 0.80, 0.00, 0.10}
\ifcolor
\ifprint\selectcolormodel{cmyk}%
\else\selectcolormodel{rgb}\fi
\else\selectcolormodel{gray}\fi

Handling hyperlinks:

\usepackage[colorlinks=true]{hyperref}
\ifprint\ifcolor\hypersetup{colorlinks=false, urlcolor=blue}\else\hypersetup{hidelinks}\fi\fi

Example of blank pages used after \begin{document}:

\ifprint\cleardoublestandardpage\fi

Or blank pages in general:

\documentclass[]{scrreprt}
\ifprint\KOMAoptions{twoside=true}\else\KOMAoptions{twoside=false}\fi

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.