2

I have been trying to create a package, which loads the babel package and sets the language with an option. I've been getting strange errors when trying to define mutually exclusive package options, so as to prevent babel options conflict. I've put together a MWE. Here is the failedpackage.sty file :

\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{failedpackage}

\newif\ifbabel@french
\newif\ifbabel@english
\newif\ifbabel@german

%% Option zone
\DeclareOption{french}{\babel@frenchtrue\babel@englishfalse\babel@germanfalse}
\DeclareOption{english}{\babel@frenchfalse\babel@englishtrue\babel@germanfalse}
\DeclareOption{german}{\babel@frenchfalse\babel@englishfalse\babel@germantrue}

\ExecuteOptions{french}

\ProcessOptions
%% end of Option zone


\ifbabel@frenchtrue
    \RequirePackage[french]{babel}
\fi
\ifbabel@englishtrue
    \RequirePackage[english]{babel}
\fi
\ifbabel@germantrue
    \RequirePackage[german]{babel}
\fi


\endinput

Here is the .tex file to compile :

\documentclass[report]

\usepackage[T1]{fontenc}
\usepackage[UTF8]{inputenc}

\usepackage{failedpackage}

\begin{document}

    Bonjour TeX.StackExchange !

\end{document}

And here is the .log document : http://paf.im/8a8tc

Well I guess the problem is caused by the fact that the compiler treats the conditional statements (e.g. \ifbabel@englishtrue) as undefined, but they have been defined right at the beginning of the .sty!

I don't understand.

Thanks in advance for your help.

3
  • 1
    No, the error is \documentclass[report] -- it must read \documentclass{report} and the \ifbabel@.... conditionals must go without true
    – user31729
    Feb 8, 2016 at 20:13
  • there is \RequirePackageWithOptions command always loads the required package with exactly the same option list as that being used by the current class or package
    – touhami
    Feb 8, 2016 at 21:52
  • @ChristianHupfer Thank you, I couldn't understand why some errors showed up in the mwe but not in other documents. Besides, the second part of your comment was the answer!
    – oowekyala
    Feb 9, 2016 at 9:13

1 Answer 1

3
  1. Remove the suffix true from the \ifbabel@.... queries! You must use \ifbabel@french etc for the query, but \babel@frenchtrue or \babel@frenchfalse to set the state of the 'variable'.

  2. Change \documentclass[report] to \documentclass{report}


\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{failedpackage}

\newif\ifbabel@french
\newif\ifbabel@english
\newif\ifbabel@german

%% Option zone
\DeclareOption{french}{\babel@frenchtrue\babel@englishfalse\babel@germanfalse}
\DeclareOption{english}{\babel@frenchfalse\babel@englishtrue\babel@germanfalse}
\DeclareOption{german}{\babel@frenchfalse\babel@englishfalse\babel@germantrue}

\ExecuteOptions{french}

\ProcessOptions
%% end of Option zone


\ifbabel@french
\RequirePackage[french]{babel}
\fi

\ifbabel@english
\RequirePackage[english]{babel}
\fi
\ifbabel@german
\RequirePackage[german]{babel}
\fi


\endinput

Main.tex

\documentclass{report}

\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc}     %

\usepackage{failedpackage}

\begin{document}

Bonjour TeX.StackExchange !

\end{document}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .