pgfopts を使用するときに他のオプションを渡す

pgfopts を使用するときに他のオプションを渡す

新しいオプションを使用してクラスをカスタマイズし、古いオプションを保持し、その一部を使用する場合は、pgfopts (および pgfkeys) を使用したいと思います。

以下は、新しいオプションで「article」を拡張し、オプション「a5paper」も設定するクラス「exa」の簡略化された例です。

\begin{filecontents}{exa.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exa}[2014/03/19 exa]
% As "article" with "a5paper" set, and an extra option "lastword".
\RequirePackage{pgfopts}
\pgfkeys{
  /exa/.cd,
  lastword/.code=\AtEndDocument{\par The last word is #1.}
}
\ProcessPgfOptions{/exa}
\PassOptionsToClass{a5paper}{article}
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{article}}
\ProcessOptions
\LoadClass{article}
\end{filecontents}

\documentclass[lastword=bar,twocolumn]{exa}

\usepackage{blindtext}
\begin{document}
\blindtext
\end{document}

ここでは、クラスによって設定された「a5paper」、"article" に送られた「twocolumn」、および新しいオプション「lastword」の 3 つのオプションが意図したとおりに動作します。ただし、未使用のグローバル オプション ["lastword=bar]" に関する警告が表示されます。

ProcessPgfOptions が処理したすべてのオプションを削除して、残りのオプションのみが「article」に送信されるようにするにはどうすればよいでしょうか?

答え1

オプションを設定するための 2 つの方法を混在させているため、警告が表示されます。

\begin{filecontents}{exa.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{exa}[2014/03/19 exa]
% As "article" with "a5paper" set, and an extra option "lastword".
\RequirePackage{pgfopts}

%%% initialize the options
\def\exa@classoptions{a5paper}

\pgfkeys{
  /exa/.cd,
  lastword/.code=\AtEndDocument{\par The last word is #1.},
  %%% unknown keys are assumed to be options to be passed to the class
  .unknown/.code={\edef\exa@classoptions{\exa@classoptions,\pgfkeyscurrentname}}
}
\ProcessPgfOptions{/exa}
\LoadClass[\exa@classoptions]{article}

\end{filecontents}

\documentclass[lastword=bar,twocolumn]{exa}

\usepackage{lipsum}
\begin{document}
\lipsum[1-10]
\end{document}

関連情報