# Create a package with optional mode and key values

I'm trying to create a package with three options as follows:

\usepackage[swpl]{mypack}


swpl option provides the environment

\begin{myexample}[forced bracketed options]...\end{myexample}


available for all xelatex/latex

\usepackage[tcb]{mypack}


tcb option provides the same environment name (with different definition)

\begin{myexample}[other forced bracketed options]...\end{myexample}


available for latex/xelatex and the third option:

\usepackage[pdf,swpl]{mypack} or \usepackage[pdf,tcb]{mypack}


provides the same environment name (with other definition) available for (pdf/lua/xe)latex. I'm triying to adapt related answer for this...but I did not succeed. If anyone can help me with a skeleton (using kvoptions or pgfkeys) I'd appreciate it. I was unable to add [requiered] for the myexample environment and boolean option for swpl and tcb.

PD: Using the same environment name because the first option uses showexpl and the second option tcolorbox for verbatim.

• – Werner Apr 17 '14 at 5:14
• Consider l3keys2e (I think that's what it's called; I'm mobile. Everyone should feel free to correct me :)) – Sean Allred Apr 17 '14 at 5:18

## 1 Answer

From the description I assume that definition of the environment mypack does not need to be changed after the package is loaded. Then two switches and classical options will do:

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{mypack}{2014/04/17 My package}

\newif\ifmypack@swpl % swpl: true, tcb: false
\newif\ifmypack@pdf  % option pdf

\DeclareOption{swpl}{\mypack@swpltrue}
\DeclareOption{tcb}{\mypack@swplfalse}
\DeclareOption{pdf}{\mypack@pdftrue}

\ProcessOptions* % process options in the order they are given


Then the switches \ifmypack@swpl and \ifmypack@pdf can be used for the implementation of environment myexample, e.g:

\ifmypack@swpl
% code for option "swpl"
\else
% code for option "tcb"
\fi

• Many thanks, I now define the [...] mandatory for the environment, xparse maybe?. – Pablo González L Apr 17 '14 at 17:40