Here a suggestion for you package. I think every important fact is written as a comment :
\begin{filecontents}{myexample.sty}
\NeedsTeXFormat{LaTeX2e}
\def\filedate{2013/11/22}
\def\fileversion{v0.1}
\ProvidesPackage{myexample}[\filedate\space\fileversion\space]
\RequirePackage{ifpdf,ifluatex,ifxetex}
\RequirePackage{kvoptions}
\RequirePackage{etoolbox}
\RequirePackage{tcolorbox}
\tcbuselibrary{listings,breakable,skins}
\SetupKeyvalOptions{
family=@pste,
prefix=@pste@
}
\DeclareBoolOption{pdf}%default is false
\ProcessKeyvalOptions*
\def\@pste@compile@noexample{}%do what you want
\def\@pste@compile@pdftrue{}%do what you want
\def\@pste@compile@pdffalse{}%do what you want
% Its no option examples is newtcblisting for latex|xelatex
\if@pste@pdf%
%option pdf is set true
\ifboolexpr{ not bool {pdf} }%
{% xelatex or latex is true
\@pste@compile@pdftrue
}%
{%otherwise
%no example environment
\@pste@compile@noexample%
}%
\else%
%\option pdf is set false / no option given
\ifboolexpr{ bool {pdf} or bool {xetex} or bool {luatex} }%
{%pdflatex or xelatex or lualatex is true
\@pste@compile@pdftrue
}%
{%otherwise
%no example environment
\@pste@compile@noexample%
}%
\fi
\end{filecontents}
The reason the following does not work
\def\in@hyperref{pdfauthor=My Name}
\hypersetup{colorlinks,linkcolor=blue,\in@hyperref}
but the following does
\def\in@hyperref{My Name}
\hypersetup{colorlinks,linkcolor=blue,pdfauthor=\in@hyperref}
is because \hypersetup
splits its argument first for commas and then tries to split the content between the commas on a =
. If none is found it assumes a valueless key and therefor takes the whole content as key.
In the first code the =
is inside another macro which is not yet expanded. Therefor the code in \hypersetup
can't find it and takes \in@hyperref
as keyname. Only then this macro is actually expanded and an not-found error is raised as there is no key with the strange name pdfauthor=My Name
.
In order to make the code working you need to expand \in@hyperref
first at least once. One way to do this is to use the TeX primitive \expandafter
, which expands the token (e.g. macro) behind the next token before that one is expanded. This means \expandafter\a\b
expands \b
first, then \a
is expanded. If \b
is another \expandafter
the whole thing repeats. So the following works:
\def\in@hyperref{pdfauthor=My Name}
\expandafter\hypersetup\expandafter{\in@hyperref,colorlinks,linkcolor=blue}
This way \hypersetup
gets the already expanded argument {pdfauthor=My Name,colorlinks,linkcolor=blue}
. Here \in@hyperref
can also include multiple comma-separated key=value pairs.
Best Answer
In common with many keyval methods, the default value is the one which will be used if only the key name is given at point of use. Thus with
giving
foo
with no value/=
sign in the option list is equivalent to givingfoo = bar
.In contrast, the initial value is used to ensure that some value has been stored before option processing. Thus
will store the value
baz
for keyfoo
'now'. This is equivalent to givingIf the user then sets the
foo
option, the initial value will be 'thrown away' and has no more influence on the outcome. In contrast, the default value is still important as in the caseIf the user does not give the
foo
option, then\mypkg@foo
will have valuebaz
. If the user gives thefoo
option with no value, the default is used and\mypkg@foo
will have valuebar
. Finally, if the user givesfoo = <some value>
then of course\mypkg@foo
will contain<some value>
.