[expl3
error corrected thanks to Skillman. Output is unchanged.]
Here's a version which is technically1 expl3
2,3,4,5:
\documentclass{article}
% ateb: https://tex.stackexchange.com/a/727927/
% ateb: https://tex.stackexchange.com/a/728868/
\usepackage{nfssext-cfr}
\makeatletter
\ExplSyntaxOn
\NewDocumentCommand \IfFontTF {mmmmmm}
{
\group_begin:
\fontencoding{#1}\fontfamily{#2}\fontseries{#3}\fontshape{#4}\try@load@fontshape
% sylwad Skillman: https://tex.stackexchange.com/questions/729130/problem-with-conditional-tf-version-working-but-not-the-p-version?noredirect=1#comment1815533_729130
\exp_args:Nc \if_meaning:w { \curr@fontshape } \relax
\group_end:
#6
\else:
\fontencoding{#1}\fontfamily{#2}\fontseries{#3}\fontshape{#4}\selectfont
\if_cs_exist:w exfs@fake@\curr@fontshape \cs_end:
\group_end:
#6
\else:
\group_end:
#5
\fi:
\fi:
}
\NewDocumentCommand \FontIfExists {ommmm}
{
\group_begin:
\fontencoding{#2}\fontfamily{#3}\fontseries{#4}\fontshape{#5}\try@load@fontshape
% sylwad Skillman: https://tex.stackexchange.com/questions/729130/problem-with-conditional-tf-version-working-but-not-the-p-version?noredirect=1#comment1815533_729130
\exp_args:Nc \if_meaning:w { \curr@fontshape } \relax
\group_end:
\IfValueT{#1}{#1}
\else:
\fontencoding{#2}\fontfamily{#3}\fontseries{#4}\fontshape{#5}\selectfont
\if_cs_exist:w exfs@fake@\curr@fontshape \cs_end:
\group_end:
\IfValueT{#1}{#1}
\else:
\group_end:
\fontencoding{#2}\fontfamily{#3}\fontseries{#4}\fontshape{#5}\selectfont
\fi:
\fi:
}
\cs_new_eq:NN \ShowFont\curr@fontshape
\makeatother
\ExplSyntaxOff
\begin{document}
\IfFontTF{OT1}{cmr}{m}{sc}{OT1/cmr/m/sc exists}{OT1/cmr/m/sc is non-existent.}
\IfFontTF{T1}{clm}{bx}{n}{T1/clm/bx/n exists}{T1/clm/bx/n is non-existent.}
\IfFontTF{T1}{clm}{bz}{n}{T1/clm/bz/n exists}{T1/clm/bz/n is non-existent.}
\IfFontTF{T1}{clmx}{bx}{n}{T1/clmx/bx/n exists}{T1/clmx/bx/n is non-existent.}
\IfFontTF{T1}{clm}{bx}{blurb}{T1/clm/bx/blurb exists}{T1/clm/bx/blurb is non-existent.}
\IfFontTF{OT1}{cmr}{m}{blurb}{YES}{NO}
\FontIfExists{OT1}{cmr}{m}{sc}
\ShowFont
\FontIfExists{T1}{clm}{bx}{n}
\ShowFont
\FontIfExists{T1}{clmx}{bx}{n}
\ShowFont
\FontIfExists[Oh, no!]{OT1}{cmr}{m}{sc}
\ShowFont
\FontIfExists[Oh, dear!]{T1}{clm}{bx}{n}
\ShowFont
\FontIfExists[Oops!]{T1}{clmx}{bx}{n}
\ShowFont
\FontIfExists[egreg says `no']{OT1}{cmr}{m}{blurb}
\ShowFont
\thispagestyle{empty}
\end{document}
Proof in pudding:
1Note that I do not claim it is in the spirit of the enterprise, but only that the replacement code technically qualifies.
2Except for font macros and \relax
.
3In case wipet ever reads this: you need not say it. I concede your point in advance.
4Do not try this at home without professional supervision. This code is not intended for domestic use.
5There is a 99% chance I will delete this later. The other 1% involves Virgin Media and/or Acts of Fate.
\cs_if_exist:cTF{curr@fontshape}{#5}{#6}
\cs_if_free:cTF{curr@fontshape}{#6}{#5}
, but I prefer the other way around.\cs_if_exist:cTF{\curr@fontshape}{#5}{#6}
?expl3
based alternatives...