![为什么对于转发到包中的除第一个选项之外的选项,我会收到“未使用的全局选项警告”?](https://linux22.com/image/472868/%E4%B8%BA%E4%BB%80%E4%B9%88%E5%AF%B9%E4%BA%8E%E8%BD%AC%E5%8F%91%E5%88%B0%E5%8C%85%E4%B8%AD%E7%9A%84%E9%99%A4%E7%AC%AC%E4%B8%80%E4%B8%AA%E9%80%89%E9%A1%B9%E4%B9%8B%E5%A4%96%E7%9A%84%E9%80%89%E9%A1%B9%EF%BC%8C%E6%88%91%E4%BC%9A%E6%94%B6%E5%88%B0%E2%80%9C%E6%9C%AA%E4%BD%BF%E7%94%A8%E7%9A%84%E5%85%A8%E5%B1%80%E9%80%89%E9%A1%B9%E8%AD%A6%E5%91%8A%E2%80%9D%EF%BC%9F.png)
我正在为我的宏和快捷方式开发一个自定义包,以及为我喜欢的文档样式开发一个自定义类。我用它来DeclareKeys
定义包中的键值选项,然后加载此包的类通过将它们转发到基类(文章)来全局转发选项。它运行良好,但我收到有关未使用的全局选项的奇怪警告。以下是代码:
% demo-pkg.sty
\NeedsTeXFormat{LaTeX2e}
\ProvidesPackage{demo-pkg}[Demo]
\RequirePackage{xstring}
\DeclareKeys[my]
{
lang.choices:nn =
{ english, hebrew }
{\ExpandArgs{Nc}\let\@my@lang{l_keys_choice_tl}},
lang.usage = load,
lang.initial:n = english,
notation.choices:nn =
{ physics, math }
{\ExpandArgs{Nc}\let\@my@notation{l_keys_choice_tl}},
notation.usage = load,
notation.initial:n = physics,
foo.choices:nn =
{ bar, baz }
{\ExpandArgs{Nc}\let\@my@foo{l_keys_choice_tl}},
foo.usage = load,
foo.initial:n = bar
}
\ProcessKeyOptions[my]
\RequirePackage{xparse}
\IfStrEqCase{\@my@notation}{%
{physics}{%
\NewDocumentCommand{\Conjugate}{ m }{{##1}^{\ast}}%
}%
{math}{%
\NewDocumentCommand{\Conjugate}{ m }{\overline{##1}}%
}%
}%
% demo-cls.cls
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{demo-cls}[Demo class]
\DeclareKeys[demo-cls]
{
unknown.code = \PassOptionsToClass{\CurrentOption}{article}
}
\ProcessKeyOptions[demo-cls]
\LoadClass[a4paper, 12pt]{article}
\RequirePackage{demo-pkg}
% main.tex
\documentclass[lang=hebrew, notation=math, foo=baz]{demo-cls}
\usepackage{amsmath}
\begin{document}
\[ z = x + iy \Longleftrightarrow \Conjugate{z} = x - iy \]
\end{document}
运行此代码会生成正确的文档,但我会收到一条警告:
LaTeX Warning: Unused global option(s):
[notation,foo].
我的包显然选择了这些选项并使用了它们(notation
为了简单起见,我仅显示选项的使用方法),那么为什么我会收到这个警告,为什么第一个选项没有警告lang=hebrew
?
更改选项的顺序会将\documentclass[notation=math, lang=hebrew, foo=baz]{demo-cls}
警告更改为
LaTeX Warning: Unused global option(s):
[lang,foo].
但该文档仍可编译并且看起来不错。
为什么除第一个选项之外的每个选项都会收到警告,我该如何解决这些警告?
答案1
这是在新的基于 l3keys 的选项处理程序中处理选项列表时出现的错误。您可以通过确保选项之间没有多余的空格来避免出现虚假警告,因此
\documentclass[lang=hebrew,notation=math,foo=baz]{demo-cls}
在这个例子中。
该代码已在 Latex 源中修复(在来自 @Skillmon 的拉取请求中),因此将在即将发布的版本中修复。
错误报告
https://github.com/latex3/latex2e/issues/1238
拉取修复请求
https://github.com/latex3/latex2e/pull/1239
感谢您的报告和干净的测试文件。