3

I try to pass the handout option from my class to beamerclass. This method works. I tried with \PassOptionsToClass but it is not clear for me.

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{beamer-nk}[2017/10/16 Beamer version nk, V4.1]

\newif\ifHandout
\Handoutfalse

\DeclareOption{handout}{\Handouttrue}

\ProcessOptions\relax

% classe de base
\ifHandout
\ExecuteOptions{handout}
\LoadClass[handout,xcolor=dvipsnames,professionalfont,french]{beamer}
\else
\LoadClass[xcolor=dvipsnames,professionalfont,french]{beamer}
\fi
2

What \PassOptionsToClass{<option>}{<class>} does is pass its first argument as an option to the class specified by its second argument. Since \DeclareOption{<option>}{<code>} causes <code> to be executed whenever <option> is passed as an option, you can use \PassOptionsToClass here to pass on an option.

The following would work for you:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{beamer-nk}[2017/10/16 Beamer version nk, V4.1]

\DeclareOption{handout}{\PassOptionsToClass{\CurrentOption}{beamer}} 
%% N.B., you could replace "\CurrentOption" by "handout" in the line above.

\ProcessOptions\relax

\LoadClass[xcolor=dvipsnames,professionalfont,french]{beamer}

If you also want to pass on other options to beamer you probably want the starred form, \DeclareOption*, which handles all unknown options (i.e., the ones you haven't declared).

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{beamer-nk}[2017/10/16 Beamer version nk, V4.1]

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{beamer}}

\ProcessOptions\relax

\LoadClass[xcolor=dvipsnames,professionalfont,french]{beamer}
  • isn't \DeclareOption*{\ClassWarning{myclass}{Unknown option '\CurrentOption'}} safer ? – Tarass Mar 7 '18 at 17:35
  • There isn't really any harm in passing on unknown options: if beamer doesn't like an option, it'll produce its own error/warning. And if you some day decide that you want to pass another option to beamer you won't have to rewrite your wrapper class. (Also: options to \documentclass aren't just passed to the class you are loading, but also to packages that can handle them regardless of whether the option is used by the class in question. A useful application of this is the draft option, which is used by many packages.) – Circumscribe Mar 7 '18 at 18:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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