Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

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}  
share|improve this question

1 Answer 1

up vote 4 down vote accepted

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}
share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.