# kvoptions and conditional environment

I'm trying to create a package with a single option, which provides an environment, which behaves differently if called by latex or pdflatex XeLaTeX. I tried to use kvoptions, but I'm a little lost. Suppose that the package name is "myexample" with the only option [pdf] and an environment called "example". The idea is as follows:

1. If I load the package without options, and run XeLaTeX Latex or the environment "example" works in one way, and you can not use this if you run pdflatex or lualatex.
2. If I load the package with [pdf] and run pdflatex or lualatex or XeLaTeX, the environment "example" works differently, and you can not use this if you run LaTeX

I read some forum and I think the solution is to use "kvoptions" and "ifpdf, ifluatex, ifxetex". The code I have is as follows:

    \RequirePackage{filecontents}
\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}
\usepackage{tcolorbox}
\tcbuselibrary{listings,breakable,skins}
\SetupKeyvalOptions{
family=@pste,
prefix=@pste@
}
% This option for latex|xelatex.(default)
\DeclareBoolOption[true]{latex}
% This option for pdflatex|lualatex|xelatex.
\DeclareBoolOption{pdf}

\ProcessKeyvalOptions*
% Its no option examples is newtcblisting for latex|xelatex
\if@pste@latex%
\tcbset{below/.style={colback=white,text and listing},myexample/.style={colframe=gray}}%
\newtcblisting{example}[1]{myexample,#1}
% if [pdf] option if true, example is newcolorbox for pdflatex|lualatex|xelatex
\if@pste@pdf%
\ifpdf
\tcbset{below/.style={colback=red,sidebyside},myexample/.style={colframe=blue}}%
\newtcolorbox{example}[1]{myexample,#1}
\else
\fi
\fi
\end{filecontents}
\documentclass{article}
\usepackage[pdf]{myexample}
\begin{document}
\begin{example}{below}
Text
\end{example}
\end{document}


Is it possible to do this? I appreciate the comments and help. Pablo

EDIT 1: Update the code using the idea proposed by @Marco Daniel, but I'm still lost, insert the code, but does not do what I want. Let me explain:

The "example" environment has two definitions

1. no options(default)

\tcbset{below/.style={colback=white,text and listing},myexample/.style={colframe=gray}}% \newtcblisting{example}[1]{myexample,#1} should be defined only for LaTeX and XeLaTeX, and give an error message if used (pdf|lua)LaTeX.

2. option [pdf]

\tcbset{below/.style={colback=red,sidebyside},myexample/.style={colframe=blue}}% \newtcolorbox{example}[1]{myexample,#1} should be defined only (Xe|pdf|lua) LaTeX and give an error message if used LaTeX whit this option.

EDIT 2: This works (based on @Marco Daniel solution), leave it as it is useful to a user:

\RequirePackage{filecontents}
\begin{filecontents}{myexample.sty}
\NeedsTeXFormat{LaTeX2e}
\def\filedate{2013/11/24}
\def\fileversion{v0.2}
\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

% if package load [pdf] option, example enviroment is a newtcolorbox for (xe/lua/pdf)latex
% and not defined for standar latex
\if@pste@pdf%
\ifboolexpr{ bool {pdf}  or bool {xetex}  or bool {luatex} }%
{% (xe/lua/pdf)latex is true
\@pste@compile@pdftrue
\tcbset{below/.style={colback=blue!50!white},myexample/.style={colframe=gray}}
\newtcolorbox{example}[1]{myexample,#1}
}%
{% If use (pdf/lua) latex whitout [pdf] show error
\@pste@compile@noexample%
\PackageError{mysty}{%
\MessageBreak%
Not use option [pdf] for example enviroment in LaTeXenviroment \MessageBreak%
}
}%
\else%
% if load whitout [pdf] (no option given) example enviroment is a newtcblisting for (xe/la)tex %
% and disable for (xe/lua/pdf)latex
\ifboolexpr{not bool {pdf}}%
{% xelatex or latex is true
\@pste@compile@pdftrue
\tcbset{below/.style={colback=gray!50!white,text and listing},myexample/.style={colframe=gray}}
\newtcblisting{example}[1]{myexample,#1}
}%
{% If use (pdf/lua) latex whitout [pdf] show error
% no  example environment
\@pste@compile@noexample%
\PackageError{mysty}{%
\MessageBreak%
Need option [pdf] for example enviroment \MessageBreak%
}
}%
\fi
\end{filecontents}
\documentclass{article}
\usepackage[pdf]{myexample}
\begin{document}
\begin{example}{below}
This is \TeX\ upper
\tcblower
This is \TeX\ lower
\end{example}
\end{document}

-

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}

-
Thank you very much Marco, try using code you offer me, but I still do not get it, working "backwards" from what I want, edit the post to clarify, grateful for all. –  Pablo González L Nov 22 '13 at 13:14
+1... Thank you .... I do that, am not perfect (not like putting warnings or errors), but is functional. salu2 –  Pablo González L Nov 23 '13 at 1:40
@PabloGonzález: Does it work now? –  Marco Daniel Nov 23 '13 at 8:19
Yes... see Edit II –  Pablo González L Nov 24 '13 at 13:05
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.9310014247894287, "perplexity": 8884.469337077622}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2014-35/segments/1409535924501.17/warc/CC-MAIN-20140909013106-00326-ip-10-180-136-8.ec2.internal.warc.gz"}