Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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

\usepackage[color=false]{foo}

and have this set

\RequirePackage[color=false]{hyperref}

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

share|improve this question
    
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 '12 at 18:56
    
My comment is a general one which doesn't take care of the package hyperref. –  projetmbc Apr 12 '12 at 19:09
    
Duplicate: tex.stackexchange.com/q/12631/5763 –  Martin Schröder Apr 13 '12 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. –  aragilar Apr 13 '12 at 14:08

2 Answers 2

up vote 12 down vote accepted

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

\DeclareOption*{\PassOptionsToPackage{\CurrentOption}{hyperref}
\ProcessOptions\relax
\RequirePackage{hyperref}

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

\RequirePackageWithOptions{hyperref}
share|improve this answer

Another option is to use keyreader

\begin{filecontents}{mypack.sty}
\ProvidesPackage{mypack}

\usepackage{keyreader}

% Define the keys in family MYFAM and set the
% macor prefix to my@
\krddefinekeys{MYFAM}[my@]{
    % define a command key 'say' that sores
    % it’s value in \my@say
    cmd/say/jump/;
    % [1] define a boolean 
    bool/colori/true/;
    % [2] define a boolean and store the value
    bool/colorii/true/\def\my@colorii{#1};
}
% booleand are not preset by defualt so we
% do it manually
\krdsetkeys{MYFAM}{colori=false,colorii=false}

% Process the package options
\krdProcessOptions<MYFAM>\relax

% with version [1]
%\ifmy@colori
%   \RequirePackage[colorlinks=true]{hyperref}
%\else
%   \RequirePackage[colorlinks=false]{hyperref}
%\fi

% with version [2]
\RequirePackage[colorlinks=\my@colorii]{hyperref}

\newcommand{\mycmd}[1]{%
    % use the value of 'say'
    #1 says \my@say.
}
\end{filecontents}

\documentclass{article}

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

\begin{document}
\mycmd{Simon}

\url{www.myurl.com}
\end{document}

Notes

  • 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.

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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