The example below was an accepted means for dealing with fonts, loading polyglossia versus babel, etc., before the 2016 changes to fontspec:
\usepackage{ifxetex}
\usepackage{ifluatex}
\ifxetex% uses fontspec
\usepackage{fontspec}% check package docs
\defaultfontfeatures{Mapping=tex-text}
\usepackage{xunicode}% check if outmoded
\usepackage{xltxtra}% check if outmoded
\else
\ifluatex% also uses fontspec
\usepackage{fontspec}% check package docs
\defaultfontfeatures{Ligatures=TeX}
\else% traditional NFSS
\usepackage[utf8]{inputenc}
\usepackage[TS1,T1]{fontenc}
\fi
\fi
So should one attempt to test for pre-2016 versions anymore? Should one just drop xunicode and xltxtra (given the fontspec doc reference to euenc)? Should {Ligatures=TeX} replace {Mapping=tex-text} since they are functionally equivalent?
My goal is to provide a generic framework for making a (relatively) engine-agnostic document. I may fold in language support into this example. I have other structures that test for xetex, pdftex, luatex in pdf or dvi mode, and regular tex dvi mode.
\usepackage{ifxetex} \usepackage{ifpdf} \ifxetex \usepackage{tikz}\else \ifpdf\usepackage{tikz}\fi \fi
\usepackage{tikz}
why wrap it in tests? (it works with at least latex, pdflatex, xetex, luatex. what other engines are you testing for?)