通过自定义类中的宏传递时无法识别 Biblatex“样式”选项

通过自定义类中的宏传递时无法识别 Biblatex“样式”选项

我正在将我的长序言移植到一个单独的类文件中,这是唯一剩下的错误。在 MWE 中,我使用 xkeyval 将两个键值选项传递给我的类,并在将它们组合成宏后将它们提供给 biblatex。这会在 biblatex.sty,16186 处引发错误“Package xkeyval Error: `style' undefined in families`blx@opt@pre'。”。对 babel 包执行相同操作不会导致任何错误。顺便说一句,我使用的是 LuaLaTeX。

这是我的 MWE:

主要.tex:

\documentclass{testclass}
\title{mwe}
\author{AdamantConlanger}
\date{October 2023}
\begin{document}
\maketitle
\section{Introduction}
\printbibliography
\end{document}

测试类.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{testclass}[2023/10/20 Some Test Class]
\RequirePackage{xkeyval}

\newcommand{\mybibstyle}{}
\newcommand{\myotherbibargs}{}
\DeclareOptionX{bibstyle}[]{\renewcommand{\mybibstyle}{#1}}
\DeclareOptionX{otherbibargs}[]{\renewcommand{\myotherbibargs}{#1}}
\ExecuteOptionsX{bibstyle=phys, otherbibargs={sorting=nyt, giveninits=true}}
\ProcessOptionsX\relax

\newcommand{\mybibargs}{\myotherbibargs, style=\mybibstyle}
\LoadClass[titlepage, USenglish, 10pt, a4paper]{article}
\RequirePackage[\mybibargs]{biblatex}

更新:感谢 David Carlisle 建议使用 进行包装\RequirePackage\expandafter这修复了上面的 MWE。但是当我使宏更复杂一些时,它再次开始出错:

测试类.cls:

\NeedsTeXFormat{LaTeX2e}
\ProvidesClass{testclass}[2023/10/20 Some Test Class]
\RequirePackage{xkeyval}
\RequirePackage{etoolbox}

\newcommand{\mybibstyle}{}
\newcommand{\myotherbibargs}{}
\DeclareOptionX{bibstyle}[]{\renewcommand{\mybibstyle}{#1}}
\DeclareOptionX{otherbibargs}[]{\renewcommand{\myotherbibargs}{#1}}
\ExecuteOptionsX{bibstyle=phys, otherbibargs={sorting=nyt, giveninits=true}}
\ProcessOptionsX\relax

\newcommand{\mybibargs}{\expandafter\notblank\expandafter{\myotherbibargs}{\myotherbibargs, style=\mybibstyle}{style=\mybibstyle}}
\LoadClass[titlepage, USenglish, 10pt, a4paper]{article}
\expandafter\RequirePackage\expandafter[\mybibargs]{biblatex}

答案1

添加 David Carlisle 的建议作为答案,这样我就可以关闭这个问题了。

简单使用\expanded{\noexpand\RequirePackage[\mybibargs]{biblatex}}确实可以消除错误并且没有任何副作用(到目前为止)。

相关内容