I want to write my own package which provides an \affidavit
command which produces some standard text in two languages (ngerman and english).
Minimal working example of this package:
\def\fileversion{0.1}
\def\filedate{2014/12/10}
\NeedsTeXFormat{LaTeX2e}
\RequirePackage[ngerman,english]{babel}
\ProvidesPackage{myaffidavit}
[\filedate\space\fileversion\space
My affidavit package]
\newcommand{\affidavit}{
\begin{otherlanguage}{ngerman}
This text will be in german stating some standard information (juristic)...
It should use correct hyphenation for german texts.
\end{otherlanguage}
\begin{otherlanguage}{english}
This text will be in english stating the same information as the german one above...
Of course this should automatically use correct hyphenation for english texts.
\end{otherlanguage}
}
As I don't control how my users are working with my package some user could try to use the following minimal working example of a latex document:
\documentclass{article}
\usepackage[ngerman]{babel}
\usepackage{myaffidavit}
\begin{document}
Hallo Welt!
\affidavit
\end{document}
Which results in this error: LaTeX Error: Option clash for package babel
My question is:
How can I write a package which outputs text in different languages (using correct hyphenation) without restricting the user of my package to the languages loaded in my package.And of course, if my user loads babel and my package the other way round I would not be able to use ngerman or english in my package, if the user didn't specify this languages in his latex document, too. (And there would be an option clash if my package tried to load additional languages after babel was already loaded by the user in the main document)
To be more precise: The point is, when I specify the languages my package is going to use inside my package using the package options for babel like this \RequirePackage[ngerman,english]{babel}
, my package is most likely producing an option clash when the user of my package loads the babel package as well.
But: If the user of my package specifies the language he wants to use as a class option (as suggested in the comments), then there would still be an "option clash" (sort of), because the first load of babel inside the document still specifies which language definitions are being loaded (the ones specified as class options).
And using the \myaffidavit
command then produces errors, because it tries to use languages which are not defined/loaded.
I am writing a package and I don't want to force the user to specify the languages, used inside my package, as well when he is loading babel.
I want it to be transparent.
Say my user wants to write in italian, so he is loading babel with the italian language option.
If he specifies it as an option when loading babel with \usepackage[italian]{babel}
there is an option clash.
When he specifies italian as a class option, there is no option clash, but the default language won't be italian anymore, when he is loading my affidavit package as well. That's not transparent! And I don't want my package to be that intrusive.
ngerman
in your document as a class option (as should be, Ithink, since version 3.9). The option clash comes from the fact that you load babel twice, with different options. Or don't load babel at all.babel
isn't loaded, and state in the error message that this package unfortunately requires (1)ngerman
andenglish
or (2) a redefinition of\affadavit
(which could be implemented as a package option).babel
at the end of the preamble (which could conflict withhyperref
). You could test if hyperref is loaded, but what about glossaries? You cannot get every possible instance, you aren't psychic. And after all, it is not your responsibility to protect the user from making mistakes.