Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I try to implement a personnal class using key-value options (I am a beginner in that field). For exemple, I would like to specify the language (for babel package) with an option "langue=xxx" with "francais" as default value. I tried the kvoptions package as follows :

Class file : (I give you the whole list of packages in case you detect a conflict)

\ProvidesClass{mepp}[2014/03/08 Personnal class development version]
\NeedsTeXFormat{LaTeX2e}

\RequirePackage{kvoptions}

\DeclareStringOption[francais]{langue}
\ProcessKeyvalOptions*


\LoadClass[twoside]{report}


\RequirePackage[paper=a4paper, lmargin=15mm, rmargin=15mm, tmargin=15mm, bmargin=15mm,
                    includeall, marginparwidth=44mm, headheight=\baselineskip]{geometry}
\RequirePackage{babel}
\RequirePackage[T1]{fontenc}
\RequirePackage[latin1]{inputenc}

\RequirePackage{emerald}
\RequirePackage{setspace}
\RequirePackage{calc}
\RequirePackage{array, multirow, tabularx}
\RequirePackage{xcolor, color, colortbl}
\RequirePackage[fleqn]{amsmath}
\RequirePackage{amssymb, mathrsfs, stmaryrd, gensymb}
\RequirePackage{graphicx, picins}
\RequirePackage{subfig}
\RequirePackage[top]{mcaption}
\RequirePackage{fancyhdr, lastpage}
\RequirePackage[fit]{truncate}
\RequirePackage[upright]{fourier}
\RequirePackage{mdwlist}
\RequirePackage{titlesec, titletoc}
\RequirePackage{ulem}
\RequirePackage{float}
\RequirePackage[globalcitecopy]{bibunits}
\RequirePackage{multido}
\RequirePackage{ragged2e}
\RequirePackage{marginfix}

\RequirePackage[geometry]{ifsym}
\RequirePackage{ifthen}
\RequirePackage[strict]{changepage}
\RequirePackage{framed}


\PassOptionsToPackage{\mepp@langue}{babel}

Tex file :

\documentclass[langue=francais]{mepp}
...

but compilation fails : compiler says there is no language specified for babel. If I do not specify any option or if I give a "wrong" option without "=" symbol, compilation works, because it assigns the default value to "langue".

So, why is the option "langue=francais" not recognized ? Thanks for your help.

(sorry for language, I am French)

share|improve this question
    
Welcome to TeX.SX! You have \PassOptionsToPackage{\mepp@langue}{babel} after \RequirePackage{babel} which is a possible source of your problem. Try \RequirePackage{\mepp@langue}{babel} instead. –  egreg Mar 30 at 9:41

1 Answer 1

up vote 5 down vote accepted

You're loading babel before \PassOptionsToPackage{\mepp@langue}{babel} so the option is not evaluated; just use

\RequirePackage[\mepp@language]{babel}

If you want to load babel only if the langue option is specified, you can do

\DeclareStringOption{langue}

and then

\ifx\mepp@langue\@empty\else
  \RequirePackage[\mepp@langue]{babel}
\fi

so if the langue=... option is not specified, babel won't be loaded.

share|improve this answer
    
Thank you, it works ! But I do not understand : if I do not specify the option "langue", \mepp@langue takes the defaut value "francais" and option is correctly evaluated although babel is loaded before the command \PassOptionToPackage... Why ? –  Emmanuel G. Mar 30 at 11:51
    
@EmmanuelG. With the syntax you use, \mepp@langue is initialized to francais. –  egreg Mar 30 at 12:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.