koma-script 中未使用的具有多阶段选项的全局选项

koma-script 中未使用的具有多阶段选项的全局选项

我们将 koma-script 用于各种不同的文档,例如报告和简短的法律文件。我想让我们的文档更加一致。我的想法是创建一个包(myBase.sty),其中包含选项、通用宏、字体配置等,这些应该在我们所有不同类型的文档之间共享。然后,这个包应该被其他特定的文档(包装器)类使用。

具体来说,类myReport.clsmyLegalDoc.cls应该继承中定义的选项myBase.sty

我创建了以下 MWE 来演示我所面临的问题:

\begin{filecontents}{myBase.sty}
\ProvidesPackage{myBase}
\DefineFamily{TEST}
\DefineFamilyMember[]{TEST}

\FamilyBoolKey[]{TEST}{inheritedopt}{TEST@inheritedopt}
\end{filecontents}

\begin{filecontents}{myReport.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myReport}[]

\RequirePackage{scrbase}
\RequirePackage{myBase}

\DefineFamily{TEST}
\DefineFamilyMember{TEST}

\FamilyBoolKey[.myReport.cls]{TEST}{classopt}{TEST@classopt}

% Pass unknown options to the parent class
\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrreprt}}

% Process options defined in myReport.cls
\FamilyProcessOptions[.myReport.cls]{TEST}\relax

% Process options defined in myBase.sty
\FamilyProcessOptions[]{TEST}\relax

\LoadClass{scrreprt}
\end{filecontents}

\documentclass[%
inheritedopt=true,%
classopt=true%
]{myReport}

\usepackage{etoolbox}

\ifbool{TEST@classopt}{%
    \typeout{classopt=true}
}{
    \typeout{classopt=false}
}

\ifbool{TEST@inheritedopt}{%
    \typeout{inheritedopt=true}
}{
    \typeout{inheritedopt=false}
}

% Leads to:
% LaTeX Warning: Unused global option(s):
%     [classopt].


\begin{document}
This is a test.
\end{document}

输出\typeout表明选项已正确处理。但是,有一个警告似乎表明classopt未正确处理:

$ pdflatex mwe.tex
This is pdfTeX, Version 3.141592653-2.6-1.40.22 (TeX Live 2022/dev/Debian) (preloaded format=pdflatex)
 restricted \write18 enabled.
entering extended mode
(./mwe.tex
LaTeX2e <2021-11-15> patch level 1
L3 programming layer <2022-01-21>

LaTeX Info: Writing file `./myBase.sty'.



LaTeX Info: Writing file `./myReport.cls'.


(./myReport.cls
Document Class: myReport
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrbase.sty
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrlfile.sty
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrlfile-hook.sty
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrlogo.sty)))
(/usr/share/texlive/texmf-dist/tex/latex/graphics/keyval.sty)) (./myBase.sty))
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrreprt.cls
Document Class: scrreprt 2021/11/13 v3.35 KOMA-Script document class (report)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrkbase.sty)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/tocbasic.sty)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/scrsize11pt.clo)
(/usr/share/texlive/texmf-dist/tex/latex/koma-script/typearea.sty))
(/usr/share/texlive/texmf-dist/tex/latex/etoolbox/etoolbox.sty)
classopt=true
inheritedopt=true
(/usr/share/texlive/texmf-dist/tex/latex/l3backend/l3backend-pdftex.def)

LaTeX Warning: Unused global option(s):
    [classopt].

(./mwe.aux) [1{/var/lib/texmf/fonts/map/pdftex/updmap/pdftex.map}] (./mwe.aux)
)</usr/share/texlive/texmf-dist/fonts/type1/public/amsfonts/cm/cmr10.pfb>
Output written on mwe.pdf (1 page, 12551 bytes).
Transcript written on mwe.log.

也许该选项被传递给 koma-script 的 scrreprt 类进行进一步处理?我怀疑这在某种程度上与此有关,\FamilyKeyState但我不确定如何进一步调试。提前致谢!


更新(2022-05-20):不幸的是,我忘了说我希望有选项来处理在myBase.sty myBase.sty.示例代码:

\begin{filecontents}{myBase.sty}
\ProvidesPackage{myBase}
\RequirePackage{scrbase}% <- added
\DefineFamily{TEST}
\DefineFamilyMember{TEST}% <- define family member .myBase.sty
\FamilyBoolKey{TEST}{inheritedopt}{TEST@inheritedopt}% inheriteopt is key of family member .myBase.sty
\FamilyProcessOptions{TEST}\relax% process (family options and) options of family member .myBase.cls

\ifbool{TEST@inheritedopt}{%
    % Do something ...
}{}
\end{filecontents}

\begin{filecontents}{myReport.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myReport}

\RequirePackage{scrbase}

\DefineFamily{TEST}
\DefineFamilyMember{TEST}% <- define family member .myReport.cls
\FamilyBoolKey{TEST}{classopt}{TEST@classopt}% classopt is key of family member .myReport.cls

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrreprt}}% pass unknown options to the parent class

\FamilyProcessOptions{TEST}\relax% process (family options and) options of family member .myReport.cls

\LoadClass{scrreprt}
\RequirePackage{myBase}% <- moved
\end{filecontents}

