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


swpl option provides the environment

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

available for all xelatex/latex


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.


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:

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

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


\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:

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

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.