0

I'm porting my long preamble into a separate class file, and this is the only error left. In the MWE, I'm passing two key-value options to my class using xkeyval and feeding them to biblatex after combining them in a macro. This raises the error "Package xkeyval Error: `style' undefined in families`blx@opt@pre'." at biblatex.sty, 16186. Doing the same for the babel package doesn't result in any errors at all. I'm using LuaLaTeX, by the way.

Here's my MWE:

main.tex:

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

testclass.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}

Update: Thanks to David Carlisle, who suggested wrapping \RequirePackage in \expandafter, which fixed the MWE above. But it starts erroring again when I make the macro a bit more involved:

testclass.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}
4
  • probably \expandafter\RequirePackage\expandafter[\mybibargs]{biblatex} Commented Oct 20, 2023 at 16:06
  • @DavidCarlisle that works for the MWE, thanks! But it doesn't work when I expand the MWE, so I'll have to edit the question to account for that. Commented Oct 20, 2023 at 16:26
  • \expanded{\noexpand\RequirePackage[\mybibargs]{biblatex}} would fully expand the options Commented Oct 20, 2023 at 18:48
  • that solved the problem entirely; thanks! I'll be closing the question now (if possible). Commented Oct 21, 2023 at 11:53

1 Answer 1

1

Adding David Carlisle's suggestion as an answer so I can close the question.

Simply using \expanded{\noexpand\RequirePackage[\mybibargs]{biblatex}} does indeed get rid of the error without any side effects (so far).

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .