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 want to be able to pass two options to a package (actually, a class) and have them be the same. What's the best way to do this?

That is, I want:

\documentclass[norsk]{myclass}

and

\documentclass[bokmal]{myclass}

to do the same thing.

share|improve this question
add comment

3 Answers

It partly depends on how you implement them internally. If the two options set some kind of flag, then it would be easiest to code them by hand

\newif\if@mypkg@norsk
\DeclareOption{norsk}{\@mypkg@norsktrue}
\DeclareOption{bokmal}{\@mypkg@norsktrue}

If the code is more complex then it might be easiest to write a macro to do the job

\newcommand*\mypkg@option@norsk{
   % Code here
}
\DeclareOption{norsk}{\mypkg@option@norsk}
\DeclareOption{bokmal}{\mypkg@option@norsk}
share|improve this answer
    
Or I guess I could combine the two: after the options are executed, do \if@mypkg@norsk code \fi. (Was hoping for a more elegant method, though.) –  Andrew Stacey Aug 4 '10 at 18:08
1  
Does \DeclareOption{bokmal}{\ExecuteOptions{norsk}} not work? –  TH. Sep 2 '10 at 15:51
    
Fair point: should do I think –  Joseph Wright Sep 2 '10 at 16:38
add comment

@Andrew: There is a potential danger with the following solution: endless back-linking in not-so-complex situations. You need a flag to avoid that. See the macro \XKV@replacepointers in the xkeyval package.

\DeclareOption{a}{%
  \renewcommand{\synonymous}{Greetings Earthlings}}
\DeclareOption{b}{\ExecuteOptions{a}}
share|improve this answer
    
It's somewhat confusing to have an answer start with "@Andrew". (Also, I don't quite understand what you're writing about "endless back-linking in not-so-complex situations". Your 3 lines of code are not complex ... Maybe you can expand a bit?) –  Hendrik Vogt Mar 3 '11 at 12:39
    
Yes, I wanted to make a comment, but the markup of the code wasn't clear enough. So I turned it into a quasi-answer. I hope the following is clear. Consider \DeclareOption{a}{\renewcommand{\synonymous}{Greetings Earthlings}\ExecuteOptions{c}} \DeclareOption{b}{\ExecuteOptions{a}} \DeclareOption{c}{\ExecuteOptions{b}}. –  Ahmed Musa Mar 3 '11 at 14:38
add comment
up vote 0 down vote accepted

I'm posting TH.'s comment to Joseph's answer as an answer as it also works. (CW as it's TH.'s answer.)

synonymous.sty contains:

\ProvidesPackage{synonymous}
\newcommand{\synonymous}{Hello world}
\DeclareOption{a}{%
  \renewcommand{\synonymous}{Greetings Earthlings}}
\DeclareOption{b}{\ExecuteOptions{a}}
\ProcessOptions

whilst synonmyous.tex is:

\documentclass{minimal}
\usepackage[a]{synonymous}
\begin{document}
\synonymous    
\end{document}

Changing the a to b has no visible effect on the outcome.

share|improve this answer
add comment

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.