Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BoldFeatures within \defaultfontfeatures #436

Open
3 of 4 tasks
Davislor opened this issue Dec 21, 2020 · 3 comments
Open
3 of 4 tasks

BoldFeatures within \defaultfontfeatures #436

Davislor opened this issue Dec 21, 2020 · 3 comments

Comments

@Davislor
Copy link

Description

Using BoldFeatures = inside \defaultfontfeatures gives an error.

Check/indicate

  • Relevant for XeTeX
  • Relevant for LuaTeX
  • Issue tracker has been searched for similar issues?
  • Links to <tex.stackexchange.com> discussion if appropriate

Minimal example demonstrating the issue

\documentclass{article}
\usepackage{fontspec}

\defaultfontfeatures[FreeSerif]{
  BoldFont=*,
  BoldFeatures = {FakeBold = 1.2} }

\setmainfont{FreeSerif}

\begin{document}
\maketitle
\end{document}

Further details

On an up-to-date TeX Live 2020, this gives the error

! LaTeX3 Error: The key 'fontspec-opentype/BoldFeatures' is unknown and is
(LaTeX3)        being ignored.
@chrullrich
Copy link
Contributor

I was able to get around that by changing fontspec-preparse to fontspec-opentype between lines 2308 and 2366 of fontspec-luatex.sty and lines 2416 and 2444 of fontspec-xetex.sty (built from current git). A very simple test document that exercises UprightFeatures, BoldFeatures, etc. combined with SizeFeatures for the optical sizes of Source Serif 4 as well as a 180-page doc that uses only a few different faces compiled with both lualatex and xelatex and looked OK to me.

No idea what may break from this change that I just have not seen yet. My guess (and it really is one) is that anything other than my exact circumstances (installed OpenType fonts on Windows) will not work anymore.

@u-fischer
Copy link
Member

I don't think that this the right fix. The problem is that \__fontspec_make_font_shapes:Nnnnn calls

\__fontspec_declare_shape:nnxx {#2} {#3} { \l__fontspec_fontopts_clist, \l__fontspec_leftover_clist } {#5}

where \l__fontspec_fontopts_clist contains the font specific options. This list contains options that have been already processed (the options from the families preparsed and preparsed-external) which \__fontspec_declare_shape:nnxx should imho simply ignore. Instead it tries to set them as keys of the final family fontspec-opentype and then errors.

The problem seems to have hit someone earlier, as there are a number of dummy key definitions

\__fontspec_keys_define_code:nnn {fontspec-opentype} {UprightFont} {}
\__fontspec_keys_define_code:nnn {fontspec-opentype} {ItalicFont} {}

One could extend that list, but imho it would make more sense to set only known keys at the end:

\documentclass{article}
\usepackage{fontspec}


\ExplSyntaxOn
\cs_set:Nn \__fontspec_get_features:n
  {
    \__fontspec_init_fontface:
    \__fontspec_keys_set_known:nxN {fontspec-renderer} {\l__fontspec_fontfeat_clist,#1}
      \l__fontspec_keys_leftover_clist
    \__fontspec_keys_set_known:nxN {fontspec} {\l__fontspec_keys_leftover_clist} \l__fontspec_keys_leftover_clist
    \keys_set_known:nV {fontspec-opentype} \l__fontspec_keys_leftover_clist %changed, set only known keys

    \tl_if_empty:NF \l__fontspec_mapping_tl
      { \__fontspec_update_featstr:n { mapping = \l__fontspec_mapping_tl } }

    \str_if_eq:eeF { \l__fontspec_hexcol_tl \l__fontspec_opacity_tl }
                     { \c__fontspec_hexcol_tl \c__fontspec_opacity_tl }
       { \__fontspec_update_featstr:n { color = {\l__fontspec_hexcol_tl\l__fontspec_opacity_tl} } }
  }
\ExplSyntaxOff
\defaultfontfeatures[FreeSerif]{
  BoldFont=*,
  BoldFeatures = {FakeBold = 1.2} }

\setmainfont{FreeSerif}

\begin{document}
xx
\end{document}

@chrullrich
Copy link
Contributor

This works perfectly with my two test documents, with both LuaTeX and XeTeX from MiKTeX and installed OpenType fonts. Guessing further, I would expect it to work in any OpenType situation. Would the same change be required for the Graphite/AAT case with XeTeX? I don't have a Mac handy to try.

chrullrich added a commit to chrullrich/fontspec that referenced this issue Jun 18, 2022
This works with OpenType fonts on Windows MikTeX, both LuaTeX and XeTeX.

latex3#436 (comment)
wspr pushed a commit that referenced this issue Apr 20, 2024
This works with OpenType fonts on Windows MikTeX, both LuaTeX and XeTeX.

#436 (comment)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants