
我正在為我的巨集和快捷方式開發一個自訂包,並為我喜歡的文件樣式開發一個自訂類別。我用來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
感謝您的報告和乾淨的測試文件。