使用 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}

相关内容