latex3 / fontspec

Font selection in LaTeX for XeTeX and LuaTeX
http://latex3.github.io/fontspec/
LaTeX Project Public License v1.3c
275 stars 33 forks source link

Global option `math` and latest `fontspec` package #501

Closed lvjr closed 4 months ago

lvjr commented 7 months ago

Description

My class defines math option as choice key with \DeclareKeys command, but latest fontspec package doesn't like it and throws an error.

! LaTeX Error: Key 'fontspec/math' accepts boolean values only.

Check/indicate

Minimal example demonstrating the issue

\documentclass[math=many]{randexam}
\usepackage{fontspec}
\begin{document}
Test
\end{document}
davidcarlisle commented 7 months ago

The issue is really with the latex format rather than fontspec. The new l3keys based option handler processes the global document class keys when handling a package, for consistency with traditional latex options.

It's possible that \ProcessKeyOptions could or should simply skip a key of the wrong type rather than throwing this error when processing the classoptions from within a package

Your class could remove the math=many from the global option list so it was not picked up by packages, which would get things working now, but I'm not sure if that's the best long term solution.


\ExplSyntaxOn
\prop_new:N\cEmptyProp
\ExplSyntaxOff
\documentclass[math=many]{randexam}
\makeatletter
\let\@raw@classoptionslist\@empty % or just remove math but simple case here
\makeatother
\usepackage{fontspec}
\begin{document}
Test
\end{document}```
u-fischer commented 7 months ago

You could also set the unknown handler (and fontspec could do that too):

\documentclass{book}
\ExplSyntaxOn
\DeclareKeys
 {
   math  .choice:,
   math / many .code:n = {\def\blub{abc}},
   math / unknown .code:n={\typeout{class??????}}
 }

\SetKeys{math=many,math=xxxx}
\show\blub

\DeclareKeys
 {
   math    .bool_gset:N = \g__fontspec_math_bool,
   math / unknown .code:n={\typeout{fontspec??????}}
 }

\SetKeys{math=true,math=blub}  
\bool_if:NT \g__fontspec_math_bool {\show\yes}

\ExplSyntaxOff

\begin{document}
abc
\end{document}
wspr commented 7 months ago

Perhaps a package should be able to opt out of inheriting the global class options? Without looking into the package exhaustively, off the top of my head I don’t think any of the standard class options are relevant.

josephwright commented 7 months ago

@wspr We talked about that on the team list :)

josephwright commented 7 months ago

Somewhere there was an issue about removing keyvals from the unused list: anyone remember where?

wspr commented 4 months ago

I am thinking of adding code to fontspec to address this. Does a warning make sense?

Package fontspec Warning: The global option 'math=yuck' is not recognised. It w
ill be ignored.

I'm thinking this would cause more harm than help.

wspr commented 4 months ago

(I thought we had word wrapping for expl3 messages...I guess I need to add it manually)