I'm using kvoptions
in my document class and it's worked nicely so far, but after a major rewrite I started getting strange errors that I was able to trace back to the babel
package.
MWE:
%% myclass.cls
\NeedsTeXFormat{LaTeX2e}[2018/04/01]
\ProvidesClass{myclass}
\RequirePackage[patch]{kvoptions}
\DeclareStringOption{title}
\ProcessKeyvalOptions*
\LoadClass{article}
\title{\myclass@title}
\RequirePackage[english]{babel}
\endinput
\documentclass[title={Here be dragons}]{myclass}
\begin{document}
Lorem Ipsum
\end{document}
An excerpt from the log (paths omitted for brevity):
babel.sty:460: LaTeX Error: Missing \begin{document}. [ {}}]
babel.sty:460: Too many }'s. [ {}}]
babel.sty:475: LaTeX Error: Missing \begin{document}. [ \ifin@\edef\bbl@tempc{\bbl@tempb}\fi}]
Without the kvoptions
patch, the errors are getting worse:
babel.sty:339: LaTeX Error: Missing \begin{document}. [\ProcessOptions*]
babel.sty:339: You can't use `macro parameter character #' in horizontal mode. [\ProcessOptions*]
TeX STOPPED: File ended while scanning use of \reserved@{##1,##2\reserved@b }\def \reserved@b ##1,\reserved@b ##2\reserved@b
TeX reports the error was in file:3
myclass.cls:13: LaTeX Error: Unknown option `english' for package `babel'. []
Analysis: The problem is that I have used spaces (and braces) in the global option (title
) and this option is obviously passed on to babel
. Without the spaces, the errors don't occur.
Question: Can I prevent document class options from being used as global options by packages? Or is there some work-around akin to \hypersetup{}
for me to use instead of options? I could live with that.
\myclasssetup
command which can process key-val input with one of the various keyval packages. – Ulrike Fischer Mar 15 '19 at 9:03