
Usando TeXlive 2023, Linux, lualatex.
Para mi sorpresa, \IfFileExists
no parece encontrar ningún *.otf
archivo, independientemente de si el archivo está instalado en texmf-dist
mi texmf
directorio 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 \IfFileExists
no 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 \IfFileExists
solo 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