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 have a custom .sty file loading needed packages and defining some commands and environments. Is there an easy way to either:

  • define an if-else option
  • define option's default value

I am using the babel package and want to specify it's options:

\usepackage[english, czech]{babel}

But sometimes, I need the opposite:

\usepackage[czech, english]{babel}

Is there a way to use it like this?

\usepackage{myPackage} % loads "english, czech"
\usepackage[en]{myPackage} % loads "czech, english"
share|improve this question
You need a bool-option. More specifications will be possible if you provide a small MWE with your used keyval package. –  Marco Daniel Jan 5 at 12:15

2 Answers 2

up vote 3 down vote accepted
\ProvidesPackage{mypackage}[2014/01/05 ...]
  \RequirePackage[czech,english]{babel}%% the default

If you need the default the other way round then change the definition.

share|improve this answer

Here is a simple way of doing it. The following code is a minimalist .sty file called yourpackagename. It defines a switch \ifyourpkgprefix@enoption and declares an option called en which, if passed to your package, sets the switch to true. After the option(s) have been processed, the babel package is loaded with options english and czech in the desired order, on the basis of the switch's value.

Of course, you should choose different package name, prefix, description, etc.

\ProvidesPackage{yourpackagename}[2014/01/05 v0.1 yourpackagedescription]

% switch for 'en' option

\DeclareOption*{\OptionNotUsed} % discard any undeclared option


    \RequirePackage[czech, english]{babel}
    \RequirePackage[english, czech]{babel}  


Here is a MWE using that package:

enter image description here

%\usepackage{yourpackagename}                   % comment one of those two lines


% --- sanity check ---
The \texttt{babel} options were loaded in the following order:
    \texttt{czech, english} (option~\texttt{en} was passed).
    \texttt{english, czech} (option~\texttt{en} was NOT passed).
% --------------------



Useful resources:

share|improve this answer

Your Answer


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.