Tenho tentado criar um pacote que carregue o babel
pacote e defina o idioma com uma opção. Tenho recebido erros estranhos ao tentar definir opções de pacotes mutuamente exclusivas, para evitar babel
conflitos de opções. Eu montei um MWE
. Aqui está o failedpackage.sty
arquivo:
\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
Aqui está o .tex
arquivo para compilar:
\documentclass[report]
\usepackage[T1]{fontenc}
\usepackage[UTF8]{inputenc}
\usepackage{failedpackage}
\begin{document}
Bonjour TeX.StackExchange !
\end{document}
E aqui está o documento .log:http://paf.im/8a8tc
Bem, acho que o problema é causado pelo fato de o compilador tratar as instruções condicionais (por exemplo, \ifbabel@englishtrue
) como indefinidas, mas elas foram definidas logo no início do .sty
!
Eu não entendo.
Agradeço antecipadamente por sua ajuda.
Responder1
Remova o sufixo
true
das\ifbabel@....
consultas! Você deve usar\ifbabel@french
etc para a consulta, mas\babel@frenchtrue
ou\babel@frenchfalse
para definir o estado da 'variável'.Mudar
\documentclass[report]
para\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
Principal.tex
\documentclass{report}
\usepackage[T1]{fontenc}
\usepackage[utf8]{inputenc} %
\usepackage{failedpackage}
\begin{document}
Bonjour TeX.StackExchange !
\end{document}