# How does one define synonymous options in style/class files?

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.

-

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}

-
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.) –  Loop Space Aug 4 '10 at 18:08
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

@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}}

-
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

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.

-