I trying to write a package, and I'd like to specify whether there should be colour or not.
I'd like to do:


and have this set


or true as the case may be. What's the best way to do this?

  • I would us two options : the default one would be bw for black and white, and the second one would be color.
    – projetmbc
    Apr 12, 2012 at 18:56
  • My comment is a general one which doesn't take care of the package hyperref.
    – projetmbc
    Apr 12, 2012 at 19:09
  • Duplicate: tex.stackexchange.com/q/12631/5763 Apr 13, 2012 at 8:19
  • I saw tex.stackexchange.com/q/12631/5763, but I wanted to know how to expand out the text, which it didn't outline. However, I did reread the documentation for pgfopts, and used that to do what I wanted. I think the main issue with pgfopts was not understanding how pgfkeys worked. Apr 13, 2012 at 14:08

3 Answers 3


If you want all the options to your package to be passed to hyperref then you can just do


see clsguide.tex documentation in the LaTeX base.

I just read clsguide:-) and if this is all you want to do, it points out that there is a more efficient shortcut to all the above three lines


Another option is to use keyreader



% Define the keys in family MYFAM and set the
% macor prefix to my@
    % define a command key 'say' that sores
    % it’s value in \my@say
    % [1] define a boolean 
    % [2] define a boolean and store the value
% booleand are not preset by defualt so we
% do it manually

% Process the package options

% with version [1]
%   \RequirePackage[colorlinks=true]{hyperref}
%   \RequirePackage[colorlinks=false]{hyperref}

% with version [2]

    % use the value of 'say'
    #1 says \my@say.


    say={sit down},
    colori=true,% [1]
    colorii=false,% [2]




  • hyperref has no color option (at least my version hasn’t)

  • Version [1] is the shorter was if you want to access only one hyperref key

  • Version [2] is better if you want to access more then one option.

    • For that we store the value of the option an pass it to hyperref later. Booleans don’t store their value by default, they only create new \if…

    • Why not use a cmd for this version? Because bool key checks if it’t value matches true or false

Maybe it’s better to use the pdf key processing since it’s more related with the beamer class, but I’m not familiar with that.


Another option is to use kvoptions and etoolbox, in your .sty file, write:


%% if the variable 'color' is
%% 1. not included                  : it will be set to 'false'
%% 2. included but not given a value: it will be set to 'true'
%% 3. included and given a value    : it will be set to the value that is given

\newif \ifcolor %% new Boolean variable is default to 'false'
\ifdefstring{\foo@color}{true}{\colortrue}{} %% set the Boolean variable to 'true' if '\foo@color' is 'true'

\RequirePackage[color = true]{hyperref}
\RequirePackage[color = false]{hyperref}

Then in your document you can specify the option 'color' with:

\usepackage[color]{foo}         %% color = true
\usepackage[color = true]{foo}  %% color = true
\usepackage[color = false]{foo} %% color = false

You must log in to answer this question.

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