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"
  • 1
    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 '14 at 12:15
\ProvidesPackage{mypackage}[2014/01/05 ...]
  \RequirePackage[czech,english]{babel}%% the default

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


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:


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.