\documentclass[
inheritedopt=true,
classopt=true
]{myReport}

\begin{document}
\makeatletter
\ifTEST@classopt
  classopt=true
\else
  classopt=false
\fi
\quad
\ifTEST@inheritedopt
  inheriteopt=true
\else
  inheriteopt=false
\fi
\makeatother
\end{document}

答案1

从您的代码中删除\FamilyProcessOptions[]{TEST}\relax。这些家庭密钥(家庭成员为空的密钥)是在\FamilyProcessOptions[.myReport.cls]{TEST}\relax家庭成员密钥之前设置的.myReport.cls

您可以使用\FamilyProcessOptions{TEST}\relax。然后设置家庭的键,然后设置家庭成员的键.\@currname.\@currextmyReport.cls加载时,.\@currname.\@currext代表.myReport.cls

根据您要执行的操作,这里有两条建议:

\begin{filecontents}{myBase.sty}
\ProvidesPackage{myBase}
\RequirePackage{scrbase}% <- added
\DefineFamily{TEST}
%\DefineFamilyMember[]{TEST}% family itself -> can be removed
\FamilyBoolKey[]{TEST}{inheritedopt}{TEST@inheritedopt}% inheriteopt is key of family TEST
\end{filecontents}

\begin{filecontents}{myReport.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myReport}

\RequirePackage{scrbase}
\RequirePackage{myBase}

\DefineFamily{TEST}
\DefineFamilyMember{TEST}% <- define family member .myReport.cls
\FamilyBoolKey{TEST}{classopt}{TEST@classopt}% classopt is key of family member .myReport.cls

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrreprt}}% pass unknown options to the parent class

\FamilyProcessOptions{TEST}\relax% process family options and options of family member .myReport.cls

\LoadClass{scrreprt}
\end{filecontents}

\documentclass[
inheritedopt=true,
classopt=true
]{myReport}

\begin{document}
\makeatletter
\ifTEST@classopt
  classopt=true
\else
  classopt=false
\fi
\quad
\ifTEST@inheritedopt
  inheriteopt=true
\else
  inheriteopt=false
\fi
\makeatother
\end{document}

或者

\begin{filecontents}{myBase.sty}
\ProvidesPackage{myBase}
\RequirePackage{scrbase}% <- added
\DefineFamily{TEST}
\DefineFamilyMember{TEST}% <- define family member .myBase.sty
\FamilyBoolKey{TEST}{inheritedopt}{TEST@inheritedopt}% inheriteopt is key of family member .myBase.sty
\FamilyProcessOptions{TEST}\relax% process (family options and) options of family member .myBase.cls
\end{filecontents}

\begin{filecontents}{myReport.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myReport}

\RequirePackage{scrbase}

\DefineFamily{TEST}
\DefineFamilyMember{TEST}% <- define family member .myReport.cls
\FamilyBoolKey{TEST}{classopt}{TEST@classopt}% classopt is key of family member .myReport.cls

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrreprt}}% pass unknown options to the parent class

\FamilyProcessOptions{TEST}\relax% process (family options and) options of family member .myReport.cls

\LoadClass{scrreprt}
\RequirePackage{myBase}% <- moved
\end{filecontents}

\documentclass[
inheritedopt=true,
classopt=true
]{myReport}

\begin{document}
\makeatletter
\ifTEST@classopt
  classopt=true
\else
  classopt=false
\fi
\quad
\ifTEST@inheritedopt
  inheriteopt=true
\else
  inheriteopt=false
\fi
\makeatother
\end{document}

其他示例(关于问题中的更新):

\begin{filecontents}{myBase.sty}
\ProvidesPackage{myBase}
\RequirePackage{scrbase}% <- added
\DefineFamily{TEST}
\DefineFamilyMember{TEST}% <- define family member .myBase.sty
\FamilyBoolKey{TEST}{inheritedopt}{TEST@inheritedopt}% inheriteopt is key of family member .myBase.sty
\FamilyProcessOptions{TEST}\relax% process (family options and) options of family member .myBase.cls
\ifTEST@inheritedopt
    \RequirePackage{showframe}
  \else
    \Ifundefinedorrelax{KOMAoptions}{}{\KOMAoptions{paper=landscape}}
  \fi 
\end{filecontents}

\begin{filecontents}{myReport.cls}
\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{myReport}

\RequirePackage{scrbase}

\DefineFamily{TEST}
\DefineFamilyMember{TEST}% <- define family member .myReport.cls
\FamilyBoolKey{TEST}{classopt}{TEST@classopt}% classopt is key of family member .myReport.cls

\DeclareOption*{\PassOptionsToClass{\CurrentOption}{scrreprt}}% pass unknown options to the parent class

\FamilyProcessOptions{TEST}\relax% process (family options and) options of family member .myReport.cls

\LoadClass{scrreprt}
\RequirePackage{myBase}% <- moved
\end{filecontents}

\documentclass[
inheritedopt=true,
classopt=true
]{myReport}

\begin{document}
\makeatletter
\ifTEST@classopt
  classopt=true
\else
  classopt=false
\fi
\quad
\ifTEST@inheritedopt
  inheriteopt=true
\else
  inheriteopt=false
\fi
\makeatother
\end{document}

相关内容