¿Aparentemente \IfFileExists no funciona con otf?

¿Aparentemente \IfFileExists no funciona con otf?

Usando TeXlive 2023, Linux, lualatex.

Para mi sorpresa, \IfFileExistsno parece encontrar ningún *.otfarchivo, independientemente de si el archivo está instalado en texmf-distmi texmfdirectorio de inicio. MWE:

% !TeX TS-program = lualatex
% !TeX encoding = UTF-8
\documentclass{article}
\usepackage{fontspec}
\IfFileExists{LibertinusSerif-Regular.otf}{
  \typeout{FOUND IT}
}{
  \typeout{NOT FOUND} % This is the response.
}
\setmainfont{Libertinus Serif}
\begin{document}
Hello World. % Prints in LibertinusSerif-Regular.otf.
\end{document}

Al compilar con lualatex, espero que la salida de la línea de comandos (y el archivo de registro) tenga FOUND IT, porque el archivo definitivamente está ahí. Si intento utilizar la familia de fuentes Libertinus Serif como mi fuente principal, funciona. Pero \IfFileExistsno encuentra el archivo con su extensión correcta.

Me doy cuenta de que hay un comando \IfFontExists, pero puede tardar mucho si la fuente no está ahí, así que no deseo hacerlo de esa manera.

Respuesta1

Con \IfFileExistssolo puede buscar en el $TEXINPUTSárbol, es decir, archivos que tengan sentido \input(junto con posiblemente algo que se haya agregado a mano).

Puede definir una función que realice búsquedas en todo el texmf-distárbol (casi), usando kpsewhich.

\documentclass{article}

\ExplSyntaxOn

\NewDocumentCommand{\IfFileInTEXTree}{O{}mmm}
 {
  \sys_get_shell:nnN { kpsewhich~#1~#2 } {\escapechar=-1\scan_stop:} \l_tmpa_tl
  \tl_if_blank:VTF \l_tmpa_tl { #4 } { #3 }
 }

\ExplSyntaxOff

\IfFileInTEXTree{LibertinusSerif-Regular.otf}{%
  \typeout{FOUND IT}%
}{
  \typeout{NOT FOUND}%
}

\IfFileInTEXTree{whatever.otf}{%
  \typeout{FOUND IT}%
}{
  \typeout{NOT FOUND}%
}

\stop

También puedes agregar opciones a kpsewhich(ver su manual)

\IfFileInTEXTree[<options>]{<filename>}{<true>}{<false>

Esto no requiere un escape de shell sin restricciones, solo el escape de shell restringido predeterminado.

El archivo de registro mostrará

(|kpsewhich  LibertinusSerif-Regular.otf)
FOUND IT
(|kpsewhich  whatever.otf)
NOT FOUND

información relacionada