fontspec icon indicating copy to clipboard operation
fontspec copied to clipboard

Allow for spaces when using the "Path" option

Open keth-tex opened this issue 2 years ago • 1 comments

Using the "Path" option it is currently not possible to load fonts with spaces in their name (or in folder names). Unfortunately there are a lot of fonts that have spaces in the file names. (I'm using Lua(La)TeX.)

\documentclass{article}
\usepackage{fontspec}
\setmainfont{TT Norms Pro Serif-Regular.otf}[
  Path= ./fonts/
]
\begin{document}
hello
\end{document}

keth-tex avatar May 19 '23 05:05 keth-tex

I encountered the same issue when attempting to access font files that have spaces in their file names and are not installed system-wide.

For me, the issue goes away if I disable \tl_remove_all:Nn #1 {~} in lines 1275 and 1523 of the file fontspec-luatex.sty:

\cs_new:Nn \__fontspec_sanitise_fontname:Nn
  {
    \tl_set:Nx #1 {#2}
  % \tl_remove_all:Nn #1 {~}  % Line 1275
    \clist_map_inline:Nn \l__fontspec_extensions_clist
      {
        \tl_if_in:NnT #1 {##1}
          {
            \tl_remove_once:Nn #1 {##1}
            \tl_set:Nn \l__fontspec_extension_tl {##1}
            \clist_map_break:
          }
      }
  }

and

\cs_new:Nn \fontspec_complete_fontname:Nn
  {
    \tl_set:Nx #1 {#2}
    \tl_replace_all:Nnx #1 {*} {\l__fontspec_basename_tl}
  % \tl_remove_all:Nn #1 {~}  % Line 1523
  }

This means that as a work-around, you can a place copy of fontspec-luatex.sty with these two modifications in the same folder as your (LuaLa)TeX document. In my case, this makes the document compile without any issues: disabling lines 1275 and 1523 has no negative consequences in my case.

HolgerGerhardt avatar Jul 02 '23 20:07 HolgerGerhardt