4

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.

5

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

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.