minted uses fancyvrb to typeset the code. The fontspec manual gives an example using fancyvrb, and in the \newfontfamily definition uses the equivalent of NFSSFamily=inconsolata. I'd suggest starting there. (https://github.com/gpoore/minted/issues/365#issuecomment-1517794111)
解决minted使用自定义字体问题
Fix #1 .
如果直接
/newfontfamily/mintedcodefont{Consolas}
,那么minted会报"Font shape TU/mintedcodefont/m/n' undefined"翻到 https://github.com/gpoore/minted/issues/365 指出:
因此此PR主要添加一行NFSSFamily=mintedcodefont,解决了自定义fontfamily失效的问题
添加默认字体Fallback策略
此外,优于原作者采用了部分生僻字体,因此不一定所有人都有安装在自己的电脑上,因此添加了找不到目标字体时Fallback到一个覆盖率更高些的字体上的策略,基于
\IfFontExistsTF
实现这样既不影响喜欢这些字体的原作者,也不影响没有这些字体的普罗大众和Overleaf,再也不用为后者特殊关照辣