From 84d56404e30a5ef1c3e7bb80d7bbb32784497c08 Mon Sep 17 00:00:00 2001 From: Ulrike Fischer Date: Sun, 17 Dec 2023 17:18:20 +0100 Subject: [PATCH 1/4] move to keyval-options --- CHANGES.md | 6 ++- fontspec-code-load.dtx | 4 +- fontspec-code-msg.dtx | 4 ++ fontspec-code-opening.dtx | 97 +++++++++++++++++---------------------- fontspec-code-vars.dtx | 6 ++- fontspec-doc-intro.tex | 16 ++++--- fontspec.ins | 2 + 7 files changed, 70 insertions(+), 65 deletions(-) diff --git a/CHANGES.md b/CHANGES.md index 10841c1..8aeb1d3 100644 --- a/CHANGES.md +++ b/CHANGES.md @@ -1,6 +1,10 @@ Change history ============== - +## [Unreleased] + * switched options to LaTeX keyval handler + * added option verbose to undo silent/quiet + * euenc/tuenc options are obsolete + * TU is the only encoding ## v2.8a (2022/01/15) * Add `SwashFont` and `BoldSwashFont` features to support LaTeX's now-builtin `\textsw` diff --git a/fontspec-code-load.dtx b/fontspec-code-load.dtx index 4f7ec3b..a61c5af 100644 --- a/fontspec-code-load.dtx +++ b/fontspec-code-load.dtx @@ -21,7 +21,7 @@ { \RequirePackage{luaotfload} \lua_now:e{require("fontspec")} - \RequirePackageWithOptions{fontspec-luatex} + \RequirePackage{fontspec-luatex} \endinput } % \end{macrocode} @@ -30,7 +30,7 @@ % \begin{macrocode} \sys_if_engine_xetex:T { - \RequirePackageWithOptions{fontspec-xetex} + \RequirePackage{fontspec-xetex} \endinput } % \end{macrocode} diff --git a/fontspec-code-msg.dtx b/fontspec-code-msg.dtx index 4d80194..b2438c4 100644 --- a/fontspec-code-msg.dtx +++ b/fontspec-code-msg.dtx @@ -193,6 +193,10 @@ { The "cm-default" package option is obsolete. } +\@@_msg_new:nn {enc-obsolete} + { + The "#1" package option is obsolete. TU is the default encoding. + } \@@_msg_new:nn {font-index-needs-ttc} { The "FontIndex" feature is only supported by TTC (TrueType Collection) fonts.\\ diff --git a/fontspec-code-opening.dtx b/fontspec-code-opening.dtx index 60253a1..2151252 100644 --- a/fontspec-code-opening.dtx +++ b/fontspec-code-opening.dtx @@ -4,75 +4,74 @@ % % \iffalse % \begin{macrocode} -%<*fontspec> +%<*options> % \end{macrocode} % \fi % % \subsection{Package options} % % \begin{macrocode} -\DeclareOption{cm-default} +\DeclareKeys { - \@@_warning:n {cm-default-obsolete} - } + cm-default .code:n = { \@@_warning:n {cm-default-obsolete} } % \end{macrocode} % % \begin{macrocode} -\DeclareOption {math} { \bool_gset_true:N \g_@@_math_bool } -\DeclareOption {no-math} { \bool_gset_false:N \g_@@_math_bool } -\DeclareOption {config} { \bool_gset_true:N \g_@@_cfg_bool } -\DeclareOption {no-config}{ \bool_gset_false:N \g_@@_cfg_bool } -\DeclareOption {euenc} { \bool_gset_true:N \g_@@_euenc_bool } -\DeclareOption {tuenc} { \bool_gset_false:N \g_@@_euenc_bool } + ,math .bool_gset:N = \g_@@_math_bool + ,math .usage:n = preamble + ,no-math .bool_gset_inverse:N = \g_@@_math_bool + ,no-math .usage:n = preamble + ,config .bool_gset:N = \g_@@_cfg_bool + ,config .usage:n = load + ,no-config .bool_gset_inverse:N = \g_@@_cfg_bool + ,no-config .usage:n = load + ,euenc .code:n = { \@@_warning:nx {enc-obsolete}{euenc} } + ,tuenc .code:n = { \@@_warning:nx {enc-obsolete}{tuenc} } % \end{macrocode} % % \begin{macrocode} -\DeclareOption {quiet} - { - \msg_redirect_module:nnn { fontspec } { warning } { info } - \msg_redirect_module:nnn { fontspec } { info } { none } - } -\DeclareOption{silent} - { - \msg_redirect_module:nnn { fontspec } { warning } { none } - \msg_redirect_module:nnn { fontspec } { info } { none } - } + ,quiet .code:n = + { + \msg_redirect_module:nnn { fontspec } { warning } { info } + \msg_redirect_module:nnn { fontspec } { info } { none } + } + ,silent .code:n = + { + \msg_redirect_module:nnn { fontspec } { warning } { none } + \msg_redirect_module:nnn { fontspec } { info } { none } + } + ,verbose .code:n = + { + \msg_redirect_module:nnn { fontspec } { warning } { warning } + \msg_redirect_module:nnn { fontspec } { info } { info } + } + } % \end{macrocode} % % \begin{macrocode} -\ExecuteOptions{config,math,tuenc} -\ProcessOptions* +\SetKeys{config,math} +\ProcessKeyOptions % \end{macrocode} % -% +% \iffalse +% \begin{macrocode} +% +%<*fontspec> +% \end{macrocode} +% \fi % % % \subsection{Encodings} % -% Soon to be the default, with a just-in-case check: +% Now the default, with a just-in-case check: % \begin{macrocode} -\bool_if:NF \g_@@_euenc_bool - { - \file_if_exist:nTF {tuenc.def} - { - \cs_if_exist:cF {T@TU} - { - \@@_warning:n {tu-clash} - \DeclareFontEncoding{TU}{}{} - \DeclareFontSubstitution{TU}{lmr}{m}{n} - } - } - { - \@@_warning:n {tu-missing} - \bool_gset_true:N \g_@@_euenc_bool - } - } -\bool_if:NTF \g_@@_euenc_bool +\cs_if_exist:cF {T@TU} { -% \tl_gset:Nn \g_fontspec_encoding_tl {EU1} -% \tl_gset:Nn \g_fontspec_encoding_tl {EU2} + \@@_warning:n {tu-clash} + \DeclareFontEncoding{TU}{}{} + \DeclareFontSubstitution{TU}{lmr}{m}{n} } - { \tl_gset:Nn \g_fontspec_encoding_tl { TU } } +\tl_gset:Nn \g_fontspec_encoding_tl { TU } % \end{macrocode} % % \begin{macrocode} @@ -100,16 +99,6 @@ % Something to do with \cmd\select@language\ ending up in the \texttt{.aux} % file which is read at the beginning of the document. % -% \begin{macrocode} -\bool_if:NT \g_@@_euenc_bool - { -% \cs_set_eq:NN \fontspec_tmp: \XeTeXpicfile -% \cs_set:Npn \XeTeXpicfile {} - \RequirePackage{xunicode} -% \cs_set_eq:NN \XeTeXpicfile \fontspec_tmp: - } -% \end{macrocode} -% % % \subsection{Generic functions} % diff --git a/fontspec-code-vars.dtx b/fontspec-code-vars.dtx index fc1321a..6c8ef4e 100644 --- a/fontspec-code-vars.dtx +++ b/fontspec-code-vars.dtx @@ -4,6 +4,7 @@ % % \iffalse % \begin{macrocode} +%<@@=fontspec> %<*fontspec> % \end{macrocode} % \fi @@ -50,9 +51,12 @@ % \end{macrocode} % For package options: % \begin{macrocode} +% +%<*options> \bool_new:N \g_@@_cfg_bool \bool_new:N \g_@@_math_bool -\bool_new:N \g_@@_euenc_bool +% +%<*fontspec> % \end{macrocode} % % \begin{macrocode} diff --git a/fontspec-doc-intro.tex b/fontspec-doc-intro.tex index 4e913b6..f062ab4 100644 --- a/fontspec-doc-intro.tex +++ b/fontspec-doc-intro.tex @@ -75,17 +75,19 @@ \section{Package loading and options} \usepackage{fontspec} \end{Verbatim} Package options will be introduced below; some preliminary details are discussed first. - +Package options are setup with the in-built \LaTeX{} keyval options handler. This means +that the package can be loaded more than once with different options without triggering +an option clash error. The \texttt{config} and \texttt{no-config} option must be used in +the first loading and are ignored later. \subsection{Font encodings} -The (default) \texttt{tuenc} package option switches the \textsc{nfss} font encoding to \texttt{TU}. +The package switches the \textsc{nfss} font encoding to \texttt{TU}. \texttt{TU} is a new Unicode font encoding, intended for both \XeTeX\ and \LuaTeX\ engines, and automatically contains support for symbols covered by \LaTeX's traditional \texttt{T1} and \texttt{TS1} font encodings (for example, |\%|, |\textbullet|, |\"u|, and so on). Some additional features are provided by \pkg{fontspec} to customise some encoding details; see Part~\vref{part:enc} for further details. -Pre-2017 behaviour can be achieved with the \texttt{euenc} package option. -This selects the \texttt{EU1} or \texttt{EU2} encoding (\XeTeX/\LuaTeX, resp.) and loads the \pkg{xunicode} package for symbol support. -Package authors and users who have referred explicitly to the encoding names \texttt{EU1} or \texttt{EU2} should update their code or documents. +Pre-2017 behaviour is now obsolete. The \texttt{euenc} and \texttt{tuenc} package options are +ignored. Package authors and users who have referred explicitly to the encoding names \texttt{EU1} or \texttt{EU2} should update their code or documents. (See internal variable names described in \vref{sec:api} for how to do this properly.) @@ -108,7 +110,7 @@ \subsection{Configuration} To customise \pkg{fontspec} to your liking, use the standard |.cfg| file as a starting point or write your own from scratch, then either place it in the same folder as the main document for isolated cases, or in a location that \XeTeX\ or \LuaTeX\ searches by default; \eg\ in Mac\TeX: \path{~/Library/texmf/tex/latex/}. -The package option |no-config| will suppress the loading of the |fontspec.cfg| file under all circumstances. +The package option |no-config| will suppress the loading of the |fontspec.cfg| file under all circumstances. Both options must be used the first time \pkg{fontspec} is loaded and are ignored in later calls. \subsection{Warnings} @@ -121,7 +123,7 @@ \subsection{Warnings} Use the |silent| package option to completely suppress these warnings if you don't even want the |.log| file cluttered up. - +Both options can also be used with \cs{Setkeys} in the document. Use the |verbose| option to get activate the warnings again. \section{Interaction with \LaTeXe\ and other packages} diff --git a/fontspec.ins b/fontspec.ins index be45e40..597ef99 100644 --- a/fontspec.ins +++ b/fontspec.ins @@ -32,6 +32,8 @@ the conditions of the LaTeX Project Public License, version 1.3c or higher \generate{\file{fontspec.sty}{ \from{fontspec.dtx}{fontspec,load\FSDEBUG} + \from{fontspec-code-vars.dtx}{options} + \from{fontspec-code-opening.dtx}{options} \from{fontspec-code-load.dtx}{fontspec,load\FSDEBUG} }} From 2f743723da41bbd1ec6d34bb8bda835046015db3 Mon Sep 17 00:00:00 2001 From: Ulrike Fischer Date: Sun, 17 Dec 2023 18:54:50 +0100 Subject: [PATCH 2/4] move missing messages into style --- fontspec-code-msg.dtx | 17 ++++++++++++----- fontspec-code-opening.dtx | 6 +++--- fontspec.ins | 1 + 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/fontspec-code-msg.dtx b/fontspec-code-msg.dtx index b2438c4..034ed6c 100644 --- a/fontspec-code-msg.dtx +++ b/fontspec-code-msg.dtx @@ -189,14 +189,21 @@ Input mapping not supported in LuaTeX.\\ Use "Ligatures=TeX" instead of "Mapping=tex-text". } -\@@_msg_new:nn {cm-default-obsolete} +% \end{macrocode} +% message for package options must be loaded earlier +% \begin{macrocode} +% +%<*options> +\msg_new:nnn {fontspec} {cm-default-obsolete} { - The "cm-default" package option is obsolete. + The~"cm-default"~package~option~is~obsolete. } -\@@_msg_new:nn {enc-obsolete} +\msg_new:nnn {fontspec} {enc-obsolete} { - The "#1" package option is obsolete. TU is the default encoding. - } + The~"#1"~package~option~is~obsolete.~TU~is~the~default~encoding. + } +% +%<*fontspec> \@@_msg_new:nn {font-index-needs-ttc} { The "FontIndex" feature is only supported by TTC (TrueType Collection) fonts.\\ diff --git a/fontspec-code-opening.dtx b/fontspec-code-opening.dtx index 2151252..d172de6 100644 --- a/fontspec-code-opening.dtx +++ b/fontspec-code-opening.dtx @@ -13,7 +13,7 @@ % \begin{macrocode} \DeclareKeys { - cm-default .code:n = { \@@_warning:n {cm-default-obsolete} } + cm-default .code:n = { \msg_warning:nn {fontspec} {cm-default-obsolete} } % \end{macrocode} % % \begin{macrocode} @@ -25,8 +25,8 @@ ,config .usage:n = load ,no-config .bool_gset_inverse:N = \g_@@_cfg_bool ,no-config .usage:n = load - ,euenc .code:n = { \@@_warning:nx {enc-obsolete}{euenc} } - ,tuenc .code:n = { \@@_warning:nx {enc-obsolete}{tuenc} } + ,euenc .code:n = { \msg_warning:nnn {fontspec} {enc-obsolete}{euenc} } + ,tuenc .code:n = { \msg_warning:nnb {fontspec} {enc-obsolete}{tuenc} } % \end{macrocode} % % \begin{macrocode} diff --git a/fontspec.ins b/fontspec.ins index 597ef99..8cc3306 100644 --- a/fontspec.ins +++ b/fontspec.ins @@ -33,6 +33,7 @@ the conditions of the LaTeX Project Public License, version 1.3c or higher \generate{\file{fontspec.sty}{ \from{fontspec.dtx}{fontspec,load\FSDEBUG} \from{fontspec-code-vars.dtx}{options} + \from{fontspec-code-msg.dtx}{options} \from{fontspec-code-opening.dtx}{options} \from{fontspec-code-load.dtx}{fontspec,load\FSDEBUG} }} From 32e4786ebabaf7091de2dd31ec08b9ca5e08440c Mon Sep 17 00:00:00 2001 From: Ulrike Fischer Date: Sun, 17 Dec 2023 19:03:27 +0100 Subject: [PATCH 3/4] grumpf --- fontspec-code-opening.dtx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fontspec-code-opening.dtx b/fontspec-code-opening.dtx index d172de6..e19c261 100644 --- a/fontspec-code-opening.dtx +++ b/fontspec-code-opening.dtx @@ -26,7 +26,7 @@ ,no-config .bool_gset_inverse:N = \g_@@_cfg_bool ,no-config .usage:n = load ,euenc .code:n = { \msg_warning:nnn {fontspec} {enc-obsolete}{euenc} } - ,tuenc .code:n = { \msg_warning:nnb {fontspec} {enc-obsolete}{tuenc} } + ,tuenc .code:n = { \msg_warning:nnn {fontspec} {enc-obsolete}{tuenc} } % \end{macrocode} % % \begin{macrocode} From 8aa51f68376885dbbdf8a6cdc31a08c9d6431d39 Mon Sep 17 00:00:00 2001 From: Ulrike Fischer Date: Sun, 17 Dec 2023 19:38:57 +0100 Subject: [PATCH 4/4] add testfile --- testfiles/00-pkg-load-twice.luatex.tlg | 16 ++++++++++++++++ testfiles/00-pkg-load-twice.lvt | 6 ++++++ testfiles/00-pkg-load-twice.tlg | 12 ++++++++++++ 3 files changed, 34 insertions(+) create mode 100644 testfiles/00-pkg-load-twice.luatex.tlg create mode 100644 testfiles/00-pkg-load-twice.lvt create mode 100644 testfiles/00-pkg-load-twice.tlg diff --git a/testfiles/00-pkg-load-twice.luatex.tlg b/testfiles/00-pkg-load-twice.luatex.tlg new file mode 100644 index 0000000..990db5e --- /dev/null +++ b/testfiles/00-pkg-load-twice.luatex.tlg @@ -0,0 +1,16 @@ +This is a generated file for the l3build validation system. +Don't change this file in any respect. +Completed box being shipped out [1] +\hbox(0.0+0.0)x0.0, glue set - 1.0, direction TLT +.\TU/lmr/m/n/10 h +.\TU/lmr/m/n/10 e +.\TU/lmr/m/n/10 l +.\TU/lmr/m/n/10 l +.\TU/lmr/m/n/10 o +.\glue(\spaceskip) 3.33 plus 1.665 minus 1.11 +.\mathon +.\OT1/cmr/m/n/10 a +.\mathoff +.\glue(\spaceskip) 3.33 plus 1.665 minus 1.11 +*************** +Compilation 1 of test file completed with exit status 0 diff --git a/testfiles/00-pkg-load-twice.lvt b/testfiles/00-pkg-load-twice.lvt new file mode 100644 index 0000000..03ee837 --- /dev/null +++ b/testfiles/00-pkg-load-twice.lvt @@ -0,0 +1,6 @@ +\input{fontspec-testsetup} +\usepackage{fontspec} +\usepackage[no-math]{fontspec} +\begin{document} +\SHIPOUT{hello $\mathrm{a}$ } +\end{document} diff --git a/testfiles/00-pkg-load-twice.tlg b/testfiles/00-pkg-load-twice.tlg new file mode 100644 index 0000000..b7e94f0 --- /dev/null +++ b/testfiles/00-pkg-load-twice.tlg @@ -0,0 +1,12 @@ +This is a generated file for the l3build validation system. +Don't change this file in any respect. +Completed box being shipped out [1] +\hbox(0.0+0.0)x0.0, glue set - 1.0 +.\TU/lmr/m/n/10 hello +.\glue 3.33 plus 1.665 minus 1.11 +.\mathon +.\OT1/cmr/m/n/10 a +.\mathoff +.\glue 3.33 plus 1.665 minus 1.11 +*************** +Compilation 1 of test file completed with exit status 0