
Usando TeXlive 2023, Linux, lualatex.
Para minha surpresa, \IfFileExists
não parece encontrar nenhum *.otf
arquivo, independentemente de o arquivo estar instalado no texmf-dist
meu texmf
diretório pessoal. 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}
Ao compilar com lualatex
, espero que a saída da linha de comando (e o arquivo de log) tenha FOUND IT
, porque o arquivo está definitivamente lá. Se tentar usar a família de fontes Libertinus Serif como fonte principal, funcionará. Mas \IfFileExists
não encontra o arquivo, com a extensão correta.
Sei que existe um comando \IfFontExists
, mas pode demorar muito se a fonte não estiver lá, então não desejo fazer dessa forma.
Responder1
Com \IfFileExists
você só pode pesquisar na $TEXINPUTS
árvore, ou seja, arquivos que fazem sentido \input
(junto com possivelmente algo que foi adicionado manualmente).
Você pode definir uma função que faça pesquisas em toda a texmf-dist
árvore (quase), 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
Você também pode adicionar opções kpsewhich
(consulte o manual)
\IfFileInTEXTree[<options>]{<filename>}{<true>}{<false>
Isso não requer escape de shell irrestrito, apenas o escape de shell restrito padrão.
O arquivo de log mostrará
(|kpsewhich LibertinusSerif-Regular.otf)
FOUND IT
(|kpsewhich whatever.otf)
NOT FOUND