使用 pgfopts 時傳遞(僅)其他選項

使用 pgfopts 時傳遞(僅)其他選項

我想在使用新選項自訂類別、保留舊選項並使用其中一些選項時使用 pgfopts(因此也使用 pgfkeys)。

這是一個帶有類別“exa”的簡化範例,它使用新選項擴展“article”,並設定選項“a5paper”。

\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”。但它給出了有關未使用的全域選項 ["lastword=bar]" 的警告。

如何刪除 ProcessPgfOptions 處理的所有選項,以便僅將其餘選項傳送至「文章」?

答案1

您混合使用兩種設定選項的方法,這會導致警告。

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

相關內容