What I actually want to do is to slightly hack an old LaTeX class written by
someone else years ago (and, I suspect, not maintained anymore).
What I want to do in particular is to create a document class based on one
of the standard LaTeX2e classes. The new class takes the language (english
or swedish only) as a parameter and (among other things) passes it down to
Babel. And I get a funny problem.
Now, I don't really know what I'm doing, but my problem boils down to this
piece of code which, it seems to me, *should* work:
-------- jarticle.cls ---------
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{jarticle}[2002/07/20 Funny mangled article class]
\DeclareOption{english}{\AtEndOfClass{\selectlanguage{english}}}
\DeclareOption{swedish}{\AtEndOfClass{\selectlanguage{swedish}}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\RequirePackage[english,swedish]{babel}
\LoadClass{article}
-------- jarticle.tex ---------
% test the jarticle doc class
\documentclass[a4paper,english]{jarticle}
\usepackage{t1enc}
\begin{document}
\section{Foo}
\today
\iflanguage{swedish}{Svenska}{English}:
Foobar\ldots
\end{document}
----------------------------------
What actually happens is that jarticle.tex gets typeset with a
swedish-formatted date and the string "Svenska".
And if I change jarticle.tex to use swedish:
\documentclass[a4paper,swedish]{jarticle}
I get a US-formatted date and the string "English"... in other words,
"swedish" and "english" seem to be swapped somewhere. Where and why?
regards,
/Jorgen
--
// Jorgen Grahn <jgrahn@ ''Battle ye not with monsters,
\X/ algonet.se> lest ye become a monster''
> \RequirePackage[english,swedish]{babel}
> \LoadClass{article}
Reverse these lines. Also, you are supposed to give the major document
language last in the list, so you should arrange to invoke
[swedish,english]{babel} when you have \documentclass[english].
(I'm no expert with Babel)
Donald Arseneau as...@triumf.ca
the problem is that the \selectlanguage is obeyed \AtEndOfClass,
whereas babel (in effect) inserts a \selectlanguage for its chosen
language -- the last in its list -- \AtBeginDocument. the effect of
babel's action is that no \selectlanguage in the preamble has any
effect.
as donald said, the solution is to make your \DeclareOption commands
set the order of the options to babel.
--
Robin Fairbairns, Cambridge -- rf10 at cam dot ac dot uk
Thanks (to you and to Donald Arseneau). I ended up with this (which I
suppose is an ugly hack; as I hinted at, it's pure cargo-cult programming):
------ jarticle.cls ---------
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{jarticle}[2002/07/20 Funny mangled article class]
\newcommand{\mylangs}{english}
\DeclareOption{english}{\renewcommand{\mylangs}{english}}
\DeclareOption{swedish}{\renewcommand{\mylangs}{swedish}}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass{article}
% \typeout{To babel: \mylangs}
\RequirePackage[\mylangs]{babel}
------------------------------
And it works well enough for my immediate needs.
(My first attempt was to define \mylangs as either swedish,english
or english,swedish. That didn't work - I would still get a swedish
babel environment when I asked for an english, and the other way around.)
regards,
> \newcommand{\mylangs}{english}
> \DeclareOption{english}{\renewcommand{\mylangs}{english}}
> \DeclareOption{swedish}{\renewcommand{\mylangs}{swedish}}
> \RequirePackage[\mylangs]{babel}
>
> (My first attempt was to define \mylangs as either swedish,english
> or english,swedish. That didn't work - I would still get a swedish
> babel environment when I asked for an english, and the other way around.)
The \RequirePackage doesn't see your list of languages because
it is hiding in a macro(*). Either do:
\expandafter\RequirePackage\expandafter[\mylangs]{babel}
or handle \mylangs like:
\newcommand{\mylangs}{\RequirePackage[swedish,english]}
\DeclareOption{english}{\renewcommand{\mylangs}{\RequirePackage[swedish,english]}
\DeclareOption{swedish}{\renewcommand{\mylangs}{\RequirePackage[english,swedish]}}
\mylangs{babel}
(*) The truth is quite tricky: \RequirePackage doesn't see the *comma*
so it takes \mylangs as a single language. I would expect that to
cause an error (there is no language "swedish,english") but Babel
re-parses the argument and splits at the comma, using only the first
language.
Donald Arseneau as...@triumf.ca
No, you have forgotten, that LaTeX expands the option list before
parsing (\edef in \@fileswith@pti@ns). The problem is that
\ProcessOptions scans the global options first. Then
\ds@<globaloption> will be set to empty, so that the option
code is not executed again, when the package option list
is executed. So babel sees the wrong order of languages.
After loading babel, the main language can set, so that
the \selectlanguage of babel at begin{document} will
be executed for the correct language:
\newcommand*{\mymain}{swedish}
\DeclareOption{swedish}{\renewcommand*{\mymain}{swedish}}
\DeclareOption{english}{\renewcommand*{\mymain}{english}}
% the star form selects the option order of option calls,
% the non-star form selects the order of declaration of the options,
% so we need the star form
\ProcessOptions*
\RequirePackage[english,swedish]{babel}
\expandafter\main@language\expandafter{\mymain}
Yours sincerely
Heiko <ober...@uni-freiburg.de>